/* Reset & Base */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #0B0B0C;
    --card: #151518;
    --card-hover: #1a1a1e;
    --border: #242429;
    --border-light: #2a2a30;
    --accent: #3B82F6;
    --accent-cyan: #06B6D4;
    --success: #10B981;
    --text: #ffffff;
    --text-secondary: #9ca3af;
    --text-tertiary: #6b7280;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 48px rgba(0,0,0,0.4);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* App Container */
.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* App Header (department selection screen) */
.app-header {
    padding: 20px 32px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.back-to-site-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.back-to-site-btn:hover {
    color: var(--text);
    border-color: var(--border-light);
    background: var(--card);
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 17px;
}

/* Department Selector */
.department-selector {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 32px;
    overflow-y: auto;
}

.department-selector h1 {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 10px;
}

.department-selector > p {
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 48px;
}

.departments-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    max-width: 820px;
    width: 100%;
}

.department-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 24px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    color: var(--text);
    font-family: inherit;
}

.department-card:hover {
    border-color: var(--accent);
    background: var(--card-hover);
    transform: translateY(-4px);
    box-shadow: 0 8px 32px rgba(59, 130, 246, 0.1);
}

.dept-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(6, 182, 212, 0.1));
    color: var(--accent);
    margin-bottom: 14px;
}

.dept-icon svg {
    width: 20px;
    height: 20px;
}

.dept-name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 6px;
}

.dept-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Chat Interface - Full Screen */
.app-chat {
    flex-direction: row;
}

.chat-wrapper {
    display: grid;
    grid-template-columns: 240px 1fr;
    width: 100%;
    height: 100vh;
    background: var(--bg);
}

/* Chat Sidebar */
.chat-sidebar {
    background: var(--card);
    border-right: 1px solid var(--border);
    padding: 16px;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    padding: 4px 0 16px;
}

.sidebar-new-chat {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
}

.sidebar-new-chat:hover {
    background: var(--card-hover);
    color: var(--text);
}

.sidebar-chats {
    flex: 1;
    margin-top: 20px;
}

.sidebar-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    padding: 0 8px;
    margin-bottom: 8px;
    display: block;
}

.sidebar-chat-item {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-chat-item.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--text);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.sidebar-back-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 12px 14px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
}

.sidebar-back-btn:hover {
    color: white;
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent);
}

/* Chat Main */
.chat-main {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 40px 32px;
    display: flex;
    flex-direction: column;
}

.chat-welcome {
    text-align: center;
    padding: 80px 0 40px;
}

.welcome-icon {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(6, 182, 212, 0.1));
    color: var(--accent);
    margin: 0 auto 16px;
}

.welcome-icon svg {
    width: 28px;
    height: 28px;
}

.chat-welcome h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.chat-welcome p {
    color: var(--text-secondary);
    font-size: 15px;
}

/* Suggested Questions */
.suggested-questions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

.suggested-q {
    padding: 14px 18px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.4;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    font-family: inherit;
}

.suggested-q:hover {
    border-color: var(--accent);
    color: var(--text);
    background: var(--card-hover);
}

/* Chat Input */
.chat-input-area {
    padding: 16px 32px 24px;
    border-top: 1px solid var(--border);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    transition: border-color var(--transition);
}

.chat-input-wrapper:focus-within {
    border-color: var(--accent);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    line-height: 1.5;
    max-height: 120px;
}

.chat-input::placeholder {
    color: var(--text-tertiary);
}

.chat-send-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent), var(--accent-cyan));
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}

.chat-send-btn:hover {
    transform: scale(1.05);
}

.chat-disclaimer {
    display: block;
    text-align: center;
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 8px;
}

/* Message Bubbles */
.message {
    margin-bottom: 24px;
    animation: messageIn 0.3s ease;
}

.message-user {
    display: flex;
    justify-content: flex-end;
}

.message-user .message-content {
    background: linear-gradient(135deg, var(--accent), #2563eb);
    color: white;
    border-radius: 16px 16px 4px 16px;
    padding: 12px 18px;
    max-width: 70%;
    font-size: 14px;
}

.message-ai {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message-ai .message-content {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
    max-width: 100%;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 16px 0;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-tertiary);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* KPI Cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin: 16px 0;
}

.kpi-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.kpi-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    margin-bottom: 6px;
}

.kpi-value {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.kpi-trend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    margin-top: 6px;
    padding: 2px 6px;
    border-radius: 4px;
}

.kpi-trend.up {
    color: var(--success);
    background: rgba(16, 185, 129, 0.1);
}

.kpi-trend.down {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* Chart Container */
.chart-container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin: 16px 0;
}

.chart-container canvas {
    max-height: 200px;
}

/* Sources */
.sources-container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin: 16px 0;
}

.sources-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sources-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.source-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(16, 185, 129, 0.05);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
}

.source-dot {
    width: 6px;
    height: 6px;
    background: var(--success);
    border-radius: 50%;
}

/* Action Cards */
.actions-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 16px 0;
}

.action-card {
    padding: 8px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.action-card:hover {
    border-color: var(--accent);
    color: var(--text);
}

/* Dashboard Preview */
.dashboard-preview {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin: 16px 0;
}

.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.dashboard-title {
    font-size: 13px;
    font-weight: 600;
}

.dashboard-badge {
    font-size: 10px;
    padding: 3px 8px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 12px;
    color: var(--accent);
}

.dashboard-kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.dashboard-kpi {
    padding: 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.dashboard-kpi-label {
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.dashboard-kpi-value {
    font-size: 18px;
    font-weight: 700;
    margin-top: 4px;
}

.dashboard-charts {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 12px;
}

.dashboard-chart-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    height: 150px;
}

/* SQL Drawer */
.sql-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    pointer-events: none;
}

.sql-drawer.open {
    pointer-events: all;
}

.sql-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sql-drawer.open .sql-drawer-backdrop {
    opacity: 1;
}

.sql-drawer-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 500px;
    max-width: 90vw;
    background: var(--card);
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}

.sql-drawer.open .sql-drawer-panel {
    transform: translateX(0);
}

.sql-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--card);
}

.sql-drawer-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.sql-drawer-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.sql-drawer-close:hover {
    color: var(--text);
    background: var(--card-hover);
}

.sql-drawer-content {
    padding: 24px;
}

.sql-section {
    margin-bottom: 24px;
}

.sql-section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    margin-bottom: 8px;
}

.sql-code {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-secondary);
    overflow-x: auto;
    white-space: pre-wrap;
}

.sql-meta {
    display: flex;
    gap: 16px;
}

.sql-meta-item {
    font-size: 13px;
    color: var(--text-secondary);
}

.sql-meta-item strong {
    color: var(--text);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes messageIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* Responsive */
@media (max-width: 768px) {
    .departments-grid { grid-template-columns: 1fr 1fr; }
    .chat-wrapper { grid-template-columns: 1fr; }
    .chat-sidebar { display: none; }
    .suggested-questions { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .dashboard-kpis { grid-template-columns: 1fr 1fr; }
    .dashboard-charts { grid-template-columns: 1fr; }
}
