:root {
  --bg: #f6f4f1; --panel: #ffffff; --text: #1f1d1a; --muted: #6f6a63; --line: #e4dfd8;
  --accent: #7a3e2e; --accent-text: #ffffff; --bot: #f1ece6; --user: #7a3e2e; --user-text: #fff;
  --note: #eef3f8; --note-line: #c9d8e8; --warn: #fff4d6; --warn-line: #e8cf8a; --err: #fdeceb; --err-line: #e7b4b0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171513; --panel: #201d1a; --text: #ece7e1; --muted: #a39c93; --line: #35302b;
    --accent: #c98a72; --accent-text: #1a1210; --bot: #2a2622; --user: #8f4c38; --user-text: #fff;
    --note: #1d2732; --note-line: #2f4256; --warn: #362d14; --warn-line: #6b5a26; --err: #3a1f1d; --err-line: #6e3833;
  }
}
:root[data-theme="dark"] {
  --bg: #171513; --panel: #201d1a; --text: #ece7e1; --muted: #a39c93; --line: #35302b;
  --accent: #c98a72; --accent-text: #1a1210; --bot: #2a2622; --user: #8f4c38; --user-text: #fff;
  --note: #1d2732; --note-line: #2f4256; --warn: #362d14; --warn-line: #6b5a26; --err: #3a1f1d; --err-line: #6e3833;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.app { max-width: 820px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; padding: 12px 16px; gap: 10px; }
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
h1 { font-size: 18px; margin: 0; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; letter-spacing: .02em; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--accent); color: var(--accent-text); white-space: nowrap; }
.badge.demo { background: #b7791f; color: #fff; }
.badge.muted { background: var(--line); color: var(--text); }
.banner { background: var(--warn); border: 1px solid var(--warn-line); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.banner.warn { background: var(--err); border-color: var(--err-line); }
.messages { flex: 1; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 240px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.msg { max-width: 88%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-text); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bot); border-bottom-left-radius: 4px; }
.msg .tag { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.note { align-self: stretch; background: var(--note); border: 1px solid var(--note-line); border-radius: 10px; padding: 8px 12px;
  font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.note .tag { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.note.error { background: var(--err); border-color: var(--err-line); }
.empty { color: var(--muted); text-align: center; margin: auto; font-size: 14px; }
.typing { color: var(--muted); font-size: 13px; padding-left: 4px; }
.dots::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.error { display: flex; align-items: center; gap: 10px; justify-content: space-between; background: var(--err);
  border: 1px solid var(--err-line); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.composer { display: flex; gap: 8px; }
textarea { flex: 1; resize: none; min-height: 44px; max-height: 140px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; }
button { font: inherit; border: 0; border-radius: 12px; padding: 10px 14px; background: var(--accent); color: var(--accent-text); cursor: pointer; }
button.secondary { background: var(--line); color: var(--text); padding: 8px 12px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
@media (max-width: 520px) {
  .app { padding: 10px 16px; }
  h1 { font-size: 16px; }
  .msg { max-width: 94%; }
  .composer button { padding: 10px; }
}
/* admin */
.admin table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin th, .admin td { border-bottom: 1px solid var(--line); text-align: left; padding: 6px; vertical-align: top; }
.admin .wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.admin h2 { font-size: 16px; margin: 14px 0 6px; }
.admin .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.admin select { font: inherit; padding: 6px; border-radius: 8px; }
.admin pre { white-space: pre-wrap; font-size: 12px; margin: 0; }
