:root {
    --bg: #0f172a;
    --panel: #111827;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top left, #1e3a8a 0, #0f172a 36%, #020617 100%);
    color: var(--text);
    min-height: 100vh;
}
.shell {
    width: min(1100px, calc(100% - 32px));
    margin: 0 auto;
    padding: 38px 0;
}
.hero {
    color: #fff;
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: flex-end;
    margin-bottom: 24px;
}
.eyebrow {
    letter-spacing: .14em;
    text-transform: uppercase;
    color: #93c5fd;
    font-weight: 700;
    font-size: .78rem;
}
h1 { margin: 0; font-size: clamp(2rem, 5vw, 4rem); line-height: 1; }
.sub { color: #cbd5e1; max-width: 680px; font-size: 1.05rem; }
.badge {
    white-space: nowrap;
    padding: 10px 14px;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 999px;
    color: #bfdbfe;
    background: rgba(255,255,255,.08);
}
.chat-card {
    background: rgba(255,255,255,.96);
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 28px;
    box-shadow: 0 24px 80px rgba(0,0,0,.32);
    overflow: hidden;
}
.messages {
    min-height: 520px;
    max-height: 65vh;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.message {
    width: min(830px, 100%);
    padding: 16px 18px;
    border-radius: 20px;
    line-height: 1.55;
    border: 1px solid var(--line);
}
.message p { margin: 8px 0 0; white-space: pre-wrap; }
.message.user {
    margin-left: auto;
    color: white;
    background: var(--accent);
    border-color: var(--accent);
}
.message.assistant { background: #f8fafc; }
.message.error { background: #fff1f2; border-color: #fecdd3; color: #9f1239; }
.sources {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.source-pill {
    font-size: .8rem;
    color: #334155;
    background: #e2e8f0;
    border-radius: 999px;
    padding: 4px 9px;
}
.composer {
    border-top: 1px solid var(--line);
    padding: 16px;
    display: grid;
    grid-template-columns: 48px 1fr 110px;
    gap: 12px;
    background: #f8fafc;
}
textarea {
    width: 100%;
    resize: vertical;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
    padding: 14px 16px;
    font: inherit;
    outline: none;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(37,99,235,.12); }
button {
    border: 0;
    border-radius: 16px;
    font: inherit;
    font-weight: 800;
    background: var(--accent);
    color: white;
    cursor: pointer;
    transition: .18s ease;
}
button:hover { background: var(--accent-dark); transform: translateY(-1px); }
#voiceBtn { background: #0f172a; }
.loading { opacity: .72; }
@media (max-width: 760px) {
    .hero { display: block; }
    .badge { display: inline-block; margin-top: 12px; }
    .composer { grid-template-columns: 44px 1fr; }
    .composer button[type="submit"] { grid-column: 1 / -1; padding: 13px; }
}

.topnav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    margin-bottom: 24px;
    color: #fff;
}
.brand {
    color: #fff;
    text-decoration: none;
    font-weight: 900;
    letter-spacing: -.02em;
}
.navlinks {
    display: flex;
    gap: 8px;
    padding: 6px;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 999px;
    background: rgba(255,255,255,.08);
}
.navlinks a {
    color: #dbeafe;
    text-decoration: none;
    padding: 8px 13px;
    border-radius: 999px;
    font-weight: 800;
    font-size: .92rem;
}
.navlinks a.active,
.navlinks a:hover {
    color: #0f172a;
    background: #fff;
}
.hero.compact h1 { font-size: clamp(2rem, 4vw, 3.2rem); }
.dark { color: #1d4ed8; }
.quick-panel,
.faq-tools {
    background: rgba(255,255,255,.96);
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 24px;
    box-shadow: 0 18px 55px rgba(0,0,0,.22);
    padding: 20px;
    margin-bottom: 18px;
}
.quick-panel {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 18px;
    align-items: center;
}
.quick-panel h2,
.faq-group h2 { margin: 0; }
.quick-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}
.quick-question,
.quick-link,
.secondary,
.ask-link {
    border-radius: 999px;
    padding: 10px 14px;
    text-decoration: none;
    font-weight: 850;
    font-size: .92rem;
}
.quick-question {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}
.quick-question:hover { background: #dbeafe; color: #1e3a8a; transform: translateY(-1px); }
.quick-link,
.ask-link {
    background: #0f172a;
    color: #fff;
    display: inline-flex;
    align-items: center;
}
.search-label {
    display: block;
    font-weight: 900;
    color: #0f172a;
    margin-bottom: 10px;
}
.faq-search-row {
    display: grid;
    grid-template-columns: 1fr 120px 110px;
    gap: 10px;
}
.faq-search-row input {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
    padding: 14px 16px;
    font: inherit;
    outline: none;
}
.faq-search-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(37,99,235,.12); }
.secondary {
    background: #e2e8f0;
    color: #0f172a;
}
.secondary:hover { background: #cbd5e1; color: #0f172a; }
.small-muted { color: var(--muted); margin: 12px 0 0; }
.faq-list {
    display: grid;
    gap: 18px;
    margin-bottom: 42px;
}
.faq-group {
    background: rgba(255,255,255,.96);
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 24px;
    box-shadow: 0 18px 55px rgba(0,0,0,.22);
    overflow: hidden;
}
.faq-group h2 {
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
    color: #0f172a;
    font-size: 1.05rem;
}
.faq-item {
    border-bottom: 1px solid var(--line);
    background: #fff;
}
.faq-item:last-child { border-bottom: 0; }
.faq-item summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 17px 20px;
    font-weight: 900;
    color: #0f172a;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary:after {
    content: '+';
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: #eff6ff;
    color: #1d4ed8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.faq-item[open] summary:after { content: '–'; }
.faq-source {
    margin-left: auto;
    color: #475569;
    background: #e2e8f0;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: .76rem;
    white-space: nowrap;
}
.faq-answer {
    padding: 0 20px 18px;
    color: #334155;
    line-height: 1.65;
}
.faq-answer p { margin: 0 0 14px; white-space: pre-wrap; }
.faq-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty-state {
    background: rgba(255,255,255,.96);
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 24px;
    padding: 24px;
    color: #475569;
    box-shadow: 0 18px 55px rgba(0,0,0,.22);
}
.error-box { color: #9f1239; background: #fff1f2; }
@media (max-width: 760px) {
    .topnav { align-items: flex-start; flex-direction: column; }
    .quick-panel { grid-template-columns: 1fr; }
    .quick-grid { justify-content: flex-start; }
    .faq-search-row { grid-template-columns: 1fr; }
    .faq-search-row button { padding: 13px; }
    .faq-item summary { align-items: flex-start; flex-direction: column; }
    .faq-source { margin-left: 0; }
}

.ai-status-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    background: rgba(255,255,255,.94);
    border: 1px solid rgba(255,255,255,.32);
    border-radius: 22px;
    padding: 18px 20px;
    margin-bottom: 22px;
    box-shadow: 0 12px 38px rgba(15,23,42,.18);
}
.ai-status-panel p { margin: 6px 0 0; color: var(--muted); }
.status-action, .secondary-btn, .quick-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 14px;
    border-radius: 14px;
    text-decoration: none;
    font-weight: 800;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--accent-dark);
    cursor: pointer;
}
.setup-grid {
    display: grid;
    grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr);
    gap: 22px;
    align-items: start;
}
.setup-card, .setup-warning {
    background: rgba(255,255,255,.96);
    border: 1px solid rgba(255,255,255,.30);
    border-radius: 26px;
    box-shadow: 0 18px 60px rgba(0,0,0,.25);
    padding: 24px;
}
.setup-warning { margin-bottom: 22px; border-color: #fbbf24; }
.setup-warning pre {
    white-space: pre-wrap;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 14px;
    padding: 14px;
    overflow-x: auto;
}
.setup-card h2 { margin-top: 0; }
.setup-card label {
    display: grid;
    gap: 8px;
    margin: 14px 0;
    font-weight: 800;
    color: #334155;
}
.setup-card input, .setup-card select {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    padding: 13px 14px;
    font: inherit;
    background: #fff;
}
.setup-card input:focus, .setup-card select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(37,99,235,.12);
}
.provider-box {
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px 16px;
    margin: 16px 0;
    background: #f8fafc;
}
.provider-box h3 { margin: 0 0 8px; }
.status-list p { margin: 10px 0; }
.setup-result {
    margin-top: 14px;
    border-radius: 14px;
    padding: 12px 14px;
    background: #f8fafc;
    color: #334155;
    min-height: 46px;
}
.success-box { background: #ecfdf5; border: 1px solid #bbf7d0; color: #065f46; }
.error-box { background: #fff1f2; border: 1px solid #fecdd3; color: #9f1239; }
code {
    background: #e2e8f0;
    padding: 2px 6px;
    border-radius: 6px;
}
button:disabled, input:disabled, select:disabled {
    opacity: .65;
    cursor: not-allowed;
}
@media (max-width: 800px) {
    .setup-grid, .ai-status-panel { grid-template-columns: 1fr; display: grid; }
}

/* PDF source viewer update */
.wide-shell {
    width: min(1420px, calc(100% - 32px));
}
.workbench {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(420px, .85fr);
    gap: 18px;
    align-items: stretch;
}
.workbench .chat-card,
.workbench .document-card {
    min-height: 720px;
}
.workbench .messages {
    min-height: 570px;
    max-height: 72vh;
}
.document-card {
    background: rgba(255,255,255,.96);
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 28px;
    box-shadow: 0 24px 80px rgba(0,0,0,.32);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.full-document-card {
    min-height: 78vh;
}
.document-toolbar {
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}
.document-toolbar p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: .9rem;
}
.compact-toolbar {
    align-items: flex-start;
}
.page-jump {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.page-jump label {
    font-weight: 900;
    color: #334155;
    font-size: .86rem;
}
.page-jump input {
    width: 78px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 10px 11px;
    font: inherit;
    font-weight: 800;
}
.page-jump button {
    min-height: 40px;
    padding: 0 14px;
    border-radius: 12px;
}
.pdf-frame {
    width: 100%;
    flex: 1;
    min-height: 610px;
    border: 0;
    background: #e2e8f0;
}
.pdf-frame.large {
    min-height: 78vh;
}
.document-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px 16px;
    border-top: 1px solid var(--line);
    background: #f8fafc;
}
.source-pill.source-link {
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
    border-radius: 999px;
    padding: 5px 10px;
    min-height: auto;
    font-size: .8rem;
    font-weight: 900;
    line-height: 1.2;
}
.source-pill.source-link:hover {
    background: #dbeafe;
    color: #1e3a8a;
    transform: translateY(-1px);
}
.faq-source {
    text-decoration: none;
}
.faq-source:hover {
    background: #cbd5e1;
}
@media (max-width: 1180px) {
    .workbench {
        grid-template-columns: 1fr;
    }
    .workbench .document-card {
        min-height: 680px;
    }
}
@media (max-width: 760px) {
    .document-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }
    .page-jump {
        justify-content: flex-start;
        width: 100%;
    }
    .pdf-frame,
    .pdf-frame.large {
        min-height: 520px;
    }
    .workbench .chat-card,
    .workbench .document-card {
        min-height: auto;
    }
}

/* Final clickable PDF source-page upgrade */
.source-pill.source-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    border: 1px solid #cbd5e1;
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 850;
}
.source-pill.source-link::before {
    content: "📄";
    font-size: .9em;
}
.source-pill.source-link:hover,
.faq-source.source-link:hover {
    background: #dbeafe;
    color: #1e40af;
    transform: translateY(-1px);
}
.source-hint {
    display: inline-flex;
    align-items: center;
    color: #64748b;
    font-size: .78rem;
    font-weight: 800;
    padding: 4px 0;
    margin-right: 2px;
}
.document-card iframe.pdf-frame {
    background: #0f172a;
}
.document-actions {
    gap: 10px;
    flex-wrap: wrap;
}
.secondary-btn,
.status-action,
.faq-source {
    cursor: pointer;
}
code {
    background: rgba(15, 23, 42, .08);
    color: inherit;
    padding: 2px 6px;
    border-radius: 7px;
}
@media (max-width: 1000px) {
    .workbench {
        grid-template-columns: 1fr;
    }
    .pdf-frame {
        min-height: 520px;
    }
}
