:root {
  --bg: #f7f6f3; --panel: #ffffff; --side: #efede8; --text: #1f1e1c; --muted: #6b6862;
  --border: #e2dfd8; --accent: #c96442; --accent-text: #fff; --code: #f1efea; --user: #ece9e2; --err: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b19; --panel: #232220; --side: #191816; --text: #ecebe8; --muted: #9b978f;
    --border: #34322e; --accent: #d97757; --code: #2c2a27; --user: #2e2c29; --err: #f97066;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.error { color: var(--err); min-height: 1.2em; margin: 0; }

.login { height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px; display: grid; gap: 12px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.login-card button, .composer button, .new-chat { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 8px; padding: 10px 14px; }

.app { display: flex; height: 100%; }
.sidebar { width: 260px; flex-shrink: 0; background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 12px; gap: 10px; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-list li { display: flex; align-items: center; border-radius: 8px; }
.chat-list li.active, .chat-list li:hover { background: var(--user); }
.chat-list a { flex: 1; padding: 8px 10px; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-list .del { background: none; border: 0; color: var(--muted); padding: 4px 8px; visibility: hidden; }
.chat-list li:hover .del { visibility: visible; }
.link { background: none; border: 0; color: var(--muted); text-align: left; padding: 6px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.topbar .title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar select { padding: 6px 8px; }
.icon { display: none; background: none; border: 0; color: var(--text); font-size: 20px; }
.warning { background: #fef3c7; color: #78350f; padding: 8px 16px; font-size: 14px; }

.messages { flex: 1; overflow-y: auto; padding: 24px 16px; }
.msg { max-width: 780px; margin: 0 auto 18px; }
.msg.user .bubble { background: var(--user); border-radius: 12px; padding: 10px 14px; white-space: pre-wrap; margin-left: auto; width: fit-content; max-width: 85%; }
.msg.error .bubble { color: var(--err); border: 1px solid var(--err); border-radius: 8px; padding: 8px 12px; white-space: pre-wrap; }
.msg.assistant .bubble { overflow-wrap: anywhere; }
.bubble pre { background: var(--code); border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 13px; position: relative; }
.bubble code { background: var(--code); border-radius: 4px; padding: 1px 5px; font-size: 0.9em; font-family: ui-monospace, Consolas, monospace; }
.bubble pre code { background: none; padding: 0; }
.bubble .copy { position: absolute; top: 6px; right: 6px; font-size: 12px; background: var(--panel); color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; }
.bubble h1, .bubble h2, .bubble h3 { line-height: 1.3; margin: 1em 0 0.4em; }
.bubble p { margin: 0.5em 0; }
.bubble a { color: var(--accent); }
.meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.empty { text-align: center; color: var(--muted); margin-top: 20vh; }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }

.composer { display: flex; gap: 8px; padding: 12px 16px 16px; max-width: 812px; width: 100%; margin: 0 auto; }
.composer textarea { flex: 1; resize: none; max-height: 220px; }
.composer button.stop { background: var(--muted); }

@media (max-width: 760px) {
  .icon { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
}
