:root {
  --bg: #f6f6f4; --panel: #ffffff; --text: #1d1d1b; --muted: #6b6b66; --line: #e2e2dc;
  --accent: #1f5f8b; --accent-text: #ffffff; --user: #e8f0f6; --error: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615; --panel: #1f1f1d; --text: #ececea; --muted: #a0a09a; --line: #33332f;
    --accent: #5ea3d6; --accent-text: #0d0d0c; --user: #23303a; --error: #f2b8b5;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; padding: 8px 14px; background: var(--accent); color: var(--accent-text); }
button:disabled { opacity: .5; cursor: default; }
button.link { background: none; color: var(--muted); padding: 0; text-decoration: underline; }
input, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }

#login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; width: min(360px, 100%); display: grid; gap: 14px; }
.card h1 { font-size: 20px; margin: 0; }
.card label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.error { color: var(--error); min-height: 1.2em; margin: 0; font-size: 13px; }

#chat { display: grid; grid-template-columns: 260px 1fr; height: 100%; }
aside { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; padding: 12px; gap: 10px; min-height: 0; }
#conversations { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#conversations li { display: flex; align-items: center; gap: 4px; border-radius: 6px; }
#conversations li.active, #conversations li:hover { background: var(--bg); }
#conversations li a { flex: 1; padding: 6px 8px; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
#conversations li button { background: none; color: var(--muted); padding: 2px 6px; }
.me { display: grid; gap: 2px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }
.me #me-name { color: var(--text); font-weight: 600; }

main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
#messages { flex: 1; overflow-y: auto; padding: 20px max(16px, calc((100% - 760px) / 2)); display: flex; flex-direction: column; gap: 14px; }
.hint { color: var(--muted); font-size: 14px; }
.msg { padding: 10px 14px; border-radius: 10px; max-width: 100%; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.user { background: var(--user); align-self: flex-end; max-width: 85%; }
.msg.assistant { background: var(--panel); border: 1px solid var(--line); }
.msg.error { color: var(--error); border: 1px solid var(--error); }
.msg code { font-family: ui-monospace, monospace; font-size: 13px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
#ask-form { display: flex; gap: 8px; padding: 12px max(16px, calc((100% - 760px) / 2)); border-top: 1px solid var(--line); background: var(--panel); }
#ask-form textarea { resize: vertical; min-height: 44px; max-height: 40vh; }

@media (max-width: 720px) {
  #chat { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  aside { border-right: 0; border-bottom: 1px solid var(--line); max-height: 30vh; }
}
