/* Chillax (Indian Type Foundry, Fontshare licence), self-hosted rather than fetched from
   a CDN: this widget runs inside an internal system, and a third-party font would announce
   every page a member of staff opens. Weights 400/500/600 only, no italic. */
@font-face {
    font-family: 'Chillax';
    src: url('/static/fonts/chillax-400.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    /* Text first in the fallback face: in a panel this small, opening blank
       reads as "it did not load". */
    font-display: swap;
}

@font-face {
    font-family: 'Chillax';
    src: url('/static/fonts/chillax-500.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Chillax';
    src: url('/static/fonts/chillax-600.woff2') format('woff2');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

:root {
    /* One place, because the page sets a font family in more than one rule and a second
       copy is how half the interface stays on the old face. */
    --font-sans: 'Chillax', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    /* Two brand colours doing different jobs: NAVY is structure — header, the
       user's words, focus rings — and GREEN is the mark and the action. Green stays
       scarce, or it stops meaning "press this". */
    --brand-navy: #00186d;
    --brand-green: #1eca4b;

    --primary-color: var(--brand-navy);
    --primary-hover: #002a9e;
    /* Navy at low opacity rather than a flat grey-blue, so tinted surfaces sit in the same
       family as the header instead of being a fourth colour nobody chose. */
    --primary-light: rgba(0, 24, 109, 0.08);
    --accent-color: var(--brand-green);
    --accent-hover: #16a83c;
    --accent-light: rgba(30, 202, 75, 0.12);
    --secondary-color: #64748b;
    --success-color: var(--brand-green);
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    /* Cool near-white and slate text: both carry a trace of the navy, which is what keeps a
       two-colour palette from looking like two colours dropped onto a grey template. */
    --background: #f6f8fc;
    --surface: #ffffff;
    --text-primary: #0b1733;
    --text-secondary: #5b6b8c;
    --border-color: #dde3f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-full: 9999px;
}

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

/* The page fills its frame exactly and never scrolls as a whole; only the message list
   does. In a 390px iframe, one element too wide otherwise cascades into three scrollbars,
   so anything that does not fit is clipped and has to be fixed. */
html,
body {
    height: 100%;
    overflow: hidden;
}

/* Form controls do not inherit the page's font, so they are declared as a family rather
   than one by one — the next control added would otherwise be found by eye. */
button,
input,
textarea,
select {
    font: inherit;
    color: inherit;
}

body {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

.app-container {
    display: flex;
    flex-direction: column;
    /* 100% of an html that is exactly the frame's height, not 100vh, which on a
       phone excludes the address bar and overflows by its height. */
    height: 100%;
    /* A flex child's default `min-height: auto` refuses to shrink below its content, which
       is how a long conversation pushes the composer off the bottom instead of scrolling. */
    min-height: 0;
}

/* Header */
/* A hairline of brand along the top edge, not a solid bar: in a 390px panel a filled
   header is a wall of colour. Navy alone and no gradient, since the host's own bar sits
   directly above it; the green lives further down, on the things you press. */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    border-top: 3px solid var(--brand-navy);
    padding: 0.75rem 1.25rem;
    box-shadow: 0 1px 2px rgba(0, 24, 109, 0.06);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
    /* Wrap rather than overflow: this row holds a name and a role supplied by
       the host system, so its width is not the designer's to decide. */
    flex-wrap: wrap;
    gap: 0.5rem;
}

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

/* Embedded, the host's bar already carries the name, so the header is just the buttons —
   hidden rather than deleted, because the standalone page has no bar above it. With the
   left side gone the actions start from the left instead of being pushed right. */
body.is-embedded .logo {
    display: none;
}

body.is-embedded .header-content {
    justify-content: flex-start;
}

.logo h1 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--brand-navy);
    letter-spacing: -0.01em;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    /* The buttons keep their labels on one line each; it is the ROW that gives way. A
       button that wraps its own text ("New\nChat") is what the narrow panel was doing. */
    min-width: 0;
}

.header-actions .btn {
    white-space: nowrap;
}

/* Shows whose role the assistant is answering as. Read-only by design: the role
   comes from the signed token, so there is nothing here to pick or change. */
.role-badge {
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-md);
    background: var(--primary-light, rgba(75, 92, 245, 0.1));
    color: var(--primary-color);
    font-size: 0.8125rem;
    font-weight: 600;
    /* One line, ellipsised: a name and a role from the host system are the only
       strings here whose length nothing on this page controls. */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    min-width: 0;
}

/* Anonymous / expired session: same shape, muted, so a limited session is visible
   without looking like an error. */
.role-badge.is-anonymous {
    background: var(--border-color);
    color: var(--text-secondary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn svg {
    width: 16px;
    height: 16px;
}

/* Navy, not green. The green button is the one that SENDS; if every confirming button were
   green the send button would stop being the thing the eye goes to. */
.btn-primary {
    background: var(--primary-color);
    color: white;
}

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

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--background);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--background);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    /* The history sheet is absolutely positioned over this area rather than over the whole
       page, so it stops below the header instead of swallowing it. */
    position: relative;
    /* Same reason as on .app-container: without it this refuses to be shorter than its
       content, and the overflow it was told to hide reappears on the document instead. */
    min-height: 0;
}

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    min-width: 0;
    min-height: 0;
}

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

/* Messages */
.message {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-avatar svg {
    width: 20px;
    height: 20px;
}

/* The robot: navy and flat, with green only in its eyes — enough to read as switched on
   without turning the top of the panel into two colours arguing. */
.assistant-message .message-avatar {
    background: var(--brand-navy);
    color: #fff;
}

.user-message .message-avatar {
    background: var(--primary-light);
    color: var(--brand-navy);
}

.message-content {
    flex: 1;
    max-width: 100%;
}

.message-text {
    background: var(--surface);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    /* Break inside a word when there is no other way: the page cannot scroll
       sideways, so a long URL or path would otherwise be clipped out of reach. */
    overflow-wrap: anywhere;
    min-width: 0;
}

.user-message .message-text {
    background: var(--brand-navy);
    color: white;
}

/* A caret while the answer is still being written — the only thing distinguishing an
   answer still arriving from one that stopped early. Inline-block, so it sits at the end
   of the text rather than on a line of its own. */
.message-text.streaming > *:last-child::after,
.message-text.streaming:empty::after {
    content: '';
    display: inline-block;
    width: 0.5rem;
    height: 1em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: var(--primary-color);
    opacity: 0.7;
    animation: caret-blink 1s steps(2, start) infinite;
}

@keyframes caret-blink {
    to { visibility: hidden; }
}

/* Someone who prefers reduced motion gets the caret without the blink. */
@media (prefers-reduced-motion: reduce) {
    .message-text.streaming > *:last-child::after,
    .message-text.streaming:empty::after { animation: none; }
}

.message-text p {
    margin-bottom: 0.75rem;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text ul, .message-text ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message-text li {
    margin-bottom: 0.25rem;
}

.message-text code {
    background: rgba(0, 0, 0, 0.1);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    font-family: monospace;
    font-size: 0.875em;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Shown only when the answer is weakly grounded: a gentle amber caveat, not an alarm,
   and never the raw score, which reads as distrust of a correct answer. */
.confidence.low {
    color: #b45309;
    cursor: help;
}

.sources-link {
    color: var(--primary-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.sources-link:hover {
    text-decoration: underline;
}

.sources-link svg {
    width: 14px;
    height: 14px;
}

.feedback-buttons {
    display: flex;
    gap: 0.5rem;
}

.feedback-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.2s;
}

.feedback-btn:hover {
    background: var(--background);
}

/* A rating that has landed has to look like it landed: green for kept, red for rejected,
   each on its own tint, with the glyph filled in — visible without comparing thumbs. */
.feedback-btn.up.active {
    color: var(--success-color);
}

.feedback-btn.down.active {
    color: var(--error-color);
}

/* Overrides the icons' fill="none" attribute. The signal is the glyph alone, with no
   tinted plate behind it, and not fully opaque — a solid thumb at 16px loses its shape. */
.feedback-btn.active svg {
    fill: currentColor;
    fill-opacity: 0.35;
}

.feedback-btn svg {
    width: 16px;
    height: 16px;
}

/* ---- "What went wrong" panel, opened by a thumbs-down ------------------------------
   Under the answer rather than in a modal, so the answer stays readable while the reason
   for rating it is picked. */
.feedback-panel {
    margin-top: 0.75rem;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--background);
    font-size: 0.8125rem;
    animation: feedbackPanelIn 0.18s ease-out;
}

@keyframes feedbackPanelIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: none; }
}

.feedback-panel-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.feedback-panel-title {
    font-weight: 600;
    color: var(--text-primary);
}

.feedback-panel-close {
    margin-left: auto;
    background: none;
    border: none;
    padding: 0.125rem;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    line-height: 0;
}

.feedback-panel-close:hover {
    background: var(--surface);
    color: var(--text-primary);
}

.feedback-panel-close svg {
    width: 14px;
    height: 14px;
}

.feedback-panel-question {
    margin: 0.5rem 0 0.5rem;
    color: var(--text-secondary);
}

.feedback-options {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

/* The whole row is the target, not the 13px circle beside it — the widget is often used
   in a narrow embedded panel where a radio button alone is an awkward thing to hit. */
.feedback-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3125rem 0.375rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-primary);
}

.feedback-option:hover {
    background: var(--surface);
}

.feedback-option input {
    accent-color: var(--primary-color);
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}

.feedback-comment-label {
    display: block;
    margin: 0.75rem 0 0.25rem;
    color: var(--text-secondary);
}

.feedback-comment {
    width: 100%;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.8125rem;
    resize: vertical;
}

.feedback-comment:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.feedback-panel-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.feedback-panel-hint {
    color: var(--error-color);
    font-size: 0.75rem;
}

.feedback-submit {
    margin-left: auto;
    padding: 0.4375rem 0.875rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary-color);
    color: #fff;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.feedback-submit:hover:not(:disabled) {
    background: var(--primary-hover);
}

.feedback-submit:disabled {
    opacity: 0.6;
    cursor: default;
}

.feedback-thanks {
    margin: 0;
    color: var(--text-secondary);
}

/* Loading indicator */
.typing-indicator {
    display: flex;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
}

/* Green: this is the one moment the machine is visibly working, and it should look alive
   rather than like three grey dots that might be stuck. */
.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--brand-green);
    border-radius: var(--radius-full);
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Shown under the dots when an answer is slow, so the wait does not read as a frozen
   widget and invite a second send at the busiest moment. */
.waiting-note {
    padding: 0 1rem 0.75rem;
    font-size: 0.8125rem;
    line-height: 1.4;
    color: var(--text-secondary);
    font-style: italic;
}

.waiting-note.hidden {
    display: none;
}

/* Ticket Banner */
.ticket-banner {
    background: linear-gradient(90deg, #fef3c7, #fde68a);
    border-top: 1px solid #fcd34d;
    padding: 0.75rem 1.5rem;
}

.ticket-banner-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: 900px;
    margin: 0 auto;
}

.ticket-banner-content svg {
    width: 20px;
    height: 20px;
    color: var(--warning-color);
    flex-shrink: 0;
}

.ticket-banner-content span {
    flex: 1;
    font-size: 0.875rem;
    color: #92400e;
}

/* Input Area */
.input-container {
    padding: 1rem 1.5rem 1.5rem;
    background: var(--surface);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 0.5rem;
    transition: border-color 0.2s;
}

/* Green while you are typing — the composer is where the user, not the assistant, acts.
   A low-opacity ring rather than a thicker border, so the box does not shift on focus. */
.input-wrapper:focus-within {
    border-color: var(--brand-green);
    box-shadow: 0 0 0 3px var(--accent-light);
}

#messageInput {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 0.9375rem;
    line-height: 1.5;
    padding: 0.5rem;
    max-height: 150px;
    color: var(--text-primary);
}

#messageInput:focus {
    outline: none;
}

#messageInput::placeholder {
    color: var(--text-secondary);
}

/* The one green button on the page. It is the only control that starts something, so it
   gets the mark's colour and nothing else competes for it. */
.send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--brand-green);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(30, 202, 75, 0.35);
}

.send-btn:disabled {
    background: var(--border-color);
    color: var(--text-secondary);
    cursor: not-allowed;
    box-shadow: none;
}

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

/* Presses in slightly. Cheap, and it is the difference between a button and a picture of
   one on a touchscreen, where there is no hover state to confirm the tap landed. */
.send-btn:not(:disabled):active {
    transform: scale(0.94);
}

.send-btn svg {
    width: 18px;
    height: 18px;
}

.input-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    text-align: center;
}

/* Sources Sidebar */
.sources-sidebar {
    width: 350px;
    background: var(--surface);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

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

.sidebar-header h3 {
    font-size: 0.9375rem;
    font-weight: 600;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.source-item {
    background: var(--background);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
}

.source-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.source-file {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--primary-color);
}

.source-score {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.source-section {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.source-preview {
    font-size: 0.8125rem;
    color: var(--text-primary);
    line-height: 1.5;
    max-height: 100px;
    overflow: hidden;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* Ticket Content */
.ticket-field {
    margin-bottom: 1rem;
}

.ticket-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.ticket-value {
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.ticket-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-low { background: #dbeafe; color: #1e40af; }
.badge-medium { background: #fef3c7; color: #92400e; }
.badge-high { background: #fee2e2; color: #991b1b; }
.badge-urgent { background: #dc2626; color: white; }

.form-group {
    margin-top: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    resize: vertical;
}

.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Recent conversations
   ------------------------------------------------------------------
   A sheet rising over the conversation and covering it: in a 390px panel a sidebar would
   be full-width anyway. One column, generous rows, nothing that needs a second glance. */
.history-panel {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    /* Rises rather than appears: 160ms is short enough to cost no time and long
       enough that the sheet reads as coming from the button. */
    animation: history-rise 0.16s ease-out;
}

@keyframes history-rise {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.history-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.25rem 0.875rem;
    border-bottom: 1px solid var(--border-color);
}

.history-head h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--brand-navy);
    line-height: 1.2;
}

.history-sub {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.35rem;
    border-radius: var(--radius-md);
    display: flex;
    line-height: 0;
    transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
    background: var(--background);
    color: var(--text-primary);
}

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

.history-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.75rem;
}

/* One row per conversation. A button, not a div with a click handler: it is focusable,
   reachable by keyboard and announced as something you can press, for free. */
/* Deliberately compact: a row carries three short things, and the point is finding one
   thread among twenty at a glance rather than scrolling past five roomy cards. */
.history-item {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.5rem 0.7rem;
    margin-bottom: 0.375rem;
    cursor: pointer;
    color: var(--text-primary);
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

/* The green edge appears only under the pointer — the one row you are about to open. A
   static accent on every row would be twenty green stripes and no signal. */
.history-item:hover {
    border-color: var(--border-color);
    border-left-color: var(--brand-green);
    background: #fbfcfe;
}

.history-item:active {
    transform: scale(0.995);
}

.history-item:focus-visible {
    outline: 2px solid var(--brand-navy);
    outline-offset: 2px;
}

/* The time, alone on its line and pushed right. `flex-end` rather than `space-between`,
   or the single remaining child would fall left and collide with the title below. */
.history-item-top {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
}

/* Line height stated rather than inherited on the small grey lines: neither ever wraps,
   so the default 1.5 is invisible slack. */
.history-when {
    font-size: 0.6875rem;
    line-height: 1.3;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Two lines, then an ellipsis: titles are short by construction, but an older
   conversation falls back to its first question. */
.history-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.8125rem;
    line-height: 1.35;
    font-weight: 500;
}

.history-meta {
    display: block;
    margin-top: 0.15rem;
    font-size: 0.6875rem;
    line-height: 1.3;
    color: var(--text-secondary);
}

/* Empty and loading states get the middle of the sheet: a grey sentence stranded under a
   heading reads as a page that failed to load. */
.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 100%;
    padding: 2rem 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.history-empty svg {
    width: 44px;
    height: 44px;
    color: var(--brand-navy);
    opacity: 0.25;
}

.history-empty strong {
    display: block;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
}

/* Skeleton rows while the list is fetched: they hold the shape the answer will have, so
   the sheet does not jump, and they say how much is coming. */
/* Sized to the row it stands in for, and kept in step with it: a placeholder that is
   taller than what replaces it makes the list jump upwards the moment it loads. */
.history-skeleton {
    height: 70px;
    border-radius: var(--radius-md);
    margin-bottom: 0.375rem;
    background: linear-gradient(90deg, #eef2f9 25%, #f7f9fd 50%, #eef2f9 75%);
    background-size: 200% 100%;
    animation: history-shimmer 1.2s infinite;
}

@keyframes history-shimmer {
    from { background-position: 200% 0; }
    to   { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .history-panel,
    .history-skeleton {
        animation: none;
    }
}

/* Locked screen
   ------------------------------------------------------------------
   Shown in place of the chat while this deployment requires a verified token and the page
   has none. Driven by state already on the body, so the page paints locked on the FIRST
   frame — hence :not(.session-verified) rather than a class that has to be added.

   Matched as "not 0", so only an explicit value unlocks the page: the raw
   /static/index.html still carries the server's unsubstituted placeholder. */
.lock-screen {
    display: none;
}

body:not([data-require-token="0"]):not(.session-verified) .lock-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 2rem 1.5rem;
}

/* Everything else is not merely disabled but absent: a disabled input reads as "the
   assistant is here and broken". The whole chrome goes, leaving the one thing to say. */
body:not([data-require-token="0"]):not(.session-verified) .header,
body:not([data-require-token="0"]):not(.session-verified) .main-content {
    display: none;
}

.lock-card {
    max-width: 24rem;
    text-align: center;
    color: var(--text-secondary);
}

.lock-icon {
    width: 56px;
    height: 56px;
    color: var(--brand-navy);
    opacity: 0.85;
    margin-bottom: 1.25rem;
}

.lock-card h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.lock-card p {
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Utility */
.hidden {
    display: none !important;
}

/* The `hidden` ATTRIBUTE, made to actually hide things: the browser's own
   `[hidden] { display: none }` loses to any author rule setting `display`. Declared once
   for every element, or the next one caught by it would be found by a user. */
[hidden] {
    display: none !important;
}

/* Responsive */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .sources-sidebar {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        max-width: 350px;
        z-index: 50;
        transform: translateX(100%);
        transition: transform 0.3s;
    }
    
    .sources-sidebar:not(.hidden) {
        transform: translateX(0);
    }
}
