:root { color-scheme: light dark;
    --color-bg: #f6f8fa;
    --color-bg-elevated: #ffffff;
    --color-sidebar-bg: #f6f8fa;
    --color-border: #d0d7de;
    --color-border-subtle: #d8dee4;
    --color-fg: #24292f;
    --color-muted: #6e7781;
    --color-link: #0969da;
    --color-link-hover: #054da7;
    --color-primary: #1f6feb;
    --color-primary-hover: #1158c7;
    --color-success: #2da44e;
    --color-input-bg: #ffffff;
    --color-input-border: #d0d7de;
    --shadow-soft: 0 1px 0 rgba(27,31,35,0.04);
}
@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #0d1117;
        --color-bg-elevated: #161b22;
        --color-sidebar-bg: #0d1117;
        --color-border: #30363d;
        --color-border-subtle: #21262d;
        --color-fg: #e6edf3;
        --color-muted: #8b949e;
        --color-link: #58a6ff;
        --color-link-hover: #1f6feb;
        --color-primary: #1f6feb;
        --color-primary-hover: #388bfd;
        --color-success: #3fb950;
        --color-input-bg: #0d1117;
        --color-input-border: #30363d;
        --shadow-soft: 0 0 0 rgba(0,0,0,0);
    }
}
[data-theme="dark"] {
    --color-bg: #0d1117;
    --color-bg-elevated: #161b22;
    --color-sidebar-bg: #0d1117;
    --color-border: #30363d;
    --color-border-subtle: #21262d;
    --color-fg: #e6edf3;
    --color-muted: #8b949e;
    --color-link: #58a6ff;
    --color-link-hover: #1f6feb;
    --color-primary: #1f6feb;
    --color-primary-hover: #388bfd;
    --color-success: #3fb950;
    --color-input-bg: #0d1117;
    --color-input-border: #30363d;
    --shadow-soft: 0 0 0 rgba(0,0,0,0);
}
[data-theme="light"] {
    --color-bg: #f6f8fa;
    --color-bg-elevated: #ffffff;
    --color-sidebar-bg: #f6f8fa;
    --color-border: #d0d7de;
    --color-border-subtle: #d8dee4;
    --color-fg: #24292f;
    --color-muted: #6e7781;
    --color-link: #0969da;
    --color-link-hover: #054da7;
    --color-primary: #1f6feb;
    --color-primary-hover: #1158c7;
    --color-success: #2da44e;
    --color-input-bg: #ffffff;
    --color-input-border: #d0d7de;
    --shadow-soft: 0 1px 0 rgba(27,31,35,0.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; font-size: 16px; line-height: 1.5; background-color: var(--color-bg); color: var(--color-fg); }
a { color: var(--color-link); text-decoration: none; }
a:hover, a:focus { text-decoration: underline; color: var(--color-link-hover); }
.skip-link { position: absolute; left: -9999px; top: 0; padding: 0.5rem 1rem; background: #000; color: #fff; z-index: 1000; }
.skip-link:focus { left: 0; }
.app { display: flex; min-height: 100vh; }
.sidebar { width: 280px; padding: 1rem; border-right: 1px solid var(--color-border); background-color: var(--color-sidebar-bg); display: flex; flex-direction: column; gap: 1rem; }
.sidebar-header { display: flex; gap: 0.75rem; align-items: center; }
.sidebar-logo { width: 32px; height: 32px; }
.sidebar-title { font-size: 1.125rem; font-weight: 600; }
.sidebar-actions { margin-top: 0.5rem; display: flex; flex-direction: column; gap: 0.5rem; }
.sidebar-button-primary { width: 100%; padding: 0.5rem 0.75rem; border-radius: 6px; border: 1px solid var(--color-primary); background-color: var(--color-primary); color: #ffffff; font-weight: 500; cursor: pointer; }
.sidebar-button-primary:hover, .sidebar-button-primary:focus { background-color: var(--color-primary-hover); border-color: var(--color-primary-hover); }
.sidebar-button-secondary { width: 100%; padding: 0.4rem 0.75rem; border-radius: 6px; border: 1px solid var(--color-border-subtle); background-color: var(--color-bg-elevated); color: var(--color-fg); font-size: 0.85rem; cursor: pointer; text-align: left; }
.sidebar-button-secondary:hover, .sidebar-button-secondary:focus { background-color: var(--color-bg); }
.sidebar-section-title { font-size: 0.9rem; font-weight: 600; margin: 0.25rem 0; }
.conversation-list { list-style: none; padding: 0; margin: 0; }
.conversation-list li { margin-bottom: 0.25rem; }
.conversation-link { display: block; padding: 0.4rem 0.6rem; border-radius: 6px; border: 1px solid transparent; background: transparent; font-size: 0.9rem; }
.conversation-link--active { border-color: var(--color-primary); background-color: var(--color-bg-elevated); font-weight: 600; }
.conversation-link:hover, .conversation-link:focus { border-color: var(--color-border-subtle); background-color: var(--color-bg-elevated); text-decoration: none; }
.sidebar-form { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }
.sidebar-form input[type="text"] { width: 100%; border: 1px solid var(--color-border); background: var(--color-input-bg); color: var(--color-fg); border-radius: 6px; padding: 0.4rem 0.6rem; font-size: 0.9rem; }
.sidebar-form button { padding: 0.3rem 0.6rem; border-radius: 6px; border: 1px solid var(--color-border-subtle); background: var(--color-bg-elevated); color: var(--color-fg); font-size: 0.8rem; cursor: pointer; text-align: left; }
.sidebar-links a { display: block; font-size: 0.85rem; margin-bottom: 0.25rem; }
.chat { flex: 1; display: flex; flex-direction: column; max-width: 1100px; margin: 0 auto; }
.chat-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--color-border); background-color: var(--color-bg-elevated); box-shadow: var(--shadow-soft); }
.chat-header h1 { margin: 0; font-size: 1.25rem; font-weight: 600; }
.chat-header-subtitle { margin: 0.25rem 0 0; font-size: 0.9rem; color: var(--color-muted); }
.creator-banner { margin: 0.75rem 1.5rem 0; padding: 0.5rem 0.75rem; border-radius: 6px; border: 1px solid #ffd8b5; background: #fff4e5; color: #8a4b00; font-size: 0.85rem; }
@media (prefers-color-scheme: dark) { .creator-banner { border-color: #5a3b13; background: #2a1906; color: #ffdf9b; } }
.chat-log { flex: 1; padding: 1rem 1.5rem; overflow-y: auto; }
.message { margin-bottom: 1.25rem; padding: 0.75rem 1rem; border-radius: 8px; border: 1px solid var(--color-border); background-color: var(--color-bg-elevated); }
.message-label { font-size: 0.85rem; font-weight: 600; color: var(--color-muted); margin-bottom: 0.25rem; }
.message-body { font-size: 0.95rem; color: var(--color-fg); }
.message--user { border-left: 4px solid var(--color-primary); }
.message--assistant { border-left: 4px solid var(--color-success); }
.message-body p { margin: 0.25rem 0; }
.message-body ul, .message-body ol { margin: 0.25rem 0 0.25rem 1.25rem; }
.snippets { margin-top: 0.5rem; font-size: 0.8rem; color: var(--color-muted); }
.snippets a { margin-right: 0.5rem; }
.alert-errors { margin: 0.5rem 1.5rem; padding: 0.5rem 0.75rem; border: 1px solid #d1242f; border-radius: 6px; background: rgba(209, 36, 47, 0.06); color: #d1242f; font-size: 0.85rem; }
.chat-input-wrapper { border-top: 1px solid var(--color-border); background-color: var(--color-bg-elevated); padding: 0.75rem 1.5rem 1rem; }
.chat-disclaimer { font-size: 0.8rem; color: var(--color-muted); margin-bottom: 0.5rem; }
.chat-input-area form { display: flex; flex-direction: column; gap: 0.5rem; }
.chat-input-row { display: flex; gap: 0.75rem; align-items: stretch; }
.chat-input-area textarea { flex: 1; min-height: 3.5rem; max-height: 200px; resize: vertical; padding: 0.5rem 0.75rem; border-radius: 6px; border: 1px solid var(--color-input-border); background-color: var(--color-input-bg); color: var(--color-fg); font: inherit; }
.chat-input-area textarea:focus { outline: 2px solid var(--color-primary); outline-offset: 1px; border-color: var(--color-primary); }
.chat-input-controls { display: flex; flex-direction: column; gap: 0.4rem; min-width: 190px; }
.btn { padding: 0.5rem 0.75rem; border-radius: 6px; border: 1px solid var(--color-border-subtle); background-color: var(--color-bg-elevated); color: var(--color-fg); font-size: 0.85rem; cursor: pointer; text-align: center; }
.btn:hover, .btn:focus { background-color: var(--color-bg); } .btn-primary { border-color: var(--color-primary); background-color: var(--color-primary); color: #ffffff; font-weight: 500; }
.btn-primary:hover, .btn-primary:focus { background-color: var(--color-primary-hover); border-color: var(--color-primary-hover); }
.file-button { position: relative; overflow: hidden; }
.file-button input[type="file"] { position: absolute; left: 0; top: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.stream-status { margin-top: 0.25rem; font-size: 0.85rem; color: var(--color-muted); min-height: 1.2em; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.sidebar-toggle { margin: 0.5rem 1rem; padding: 0.4rem 0.75rem; border-radius: 999px; border: 1px solid var(--color-border-subtle); background-color: var(--color-bg-elevated); color: var(--color-fg); font-size: 0.85rem; cursor: pointer; }
.sidebar-toggle:hover, .sidebar-toggle:focus { background-color: var(--color-bg); }
[data-sidebar="closed"] .sidebar { display: none; }
[data-sidebar="closed"] .chat { max-width: 100%; }

.scroll-bottom-btn {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1000;
    border-radius: 999px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border-subtle);
    background: var(--color-bg-elevated);
    color: var(--color-fg);
    box-shadow: var(--shadow-soft);
}
.scroll-bottom-btn[hidden] { display: none; }

@media (max-width: 768px) {
    .app { flex-direction: column; }
    .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--color-border); }
    .chat { max-width: 100%; }
    .chat-input-row { flex-direction: column; }
    .chat-input-controls { flex-direction: row; flex-wrap: wrap; gap: 0.5rem; min-width: 0; }
    .chat-input-controls .btn { flex: 1 1 30%; }
}