/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box; margin: 0; padding: 0;
    transition: background-color .22s ease, color .22s ease,
                border-color .22s ease, box-shadow .22s ease;
}

/* ── Themes ──────────────────────────────────────────────────── */
html, html[data-theme="dark"] {
    --bg:           #0d0f16;
    --bg2:          #11141e;
    --surface:      #181b27;
    --surface2:     #1f2333;
    --surface3:     #262b3d;
    --border:       #2a2f45;
    --border-light: #33395a;
    --accent:       #7c6fff;
    --accent-hover: #6b5fe8;
    --accent-dim:   rgba(124,111,255,.14);
    --text:         #e4e6f4;
    --text-muted:   #6b7094;
    --text-faint:   #3e4266;
    --green:        #34d399;
    --red:          #f87171;
    --amber:        #fbbf24;
    --blue:         #60a5fa;
    --purple:       #a78bfa;
    --orange:       #fb923c;
    --shadow:       0 2px 8px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.03);
    --shadow-sm:    0 1px 3px rgba(0,0,0,.35);
    --shadow-lg:    0 8px 32px rgba(0,0,0,.5);
    --radius:       12px;
    --sidebar-w:    282px;
}

html[data-theme="light"] {
    --bg:           #f4f4f8;
    --bg2:          #ebebf0;
    --surface:      #ffffff;
    --surface2:     #f0f0f6;
    --surface3:     #e6e6ef;
    --border:       #dcdce8;
    --border-light: #ccccd8;
    --accent:       #6c63ff;
    --accent-hover: #5b52e8;
    --accent-dim:   rgba(108,99,255,.09);
    --text:         #111118;
    --text-muted:   #666678;
    --text-faint:   #aaaabc;
    --green:        #059669;
    --red:          #dc2626;
    --amber:        #d97706;
    --blue:         #2563eb;
    --purple:       #7c3aed;
    --orange:       #ea580c;
    --shadow:       0 2px 8px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04);
    --shadow-sm:    0 1px 3px rgba(0,0,0,.06);
    --shadow-lg:    0 8px 32px rgba(0,0,0,.12);
    --radius:       12px;
    --sidebar-w:    282px;
}

/* ── Base ────────────────────────────────────────────────────── */
html, body {
    height: 100%;
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ──────────────────────────────────────────────────── */
.layout { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 18px;
    height: 56px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}

.logo-icon {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(124,111,255,.35);
}

.logo-text {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -.2px;
    color: var(--text);
}

.sidebar-body { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 24px; }

.sidebar-section-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-faint);
    margin-bottom: 6px;
    padding: 0 6px;
}

.suggestions { list-style: none; display: flex; flex-direction: column; gap: 2px; }

.suggestion-btn {
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    line-height: 1.45;
    position: relative;
    transition: background .15s, color .15s;
}
.suggestion-btn::before {
    content: '';
    position: absolute;
    left: 0; top: 50%; transform: translateY(-50%);
    width: 2px; height: 0;
    background: var(--accent);
    border-radius: 2px;
    transition: height .15s;
}
.suggestion-btn:hover {
    background: var(--surface2);
    color: var(--text);
}
.suggestion-btn:hover::before { height: 60%; }

.history-btn { color: var(--text-muted); }
.history-btn:hover { color: var(--text); }

/* ── Chat area ───────────────────────────────────────────────── */
.chat-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* ── Chat header ─────────────────────────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    height: 56px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -.1px;
}

.chat-header-title .header-dot {
    width: 7px; height: 7px;
    background: var(--green);
    border-radius: 50%;
    box-shadow: 0 0 6px var(--green);
    flex-shrink: 0;
}

.chat-header-actions { display: flex; align-items: center; gap: 8px; }

.theme-toggle {
    width: 36px; height: 36px;
    border: 1px solid var(--border);
    background: var(--surface2);
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, border-color .15s, transform .15s;
}
.theme-toggle:hover {
    background: var(--surface3);
    border-color: var(--border-light);
    transform: scale(1.05);
}

/* ── Chat messages ───────────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 28px 8%;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ── Welcome card ────────────────────────────────────────────── */
.welcome-card {
    text-align: center;
    padding: 64px 24px 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.welcome-icon {
    width: 64px; height: 64px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    border-radius: 20px;
    display: flex; align-items: center; justify-content: center;
    font-size: 30px;
    margin-bottom: 4px;
    box-shadow: 0 8px 24px rgba(124,111,255,.3);
}

.welcome-card h1 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -.5px;
    background: linear-gradient(135deg, var(--text) 40%, var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-card p {
    font-size: 15px;
    color: var(--text-muted);
    max-width: 420px;
    line-height: 1.65;
}

.welcome-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 8px;
}

.welcome-chip {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.welcome-chip:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Chat bubbles ────────────────────────────────────────────── */
.bubble { max-width: 100%; }
.bubble.user { align-self: flex-end; max-width: 72%; }

.bubble.user .bubble-body {
    background: linear-gradient(135deg, var(--accent) 0%, #5b52e8 100%);
    color: #fff;
    border-radius: var(--radius) var(--radius) 3px var(--radius);
    padding: 12px 18px;
    font-size: 15px;
    line-height: 1.55;
    box-shadow: var(--shadow-sm), 0 0 0 1px rgba(255,255,255,.08) inset;
}

.bubble.assistant .bubble-body {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: var(--shadow-sm);
}

/* ── Professional loading animation ─────────────────────────── */
.ai-loader {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 4px;
    min-height: 60px;
}

.ai-spinner-wrap {
    position: relative;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
}

.ai-spinner-ring {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    animation: ai-spin 0.85s linear infinite;
}

.ai-spinner-inner {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 18px; height: 18px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-bottom-color: var(--purple);
    animation: ai-spin-rev 1.3s linear infinite;
}

@keyframes ai-spin {
    to { transform: rotate(360deg); }
}
@keyframes ai-spin-rev {
    to { transform: translate(-50%, -50%) rotate(-360deg); }
}

.ai-loader-text {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.ai-loader-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.ai-loader-sub {
    font-size: 12px;
    color: var(--text-muted);
}

.ai-dots span {
    display: inline-block;
    width: 4px; height: 4px;
    border-radius: 50%;
    background: var(--accent);
    margin: 0 2px;
    vertical-align: middle;
    animation: ai-dot-pulse 1.4s ease-in-out infinite;
}
.ai-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-dot-pulse {
    0%, 100% { opacity: 0.25; transform: scale(0.8); }
    50%       { opacity: 1;    transform: scale(1.2); }
}

/* ── Result header ───────────────────────────────────────────── */
.result-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2px;
    animation: fade-slide-down 0.3s ease;
}

.result-status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
    flex-shrink: 0;
}

.result-header-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.9px;
    color: var(--text-muted);
}

@keyframes fade-slide-down {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Send button press ───────────────────────────────────────── */
@keyframes btn-send-press {
    0%, 100% { transform: scale(1); }
    40%       { transform: scale(0.88); }
    70%       { transform: scale(1.08); }
}
.send-btn.btn-sending {
    animation: btn-send-press 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ── Result bubble slide-in ──────────────────────────────────── */
@keyframes result-slide-in {
    0%   { opacity: 0; transform: translateY(12px); }
    100% { opacity: 1; transform: translateY(0); }
}
.bubble.result-in .bubble-body {
    animation: result-slide-in 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ── SQL block ───────────────────────────────────────────────── */
.sql-block {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    border-left: 3px solid var(--accent);
}

.sql-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
}

.sql-block-label {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--text-muted);
}

.sql-block-label .sql-dot {
    width: 6px; height: 6px;
    background: var(--green);
    border-radius: 50%;
}

.copy-btn {
    background: var(--surface3);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 6px;
    transition: background .15s, color .15s, border-color .15s;
}
.copy-btn:hover {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent);
}

.sql-code {
    padding: 16px;
    font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--green);
    line-height: 1.7;
}

/* ── Results meta bar ────────────────────────────────────────── */
.results-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-muted);
    flex-wrap: wrap;
    padding: 2px 0;
}

.results-meta .count {
    background: rgba(52,211,153,.12);
    color: var(--green);
    font-weight: 600;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 20px;
    border: 1px solid rgba(52,211,153,.2);
}

.results-meta .elapsed {
    color: var(--text-faint);
    font-size: 12px;
    display: flex; align-items: center; gap: 4px;
}

/* ── Export button ───────────────────────────────────────────── */
.export-btn {
    margin-left: auto;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 7px;
    cursor: pointer;
    display: flex; align-items: center; gap: 5px;
    transition: background .15s, border-color .15s, color .15s;
}
.export-btn:hover {
    background: rgba(52,211,153,.1);
    border-color: var(--green);
    color: var(--green);
}

/* ── Data table ──────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    border-radius: 10px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead { background: var(--surface2); position: sticky; top: 0; z-index: 1; }

th {
    padding: 10px 16px;
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .6px;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    word-break: break-word;
    color: var(--text);
}

tr:last-child td { border-bottom: none; }

tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface2); }
tbody tr:hover td:first-child { border-left: 2px solid var(--accent); padding-left: 14px; }

/* ── Chart ───────────────────────────────────────────────────── */
.chart-wrap {
    position: relative;
    height: 340px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

/* ── Text explanation ────────────────────────────────────────── */
.text-explanation {
    font-size: 14px;
    line-height: 1.75;
    color: var(--text);
    background: var(--accent-dim);
    border: 1px solid rgba(124,111,255,.22);
    border-left: 3px solid var(--accent);
    border-radius: 10px;
    padding: 14px 18px;
}

.text-explanation-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--accent);
    font-weight: 600;
    display: block;
    margin-bottom: 8px;
}

/* ── Special bubbles — uses CSS vars so both themes work ─────── */

/* Typo */
.typo-body {
    background: var(--surface);
    border: 1px solid var(--blue);
    border-radius: var(--radius);
    padding: 14px 18px;
    display: flex; flex-direction: column; gap: 10px;
}
.typo-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
    color: var(--blue); font-weight: 600;
}
.typo-text { font-size: 15px; color: var(--text); line-height: 1.6; }
.typo-text strong { color: var(--blue); font-weight: 700; }
.typo-actions { display: flex; gap: 8px; }
.typo-btn {
    padding: 6px 16px; border-radius: 7px;
    font-size: 13px; font-weight: 600; cursor: pointer;
    border: 1px solid var(--blue);
    transition: background .15s, color .15s;
}
.typo-btn:disabled { opacity: .4; cursor: not-allowed; }
.typo-yes { background: var(--blue); color: #fff; }
.typo-yes:hover:not(:disabled) { opacity: .85; }
.typo-no  { background: none; color: var(--blue); }
.typo-no:hover:not(:disabled) { background: rgba(96,165,250,.12); }

/* Clarification */
.clarification-body {
    background: var(--surface);
    border: 1px solid var(--amber);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: flex; flex-direction: column; gap: 10px;
}
.clarification-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
    color: var(--amber); font-weight: 600;
}
.clarification-text { font-size: 15px; color: var(--text); line-height: 1.6; }

/* Combo chart */
.combo-body {
    background: var(--surface);
    border: 1px solid var(--purple);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: flex; flex-direction: column; gap: 8px;
}
.combo-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
    color: var(--purple); font-weight: 600;
}
.combo-text { font-size: 15px; color: var(--text); line-height: 1.6; }
.combo-text strong { color: var(--purple); }
.combo-hint { font-size: 12px; color: var(--text-muted); font-style: italic; }

/* Prediction */
.prediction-body {
    background: var(--surface);
    border: 1px solid var(--orange);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: flex; flex-direction: column; gap: 10px;
}
.prediction-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
    color: var(--orange); font-weight: 600;
}
.prediction-text { font-size: 15px; color: var(--text); line-height: 1.6; }
.prediction-text strong { color: var(--orange); }
.prediction-hint { font-size: 12px; color: var(--text-muted); font-style: italic; }

/* ── Error ───────────────────────────────────────────────────── */
.error-msg {
    color: var(--red);
    font-size: 14px;
    background: rgba(248,113,113,.08);
    border: 1px solid rgba(248,113,113,.22);
    border-left: 3px solid var(--red);
    border-radius: 8px;
    padding: 10px 14px;
    line-height: 1.5;
}

/* ── Input area ──────────────────────────────────────────────── */
.chat-input-area {
    padding: 10px 8% 20px;
    background: var(--bg);
    flex-shrink: 0;
}

.input-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 10px 14px 12px;
}

/* ── View toolbar (inside input card) ───────────────────────── */
.view-toolbar {
    display: flex;
    align-items: center;
    gap: 5px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.toolbar-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-faint);
    margin-right: 2px;
}

.toolbar-sep {
    width: 1px;
    height: 14px;
    background: var(--border);
    margin: 0 5px;
    flex-shrink: 0;
}

.view-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s, opacity .15s;
}
.view-toggle:hover { border-color: var(--border-light); color: var(--text); }
.view-toggle.active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
}
.view-toggle.active:hover { background: rgba(124,111,255,.2); }
.view-toggle.text-mode-on { opacity: .35; pointer-events: none; }

/* ── Textarea row ────────────────────────────────────────────── */
.input-row { display: flex; gap: 10px; align-items: flex-end; }

.question-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    padding: 4px 4px 2px;
    resize: none;
    outline: none;
    line-height: 1.55;
    max-height: 160px;
    overflow-y: auto;
}
.question-input::placeholder { color: var(--text-faint); }

.send-btn {
    width: 38px; height: 38px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 17px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .12s;
    box-shadow: 0 2px 8px rgba(124,111,255,.4);
}
.send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
.send-btn:active { transform: scale(.96); }
.send-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
