:root {
  --bg: #1c1b19;
  --panel: #232220;
  --raise: #2b2a27;
  --line: #36342f;
  --text: #ece8df;
  --muted: #9c978c;
  --brass: #c8a15a;
  --brass-ink: #1c1b19;
  --brass-soft: rgba(200, 161, 90, .14);
  --danger: #e07b6a;
  --ok: #8fb37a;
  --user-bubble: #2f2d29;
  --code-bg: #151412;
  --sans: "Onest", system-ui, sans-serif;
  --display: "Bricolage Grotesque", "Onest", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sidebar: 280px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f2f0; --panel: #e8e7e3; --raise: #ffffff; --line: #d6d4ce; --text: #1f1e1b; --muted: #6c685f;
    --brass: #8c6a2b; --brass-ink: #ffffff; --brass-soft: rgba(140, 106, 43, .12); --user-bubble: #e4e2dc; --code-bg: #1f1e1b;
    --danger: #b4483a; --ok: #4f7a3a; color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
#app { height: 100dvh; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
a { color: var(--brass); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- buttons & inputs ---------- */
.btn { color: var(--text); text-decoration: none; border: 1px solid var(--line); background: var(--raise); border-radius: 10px; padding: 8px 14px; font-weight: 500; display: inline-flex; align-items: center; gap: 8px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brass); color: var(--brass-ink); border-color: var(--brass); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--raise); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: grid; gap: 6px; }
.field span { font-size: 13px; color: var(--muted); }
.input, select.input { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.input:focus { border-color: var(--brass); outline: none; }
.err { color: var(--danger); font-size: 14px; min-height: 1.4em; }
.icon { width: 18px; height: 18px; flex: none; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); }
.mark { display: flex; align-items: center; gap: 12px; }
.mark img { width: 40px; height: 40px; }
.mark b { font: 700 24px/1 var(--display); letter-spacing: -.01em; }
.login-card p { color: var(--muted); margin: 14px 0 28px; }
.login-card form { display: grid; gap: 16px; }
.login-card .btn { justify-content: center; padding: 11px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100%; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 16px 14px 10px; display: grid; gap: 12px; }
.side-head .mark img { width: 30px; height: 30px; }
.side-head .mark b { font-size: 19px; }
.new-chat { justify-content: center; }
.search { padding: 8px 12px; font-size: 14px; }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.group-label { font-size: 12px; color: var(--muted); padding: 14px 8px 4px; }
.chat-item { display: flex; align-items: center; border-radius: 8px; }
.chat-item a { flex: 1; min-width: 0; padding: 7px 8px; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-item:hover { background: var(--raise); }
.chat-item.active { background: var(--brass-soft); }
.chat-item.active a { color: var(--text); }
.chat-item .more { opacity: 0; padding: 4px 6px; border: 0; background: none; color: var(--muted); border-radius: 6px; }
.chat-item:hover .more, .chat-item.active .more, .chat-item .more:focus-visible { opacity: 1; }
.empty-list { color: var(--muted); font-size: 14px; padding: 12px 8px; }
.side-foot { border-top: 1px solid var(--line); padding: 8px; display: grid; gap: 2px; }
.side-foot .btn { justify-content: flex-start; width: 100%; font-size: 14px; padding: 7px 10px; }
.side-foot .btn[aria-current="page"] { background: var(--brass-soft); }
.who { display: flex; align-items: center; gap: 10px; padding: 8px 10px 6px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brass-soft); color: var(--brass); display: grid; place-items: center; font: 600 13px var(--display); flex: none; }
.who-name { font-weight: 600; font-size: 14px; line-height: 1.2; }
.who-role { font-size: 12px; color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); min-height: 56px; }
.topbar h1 { font: 600 16px/1.3 var(--sans); margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { display: none; }
.model-pick { max-width: 240px; padding: 6px 10px; font-size: 13px; }

/* ---------- conversation ---------- */
.thread { flex: 1; overflow-y: auto; }
.thread-inner { max-width: 780px; margin: 0 auto; padding: 28px 20px 12px; display: grid; gap: 22px; }
.msg.user { justify-self: end; max-width: 85%; background: var(--user-bubble); padding: 10px 16px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant { display: grid; grid-template-columns: 28px 1fr; gap: 12px; }
.msg.assistant .dot { width: 28px; height: 28px; margin-top: 2px; }
.msg.assistant .body { min-width: 0; overflow-wrap: anywhere; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; gap: 12px; align-items: center; }
.msg .meta button { border: 0; background: none; color: var(--muted); padding: 2px 0; font-size: 12px; }
.msg .meta button:hover { color: var(--text); }
.msg.error .body { color: var(--danger); }
.typing { display: inline-flex; gap: 4px; padding-top: 10px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .6; } }

/* markdown */
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--display); line-height: 1.3; margin: 20px 0 8px; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3, .md h4 { font-size: 16px; }
.md ul, .md ol { padding-left: 22px; } .md li { margin: 3px 0; }
.md blockquote { border-left: 3px solid var(--brass); padding-left: 12px; color: var(--muted); }
.md code { font: 13px var(--mono); background: var(--raise); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--code-bg); color: #e8e4da; border-radius: 10px; overflow: hidden; }
.md pre .code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; font: 12px var(--mono); color: #9c978c; border-bottom: 1px solid #2c2a26; }
.md pre .code-head button { border: 0; background: none; color: #9c978c; font-size: 12px; }
.md pre .code-head button:hover { color: #e8e4da; }
.md pre code { display: block; background: none; padding: 12px; overflow-x: auto; font-size: 13px; line-height: 1.55; white-space: pre; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.md th { background: var(--raise); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* empty chat */
.hello { max-width: 640px; margin: 0 auto; padding: 12vh 20px 20px; }
.hello h2 { font: 700 clamp(26px, 4vw, 34px)/1.15 var(--display); letter-spacing: -.015em; margin: 0 0 8px; }
.hello p { color: var(--muted); margin: 0 0 24px; }
.ideas { display: grid; gap: 8px; }
.idea { text-align: left; border: 1px solid var(--line); background: transparent; border-radius: 12px; padding: 12px 14px; color: var(--text); }
.idea:hover { border-color: var(--brass); background: var(--brass-soft); }
.idea small { display: block; color: var(--muted); font-size: 12px; }

/* composer */
.composer { padding: 8px 20px 18px; }
.composer form { max-width: 780px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--raise); border: 1px solid var(--line); border-radius: 16px; padding: 8px 8px 8px 16px; }
.composer form:focus-within { border-color: var(--brass); }
.composer textarea { flex: 1; border: 0; background: none; resize: none; outline: none; max-height: 240px; padding: 7px 0; line-height: 1.5; }
.send { width: 38px; height: 38px; border-radius: 11px; border: 0; background: var(--brass); color: var(--brass-ink); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .35; cursor: default; }
.send.stop { background: var(--text); color: var(--bg); }
.hint { max-width: 780px; margin: 6px auto 0; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- pages (usage/admin) ---------- */
.page { flex: 1; overflow-y: auto; }
.page-inner { max-width: 1040px; margin: 0 auto; padding: 28px 20px 48px; }
.page h2 { font: 700 28px/1.2 var(--display); letter-spacing: -.01em; margin: 0 0 4px; }
.page .sub { color: var(--muted); margin: 0 0 24px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 24px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--brass); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat b { display: block; font: 700 26px/1.1 var(--display); }
.stat span { color: var(--muted); font-size: 13px; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 20px; }
.card h3 { font: 600 15px var(--sans); margin: 0 0 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.range { display: inline-flex; gap: 2px; background: var(--panel); border-radius: 8px; padding: 2px; }
.range button { border: 0; background: none; padding: 3px 10px; border-radius: 6px; font-size: 13px; color: var(--muted); }
.range button[aria-pressed="true"] { background: var(--raise); color: var(--text); }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .actions { text-align: right; white-space: nowrap; }
table.data .actions .btn { padding: 4px 10px; font-size: 13px; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--panel); color: var(--muted); }
.badge.admin { background: var(--brass-soft); color: var(--brass); }
.badge.off { color: var(--danger); }
.muted { color: var(--muted); }
.bar { height: 6px; background: var(--panel); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar i { display: block; height: 100%; background: var(--brass); border-radius: 3px; }
.chart { width: 100%; height: 180px; display: block; }
.chart .grid { stroke: var(--line); }
.chart .col { fill: var(--brass); }
.chart .col:hover { fill: var(--text); }
.chart text { fill: var(--muted); font: 11px var(--sans); }
.chart-tip { font-size: 13px; color: var(--muted); min-height: 1.5em; margin-top: 6px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.note { font-size: 13px; color: var(--muted); }

/* dialog */
dialog { border: 1px solid var(--line); background: var(--raise); color: var(--text); border-radius: 14px; padding: 22px; width: min(420px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h3 { margin: 0 0 16px; font: 700 19px var(--display); }
dialog form { display: grid; gap: 14px; }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.pop { position: fixed; z-index: 20; background: var(--raise); border: 1px solid var(--line); border-radius: 10px; padding: 4px; min-width: 160px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.pop button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 6px; font-size: 14px; }
.pop button:hover { background: var(--panel); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 30; }

/* ---------- mobile ---------- */
.scrim { display: none; }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(var(--sidebar), 86vw); z-index: 15; transform: translateX(-100%); transition: transform .2s ease; }
  .shell.drawer .side { transform: none; }
  .shell.drawer .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 14; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 8px 12px; }
  .model-pick { max-width: 140px; }
  .thread-inner { padding: 20px 16px 8px; }
  .composer { padding: 6px 12px max(12px, env(safe-area-inset-bottom)); }
  .page-inner { padding: 20px 16px 40px; }
  .msg.user { max-width: 92%; }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }

/* logo Chatatan Group */
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { height: 54px; width: auto; display: block; }
.brand span { font: 600 12px/1 var(--sans); color: var(--brass); border: 1px solid var(--brass); border-radius: 6px; padding: 4px 7px; }
.login .brand img { height: 110px; }
.login .brand span { font-size: 14px; }
@media (prefers-color-scheme: light) { .brand img { filter: invert(1); } }
.msg.assistant { grid-template-columns: 36px 1fr; }
.msg.assistant .dot { width: 36px; height: 36px; margin-top: 0; object-fit: contain; background: var(--raise); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
@media (prefers-color-scheme: light) { .msg.assistant .dot { filter: invert(1); background: #1f1e1b; border-color: #1f1e1b; } }
