/* Punter AI - minimalist UI. One accent, neutral palette, CSS variables for light/dark. */
:root {
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r-sm: 6px; --r: 10px; --r-lg: 16px; --r-full: 999px;
  --side-w: 264px; --content-w: 760px;
  --ease: 150ms ease;
  color-scheme: light;
  --bg: #ffffff; --bg-subtle: #f9f9fa; --surface: #ffffff; --surface-2: #f4f4f5; --hover: #f1f1f3;
  --border: #e7e7ea; --border-strong: #d4d4d8;
  --text: #18181b; --text-2: #3f3f46; --muted: #71717a; --faint: #a1a1aa;
  --accent: #4f46e5; --accent-hover: #4338ca; --accent-soft: #eef0ff; --accent-fg: #ffffff;
  --danger: #dc2626; --danger-soft: #fef2f2; --ok: #16a34a; --ok-soft: #f0fdf4; --warn: #b45309;
  --overlay: rgba(9, 9, 11, .4);
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111113; --bg-subtle: #161618; --surface: #18181b; --surface-2: #222226; --hover: #232327;
  --border: #2a2a2e; --border-strong: #3a3a40;
  --text: #f4f4f5; --text-2: #d4d4d8; --muted: #a1a1aa; --faint: #71717a;
  --accent: #818cf8; --accent-hover: #a5b4fc; --accent-soft: #1f1d3d; --accent-fg: #0b0b0f;
  --danger: #f87171; --danger-soft: #2a1515; --ok: #4ade80; --ok-soft: #12261a; --warn: #fbbf24;
  --overlay: rgba(0, 0, 0, .6);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.6 var(--font); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; line-height: 1.3; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 15px; } h4 { font-size: 13px; color: var(--text-2); margin: var(--s5) 0 var(--s2); }
p { margin: var(--s2) 0; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s3) 0; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: var(--r-sm); }
::selection { background: var(--accent-soft); }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- form controls ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  padding: 8px 12px; min-height: 38px; transition: border-color var(--ease), box-shadow var(--ease);
}
textarea { line-height: 1.5; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: 16px; height: 16px; min-height: 0; padding: 0; accent-color: var(--accent); margin: 0; vertical-align: -3px; }
input[type=file] { padding: 6px; }
label { display: block; color: var(--muted); font-size: 12px; font-weight: 500; margin: var(--s3) 0 var(--s1); }
button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  background: var(--accent); color: var(--accent-fg); border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 0 14px; min-height: 36px; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background var(--ease), border-color var(--ease), color var(--ease);
}
button:hover { background: var(--accent-hover); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: default; }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
button.secondary:hover { background: var(--hover); }
button.ghost { background: transparent; color: var(--text-2); }
button.ghost:hover { background: var(--hover); color: var(--text); }
button.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
button.danger:hover { background: var(--danger); color: #fff; }
button.small { min-height: 28px; padding: 0 10px; font-size: 12.5px; }
button.icon { width: 36px; padding: 0; background: transparent; color: var(--text-2); }
button.icon:hover { background: var(--hover); color: var(--text); }
button.icon.sm { width: 28px; min-height: 28px; }
.full { width: 100%; }

/* theme toggle (icons swap via data-theme) */
.theme-toggle .sun { display: none; } [data-theme="dark"] .theme-toggle .sun { display: block; } [data-theme="dark"] .theme-toggle .moon { display: none; }

/* ---------- utilities ---------- */
.hidden { display: none !important; }
.muted { color: var(--muted); } .small-text { font-size: 12.5px; } .err { color: var(--danger); } .okc { color: var(--ok); }
.row { display: flex; gap: var(--s3); align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; min-width: 0; }
.row > .auto { flex: 0 0 auto; }
.row.center { align-items: center; }
.spacer { flex: 1 1 auto !important; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--s3); }
.stack > * + * { margin-top: var(--s3); }

/* ---------- cards, stats, tables, tags ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: var(--s5); margin-bottom: var(--s4); }
.card > h3:first-child { margin-bottom: var(--s3); }
.card .hint { color: var(--muted); font-size: 12.5px; margin-top: calc(-1 * var(--s2)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: var(--s4); display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 12.5px; }
.stat b { color: var(--text); font-size: 22px; font-weight: 600; letter-spacing: -.02em; line-height: 1.3; }
.stat .bar { margin: var(--s2) 0 var(--s1); }
.table-wrap { overflow-x: auto; margin: 0 calc(-1 * var(--s2)); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px var(--s2); border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--bg-subtle); }
td .row { flex-wrap: nowrap; gap: var(--s1); justify-content: flex-end; }
.tag { display: inline-flex; align-items: center; background: var(--surface-2); color: var(--text-2); border-radius: var(--r-full); padding: 0 8px; font-size: 11.5px; line-height: 20px; margin: 1px 2px 1px 0; white-space: nowrap; }
.tag.admin { background: var(--accent-soft); color: var(--accent); }
.tag.off { background: var(--danger-soft); color: var(--danger); }
.tag.on { background: var(--ok-soft); color: var(--ok); }
.bar { height: 6px; background: var(--surface-2); border-radius: var(--r-full); overflow: hidden; min-width: 80px; }
.bar > div { height: 100%; background: var(--accent); border-radius: var(--r-full); }
.checks { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); padding: var(--s1) 0; }
.checks label { display: inline-flex; gap: var(--s2); align-items: center; color: var(--text); font-size: 13px; font-weight: 400; margin: 0; }
label.inline { display: inline-flex; gap: var(--s2); align-items: center; color: var(--text-2); font-size: 13px; font-weight: 400; margin: 0; min-height: 38px; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--s3); overflow: auto; font: 12.5px/1.55 var(--mono); }

/* ---------- toast & modal ---------- */
#toast { position: fixed; left: 50%; bottom: var(--s5); transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--s2); z-index: 100; width: max-content; max-width: calc(100vw - 32px); }
#toast div { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--r); font-size: 13.5px; }
#toast div.e { background: var(--danger); color: #fff; }
.modal-bg { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center; z-index: 60; padding: var(--s4); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s5); width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.modal > h3 { font-size: 16px; margin-bottom: var(--s3); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s5); }

/* ---------- login ---------- */
.corner { position: fixed; top: var(--s4); right: var(--s4); }
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: var(--s5); background: var(--bg-subtle); }
.login { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s6); }
.brand-mark { width: 36px; height: 36px; border-radius: var(--r); background: var(--accent); color: var(--accent-fg); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; }
.login h1 { margin-top: var(--s4); font-size: 22px; }
.login .sub { color: var(--muted); margin: var(--s1) 0 var(--s5); }
.login button[type=submit] { margin-top: var(--s5); min-height: 40px; }
.login #msg { min-height: 1.6em; margin: var(--s3) 0 0; font-size: 13px; }
.foot-note { text-align: center; color: var(--faint); font-size: 12px; margin-top: var(--s5); }

/* ---------- shared shell (chat + admin) ---------- */
.shell { display: flex; height: 100%; }
.side { width: var(--side-w); flex: none; background: var(--bg-subtle); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s3) var(--s2); }
.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 600; font-size: 15px; color: var(--text); padding: 0 var(--s1); flex: 1; }
.brand .brand-mark { width: 26px; height: 26px; font-size: 13px; border-radius: 7px; }
.side-body { flex: 1; overflow-y: auto; padding: var(--s2) var(--s2); }
.side-foot { border-top: 1px solid var(--border); padding: var(--s2); }
.nav-item { display: flex; align-items: center; gap: var(--s3); width: 100%; padding: 8px 10px; border-radius: var(--r-sm); color: var(--text-2); cursor: pointer; text-decoration: none; background: none; border: 0; min-height: 0; font-weight: 400; font-size: 13.5px; justify-content: flex-start; }
.nav-item:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--surface-2); color: var(--text); font-weight: 500; }
.nav-item svg.i { width: 17px; height: 17px; color: var(--muted); }
.nav-label { font-size: 11.5px; color: var(--faint); font-weight: 500; padding: var(--s4) 10px var(--s1); text-transform: uppercase; letter-spacing: .05em; }
.user-chip { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) 10px; }
.avatar { width: 28px; height: 28px; border-radius: var(--r-full); background: var(--accent-soft); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12.5px; flex: none; text-transform: uppercase; }
.user-chip .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s4); min-height: 56px; border-bottom: 1px solid var(--border); background: var(--bg); }
.topbar .title { font-weight: 600; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }
.scrim { display: none; }

/* ---------- chat ---------- */
.conv-group { font-size: 11.5px; color: var(--faint); font-weight: 500; padding: var(--s4) 10px var(--s1); }
.conv { display: flex; align-items: center; gap: var(--s1); padding: 7px 6px 7px 10px; border-radius: var(--r-sm); cursor: pointer; color: var(--text-2); font-size: 13.5px; }
.conv:hover { background: var(--hover); color: var(--text); }
.conv.active { background: var(--surface-2); color: var(--text); }
.conv span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv button { visibility: hidden; }
.conv:hover button, .conv.active button { visibility: visible; }
.conv-search { margin: 0 var(--s1) var(--s1); width: calc(100% - 8px); min-height: 34px; font-size: 13px; background: var(--bg); }
.model-select { width: auto; max-width: 340px; border-color: transparent; background: transparent; font-weight: 600; font-size: 15px; padding: 6px 28px 6px 8px; cursor: pointer; }
.model-select:hover { background: var(--hover); }
.model-select:focus { box-shadow: none; border-color: var(--border-strong); }
.model-info { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.msgs { flex: 1; overflow-y: auto; padding: var(--s6) var(--s4) var(--s4); }
.thread { max-width: var(--content-w); margin: 0 auto; }
.msg { margin-bottom: var(--s6); }
.msg .who { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: var(--s1); }
.msg .body { overflow-wrap: anywhere; line-height: 1.7; font-size: 15px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .who { display: none; }
.msg.user .body { background: var(--surface-2); border-radius: 18px; padding: 10px 16px; max-width: 85%; white-space: pre-wrap; }
.msg.user .meta { justify-content: flex-end; }
.msg .body pre { margin: var(--s3) 0; }
.msg .body pre code { background: none; padding: 0; font-size: 13px; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: var(--s2); display: flex; gap: var(--s2) var(--s4); flex-wrap: wrap; align-items: center; }
.msg .meta a { display: inline-flex; align-items: center; gap: 5px; color: var(--text-2); border: 1px solid var(--border); border-radius: var(--r-full); padding: 2px 10px; font-size: 12px; }
.msg .meta a:hover { background: var(--hover); text-decoration: none; color: var(--text); }
.msg .meta a svg.i { width: 14px; height: 14px; }
.msg details { font-size: 13px; color: var(--muted); margin-bottom: var(--s2); border-left: 2px solid var(--border); padding-left: var(--s3); }
.msg details summary { cursor: pointer; }
.msg details div { white-space: pre-wrap; margin-top: var(--s1); }
.typing { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.empty { text-align: center; margin-top: 18vh; }
.empty h2 { font-size: 26px; font-weight: 600; }
.empty p { color: var(--muted); }
.composer-wrap { padding: 0 var(--s4) var(--s4); }
.composer { max-width: var(--content-w); margin: 0 auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg); padding: var(--s2); transition: border-color var(--ease), box-shadow var(--ease); }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea { border: 0; background: transparent; resize: none; min-height: 44px; max-height: 240px; padding: var(--s2) var(--s2); box-shadow: none; font-size: 15px; }
.composer textarea:focus { box-shadow: none; }
.composer-bar { display: flex; align-items: center; gap: var(--s2); }
.composer-bar .grow { flex: 1; color: var(--faint); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.send-btn { width: 36px; padding: 0; border-radius: var(--r-full); }
.chips { display: flex; gap: var(--s2); flex-wrap: wrap; padding: var(--s1) var(--s1) 0; }
.chip { display: inline-flex; align-items: center; gap: var(--s2); background: var(--surface-2); border-radius: var(--r-sm); padding: 4px 6px 4px 10px; font-size: 12.5px; max-width: 260px; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { width: 22px; min-height: 22px; }
.disclaimer { max-width: var(--content-w); margin: var(--s2) auto 0; text-align: center; color: var(--faint); font-size: 11.5px; }

/* ---------- admin ---------- */
.content { flex: 1; overflow-y: auto; }
.content-inner { max-width: 1200px; margin: 0 auto; padding: var(--s5) var(--s5) var(--s7); }
.section-title { margin: var(--s2) 0 var(--s3); font-size: 15px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .menu-btn { display: inline-flex; }
  .side { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform 200ms ease; background: var(--bg); }
  .shell.nav-open .side { transform: none; }
  .shell.nav-open .scrim { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 30; }
  .content-inner { padding: var(--s4) var(--s4) var(--s6); }
  .card { padding: var(--s4); }
  .msgs { padding: var(--s5) var(--s3) var(--s3); }
  .composer-wrap { padding: 0 var(--s2) var(--s2); }
  .msg.user .body { max-width: 92%; }
  .model-info { display: none; }
  .login { padding: var(--s5); }
}
.qr { display: inline-block; background: #fff; padding: var(--s2); border-radius: var(--r); border: 1px solid var(--border); margin: var(--s2) 0; }
.qr img { display: block; }
.modal .row { margin-top: var(--s3); }

/* ---------- brand logos: swap by theme (theme.js sets data-theme before first paint) ---------- */
:root:not([data-theme="dark"]) .logo-for-dark { display: none !important; }
[data-theme="dark"] .logo-for-light { display: none !important; }
@media (prefers-color-scheme: dark) {   /* no-JS fallback follows the OS */
  :root:not([data-theme]) .logo-for-light { display: none !important; }
  :root:not([data-theme]) .logo-for-dark { display: revert !important; }
}
.logo-mark { width: 28px; height: 28px; object-fit: contain; flex: none; }
.login-logo { display: flex; justify-content: center; margin: calc(-1 * var(--s2)) 0 var(--s4); }
.login-logo img { width: 200px; height: auto; }
.login h1 { text-align: center; margin-top: var(--s2); }
.login .sub { text-align: center; }
