/* ============================================
   Module 100: HTAgent Styles
   ============================================ */

:root {
    --primary: #00523B;
    --primary-dark: #003D2C;
    --primary-light: #e6f0ec;
    --success: #059669;
    --warning: #d97706;
    --error: #dc2626;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --sidebar-width: 240px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

/* ============ Navbar ============ */

.navbar {
    background: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    border-bottom: 1px solid var(--gray-200);
    z-index: 100;
    height: 56px;
    position: relative;
}

.nav-brand-link {
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-logo {
    height: 28px;
    width: auto;
}

.nav-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.nav-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.nav-nemeton {
    font-family: 'Source Sans Pro', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: 0.15em;
    color: var(--primary);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-email {
    color: var(--gray-500);
    font-size: 0.8rem;
}

/* ============ Buttons ============ */

.btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

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

.btn-outline {
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-100); }

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-full { width: 100%; justify-content: center; }

/* ============ Flash Messages ============ */

.flash-messages { padding: 0 1rem; }
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin: 0.5rem 0;
    font-size: 0.875rem;
}
.flash {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.flash-close {
    background: none; border: none; font-size: 1.2rem; cursor: pointer;
    color: inherit; opacity: 0.6; padding: 0 0.25rem; margin-left: 0.5rem;
}
.flash-close:hover { opacity: 1; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.flash-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.flash-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ============ Auth Pages ============ */

.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 2rem;
}

.auth-card {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}

.auth-header { text-align: center; margin-bottom: 2rem; }
.auth-logo { max-width: 240px; margin-bottom: 1.25rem; }
.auth-header h1 { color: var(--primary); font-size: 1.75rem; margin-bottom: 0.5rem; }
.auth-header p { color: var(--gray-500); }

.auth-form .form-group { margin-bottom: 1rem; }
.auth-form label { display: block; font-weight: 500; margin-bottom: 0.25rem; font-size: 0.875rem; color: var(--gray-700); }
.auth-form input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: border-color 0.15s;
}
.auth-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

.auth-footer { text-align: center; margin-top: 1.5rem; font-size: 0.875rem; color: var(--gray-500); }
.auth-footer a { color: var(--primary); text-decoration: none; font-weight: 500; }

/* ============ Chat Layout ============ */

.chat-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar Toggle Button (when collapsed) */
.sidebar-toggle {
    position: absolute;
    left: 8px;
    top: 12px;
    z-index: 50;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 6px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    display: none;
    color: var(--gray-600);
}
.sidebar-toggle:hover { background: var(--gray-100); }
.sidebar-toggle.visible { display: flex; }

.sidebar-collapse-btn {
    background: none; border: none; cursor: pointer; color: var(--gray-400);
    padding: 2px; display: flex; align-items: center;
}
.sidebar-collapse-btn:hover { color: var(--gray-700); }

/* Session Sidebar */
.session-sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.25s ease, opacity 0.2s ease;
    overflow: hidden;
    position: relative;
}

.session-sidebar.collapsed {
    width: 0;
    border-right: none;
}

.session-sidebar.resizing {
    transition: none;
    user-select: none;
}

.sidebar-resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 4px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.15s ease;
    z-index: 5;
}
.sidebar-resize-handle:hover,
.session-sidebar.resizing .sidebar-resize-handle { background: var(--primary-light); }
.session-sidebar.collapsed .sidebar-resize-handle { display: none; }

.sidebar-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 { font-size: 0.875rem; color: var(--gray-700); }

.sidebar-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    flex: 1;
    text-align: center;
}

.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
}

.sidebar-user-email {
    color: var(--gray-500);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.sidebar-footer-link {
    color: var(--gray-500);
    text-decoration: none;
    font-weight: 500;
}
.sidebar-footer-link:hover { color: var(--primary); }

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.session-item {
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--gray-700);
    margin-bottom: 0.15rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
}
.session-item:hover { background: var(--gray-100); }
.session-item.active { background: var(--primary-light); color: var(--primary-dark); }

.session-item .session-title {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-actions {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.session-item:hover .session-actions { opacity: 1; }

.session-action-btn {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 0.2rem;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}
.session-action-btn:hover { color: var(--gray-700); background: var(--gray-200); }
.session-action-btn.delete-btn:hover { color: #c0392b; }

.session-rename-input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    padding: 0.15rem 0.35rem;
    font: inherit;
    color: var(--gray-700);
    background: white;
    outline: none;
}

/* New chat icon button */
.sidebar-icon-btn {
    background: none;
    border: 1px solid var(--gray-200);
    color: var(--gray-600);
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.sidebar-icon-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}


/* Chat Panel */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 380px;
}

.chat-logo-header {
    text-align: center;
    padding: 0.75rem 0 0.25rem;
    font-family: 'Source Sans Pro', sans-serif;
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: 0.15em;
    color: var(--primary);
    text-transform: uppercase;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Welcome Screen — centered layout */
.chat-panel:not(.chat-active) {
    justify-content: center;
}

.chat-panel:not(.chat-active) .chat-messages {
    flex: 0;
    overflow: visible;
    padding: 0;
}

.chat-panel:not(.chat-active) .chat-input-area {
    border-top: none;
    background: transparent;
    padding: 0 1.5rem 1.5rem;
    max-width: 680px;
    margin: 0 auto;
    width: 100%;
}

.welcome-message {
    text-align: center;
    padding: 0 2rem 1.5rem;
}

.welcome-logo {
    height: 48px;
    width: auto;
    margin-bottom: 1rem;
}

.welcome-greeting {
    color: var(--gray-800);
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.welcome-subtitle {
    color: var(--gray-400);
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}

.powered-by {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-500);
    margin-bottom: 0;
}

/* Input box wrapper */
.chat-input-box {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    padding: 0.5rem 0.75rem;
    box-shadow: var(--shadow-md);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-input-box:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light), var(--shadow-md);
}

.chat-panel:not(.chat-active) .chat-input-box {
    border-radius: 16px;
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow-lg);
}

/* Override textarea styles when inside input-box */
.chat-input-box #chatInput {
    border: none;
    padding: 0.375rem 0;
    box-shadow: none;
}
.chat-input-box #chatInput:focus {
    box-shadow: none;
    border: none;
}

.chat-input-box .chat-filters {
    margin-bottom: 0;
    margin-top: 0.375rem;
    padding-top: 0.375rem;
    border-top: 1px solid var(--gray-100);
}

/* Send button removed — Enter key submits */

/* Welcome chips — 2x2 grid */
.welcome-chips {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.welcome-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 0.625rem 0.75rem;
    text-align: left;
    cursor: pointer;
    font-size: 0.825rem;
    color: var(--gray-600);
    transition: all 0.15s;
    line-height: 1.3;
}

.welcome-chip:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary-dark);
}

.chip-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke: var(--gray-400);
}

.welcome-chip:hover .chip-icon {
    stroke: var(--primary);
}

/* Hide welcome elements in active chat */
.chat-panel.chat-active .welcome-message { display: none; }
.chat-panel.chat-active .welcome-chips { display: none; }

/* Active chat: restore normal input positioning */
.chat-panel.chat-active .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.chat-panel.chat-active .chat-input-area {
    border-top: 1px solid var(--gray-200);
    background: white;
    padding: 0.75rem 1.5rem 1rem;
    max-width: none;
    margin: 0;
}

/* Responsive: stack chips on narrow screens */
@media (max-width: 600px) {
    .welcome-chips {
        grid-template-columns: 1fr;
    }
}

/* Message Bubbles */
.message {
    max-width: 85%;
    animation: fadeIn 0.2s ease-out;
}

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

.message-user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 12px 12px 4px 12px;
    font-size: 0.9rem;
}

.message-assistant {
    align-self: stretch;
    background: transparent;
    border: none;
    padding: 0.25rem 0;
    border-radius: 0;
    font-size: 0.95rem;
    line-height: 1.7;
    box-shadow: none;
    max-width: 100%;
}

.message-assistant h1, .message-assistant h2, .message-assistant h3 { margin-top: 0.75rem; margin-bottom: 0.5rem; }
.message-assistant p { margin-bottom: 0.5rem; }
.message-assistant ul, .message-assistant ol { padding-left: 1.25rem; margin-bottom: 0.5rem; }
/* "Loose" markdown lists (where the model emitted a blank line between items)
   render each <li> with a wrapping <p>, and that <p> inherits the global
   `.message-assistant p { margin-bottom: 0.5rem }` rule above — producing the
   visible gap between items the user complained about. Zero out the margin
   on these inner <p> elements so loose and tight lists render identically.  */
.message-assistant li, .message-assistant li > p { margin: 0; padding: 0; }
.message-assistant li + li { margin-top: 0.1rem; }
.message-assistant code { background: var(--gray-100); padding: 0.125rem 0.375rem; border-radius: 4px; font-size: 0.85em; }
.message-assistant pre { background: var(--gray-100); padding: 0.75rem; border-radius: var(--radius); overflow-x: auto; margin-bottom: 0.5rem; }
.message-assistant pre code { background: none; padding: 0; }

/* External links (web_search citations to HTA agency websites). Distinct
   from internal citation badges so users see where they're navigating. */
.message-assistant a.external-link {
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1px dashed currentColor;
    padding-bottom: 1px;
    transition: background 0.15s, color 0.15s;
}
.message-assistant a.external-link:hover {
    background: var(--primary-light);
    border-bottom-style: solid;
}
.message-assistant a.external-link::after {
    content: "↗";
    font-size: 0.75em;
    margin-left: 0.15em;
    vertical-align: 0.1em;
    opacity: 0.6;
}

/* Markdown tables in assistant messages */
.message-assistant table {
    border-collapse: collapse;
    margin: 0.75rem 0;
    width: 100%;
    font-size: 0.88rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    overflow: hidden;
}
.message-assistant thead {
    background: var(--gray-50);
}
.message-assistant th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    font-weight: 600;
    color: var(--gray-700);
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.message-assistant td {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--gray-100);
    vertical-align: top;
    line-height: 1.5;
    /* Give the content columns (Indication / Comparator / Patient
       Population / Intervention) room to breathe and wrap onto multiple
       bulleted lines instead of being squeezed into a narrow run-on. The
       short metadata columns (Document / Date) stay narrow because their
       content is short and table-layout is content-driven. */
    white-space: normal;
    word-break: break-word;
    min-width: 92px;
    max-width: 340px;
}
.message-assistant table { table-layout: auto; }
/* Document + Assessment Date are short — keep them tight. */
.message-assistant td:first-child,
.message-assistant td:nth-child(2) { white-space: nowrap; min-width: 0; }
.message-assistant tbody tr:nth-child(odd) {
    background: rgba(0, 0, 0, 0.015);
}
.message-assistant tbody tr:hover {
    background: var(--primary-light);
}

/* Citation Badges */
.citation-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    vertical-align: middle;
}
.citation-badge:hover { background: var(--primary); color: white; }

/* Warning variant: backend flagged the citation as verdict_collapsed or
   missing_citation. Same shape, orange palette so the eye picks it out
   without the user having to read the ⚠ glyph in the label. */
.citation-badge-warn {
    background: #fff7ed;
    color: var(--warning);
    border: 1px solid #fed7aa;
}
.citation-badge-warn:hover {
    background: var(--warning);
    color: white;
    border-color: var(--warning);
}

/* No-source variant: the cell has a value but no verbatim source sentence
   was located (quote_status 'empty') — e.g. a synthesised/stratified
   comparator. Muted grey with a dashed border + a trailing ° glyph so the
   gap is visible and clearly distinct from the warning (orange) pill. */
.citation-badge-nosrc {
    background: var(--gray-50);
    color: var(--gray-500);
    border: 1px dashed var(--gray-300);
}
.citation-badge-nosrc:hover {
    background: var(--gray-200);
    color: var(--gray-700);
}

/* Inline ⚠ chip injected by chat.js injectMissingCitationMarkers().
   Sits inside a typed-column table cell that has no citation pill.
   Distinct from .citation-badge-warn (which is a clickable PILL) —
   this is just a small inline glyph with a tooltip. No hover state,
   no click handler. Cursor:help is the accessibility cue that the
   tooltip carries the explanation. */
.missing-cite-warn {
    display: inline-block;
    margin-left: 0.25rem;
    color: var(--warning);
    font-weight: 600;
    font-size: 0.85em;
    cursor: help;
}

/* Visible, diagnostic evidence gap in an evidence-first table cell. The ° is
   the CLAUDE.md "visible gap" signal; its title tooltip states the honest
   reason (not stated / not retrieved / not verbatim-locatable). Muted so it
   reads as an intentional gap, not a value. */
.ef-gap {
    color: var(--gray-400);
    font-weight: 700;
    cursor: help;
    border-bottom: 1px dotted var(--gray-400);
}

/* Citation Cards */
.citation-cards {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.citation-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
}
.citation-card:hover { border-color: var(--primary); background: var(--primary-light); }

.citation-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.citation-card-num {
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.citation-card-meta {
    color: var(--gray-500);
    font-size: 0.75rem;
}

.citation-card-excerpt {
    color: var(--gray-600);
    font-size: 0.8rem;
    font-style: italic;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Retrieval Progress Steps */
.message-loading {
    align-self: stretch;
    background: transparent;
    border: none;
    padding: 0.25rem 0;
    border-radius: 0;
    box-shadow: none;
    max-width: 100%;
}

.thinking-placeholder {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--gray-400);
    padding: 0.5rem 0;
}
.thinking-text { animation: textPulse 1.5s ease-in-out infinite; }
.thinking-dots span {
    animation: dotBounce 1.4s infinite ease-in-out both;
    font-size: 1.2rem;
    line-height: 1;
    color: var(--primary);
}
.thinking-dots span:nth-child(1) { animation-delay: 0s; }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
    0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-4px); }
}

.retrieval-steps {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 260px;
}

.retrieval-step {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--gray-400);
    transition: color 0.2s;
}

.retrieval-step-understood .step-text {
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.9rem;
}

/* Blinking caret on the actively streaming step */
.step-caret {
    display: inline-block;
    width: 6px;
    height: 0.95em;
    background: var(--primary);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 0.9s step-end infinite;
}

/* Inline tool-result continuation — same line as the action, dimmer */
.step-result {
    color: var(--gray-500);
    font-weight: 400;
    font-size: 0.8rem;
    margin-left: 0.25rem;
}

/* Unified chronological timeline. Thinking blocks AND tool steps live in
   `.retrieval-steps` together, in arrival order. */

.timeline-thinking,
.agent-thinking-block {
    color: var(--gray-600);
    font-size: 0.85rem;
    line-height: 1.65;
    border-left: 2px solid var(--gray-200);
    padding-left: 0.85rem;
    white-space: pre-wrap;
    margin: 0.1rem 0;
}

/* The model's narrated commentary between tool calls — italic gray. */
.agent-thinking-narration {
    font-style: italic;
    color: var(--gray-500);
}

/* Anthropic native CoT — non-italic, slightly darker, no pill. */
.agent-thinking-extended {
    font-style: normal;
    color: var(--gray-700);
}

/* Parsed entity chips on the "understood" step */
.entity-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.35rem;
    margin-left: 1.5rem;
    flex-basis: 100%;
}
.entity-chip {
    font-size: 0.72rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    border: 1px solid var(--gray-200);
    background: white;
    animation: fadeIn 0.3s ease-out;
}
.entity-therapy { color: #b45309; background: #fffbeb; border-color: #fde68a; }
.entity-country { color: #1e40af; background: #eff6ff; border-color: #bfdbfe; }
.entity-indication { color: #6d28d9; background: #f5f3ff; border-color: #ddd6fe; }
.entity-chapter { color: var(--gray-600); background: var(--gray-50); }

/* Query-expansion list */
.expansion-list {
    margin-top: 0.3rem;
    margin-left: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex-basis: 100%;
}
.expansion-item {
    font-size: 0.72rem;
    color: var(--gray-500);
    font-family: ui-monospace, monospace;
    animation: fadeIn 0.3s ease-out;
}

/* Persistent collapsible reasoning trace (replaces .message-loading on done) */
.retrieval-trace-details {
    align-self: stretch;
    background: transparent;
    border: none;
    border-left: 2px solid var(--gray-200);
    border-radius: 0;
    padding: 0.25rem 0 0.25rem 0.85rem;
    margin-bottom: 0.5rem;
    max-width: 100%;
}
.retrieval-trace-details[open] {
    background: transparent;
    box-shadow: none;
    border-left-color: var(--primary-light);
}
.retrieval-trace-summary {
    cursor: pointer;
    font-size: 0.78rem;
    color: var(--gray-500);
    list-style: none;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.retrieval-trace-summary::-webkit-details-marker { display: none; }
.retrieval-trace-summary::before {
    content: '▸';
    font-size: 0.7rem;
    color: var(--gray-400);
    transition: transform 0.15s;
}
.retrieval-trace-details[open] .retrieval-trace-summary::before {
    transform: rotate(90deg);
}
.retrieval-trace-summary .trace-check {
    color: var(--success);
    font-weight: 700;
}
.retrieval-trace-details[open] .retrieval-steps {
    margin-top: 0.6rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--gray-200);
}
.retrieval-trace-details:not([open]) .retrieval-steps {
    display: none;
}

.retrieval-step.active { color: var(--primary); font-weight: 500; }
.retrieval-step.active .step-text { animation: textPulse 1.5s ease-in-out infinite; }
@keyframes textPulse { 50% { opacity: 0.5; } }
.retrieval-step.done { color: var(--success); }

.step-icon {
    width: 18px; height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
}

.step-icon.spinner {
    border: 2px solid var(--gray-200);
    border-top: 2px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.retrieval-step.done .step-icon::after { content: '\2713'; color: var(--success); font-weight: 700; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Streaming cursor */
.streaming-cursor {
    animation: blink 0.8s step-end infinite;
    color: var(--primary);
    font-weight: 300;
}
@keyframes blink { 50% { opacity: 0; } }

.retrieval-step .step-text {
    font-size: 0.83rem;
    line-height: 1.4;
}

/* Rich RAG step detail cards */
.step-detail-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.4rem;
    margin-left: 1.5rem;
}
.step-detail-card {
    font-size: 0.7rem;
    color: var(--gray-500);
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    animation: fadeIn 0.3s ease-out;
}
.step-source-list {
    margin-top: 0.4rem;
    margin-left: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.step-source-item {
    font-size: 0.75rem;
    color: var(--gray-600);
    display: flex;
    gap: 0.3rem;
    align-items: baseline;
    animation: fadeIn 0.3s ease-out;
}
.step-source-rank {
    color: var(--primary);
    font-weight: 600;
    flex-shrink: 0;
}
.step-source-meta {
    color: var(--gray-500);
    font-size: 0.7rem;
    flex-shrink: 0;
}
.step-source-excerpt {
    color: var(--gray-400);
    font-size: 0.7rem;
    font-style: italic;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: 300px;
}

/* Chat Input */
.chat-input-area {
    padding: 0.75rem 1.5rem 1rem;
    background: white;
    border-top: 1px solid var(--gray-200);
}

.chat-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    row-gap: 0.4rem;
    margin-bottom: 0;
}

.filter-select {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--gray-500);
    background: var(--gray-50);
    cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--primary); }

.chat-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

#chatInput {
    flex: 1;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
}
#chatInput:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

#sendBtn {
    padding: 0.625rem;
    border-radius: var(--radius);
    flex-shrink: 0;
}

/* ============ PDF Panel ============ */

.pdf-panel {
    width: 0;
    background: white;
    border-left: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    overflow: hidden;
}

.pdf-panel.open {
    width: 50%;
}

/* Resize Handles */
.resize-handle-v {
    width: 6px;
    cursor: col-resize;
    background: var(--gray-200);
    flex-shrink: 0;
    display: none;
    transition: background 0.15s;
    z-index: 10;
}
.resize-handle-v:hover, .resize-handle-v.dragging { background: var(--primary); }

.resize-handle-h {
    height: 6px;
    cursor: row-resize;
    background: var(--gray-200);
    flex-shrink: 0;
    transition: background 0.15s;
}
.resize-handle-h:hover, .resize-handle-h.dragging { background: var(--primary); }

.pdf-header {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.pdf-tabs {
    display: flex;
    gap: 0.25rem;
    overflow-x: auto;
    flex: 1;
}

.pdf-tab {
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
    background: var(--gray-100);
    color: var(--gray-600);
    border: none;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.pdf-tab.active { background: var(--primary-light); color: var(--primary-dark); }

.pdf-tab-close {
    font-size: 0.7rem;
    cursor: pointer;
    opacity: 0.5;
    border: none;
    background: none;
    color: inherit;
    padding: 0;
}
.pdf-tab-close:hover { opacity: 1; }

.pdf-viewer-container {
    flex: 1;
    min-height: 0;
}

.pdf-viewer {
    width: 100%;
    height: 100%;
    border: none;
}

/* Translation Panel */
.translation-panel {
    border-top: 1px solid var(--gray-200);
    height: 200px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.translation-header {
    padding: 0.5rem 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--gray-100);
}

.translation-header h4 { font-size: 0.8rem; color: var(--gray-700); }

.translation-content {
    padding: 0.75rem;
    overflow-y: auto;
    flex: 1;
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--gray-700);
}

.translation-placeholder {
    color: var(--gray-400);
    font-style: italic;
    font-size: 0.8rem;
}

/* ============ Admin Page ============ */

.admin-container {
    max-width: 900px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.admin-container h2 { color: var(--primary); margin-bottom: 0; }

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.admin-close {
    text-decoration: none;
    white-space: nowrap;
}

.admin-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    margin-left: 0.4rem;
    background: var(--primary);
    color: white;
    border-radius: var(--radius);
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
}

.grant-form {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.grant-form input[type="number"] {
    width: 70px;
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.8rem;
}

.admin-section {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.admin-section h3 { font-size: 1rem; margin-bottom: 0.75rem; color: var(--gray-700); }

.admin-form .form-row { display: flex; gap: 0.5rem; }
.admin-form input { flex: 1; padding: 0.5rem 0.75rem; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: 0.875rem; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.admin-table th { text-align: left; padding: 0.5rem; color: var(--gray-500); font-weight: 500; border-bottom: 1px solid var(--gray-200); }
.admin-table td { padding: 0.5rem; border-bottom: 1px solid var(--gray-100); }

/* ============ Query Credits ============ */

.agent-toggle {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--gray-500);
    user-select: none;
}
.agent-toggle input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--primary);
    cursor: pointer;
}
.agent-toggle-label { white-space: nowrap; }
.agent-toggle:has(input:checked) .agent-toggle-label {
    color: var(--primary);
    font-weight: 600;
}

.query-credits {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-left: auto;
    white-space: nowrap;
    flex-shrink: 0;
}

.query-credits.low {
    color: var(--warning);
    font-weight: 600;
}

.btn-invite {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--primary);
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
}

/* Source balloon text: fixed-height scrollable box, identical across all
   countries so the panel doesn't jump around as users click through citations.
   Explicit `user-select: text` so drag-selection works even though the parent
   balloon's older builds inherited a non-text default from elsewhere. */
.source-balloon-text {
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.83rem;
    line-height: 1.5;
    margin-top: 0.25rem;
    white-space: pre-wrap;
    word-break: break-word;
    user-select: text;
    cursor: text;
}

/* English-translation companion below the native quote. Visually subordinate
   so the user's eye anchors to the source-language passage first, with the
   translation as a quick-skim aid below. Separated by a thin top border. */
.source-balloon-text.source-balloon-text-en {
    margin-top: 0.45rem;
    padding-top: 0.4rem;
    border-top: 1px dashed var(--gray-300);
    color: var(--gray-600);
    font-style: italic;
    font-size: 0.78rem;
}
/* Native + English side-by-side. flex-wrap means they collapse to
   stacked when the PDF panel is narrowed. Inside the pair wrapper the
   English balloon's top-border separator is moved to a LEFT-border so
   the visual separator works horizontally. */
.source-balloon-pair {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: stretch;
    margin-top: 0.25rem;
}
.source-balloon-pair .source-balloon-col {
    flex: 1 1 220px;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.source-balloon-pair .source-balloon-col-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gray-500);
    margin-bottom: 0.2rem;
    font-weight: 600;
}
.source-balloon-pair .source-balloon-text {
    margin-top: 0;
    flex: 1;
}
.source-balloon-pair .source-balloon-text.source-balloon-text-en {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

/* Failure-state body for citations whose model-emitted source_quote either
   was empty or didn't byte-match the chunk text after normalization. We
   render this instead of hiding the balloon so failures are visible per
   citation — the user can tell at a glance which rows are unanchored. */
.source-balloon-text-empty {
    color: var(--gray-500);
    font-style: italic;
    font-size: 0.78rem;
    padding: 0.4rem 0;
}

.btn-invite:hover {
    background: var(--primary);
    color: white;
}

/* ============ Invite Modal ============ */

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 480px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.modal-card h3 {
    margin-bottom: 0.5rem;
    color: var(--gray-800);
}

.modal-card p {
    font-size: 0.9rem;
    color: var(--gray-600);
    margin-bottom: 0.75rem;
}

.invite-link-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.invite-link-input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.85rem;
    background: var(--gray-50);
    color: var(--gray-700);
}

.invite-stats {
    font-size: 0.8rem;
    color: var(--gray-400);
}
