/* George Eliot Scholar — Chat UI */

:root {
    --bg: #FAF7F2;
    --header-bg: #2C1810;
    --header-text: #F5E6D3;
    --user-bg: #E8F0FE;
    --user-text: #1A3A5C;
    --assistant-bg: #FFFFFF;
    --assistant-border: #D4C5B2;
    --text: #2D2D2D;
    --text-muted: #6B6B6B;
    --input-bg: #FFFFFF;
    --input-border: #C8B9A6;
    --accent: #7B3F00;
    --accent-hover: #5B2C00;
    --shadow: rgba(44, 24, 16, 0.08);
    --radius: 12px;
}

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

html, body {
    height: 100%;
    font-family: Georgia, 'Times New Roman', serif;
    background: var(--bg);
    color: var(--text);
}

body {
    display: flex;
    flex-direction: column;
}

/* Login overlay */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-overlay.hidden {
    display: none;
}

.login-card {
    background: var(--assistant-bg);
    border: 1px solid var(--assistant-border);
    border-radius: var(--radius);
    padding: 40px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 4px 24px var(--shadow);
}

.login-card h2 {
    font-size: 1.6rem;
    color: var(--header-bg);
    margin-bottom: 8px;
}

.login-card > p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

#login-form {
    display: flex;
    gap: 10px;
}

#login-form input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.9rem;
}

#login-form input:focus {
    outline: none;
    border-color: var(--accent);
}

#login-form button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

#login-form button:hover {
    background: var(--accent-hover);
}

.login-error {
    color: #A04040;
    font-size: 0.85rem;
    margin-top: 12px;
}

.hidden {
    display: none !important;
}

/* Header */
header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.header-content h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.subtitle {
    font-size: 0.85rem;
    opacity: 0.75;
    margin-top: 2px;
    font-style: italic;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.header-actions button {
    background: none;
    border: 1px solid rgba(245, 230, 211, 0.3);
    color: var(--header-text);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background 0.2s;
}

.header-actions button:hover {
    background: rgba(245, 230, 211, 0.15);
}

/* Settings panel */
.settings-panel {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 16px 24px;
    border-bottom: 1px solid rgba(245, 230, 211, 0.1);
    flex-shrink: 0;
}

.settings-panel label {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 4px;
    opacity: 0.85;
}

.settings-row {
    margin-bottom: 8px;
}

.settings-row input[type="range"] {
    width: 100%;
    margin-top: 4px;
}

#settings-save {
    background: var(--accent);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    margin-top: 8px;
    transition: background 0.2s;
}

#settings-save:hover {
    background: var(--accent-hover);
}

/* Chat area */
main {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

#messages {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Messages */
.message {
    display: flex;
    animation: fadeIn 0.3s ease;
}

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

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

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

.message-content {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: var(--radius);
    line-height: 1.65;
    font-size: 0.95rem;
    box-shadow: 0 1px 4px var(--shadow);
}

.message.user .message-content {
    background: var(--user-bg);
    color: var(--user-text);
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--assistant-bg);
    border: 1px solid var(--assistant-border);
    border-bottom-left-radius: 4px;
}

.message-content p {
    margin-bottom: 0.5em;
}

.message-content h3, .message-content h4 {
    font-family: "Playfair Display", Georgia, serif;
    font-weight: 600;
    margin: 0.9em 0 0.35em;
    line-height: 1.3;
}
.message-content h3 { font-size: 1.08em; }
.message-content h4 { font-size: 1em; font-style: italic; font-weight: 500; }
.message-content ul, .message-content ol { margin: 0.4em 0 0.8em 1.3em; padding: 0; }
.message-content li { margin: 0.25em 0; }
.message-content code { font-family: "JetBrains Mono", Menlo, monospace; font-size: 0.9em; }
.message-content p:last-child {
    margin-bottom: 0;
}

/* Streaming cursor */
.streaming .message-content::after {
    content: '\2588';
    animation: blink 0.8s step-end infinite;
    color: var(--accent);
}

@keyframes blink {
    50% { opacity: 0; }
}

/* Error state */
.message.error .message-content {
    background: #FFF0F0;
    border-color: #E0B0B0;
    color: #8B2020;
}

/* Input area */
footer {
    flex-shrink: 0;
    padding: 16px 24px;
    background: var(--bg);
    border-top: 1px solid var(--assistant-border);
}

#chat-form {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#user-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    background: var(--input-bg);
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 0.95rem;
    color: var(--text);
    resize: none;
    line-height: 1.5;
    max-height: 150px;
    box-shadow: 0 1px 4px var(--shadow);
    transition: border-color 0.2s;
}

#user-input:focus {
    outline: none;
    border-color: var(--accent);
}

#send-btn {
    background: var(--accent);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
}

#send-btn:hover {
    background: var(--accent-hover);
}

#send-btn:active {
    transform: scale(0.95);
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Responsive */
@media (max-width: 600px) {
    header {
        padding: 12px 16px;
    }

    .header-content h1 {
        font-size: 1.2rem;
    }

    .subtitle {
        display: none;
    }

    main {
        padding: 16px;
    }

    .message-content {
        max-width: 88%;
        font-size: 0.9rem;
    }

    footer {
        padding: 12px 16px;
    }

    .login-card {
        padding: 24px;
    }
}

/* ---------------------------------------------------------------------- */
/* Grounded chat: query bar, status, evidence block, badges, citations    */
/* ---------------------------------------------------------------------- */

:root {
    --eliot: #2E7D32;
    --joint: #B08900;
    --lewes: #B3261E;
    --other: #6A1B9A;
    --editorial: #1565C0;
    --notice-bg: #FFF8E6;
    --notice-border: #E6C97A;
}

/* Status pill in the header */
.status-pill {
    font-size: 0.72rem;
    letter-spacing: 0.02em;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid rgba(245, 230, 211, 0.3);
    opacity: 0.85;
    white-space: nowrap;
    align-self: center;
}
.status-pill.ok { border-color: #7CB342; color: #C5E1A5; }
.status-pill.warn { border-color: #FFB74D; color: #FFE0B2; }
.status-pill.down { border-color: #E57373; color: #FFCDD2; }

/* Settings extras */
.settings-panel select {
    width: 100%;
    max-width: 420px;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--input-border);
    font-family: inherit;
    font-size: 0.9rem;
    margin-top: 4px;
}
.settings-help {
    font-size: 0.78rem;
    opacity: 0.7;
    margin-top: 4px;
    max-width: 520px;
}

/* Query bar above the input */
#query-bar {
    max-width: 800px;
    margin: 0 auto 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    align-items: center;
    font-size: 0.82rem;
    color: var(--text-muted);
}
#query-bar label {
    display: flex;
    align-items: center;
    gap: 6px;
}
#query-bar select {
    padding: 5px 8px;
    border-radius: 6px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    font-family: inherit;
    font-size: 0.82rem;
    color: var(--text);
    max-width: 320px;
}
.scope-note {
    font-style: italic;
    opacity: 0.8;
}

/* An assistant turn is a column: evidence first, answer beneath */
.message.turn .turn-column {
    max-width: 88%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.message.turn .message-content {
    max-width: 100%;
}
.message.turn .message-content:empty { display: none; }
.evidence-slot:empty { display: none; }

/* Evidence block */
.evidence {
    background: #FFFDF8;
    border: 1px solid var(--assistant-border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    padding: 12px 16px;
    font-size: 0.86rem;
    line-height: 1.5;
    box-shadow: 0 1px 4px var(--shadow);
}
.evidence.voice { border-left-color: #9E9E9E; }
.evidence.blocked { border-left-color: var(--lewes); }
.evidence-head {
    font-weight: 600;
    color: var(--header-bg);
}
.evidence-meta {
    font-style: italic;
    color: var(--text-muted);
    margin-top: 2px;
}
.evidence-notes {
    margin: 8px 0 0 0;
    padding-left: 18px;
    color: var(--text-muted);
}
.evidence-notes li { margin-bottom: 3px; }
.evidence-empty { margin-top: 8px; color: var(--lewes); }

details.passages { margin-top: 8px; }
details.passages > summary {
    cursor: pointer;
    color: var(--accent);
    font-weight: 600;
}
details.passages ol {
    list-style: none;
    padding: 0;
    margin: 8px 0 0 0;
}
.passage {
    padding: 6px 8px;
    border-top: 1px solid #EFE7DA;
    transition: background 0.4s;
}
.passage.flash { background: #FFF3C4; }
.passage summary {
    cursor: pointer;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 8px;
    align-items: baseline;
}
.passage summary::-webkit-details-marker { display: none; }
.ordinal {
    font-family: monospace;
    color: var(--text-muted);
}
.byline { color: var(--text); }
.record-link {
    color: var(--accent);
    font-size: 0.8rem;
}
.literal {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--editorial);
}
.excerpt {
    margin: 8px 0 4px 14px;
    padding-left: 10px;
    border-left: 2px solid var(--assistant-border);
    color: var(--text);
    white-space: pre-wrap;
    font-size: 0.86rem;
}

/* Attribution badges: three different non-Eliot marks, never one shared one */
.badge {
    display: inline-block;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 2px 7px;
    border-radius: 4px;
    color: #fff;
    white-space: nowrap;
}
.badge-eliot { background: var(--eliot); }
.badge-joint { background: var(--joint); }
.badge-lewes { background: var(--lewes); }
.badge-other { background: var(--other); }
.badge-editorial { background: var(--editorial); }

/* Citation links in the answer */
a.cite {
    color: var(--accent);
    text-decoration: none;
    font-family: monospace;
    font-size: 0.85em;
    padding: 0 2px;
    border-radius: 3px;
}
a.cite:hover { background: #F3E9DA; }

/* Notices inside an answer bubble */
.notice {
    background: var(--notice-bg);
    border: 1px solid var(--notice-border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.85rem;
    color: #5A4300;
    margin-top: 6px;
}
.message-content .small { font-size: 0.85em; margin-top: 8px; }

@media (max-width: 600px) {
    .status-pill { display: none; }
    .message.turn .turn-column { max-width: 100%; }
    #query-bar select { max-width: 100%; }
}
