:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --text: #18212f;
    --muted: #657184;
    --line: #dce2ea;
    --accent: #12715b;
    --accent-dark: #0c5544;
    --danger: #a83232;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }

button, textarea, input {
    font: inherit;
}

.container {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
}

.site-header {
    background: rgba(255,255,255,.92);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(12px);
}

.site-nav {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    color: var(--text);
    font-weight: 800;
    font-size: 1.25rem;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    color: var(--muted);
}

.nav-actions form { margin: 0; }
.nav-actions button, .nav-button, .auth-card button, .composer button, .cookie-banner button, .new-chat {
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    padding: 10px 14px;
    cursor: pointer;
}

.nav-actions button { background: #273244; }

.landing-shell {
    width: min(1240px, calc(100% - 28px));
    margin: 28px auto 40px;
}

.intro-panel {
    display: grid;
    gap: 10px;
    margin-bottom: 22px;
}

.eyebrow {
    margin: 0;
    color: var(--accent);
    font-weight: 800;
    text-transform: uppercase;
    font-size: .78rem;
    letter-spacing: 0;
}

.intro-panel h1 {
    max-width: 760px;
    margin: 0;
    font-size: clamp(2rem, 5vw, 4.25rem);
    line-height: 1.03;
}

.intro-panel p {
    max-width: 760px;
    margin: 0;
    color: var(--muted);
    font-size: 1.05rem;
}

.donation {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
    color: #344256;
}

.donation-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: fit-content;
    max-width: 100%;
    border: 1px solid #f0c36c;
    border-radius: 8px;
    background: #fff7df;
    color: #5b3b00;
    padding: 9px 12px;
    font-weight: 800;
}

.donation-link:hover {
    background: #ffe9a8;
    color: #3b2800;
}

.donation-icon {
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 999px;
    background: #ffdd72;
    font-size: 1rem;
}

.public-queue-status {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 12px;
    width: fit-content;
    max-width: 100%;
    margin-top: 8px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--muted);
}

.public-queue-status span {
    color: var(--text);
    font-weight: 700;
}

.public-queue-status strong {
    color: var(--accent);
    font-size: 1.35rem;
}

.public-queue-status small {
    color: var(--muted);
}

.chat-layout {
    display: grid;
    gap: 16px;
}

.chat-layout.authenticated {
    grid-template-columns: minmax(0, 260px) minmax(0, 1fr);
}

.chat-layout.public {
    grid-template-columns: minmax(0, 1fr);
}

.chat-layout.public .chat-panel {
    width: min(960px, 100%);
    margin: 0 auto;
}

.conversation-list {
    background: #edf1f5;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    height: 720px;
    overflow: auto;
}

.conversation-item {
    width: 100%;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    display: block;
    padding: 10px;
    margin-top: 6px;
    text-align: left;
    cursor: pointer;
}

.conversation-item.active, .conversation-item:hover {
    background: #fff;
}

.chat-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    min-height: 720px;
    display: grid;
    grid-template-rows: 1fr auto auto;
}

.messages {
    min-height: 0;
    max-height: 600px;
    overflow-y: auto;
    padding: 26px;
}

.empty-chat {
    min-height: 420px;
    display: grid;
    place-content: center;
    justify-items: center;
    color: var(--muted);
    text-align: center;
    gap: 8px;
}

.message {
    display: flex;
    margin: 12px 0;
}

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

.bubble {
    max-width: min(760px, 88%);
    border-radius: 8px;
    padding: 14px 16px;
    background: #eef3f8;
}

.message.user .bubble {
    background: #dff3ec;
}

.role {
    display: block;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 800;
    margin-bottom: 6px;
}

.bubble p {
    margin: 0;
    white-space: pre-wrap;
}

.bubble.typing p::after {
    content: "";
    display: inline-block;
    width: 7px;
    height: 1em;
    margin-left: 3px;
    vertical-align: -2px;
    background: currentColor;
    animation: typing-caret 0.9s steps(2, start) infinite;
}

.bubble.loading p::after {
    content: "...";
    display: inline-block;
    min-width: 22px;
    animation: loading-dots 1.2s steps(4, end) infinite;
}

@keyframes typing-caret {
    50% {
        opacity: 0;
    }
}

@keyframes loading-dots {
    0% {
        content: "";
    }
    25% {
        content: ".";
    }
    50% {
        content: "..";
    }
    75%, 100% {
        content: "...";
    }
}

.bubble small {
    display: block;
    margin-top: 8px;
    color: var(--muted);
}

.composer {
    border-top: 1px solid var(--line);
    padding: 14px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    background: #fbfcfd;
}

.composer textarea {
    resize: none;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 13px 14px;
    min-height: 54px;
}

.composer button:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.save-hint {
    margin: 0;
    padding: 0 16px 14px;
    color: var(--muted);
    font-size: .92rem;
}

.cookie-banner {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    width: min(760px, calc(100% - 28px));
    background: #172033;
    color: #fff;
    border-radius: 8px;
    padding: 14px;
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    z-index: 20;
}

.cookie-banner a { color: #9ce0cb; }
.cookie-banner button { background: #fff; color: #172033; }

.site-footer {
    border-top: 1px solid var(--line);
    padding: 24px 0;
    color: var(--muted);
}

.footer-links {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.auth-page, .legal-page, .admin-page {
    padding: 42px 0;
}

.auth-card {
    width: min(440px, 100%);
    margin: 0 auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
    display: grid;
    gap: 10px;
}

.auth-card input {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.validation { color: var(--danger); font-size: .9rem; }

.legal-page {
    max-width: 860px;
    line-height: 1.7;
}

.legal-page h1, .admin-header h1 { margin-top: 0; }
.legal-page h2 { margin-top: 28px; font-size: 1.2rem; }

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    margin-bottom: 22px;
}

.admin-subtitle {
    margin: 6px 0 0;
    color: var(--muted);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.metrics-grid div, .admin-row {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.metrics-grid .queue-main {
    border-color: var(--accent);
    background: #eaf7f2;
}

.metrics-grid span {
    display: block;
    color: var(--muted);
}

.metrics-grid strong {
    display: block;
    font-size: 1.5rem;
}

.admin-columns {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-top: 24px;
}

.ai-config-panel {
    margin-top: 24px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    display: grid;
    grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
    gap: 22px;
}

.ai-config-panel h2 {
    margin: 0 0 8px;
}

.ai-config-panel p {
    color: var(--muted);
}

.ai-config-form {
    display: grid;
    gap: 9px;
}

.ai-config-form input,
.ai-config-form select,
.ai-config-form textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
}

.ai-config-form button {
    justify-self: start;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    padding: 10px 14px;
    cursor: pointer;
}

.check-line {
    display: flex;
    align-items: center;
    gap: 8px;
}

.check-line input {
    width: auto;
}

.admin-alert {
    border-radius: 8px;
    padding: 12px 14px;
    margin: 16px 0 0;
}

.admin-alert.success {
    background: #dff3ec;
}

.admin-alert.error {
    background: #ffe8e8;
    color: var(--danger);
}

.admin-row {
    margin-bottom: 10px;
}

.admin-row span {
    display: block;
    color: var(--muted);
    font-size: .88rem;
}

.admin-row p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-row.error strong { color: var(--danger); }

@media (max-width: 820px) {
    .site-nav, .nav-actions, .cookie-banner, .admin-header {
        align-items: flex-start;
        flex-direction: column;
        height: auto;
        padding: 12px 0;
    }

    .chat-layout, .metrics-grid, .admin-columns, .ai-config-panel {
        grid-template-columns: 1fr;
    }

    .conversation-list {
        height: auto;
        max-height: 220px;
    }

    .composer {
        grid-template-columns: 1fr;
    }
}
