﻿/* ── Extra Fonts ────────────────────────────────────────────────── */
@font-face {
    font-family: 'The Slug And Lion';
    src: url('/The-Slug-And-Lion.woff') format('woff');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

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

/* ── Tokens / design system ────────────────────────────────────── */
:root {
    --accent: #EB2025;
    --accent-dark: #cc1b20;
    --accent-dim: #fde8e8;
    --accent-ring: #f6a1a3;
    --green: #22a06b;
    --red: #e5334b;

    --bg: #f0f2f5;
    --surface: #ffffff;
    --surface-raised: #f8f9fb;
    --border: #e8eaed;
    --border-mid: #d0d5dd;

    --text-primary: #1a1d23;
    --text-secondary: #475467;
    --text-muted: #8b92a5;
    --text-faint: #b0b7c9;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
    --shadow: 0 4px 12px rgba(0, 0, 0, .07), 0 1px 3px rgba(0, 0, 0, .04);

    --sidebar-w: 248px;
    --panel-w: 340px;
    --font: 'Roboto', 'Helvetica Neue', Helvetica, Arial, system-ui, -apple-system, sans-serif;
    --font-display: 'The Slug And Lion', serif;
    --safe-vh: 100dvh;
}

/* ── Base ───────────────────────────────────────────────────────── */
html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
    color: var(--text-primary);
    background: var(--bg);
    font-weight: 400;
}

/* ── App shell ──────────────────────────────────────────────────── */
.app {
    display: grid;
    /* Default to hidden panel, only 2 columns shown */
    grid-template-columns: var(--sidebar-w) 1fr 0;
    height: var(--safe-vh);
    transition: grid-template-columns .3s ease;
}

body.panel-open .app {
    grid-template-columns: var(--sidebar-w) 1fr var(--panel-w);
}

/* ─────────────────────────────────────────────────────────────────
   SIDEBAR
───────────────────────────────────────────────────────────────── */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 16px 16px;
    overflow-y: auto;
    gap: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
    flex-shrink: 0;
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 12px;
    letter-spacing: -.5px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(235, 32, 37, .35);
}

.brand-text-img-container {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
}

.brand-text-img {
    height: 40px;
    width: auto;
    object-fit: contain;
    max-width: 100%;
    background: #262525;
    /* ensure readable against dark backgrounds */
}

.brand-icon-img {
    height: 36px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}

.sidebar-label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 6px;
    flex-shrink: 0;
}

.book-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.btn-action {
    background: var(--surface);
    border: 1px solid var(--border-mid);
    color: var(--text-primary);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    flex: 1;
    text-align: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-action:hover {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent-ring);
}

.btn-text {
    background: transparent;
    border: none;
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-text svg {
    width: 14px;
    height: 14px;
}

.btn-text:hover {
    text-decoration: underline;
    color: var(--accent-dark);
}

.btn-danger {
    color: var(--red);
}

.btn-danger:hover {
    color: #c92a3d;
}

/* Book list */
.book-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 14px;
    min-height: 40px;
}

/* Collapsible category groups */
.book-category {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    overflow: clip;
}

.book-category-title {
    list-style: none;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    background: var(--surface-raised, #f8f9fb);
}

.book-category-title::-webkit-details-marker {
    display: none;
}

.book-category-title::after {
    content: '';
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(45deg) translateY(-2px);
    transition: transform .2s ease;
}

.book-category[open] .book-category-title::after {
    transform: rotate(-135deg) translateY(-1px);
}

.book-category-list {
    overflow: hidden;
    padding: 4px;
    transition: height .22s cubic-bezier(0.16, 1, 0.3, 1), opacity .22s ease;
    will-change: height;
}

.book-category.collapsing .book-category-list {
    opacity: .85;
}

.book-category.expanding .book-category-list {
    opacity: 1;
}

/* old placeholder category styles removed; real styles are below */

.book-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background .12s, border-color .12s;
    border: 1px solid transparent;
    user-select: none;
}

.book-item:hover {
    background: #f5f6fc;
}

.book-item.checked {
    background: var(--accent-dim);
    border-color: var(--accent-ring);
}

.book-item input[type=checkbox] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    cursor: pointer;
}

.book-item-cover {
    width: 31px;
    height: 43px;
    object-fit: cover;
    border-radius: 3px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    border: 1px solid var(--border);
    background: var(--surface);
}

.book-item-info {
    flex: 1;
    min-width: 0;
}

.book-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.3;
    word-break: break-word;
}

.book-item-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Apply button */
.btn-primary {
    width: 100%;
    padding: 9px 0;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, transform .1s;
    flex-shrink: 0;
    margin-bottom: 8px;
}

.btn-primary:hover {
    background: var(--accent-dark);
}

.btn-primary:active {
    transform: scale(.98);
}

.btn-primary.applied {
    background: var(--green);
}

.btn-primary:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.status-text {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    flex-shrink: 0;
}

/* sidebar-footer removed */

/* Selection feedback badge */
#selection-feedback {
    min-height: 18px;
    margin-bottom: 8px;
    transition: background .15s, color .15s, border-color .15s, opacity .15s;
}

#selection-feedback.show {
    padding: 6px 8px;
    border-radius: 8px;
    background: var(--accent-dim);
    color: var(--text-primary);
    border: 1px solid var(--border-mid);
    box-shadow: var(--shadow-sm);
    animation: popin .16s ease-out;
}

#selection-feedback.add {
    background: rgba(34, 160, 107, .14);
    color: var(--green);
    border-color: var(--green);
}

#selection-feedback.remove {
    background: rgba(229, 51, 75, .16);
    color: var(--red);
    border-color: var(--red);
}

#selection-feedback.add::before {
    content: '✓ ';
    font-weight: 800;
}

#selection-feedback.remove::before {
    content: '– ';
    font-weight: 800;
}

@keyframes popin {
    from {
        transform: scale(.98);
        opacity: .85;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* ─────────────────────────────────────────────────────────────────
   MAIN AREA
───────────────────────────────────────────────────────────────── */
.main {
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(circle at top left, rgba(235, 32, 37, 0.06), transparent 28%),
        radial-gradient(circle at bottom right, rgba(235, 32, 37, 0.04), transparent 30%),
        var(--bg);
    min-width: 0;
    min-height: 0;
    transition: background .2s;
}

/* Top header bar */
.qa-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 46px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: -.1px;
    transition: background .2s, border-color .2s;
}

.chat-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.app-title {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: none;
    line-height: 1.2;
}

/* Responsive title: only show full title on large screens by default */
.title-full {
    display: block;
}

.title-medium {
    display: none;
}

.title-short {
    display: none;
}

/* Header logo – always visible */
.header-logo {
    height: 30px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
    margin-right: 4px;
}

/* Stream badge */
.stream-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--accent);
    background: var(--accent-dim);
    padding: 3px 10px;
    border-radius: 999px;
}

.stream-dot {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: .4;
        transform: scale(.75);
    }
}

.hidden {
    display: none !important;
}

/* Dark mode toggle */
.btn-icon {
    width: 30px;
    height: 30px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: background .15s, color .15s, border-color .15s;
    padding: 0;
}

.btn-icon:hover {
    background: var(--accent-dim);
    color: var(--accent);
}

.btn-icon svg {
    width: 15px;
    height: 15px;
}

.mobile-only {
    display: none;
}

/* ── Q&A input section ─────────────────────────────────────────── */
.qa-input-section {
    flex-shrink: 0;
    padding: 16px 20px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    transition: background .2s, border-color .2s;
}

#qa-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#qa-input {
    flex: 1;
    padding: 10px 14px;
    font-size: 16px;
    font-family: var(--font);
    line-height: 1.55;
    color: var(--text-primary);
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    resize: none;
    outline: none;
    transition: border-color .15s, box-shadow .15s, background .2s;
}

#qa-input::placeholder {
    color: var(--text-faint);
}

#qa-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(235, 32, 37, .12);
}

.btn-ask {
    padding: 0 22px;
    height: 42px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, transform .1s, opacity .15s;
}

.btn-ask:hover {
    background: var(--accent-dark);
}

.btn-ask:active {
    transform: scale(.97);
}

.btn-ask:disabled {
    opacity: .45;
    cursor: not-allowed;
    background: var(--accent);
}

/* ── Q&A answer body ───────────────────────────────────────────── */
.qa-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px 28px;
    min-height: 0;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.3), transparent 18%),
        var(--bg);
}

.qa-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 14px;
    max-width: 520px;
    margin: 36px auto 0;
    padding: 28px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-sm);
    color: var(--text-muted);
}

.qa-empty svg {
    width: 40px;
    height: 40px;
    opacity: .3;
}

.qa-empty p {
    font-size: 13.5px;
    line-height: 1.65;
}

/* Q&A history pairs */
.qa-history {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
    max-width: 920px;
    margin: 0 auto;
}

.chat-message {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    width: 100%;
    animation: fadein 0.28s ease-out;
}

.chat-message-shell {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
    flex: 1;
    max-width: min(760px, calc(100% - 56px));
}

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

.chat-message-user .chat-message-shell {
    align-items: flex-end;
}

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

.chat-message-assistant {
    justify-content: flex-start;
}

.chat-message-assistant .chat-message-shell {
    align-items: flex-start;
}

.chat-message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 20px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.chat-message-role {
    opacity: .95;
}

.chat-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.chat-avatar-user {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .08em;
}

.chat-avatar-assistant {
    background: var(--surface);
}

.chat-user-bubble {
    padding: 14px 16px;
    border-radius: 18px 18px 6px 18px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
    font-size: 15px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: var(--shadow-sm);
}

.chat-answer-bubble {
    width: 100%;
    min-height: 0;
    border-radius: 18px 18px 18px 6px;
}

.chat-copy-btn {
    margin-left: auto;
    padding: 5px 10px;
}

.chat-copy-btn svg {
    width: 11px;
    height: 11px;
}

.qa-pair {
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: fadein 0.3s ease-out;
}

@keyframes fadein {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.qa-q-label,
.qa-a-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.qa-question-wrapper,
.qa-answer-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.qa-question-wrapper {
    cursor: pointer;
    transition: opacity 0.2s;
}

.qa-question-wrapper:hover {
    opacity: 0.85;
}

/* Expansion caret */
.qa-question-wrapper::after {
    content: '';
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b92a5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='18 15 12 9 6 15'%3E%3C/polyline%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    margin-top: 10px;
    transition: transform 0.2s;
}

.minimized .qa-question-wrapper::after {
    transform: rotate(180deg);
}

.minimized .qa-answer-wrapper,
.minimized .qa-a-label {
    display: none;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px) scaleY(0.96);
        transform-origin: top;
    }

    to {
        opacity: 1;
        transform: translateY(0) scaleY(1);
        transform-origin: top;
    }
}

.qa-pair.expanding .qa-answer-wrapper,
.qa-pair.expanding .qa-a-label {
    animation: slideDown 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: contain;
    flex-shrink: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 2px;
}

.user-avatar {
    background: #f0f2f5;
}

.mascot-avatar {
    background: #ffffff;
}

.qa-question {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.5;
    padding: 12px 16px;
    background: var(--accent-dim);
    border-radius: var(--radius-sm);
    white-space: pre-wrap;
    word-break: break-word;
    flex: 1;
}

.qa-answer-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.qa-answer {
    font-size: 16px;
    line-height: 1.75;
    color: var(--text-primary);
    word-break: break-word;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px 18px 18px 6px;
    min-height: 0;
    box-shadow: var(--shadow-sm);
    transition: background .2s, border-color .2s;
}

.qa-answer-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
    width: 100%;
}

.btn-copy {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-copy:hover {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent-ring);
}

.btn-copy svg {
    width: 12px;
    height: 12px;
}

.chunk-list-inline {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px dashed var(--border);
    padding-top: 12px;
}

/* ── Markdown content inside qa-answer ──────────────────────────── */
.qa-answer h1,
.qa-answer h2,
.qa-answer h3,
.qa-answer h4,
.qa-answer h5,
.qa-answer h6 {
    margin: 18px 0 8px;
    font-weight: 700;
    line-height: 1.35;
    color: var(--text-primary);
}

.qa-answer h1 {
    font-size: 1.3em;
}

.qa-answer h2 {
    font-size: 1.15em;
}

.qa-answer h3 {
    font-size: 1.05em;
}

.qa-answer h4 {
    font-size: 1em;
}

.qa-answer h1:first-child,
.qa-answer h2:first-child,
.qa-answer h3:first-child {
    margin-top: 0;
}

.qa-answer p {
    margin: 0 0 10px;
}

.qa-answer p:last-child {
    margin-bottom: 0;
}

.qa-answer ul,
.qa-answer ol {
    margin: 6px 0 12px;
    padding-left: 22px;
}

.qa-answer li {
    margin-bottom: 4px;
}

.qa-answer li>ul,
.qa-answer li>ol {
    margin-top: 4px;
    margin-bottom: 4px;
}

.qa-answer strong {
    font-weight: 700;
    color: var(--text-primary);
}

.qa-answer em {
    font-style: italic;
}

.qa-answer code {
    font-family: 'Menlo', 'Consolas', monospace;
    font-size: 0.88em;
    padding: 2px 5px;
    background: var(--accent-dim);
    border-radius: 4px;
}

.qa-answer pre {
    background: var(--accent-dim);
    padding: 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 8px 0;
}

.qa-answer pre code {
    padding: 0;
    background: none;
}

.qa-answer blockquote {
    border-left: 3px solid var(--accent);
    margin: 8px 0;
    padding: 6px 14px;
    color: var(--text-muted);
}

.qa-answer hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 14px 0;
}

.qa-answer table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 13px;
}

.qa-answer th,
.qa-answer td {
    border: 1px solid var(--border-mid);
    padding: 7px 10px;
    text-align: left;
}

.qa-answer th {
    background: var(--accent-dim);
    font-weight: 600;
}

.qa-answer a {
    color: var(--accent);
    text-decoration: underline;
}

.qa-answer.streaming::after {
    content: '\25C4';
    color: var(--accent);
    animation: blink .7s step-end infinite;
    margin-left: 2px;
}

.chat-message .qa-answer.streaming::after {
    margin-left: 4px;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Thinking dots */
.thinking-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.thinking-dots span {
    display: block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: dot .8s infinite;
}

.thinking-dots span:nth-child(2) {
    animation-delay: .15s;
}

.thinking-dots span:nth-child(3) {
    animation-delay: .30s;
}

@keyframes dot {

    0%,
    80%,
    100% {
        transform: scale(.65);
        opacity: .4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ─────────────────────────────────────────────────────────────────
   RIGHT PANEL
───────────────────────────────────────────────────────────────── */
.panel.hidden-panel {
    display: none;
}

.panel {
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background .2s, border-color .2s;
    width: var(--panel-w);
    /* force width when open */
}

.panel-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
    border-bottom: none;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--surface);
    transition: background .2s, border-color .2s;
}

.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--accent-dim);
    color: var(--accent);
    text-transform: none;
    letter-spacing: 0;
}

.panel-body {
    overflow-y: auto;
    flex: 1;
    padding: 12px;
}

.empty-state {
    color: var(--text-faint);
    font-size: 12px;
    text-align: center;
    padding: 20px 8px;
    line-height: 1.6;
}

/* ── Reasoning items ───────────────────────────────────────────── */
.r-book {
    margin-bottom: 14px;
}

.r-book-name {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 7px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.r-book-name::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
}

.r-depth {
    margin-bottom: 6px;
    padding: 8px 10px;
    background: var(--surface-raised, #f8f9fb);
    border-radius: var(--radius-sm);
    border-left: 2px solid var(--accent-ring);
}

.r-depth-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.r-thinking {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.r-nodes {
    margin-top: 7px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.r-node-tag {
    background: var(--accent-dim);
    color: var(--accent);
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
    font-family: monospace;
}

/* ── Chunk cards ───────────────────────────────────────────────── */
.chunk-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    overflow: hidden;
    transition: box-shadow .15s, border-color .2s;
}

.chunk-card:hover {
    box-shadow: var(--shadow-sm);
}

.chunk-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 10px;
    background: var(--surface-raised, #f8f9fb);
    border-bottom: 1px solid var(--border);
    gap: 6px;
    transition: background .2s;
}

.chunk-source {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-primary);
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chunk-meta {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}

.chunk-page,
.chunk-idx {
    font-size: 10px;
    font-weight: 600;
    background: var(--accent-dim);
    color: var(--accent);
    padding: 2px 6px;
    border-radius: 4px;
}

.chunk-body {
    padding: 9px 11px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.55;
    white-space: pre-wrap;
    max-height: 110px;
    overflow-y: auto;
}

/* ── Dark mode ─────────────────────────────────────────────────── */
[data-theme="dark"] {
    --bg: #1B1A1A;
    --surface: #262525;
    --surface-raised: #2f2e2e;
    --border: #3b3a3a;
    --border-mid: #4d4c4c;

    --text-primary: #f2f2f2;
    --text-secondary: #bcbbbb;
    --text-muted: #8d8c8c;
    --text-faint: #5f5e5e;

    --accent-dim: #3d1c1d;
    --accent-ring: #882225;

    --shadow-sm: 0 1px 4px rgba(0, 0, 0, .45);
    --shadow: 0 4px 16px rgba(0, 0, 0, .6);

    color-scheme: dark;
}

[data-theme="dark"] .qa-header,
[data-theme="dark"] .panel,
[data-theme="dark"] .panel-header,
[data-theme="dark"] .qa-input-section {
    background: var(--surface);
}

[data-theme="dark"] .qa-answer {
    background: var(--surface);
}

[data-theme="dark"] .qa-body {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 18%),
        var(--bg);
}

[data-theme="dark"] .chat-user-bubble {
    background: linear-gradient(135deg, #c61e24, #89161a);
}

[data-theme="dark"] .chat-answer-bubble,
[data-theme="dark"] .qa-answer {
    background: var(--surface);
}

[data-theme="dark"] .qa-empty {
    background: var(--surface);
}

[data-theme="dark"] .r-depth {
    background: #20243a;
}

[data-theme="dark"] .chunk-card-head {
    background: #20243a;
}

[data-theme="dark"] .book-item:hover {
    background: #20243a;
}

/* ── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
}

/* ───────────────────────────────────────────────────────────────
   BOTTOM NAVIGATION BAR
─────────────────────────────────────────────────────────────── */
.bottom-nav {
    display: none;
    /* hidden on desktop by default */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 40;
    align-items: center;
    justify-content: space-around;
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, .08);
    transition: background .2s, border-color .2s;
}

.bottom-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .02em;
    padding: 6px 0;
    cursor: pointer;
    transition: color .15s;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.bottom-nav-btn svg {
    width: 22px;
    height: 22px;
    transition: transform .15s;
}

.bottom-nav-btn.active {
    color: var(--accent);
}

.bottom-nav-btn.active svg {
    transform: scale(1.1);
}

.bottom-nav-btn.active::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 22px;
    height: 3px;
    background: var(--accent);
    border-radius: 2px;
}

/* ───────────────────────────────────────────────────────────────
   RESPONSIVE LAYOUT
─────────────────────────────────────────────────────────────── */
@media (max-width: 1120px) {
    :root {
        --panel-w: 300px;
    }
}

/* ── Medium screens & below (phones + tablets): mobile layout ── */
@media (max-width: 1024px) {
    .mobile-only {
        display: inline-flex;
    }

    /* Show bottom nav */
    .bottom-nav {
        display: flex;
    }

    /* Responsive title: show medium text */
    .title-full {
        display: none !important;
    }

    .title-medium {
        display: block !important;
    }

    .title-short {
        display: none !important;
    }

    .app {
        grid-template-columns: 1fr;
        height: var(--safe-vh);
        position: relative;
        overflow: hidden;
    }

    .sidebar,
    .panel {
        position: fixed;
        top: 0;
        bottom: 56px;
        /* above the bottom nav */
        width: 100%;
        max-width: 100vw;
        background: var(--surface);
        z-index: 30;
        box-shadow: var(--shadow);
        transition: transform .25s ease, visibility .25s ease;
    }

    .sidebar {
        left: 0;
        transform: translateX(-102%);
        border-right: none;
    }

    .panel {
        right: 0;
        transform: translateX(102%);
        border-left: none;
    }

    /* When drawers are open */
    body.drawer-open-left .sidebar {
        transform: translateX(0);
    }

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

    /* Make main take full width with room for bottom nav */
    .main {
        grid-column: 1 / -1;
        padding-bottom: 56px;
    }

    /* Input spacing tweaks */
    .qa-input-section {
        padding: 12px 12px;
    }

    #qa-form {
        gap: 8px;
    }

    #qa-input {
        min-height: 80px;
    }

    .qa-body {
        padding: 16px;
    }

    .chat-message-shell {
        max-width: calc(100% - 44px);
    }

    .chat-user-bubble,
    .qa-answer {
        font-size: 14px;
        padding: 12px 14px;
    }

    .chat-avatar {
        width: 30px;
        height: 30px;
    }
}

/* ── Tablet landscape: revert to desktop layout ── */
@media (min-width: 601px) and (max-width: 1024px) and (orientation: landscape) {
    .bottom-nav {
        display: none !important;
    }

    /* Responsive title: show medium text in landscape too */
    .title-full {
        display: none !important;
    }

    .title-medium {
        display: block !important;
    }

    .title-short {
        display: none !important;
    }

    .app {
        grid-template-columns: var(--sidebar-w) 1fr 0;
    }

    body.panel-open .app {
        grid-template-columns: var(--sidebar-w) 1fr var(--panel-w);
    }

    .sidebar {
        position: static;
        transform: none;
        width: auto;
        max-width: none;
        bottom: auto;
        box-shadow: none;
        border-right: 1px solid var(--border);
    }

    .panel {
        position: static;
        transform: none;
        width: var(--panel-w);
        max-width: none;
        bottom: auto;
        box-shadow: none;
        border-left: 1px solid var(--border);
    }

    .main {
        padding-bottom: 0;
    }
}

/* ── Extra small screens (Phones) ── */
@media (max-width: 600px) {

    /* Show short title, hide others */
    .title-full {
        display: none !important;
    }

    .title-medium {
        display: none !important;
    }

    .title-short {
        display: block !important;
    }

    .btn-text-content {
        display: none;
    }

    .qa-header {
        padding: 0 12px;
        font-size: 13px;
    }

    .header-logo {
        height: 26px;
    }

    .qa-question {
        font-size: 14px;
        padding: 10px 14px;
    }

    .qa-answer {
        font-size: 13px;
        padding: 12px 14px;
    }

    .avatar {
        width: 32px;
        height: 32px;
    }

    .chat-message-shell {
        max-width: calc(100% - 38px);
    }

    #qa-input {
        font-size: 13px;
        min-height: 60px;
    }

    .btn-ask {
        padding: 0 16px;
        height: 38px;
        font-size: 13px;
    }

    .qa-answer-wrapper {
        gap: 8px;
    }
}

/* Overlay shown when a drawer is open */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    z-index: 20;
}

body.drawer-open-left .overlay,
body.drawer-open-right .overlay {
    display: block !important;
}