:root {
    color-scheme: light;

    --background: #f6f7f9;
    --surface: #ffffff;
    --border: #dfe3e8;
    --text: #20242a;
    --muted: #68717d;
    --accent: #2457a6;
    --accent-hover: #1c478b;
    --error: #a32626;

    --radius: 8px;
    --content-width: 900px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--background);
    color: var(--text);
    font-family:
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    line-height: 1.6;
}

.chat {
    width: min(100% - 2rem, var(--content-width));
    margin: 0 auto;
    padding: 3rem 0 5rem;
}

h1 {
    margin: 0 0 2rem;
    font-size: 2rem;
    line-height: 1.2;
}

h2 {
    margin: 2.5rem 0 1rem;
    font-size: 1.25rem;
}

.question-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

#question {
    overflow-x: hidden;
}

textarea {
    flex: 1;
    min-height: 90px;
    padding: 0.8rem 0.9rem;

    border: 1px solid var(--border);
    border-radius: var(--radius);

    background: var(--surface);
    color: var(--text);

    font: inherit;
    resize: vertical;
}

textarea:focus {
    outline: 2px solid color-mix(in srgb,
            var(--accent) 30%,
            transparent);
    border-color: var(--accent);
}

button {
    min-height: 44px;
    padding: 0.65rem 1.1rem;

    border: 0;
    border-radius: var(--radius);

    background: var(--accent);
    color: white;

    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

button:hover:not(:disabled) {
    background: var(--accent-hover);
}

button:disabled {
    opacity: 0.55;
    cursor: default;
}

.status {
    margin: 1.25rem 0;
    color: var(--muted);
    font-size: 0.95rem;
}

#answer {
    padding: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

#answer h1,
#answer h2,
#answer h3 {
    line-height: 1.3;
}

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

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

#answer a {
    color: var(--accent);
}

#answer blockquote {
    margin: 1rem 0;
    padding-left: 1rem;
    border-left: 3px solid var(--border);
    color: var(--muted);
}

#sources,
#unused-sources {
    display: grid;
    gap: 0.75rem;
    padding: 0;
    list-style: none;
}

#sources li {
    padding: 1rem 1.1rem;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.source-title {
    font-weight: 600;
}

.source-meta {
    margin-top: 0.2rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.source-link {
    display: inline-block;
    margin-top: 0.5rem;
    color: var(--accent);
    font-weight: 500;
}

.source {
    scroll-margin-top: 1.5rem;
}

.answer a {
    text-decoration: none;
    font-weight: 600;
}

.answer a:hover {
    text-decoration: underline;
}

#error-section {
    margin-top: 1.5rem;
    padding: 1rem;
    border: 1px solid #e2baba;
    border-radius: var(--radius);
    color: var(--error);
    background: #fff7f7;
}

@media (max-width: 600px) {
    .chat {
        width: min(100% - 1rem, var(--content-width));
        padding-top: 1.5rem;
    }

    .question-row {
        flex-direction: column;
        align-items: stretch;
    }

    button {
        width: 100%;
    }

    #answer {
        padding: 1rem;
    }
}