:root {
    --bg:           #f6f6f6;
    --sidebar-bg:   #ffffff;
    --surface:      #ffffff;
    --surface-2:    #f0f0f0;
    --border:       #e5e5e5;
    --border-soft:  #ebebeb;

    --accent:       #FF5F14;
    --accent-hover: #e8530f;
    --accent-dim:   rgba(255, 95, 20, 0.08);
    --accent-glow:  rgba(255, 95, 20, 0.12);
    --accent-border:rgba(255, 95, 20, 0.30);
    --accent-text:  #ffffff;

    --green:  #348f70;
    --blue:   #0056ef;
    --yellow: #ffbc00;

    --text:       #111111;
    --text-muted: #9a9a9a;
    --text-soft:  #666666;

    --radius:    10px;
    --radius-lg: 14px;
    --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
    --mono:      'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* ── Home View ────────────────────────────────────────────────────────────── */

/* align-items: flex-start (not center) + overflow-y: auto — with 6 Dashboards
   cards + 4 Features cards, this view can be taller than the viewport on
   smaller screens; centering vertically with no scroll (the old behavior)
   pushed the top of the page — sometimes the header itself — above the
   visible area with no way to reach it. Starting from the top and scrolling
   when needed keeps the header always reachable first. */
.home-view {
    height: 100vh;
    overflow-y: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: var(--bg);
}

.home-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    text-align: center;
    padding: 56px 24px 40px;
    max-width: 620px;
    width: 100%;
}

.home-brand {
    display: flex;
    align-items: center;
    gap: 13px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.home-brand-text {
    text-align: left;
}

.home-logo {
    width: 80px;
    object-fit: contain;
    flex-shrink: 0;
}

.home-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.home-subtitle {
    font-size: 10.5px;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.09em;
    text-transform: uppercase;
    margin-top: 3px;
}

.home-search {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 13px 13px;
    margin-top: 6px;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
}

.home-search:focus-within {
    border-color: var(--accent-border);
    box-shadow: 0 4px 28px rgba(255, 95, 20, 0.10);
}

.home-search textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 15px;
    font-family: var(--font);
    resize: none;
    line-height: 1.5;
    max-height: 120px;
    overflow-y: auto;
}

.home-search textarea::placeholder { color: var(--text-muted); }

.home-send-btn {
    background: var(--accent);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 9px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}
.home-send-btn:hover { background: var(--accent-hover); }

/* Internal Comms/Guanxi homes: same search box as Comms, disabled — chat isn't
   wired up for those projects yet, but the layout should look identical to
   avoid the page reading as unfinished. */
.home-search.disabled { opacity: 0.55; box-shadow: none; }
.home-search.disabled:focus-within { box-shadow: none; border-color: var(--border); }
.home-search.disabled textarea { cursor: not-allowed; }
.home-send-btn:disabled { cursor: not-allowed; background: var(--text-muted); }
.home-send-btn:disabled:hover { background: var(--text-muted); }

.home-questions {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
}

.home-question-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 7px 10px;
    text-align: left;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font);
    width: 100%;
}

.home-question-btn:hover {
    border-color: var(--border);
    color: var(--text-soft);
    background: var(--surface);
}

.home-question-arrow {
    flex-shrink: 0;
    color: transparent;
    transition: transform 0.15s, color 0.15s;
}

.home-question-btn:hover .home-question-arrow {
    color: var(--text-muted);
    transform: translateX(2px);
}

.features-section {
    width: 100%;
    margin-top: 4px;
}

.features-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-soft);
    margin-bottom: 10px;
    text-align: left;
}

/* Dashboards is the more important of the two sections on every project home
   (Comms/Internal Comms/Guanxi) — same title style as .features-title now,
   just slightly bigger cards than the plain .feature-item used for "Features"
   below it, so it reads as the primary section without a full re-layout. */
.features-title-primary {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-soft);
    margin-bottom: 10px;
    text-align: left;
}

.features-grid-primary { gap: 8px; }
.features-grid-primary .feature-item { padding: 14px 14px 12px; }
.features-grid-primary .feature-icon { font-size: 18px; margin-bottom: 7px; }
.features-grid-primary .feature-name { font-size: 12.5px; }
.features-grid-primary .feature-desc { font-size: 10.5px; }

.features-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

/* Real destinations (Comms Analytics, Press Cycles, News Extractor, Data
   Quality...) are <a href> elements so the browser's native "open in new
   tab" (right-click / middle-click / ctrl+click) works — display:block and
   text-decoration/color resets undo the anchor tag's default inline-link
   look so it still reads as a plain card, not a hyperlink. */
.feature-item {
    display: block;
    background: transparent;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    padding: 10px 10px 8px;
    text-align: left;
    text-decoration: none;
    color: inherit;
    transition: all 0.15s;
    opacity: 0.55;
}

.feature-item:not(.soon) {
    cursor: pointer;
    opacity: 0.9;
}

.feature-item:not(.soon):hover {
    opacity: 1;
    border-color: var(--border);
    background: var(--surface);
}

.feature-item.soon {
    opacity: 0.15;
}

.feature-icon {
    font-size: 14px;
    margin-bottom: 5px;
}

.feature-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-soft);
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.feature-desc {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
    line-height: 1.35;
}

/* ── Project Select View (post-login landing, above the 3 project homes) ──── */

.project-select-view {
    height: 100vh;
    overflow-y: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: var(--bg);
}

.project-select-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;
    text-align: center;
    padding: 72px 24px 40px;
    max-width: 820px;
    width: 100%;
}

.project-select-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    width: 100%;
}

@media (max-width: 700px) {
    .project-card { flex-basis: 100% !important; }
}

.project-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 20px;
    transition: all 0.15s;
    flex: 0 1 240px;
}

.project-card:hover {
    border-color: var(--accent-border);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    transform: translateY(-1px);
}

.project-card-icon {
    font-size: 30px;
    margin-bottom: 12px;
}

.project-card-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.project-card-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.project-select-footer {
    margin-top: -8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
}

.project-select-logout,
.project-select-admin {
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
}

.project-select-logout:hover,
.project-select-admin:hover { color: var(--text-soft); text-decoration: underline; }

/* ── Chat View ────────────────────────────────────────────────────────────── */

.chat-view {
    height: 100vh;
    display: none;
    flex-direction: column;
}

/* ── Chat topbar ──────────────────────────────────────────────────────────── */

.chat-topbar {
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
    position: relative;
    gap: 16px;
}

.chat-topbar-left,
.chat-topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 160px;
}

.chat-topbar-right { justify-content: flex-end; }

.chat-topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 8px;
    transition: background 0.15s;
    font-family: var(--font);
}
.chat-topbar-brand:hover { background: var(--surface-2); }

.chat-toolbar {
    padding: 10px 16px 0;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.chat-panel-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}
.chat-panel-toggle:hover { color: var(--text); border-color: var(--text-muted); }
.chat-panel-toggle.active {
    background: var(--accent-dim);
    border-color: var(--accent-border);
    color: var(--accent);
}

/* ── Chat body ────────────────────────────────────────────────────────────── */

.chat-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* ── Collapsible panel ────────────────────────────────────────────────────── */

.chat-panel {
    width: 260px;
    min-width: 160px;
    max-width: 400px;
    flex-shrink: 0;
    position: relative;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: none;
    flex-direction: column;
    padding: 16px 10px;
    gap: 16px;
    overflow-y: auto;
}

.chat-panel.open { display: flex; }

.panel-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    width: 4px;
    height: 100%;
    cursor: ew-resize;
    z-index: 5;
    transition: background 0.15s;
}
.panel-resize-handle:hover,
.panel-resize-handle.resizing { background: var(--accent-border); }

.chat-panel-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-panel-title {
    font-size: 9.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.10em;
    color: var(--text-muted);
    padding: 0 4px;
    margin-bottom: 5px;
}

.chat-suggestion {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 5px 7px;
    border-radius: 6px;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font);
    line-height: 1.4;
}
.chat-suggestion:hover {
    color: var(--text-soft);
    background: var(--surface-2);
}

/* ── Main ─────────────────────────────────────────────────────────────────── */

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ── Messages ─────────────────────────────────────────────────────────────── */

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px max(24px, calc((100% - 720px) / 2)) 16px;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: #d0d0d0; border-radius: 3px; }

/* ── Welcome ──────────────────────────────────────────────────────────────── */

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 16px;
    text-align: center;
    padding: 48px 32px;
}

.welcome-mark {
    width: 64px;
    height: 64px;
    background: #ffffff;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px rgba(255, 95, 20, 0.20);
}

.welcome-dsmile {
    width: 46px;
    height: 46px;
    object-fit: contain;
}

.welcome h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.03em;
}

.welcome-sub {
    font-size: 14.5px;
    line-height: 1.65;
    color: var(--text-soft);
    max-width: 400px;
}

.market-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    justify-content: center;
    margin-top: 4px;
}

.market-chip {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-soft);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font);
}
.market-chip:hover {
    border-color: var(--accent-border);
    color: var(--accent);
    background: var(--accent-dim);
}

/* ── Message rows ─────────────────────────────────────────────────────────── */

.message-row {
    padding: 10px 40px;
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.message-row.user { flex-direction: row-reverse; }

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 700;
    font-size: 12px;
}

.avatar.assistant-avatar {
    background: #ffffff;
    overflow: hidden;
    padding: 3px;
}
.avatar.assistant-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.avatar.user-avatar {
    background: var(--surface-2);
    color: var(--text-soft);
    font-size: 10px;
    letter-spacing: 0.02em;
}

.bubble {
    flex: 1;
    min-width: 0;
    max-width: 780px;
}

.message-row.user .bubble {
    flex: none;
    max-width: 600px;
}

.user-text {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 11px 15px;
    font-size: 14px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ── Assistant content ────────────────────────────────────────────────────── */

.assistant-content {
    font-size: 14.5px;
    line-height: 1.80;
    color: var(--text);
    padding-top: 2px;
}

.assistant-content p { margin-bottom: 12px; }
.assistant-content p:last-child { margin-bottom: 0; }

.assistant-content h1,
.assistant-content h2,
.assistant-content h3 { margin: 20px 0 10px; font-weight: 700; letter-spacing: -0.02em; }
.assistant-content h1 { font-size: 19px; }
.assistant-content h2 { font-size: 16px; }
.assistant-content h3 { font-size: 14.5px; color: var(--text-soft); }

.assistant-content ul,
.assistant-content ol { padding-left: 22px; margin-bottom: 12px; }
.assistant-content li { margin-bottom: 5px; }

.assistant-content strong { font-weight: 700; }
.assistant-content em { font-style: italic; }

.assistant-content code {
    font-family: var(--mono);
    background: #f0f0f0;
    border: 1px solid var(--border);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: #c0392b;
}

.assistant-content pre {
    background: #f7f7f7;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
}

.assistant-content pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: 13px;
    color: inherit;
}

.assistant-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin: 12px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.assistant-content th {
    background: var(--surface-2);
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    color: var(--accent);
}

.assistant-content td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-soft);
}

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

/* ── SQL section ──────────────────────────────────────────────────────────── */

.sql-section {
    margin-top: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #f8f8f8;
}

.sql-section details > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    user-select: none;
    list-style: none;
    transition: color 0.15s;
    font-family: var(--font);
}

.sql-section details > summary::-webkit-details-marker { display: none; }
.sql-section details > summary:hover { color: var(--text-soft); }

.sql-toggle {
    font-size: 9px;
    transition: transform 0.15s;
    opacity: 0.5;
}

details[open] .sql-toggle { transform: rotate(90deg); }

.sql-badge {
    background: var(--accent-dim);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.sql-badge.error {
    background: rgba(239, 68, 68, 0.10);
    color: #ef4444;
}

.sql-code-block { border-top: 1px solid var(--border); }

.sql-code-block pre {
    margin: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    font-size: 12.5px !important;
}

/* ── Result table ─────────────────────────────────────────────────────────── */

.result-wrapper {
    border-top: 1px solid var(--border);
    overflow-x: auto;
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

.result-table th {
    background: var(--surface-2);
    padding: 7px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    white-space: nowrap;
    color: var(--accent);
    font-family: var(--font);
    font-size: 11.5px;
    letter-spacing: 0.02em;
}

.result-table td {
    padding: 6px 14px;
    border-bottom: 1px solid var(--border-soft);
    white-space: nowrap;
    font-family: var(--mono);
    color: #555;
}

.result-table tr:last-child td { border-bottom: none; }
.result-table tr:hover td { background: rgba(0, 0, 0, 0.02); }

.more-rows {
    font-size: 11.5px;
    color: var(--text-muted);
    padding: 7px 14px;
    font-style: italic;
    border-top: 1px solid var(--border);
}

.error-result {
    color: #ef4444;
    font-size: 13px;
    padding: 10px 14px;
    font-family: var(--mono);
    border-top: 1px solid var(--border);
}

/* ── Loading ──────────────────────────────────────────────────────────────── */

.loading-dots {
    display: flex;
    gap: 5px;
    padding: 6px 0;
    align-items: center;
}

.loading-dots span {
    width: 7px;
    height: 7px;
    background: var(--accent);
    border-radius: 50%;
    animation: bounce 1.2s ease-in-out infinite;
    opacity: 0.7;
}

.loading-dots span:nth-child(2) { animation-delay: 0.18s; }
.loading-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.7; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Input area ───────────────────────────────────────────────────────────── */

.input-area {
    padding: 12px 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.input-box {
    width: 100%;
    max-width: 680px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 11px 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-box:focus-within {
    border-color: var(--accent-border);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#user-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 14.5px;
    font-family: var(--font);
    resize: none;
    line-height: 1.6;
    max-height: 150px;
    overflow-y: auto;
}

#user-input::placeholder { color: var(--text-muted); }
#user-input::-webkit-scrollbar { width: 4px; }
#user-input::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

.send-btn {
    background: var(--accent);
    border: none;
    color: var(--accent-text);
    width: 34px;
    height: 34px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s;
}

.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.30; cursor: not-allowed; }

.disclaimer {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    opacity: 0.55;
}

/* ── Conversation list ────────────────────────────────────────────────────── */

.conv-empty {
    font-size: 12px;
    color: var(--text-muted);
    padding: 4px;
    font-style: italic;
}

.conv-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 7px 10px;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font);
}

.conv-item:hover {
    background: var(--accent-dim);
    border-color: var(--accent-border);
}

.conv-item.active {
    background: var(--accent-dim);
    border-color: var(--accent-border);
}

.conv-title {
    font-size: 12.5px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.conv-time {
    font-size: 10.5px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ── Sidebar user ─────────────────────────────────────────────────────────── */

.sidebar-user {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 6px;
    border-top: 1px solid var(--border);
}

.sidebar-user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.sidebar-user-name {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-email {
    font-size: 10.5px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}
.btn-logout:hover {
    color: var(--text-soft);
    background: rgba(0, 0, 0, 0.05);
}

/* ── Login ────────────────────────────────────────────────────────────────── */

body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    overflow: auto;
    background: var(--bg);
}

.login-card {
    width: 100%;
    max-width: 360px;
    padding: 40px 32px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    text-align: center;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.09);
}

.login-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.login-dsmile {
    width: 80px;
    object-fit: contain;
}

.login-logo-name {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.03em;
}

.login-logo-tag {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.10em;
    text-transform: uppercase;
    margin-top: -4px;
}

.login-subtitle {
    font-size: 13.5px;
    color: var(--text-muted);
    line-height: 1.55;
    max-width: 260px;
}

.login-btn-google {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    border-radius: var(--radius);
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    font-family: var(--font);
    transition: background 0.15s;
    width: 100%;
    justify-content: center;
    letter-spacing: -0.01em;
}
.login-btn-google:hover { background: var(--accent-hover); }

.login-note {
    font-size: 11px;
    color: var(--text-muted);
}

.login-error {
    width: 100%;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.20);
    color: #ef4444;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
}

/* ── Action buttons ───────────────────────────────────────────────────────── */

.action-buttons {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    font-family: var(--font);
    transition: all 0.15s;
}

.excel-btn {
    background: rgba(52, 143, 112, 0.10);
    color: var(--green);
    border-color: rgba(52, 143, 112, 0.25);
}
.excel-btn:hover {
    background: rgba(52, 143, 112, 0.18);
    border-color: rgba(52, 143, 112, 0.45);
}

.chart-btn {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent-border);
}
.chart-btn:hover {
    background: rgba(255, 95, 20, 0.15);
    border-color: rgba(255, 95, 20, 0.50);
}

/* ── Chart Modal ──────────────────────────────────────────────────────────── */

.chart-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.chart-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    width: min(720px, 95vw);
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: 90vh;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.14);
}

.chart-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.chart-modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.15s;
    font-family: var(--font);
}
.chart-modal-close:hover { color: var(--text); }

.chart-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.chart-type-btns { display: flex; gap: 5px; }

.chart-type-btn {
    padding: 5px 13px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-family: var(--font);
    transition: all 0.15s;
}
.chart-type-btn:hover,
.chart-type-btn.active {
    background: var(--accent-dim);
    border-color: var(--accent-border);
    color: var(--accent);
}

.chart-selectors {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.chart-selectors label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.chart-selectors select {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 5px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-family: var(--font);
    cursor: pointer;
    min-width: 130px;
}
.chart-selectors select:focus {
    outline: none;
    border-color: var(--accent-border);
}

.chart-canvas-wrapper {
    height: 320px;
    position: relative;
}

/* ── Brief View ───────────────────────────────────────────────────────────── */

.brief-view {
    height: 100vh;
    display: none;
    flex-direction: column;
    background: var(--bg);
}

/* Topbar */
.brief-topbar {
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
    position: relative;
}

.brief-back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 5px 11px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-soft);
    text-decoration: none;
    cursor: pointer;
    font-family: var(--font);
    transition: all 0.15s;
}
.brief-back-btn:hover { border-color: var(--text-muted); color: var(--text); }

/* .brief-back-btn/.brief-topbar-brand are <a href> (not <button>) so the
   browser's native "open in new tab" works on real navigational elements —
   text-decoration/color resets undo the anchor tag's default look. */
.brief-topbar-brand {
    background: transparent;
    border: none;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    font-family: var(--font);
    padding: 4px 12px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    transition: background 0.15s;
}
.brief-topbar-brand:hover { background: rgba(255,255,255,0.05); }

.brief-topbar-logo { width: 24px; object-fit: contain; }

.brief-topbar-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.brief-topbar-date {
    font-size: 11px;
    color: var(--text-muted);
    padding: 2px 8px;
    background: var(--surface-2);
    border-radius: 20px;
    border: 1px solid var(--border);
}

.brief-topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brief-regen-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 5px 11px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-soft);
    cursor: pointer;
    font-family: var(--font);
    transition: all 0.15s;
}
.brief-regen-btn:hover {
    border-color: var(--accent-border);
    color: var(--accent);
    background: var(--accent-dim);
}

.brief-topbar-user {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Scrollable body */
.brief-body {
    flex: 1;
    overflow-y: auto;
}

/* Page content — centered, max-width */
.brief-page {
    max-width: 840px;
    margin: 0 auto;
    padding: 44px 32px 24px;
}

.brief-page-header { margin-bottom: 36px; }

.brief-page-title {
    font-size: 30px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.04em;
    margin-bottom: 6px;
}

.brief-date-range {
    font-size: 12px;
    color: var(--text-muted);
}

.brief-section { margin-bottom: 40px; }

.brief-section-label {
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
    margin-bottom: 14px;
}

/* Charts */
.brief-charts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

@media (max-width: 860px) {
    .brief-charts-grid { grid-template-columns: 1fr; }
    .brief-page { padding: 28px 20px 16px; }
}

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

.brief-chart-title {
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 12px;
}

.brief-chart-wrap {
    height: 180px;
    position: relative;
}

.brief-no-data {
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
    padding: 16px 0;
    grid-column: 1 / -1;
}

/* Narrative */
.brief-narrative {
    font-size: 14.5px;
    line-height: 1.78;
    color: var(--text);
}

.brief-narrative h2 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin: 30px 0 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-soft);
    letter-spacing: -0.02em;
}

.brief-narrative h2:first-child { margin-top: 0; }

.brief-narrative p { margin-bottom: 10px; color: var(--text-soft); }
.brief-narrative strong { color: var(--text); font-weight: 600; }

.brief-narrative blockquote {
    border-left: 3px solid var(--accent-border);
    padding: 4px 0 4px 14px;
    margin: 6px 0 10px;
    color: var(--text-muted);
    font-size: 13.5px;
}

.brief-narrative ul { padding-left: 20px; margin-bottom: 10px; }
.brief-narrative li { margin-bottom: 4px; color: var(--text-soft); }

/* Follow-up messages — aligned with brief page width */
#brief-messages {
    max-width: 840px;
    margin: 0 auto;
    padding: 0 32px 8px;
}

/* Loading */
.brief-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 52px);
    gap: 12px;
    padding: 60px 24px;
    text-align: center;
}

.brief-loading-emoji { font-size: 40px; margin-bottom: 4px; }

.brief-loading-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.brief-loading-step {
    font-size: 13px;
    color: var(--text-muted);
    min-height: 18px;
}

.brief-loading-bar {
    width: 240px;
    height: 3px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
    margin-top: 4px;
}

.brief-loading-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 99px;
    width: 0%;
    transition: width 0.8s ease;
}

/* Input — home-search style */
.brief-input-wrap {
    flex-shrink: 0;
    padding: 10px 0 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    background: linear-gradient(to top, var(--bg) 80%, transparent);
    border-top: 1px solid var(--border);
}

.brief-search {
    width: calc(100% - 48px);
    max-width: 620px;
    margin: 0 auto;
}

.brief-error {
    color: var(--text-muted);
    font-size: 13px;
    padding: 40px 24px;
    text-align: center;
    max-width: 840px;
    margin: 0 auto;
}

.brief-error a { color: var(--accent); text-decoration: none; }

/* Brief follow-up blocks */
.brief-followup-q {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 840px;
    margin: 28px auto 14px;
    padding: 0 32px;
}

.brief-followup-line {
    flex: 1;
    height: 1px;
    background: var(--border-soft);
}

.brief-followup-qtext {
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
    flex-shrink: 0;
    max-width: 65%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brief-followup-a {
    max-width: 840px;
    margin: 0 auto;
    padding: 0 32px 20px;
}

.brief-inline-chart-wrap {
    margin-top: 20px;
    height: 300px;
    width: 100%;
}

.brief-followup-loading {
    max-width: 840px;
    margin: 12px auto;
    padding: 0 32px;
}
