:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --ink: #1b2130; --muted: #5d6475;
  --line: #e3e6ec; --brand: #e63946; --brand-ink: #b3202d; --ok: #1f7a3a; --ok-bg: #e4f5e9;
  --warn: #8a5a00; --warn-bg: #fff3d6; --bad: #b3261e; --bad-bg: #fde7e5; --info-bg: #e8f0fe; --info: #1a4fa0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151c; --surface: #1b1f29; --surface-2: #232836; --ink: #e8eaf0; --muted: #a0a7b8;
    --line: #2e3445; --brand: #ff5d6a; --brand-ink: #ff8a93; --ok: #7fd89a; --ok-bg: #173522;
    --warn: #ffd27a; --warn-bg: #3a2c0c; --bad: #ff8a80; --bad-bg: #3d1a18; --info-bg: #1b2a45; --info: #9cc2ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151c; --surface: #1b1f29; --surface-2: #232836; --ink: #e8eaf0; --muted: #a0a7b8;
  --line: #2e3445; --brand: #ff5d6a; --brand-ink: #ff8a93; --ok: #7fd89a; --ok-bg: #173522;
  --warn: #ffd27a; --warn-bg: #3a2c0c; --bad: #ff8a80; --bad-bg: #3d1a18; --info-bg: #1b2a45; --info: #9cc2ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand-ink); }
h1 { font-size: 24px; margin: 0; letter-spacing: -.3px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.loading { padding: 64px; text-align: center; color: var(--muted); }

/* layout */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-inner { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; min-height: 60px; flex-wrap: wrap; }
.brand { font-weight: 800; display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 26px; height: 26px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; color: #fff; font-size: 15px; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs a { text-decoration: none; color: var(--muted); font-weight: 600; padding: 8px 12px; border-radius: 8px; white-space: nowrap; }
.tabs a.on { color: var(--ink); background: var(--surface-2); }
.who { color: var(--muted); font-size: 14px; display: flex; gap: 12px; align-items: center; }
main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.stat .n { font-size: 28px; font-weight: 800; letter-spacing: -.5px; }
.stat .l { color: var(--muted); font-size: 13.5px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sub { color: var(--muted); font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* bits */
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.notice { background: var(--info-bg); color: var(--info); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
button, .btn { font: inherit; font-weight: 700; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: var(--surface-2); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { filter: brightness(.95); background: var(--brand); }
button.link { border: 0; background: none; color: var(--brand-ink); padding: 4px 6px; }
button.link.danger { color: var(--bad); padding-left: 0; }
.delete-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 22px; }
tr[hidden] { display: none; }
button:disabled { opacity: .6; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
label.field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; }
textarea { resize: vertical; min-height: 70px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--surface-2); border-radius: 10px; padding: 12px; word-break: break-all; white-space: pre-wrap; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
.swatch { width: 44px; height: 38px; padding: 2px; }

/* mascot picker */
.mascot-picker { border: 0; padding: 0; margin: 0; min-width: 0; }
.mascot-picker legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 4px; }
.mascot-picker .hint { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.mascot-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px; }
.mascot-option { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px 8px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; font-size: 13px; font-weight: 600; text-align: center; }
.mascot-option input { position: absolute; opacity: 0; pointer-events: none; width: auto; }
.mascot-option:hover { border-color: var(--muted); }
.mascot-option:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.mascot-option:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }
.mascot-option svg { display: block; }

/* transcript */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 620px; overflow-y: auto; padding: 4px; }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.assistant { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 5px; }
.bubble.shopper { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 5px; }
.bubble.event { align-self: center; background: none; color: var(--muted); font-size: 12.5px; font-style: italic; padding: 2px; }

/* outbox */
.msg { border-top: 1px solid var(--line); padding: 14px 0; }
.msg:first-child { border-top: 0; padding-top: 0; }
.msg-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.msg pre { margin: 0; white-space: pre-wrap; word-wrap: break-word; font: 13.5px/1.45 ui-sans-serif, system-ui, sans-serif; color: var(--ink); background: var(--surface-2); padding: 10px 12px; border-radius: 10px; max-height: 260px; overflow: auto; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { margin-bottom: 4px; }
.login form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.err { color: var(--bad); font-size: 14px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(100px); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; transition: transform .25s; max-width: calc(100vw - 32px); z-index: 20; }
#toast.show { transform: translateX(-50%) translateY(0); }
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 22px; background: var(--surface); color: var(--ink); width: min(640px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 12, 18, .45); }

/* login extras and the paused notice */
.login-links { margin-top: 14px; font-size: 14px; text-align: center; }
.login .note { color: var(--ok); font-size: 14px; min-height: 1em; }
.paused { background: var(--warn-bg); color: var(--warn); padding: 10px 16px; text-align: center; font-weight: 600; }
.paused a { color: inherit; }
