:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1b1f24; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --accent-text: #fff; --user: #e8f0fe; --error: #b91c1c;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --panel: #171a21; --text: #e6e8eb; --muted: #9aa3af; --line: #2a2f3a; --user: #1e2a44; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; margin-left: 0.5rem; }
.error { color: var(--error); min-height: 1.2em; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; padding: 0.6rem 1rem;
  background: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button:disabled { opacity: 0.6; cursor: wait; }
input, textarea { font: inherit; width: 100%; padding: 0.6rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 2rem; }
.login { max-width: 380px; margin: 10vh auto; }
.login .logo { display: block; margin-bottom: 0.8rem; }
.login h1 { margin: 0 0 0.25rem; }
.login .muted { margin: 0 0 1.5rem; display: block; }
.login label { display: block; margin-bottom: 1rem; font-size: 0.9rem; }
.login label input { margin-top: 0.3rem; }
.login button { width: 100%; }

.chat { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 1100px; margin: 0 auto; }
.chat header { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand .muted { margin-left: 0; }
.chat .actions { display: flex; gap: 0.5rem; }
#messages { flex: 1; min-height: 0; overflow-y: auto; padding: 1.2rem 1rem; display: flex; flex-direction: column; gap: 0.8rem; }
.msg { flex: none; align-self: flex-start; overflow-wrap: anywhere; max-width: 85%; padding: 0.7rem 1rem; border-radius: 12px; line-height: 1.45; background: var(--panel);
  border: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; }
.msg.user { align-self: flex-end; background: var(--user); border-color: transparent; white-space: pre-wrap; }
.msg.assistant { padding-left: 3.2rem; background: var(--panel) url("/logo.svg") no-repeat 0.8rem 0.8rem / 1.7rem; }
.msg.assistant p { margin: 0.3rem 0; }
.msg table { border-collapse: collapse; margin: 0.5rem 0; font-size: 0.9rem; }
.msg th, .msg td { overflow-wrap: normal; border: 1px solid var(--line); padding: 0.3rem 0.6rem; text-align: left; }
.msg .files a { display: inline-block; margin-top: 0.5rem; margin-right: 0.5rem; }
.msg.thinking { color: var(--muted); font-style: italic; }
.hint { color: var(--muted); }
.chip { background: transparent; color: var(--text); border: 1px solid var(--line); margin: 0.25rem; font-size: 0.9rem; }
#chat-form { display: flex; gap: 0.5rem; padding: 0.8rem 1rem; border-top: 1px solid var(--line); background: var(--panel); }
#chat-form textarea { resize: none; max-height: 160px; }
@media (max-width: 600px) { .msg { max-width: 96%; } }
