:root {
  --ink: #17154e;
  --blue: #25206a;
  --gold: #f4b52a;
  --paper: #f7f5ec;
  --surface: #ffffff;
  --line: #e5dfc9;
  --line-strong: #c9bf9c;
  --text: #17154e;
  --muted: #5e5a78;
  --accent: #25206a;
  --accent-ink: #ffffff;
  --ok: #1e7e46;
  --warn: #a96a05;
  --bad: #b3261e;
  --focus: #d99a12;
  --radius: 8px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0d0c18;
    --surface: #17162b;
    --line: #302d51;
    --line-strong: #49446e;
    --text: #f3f0e4;
    --muted: #b7b2ca;
    --accent: #f4b52a;
    --accent-ink: #17154e;
    --ok: #52c585;
    --warn: #f0b34a;
    --bad: #ff8a80;
    --focus: #ffd775;
  }
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font: 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0; letter-spacing: -0.012em; line-height: 1.2; }
h1 { font-size: 1.65rem; font-weight: 750; }
h2 { font-size: 1.05rem; font-weight: 700; }
h3 { font-size: 0.95rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--ink);
  color: #e8eefb;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark { width: 34px; height: 34px; border-radius: 7px; background: var(--blue); position: relative; flex: none; display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 14px; }
.brand-mark::after { content: ""; position: absolute; left: 7px; right: 7px; bottom: 6px; height: 3px; background: var(--gold); }
.brand-name { font-weight: 750; font-size: 1.05rem; line-height: 1.15; }
.brand-sub { font-size: 0.78rem; color: #9db0cf; }
.nav-group { display: grid; gap: 2px; }
.nav-title { font-size: 0.78rem; color: #8ea3c6; padding: 6px 12px; font-weight: 600; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 6px;
  color: #d6e0f5; text-decoration: none; border-left: 3px solid transparent; font-weight: 500;
}
.nav-link:hover { background: rgba(255,255,255,0.07); }
.nav-link[aria-current="page"] { background: rgba(255,255,255,0.1); border-left-color: var(--gold); color: #fff; font-weight: 700; }
.nav-link .count { margin-left: auto; background: var(--gold); color: var(--ink); border-radius: 99px; font-size: 0.75rem; font-weight: 800; padding: 0 7px; min-width: 20px; text-align: center; }
.side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,0.12); display: grid; gap: 8px; }
.who { font-size: 0.85rem; overflow-wrap: anywhere; }
.who b { display: block; }
.who span { color: #9db0cf; }
.side .btn.ghost { color: #e8eefb; border-color: rgba(255,255,255,0.3); }
.side .btn.ghost:hover { background: rgba(255,255,255,0.08); }
.main { padding: 28px clamp(16px, 3.2vw, 40px) 64px; max-width: 1180px; width: 100%; }
.topbar { display: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); margin-top: 4px; max-width: 62ch; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  font-weight: 650; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn.ghost:hover { background: color-mix(in srgb, var(--text) 6%, transparent); filter: none; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost.danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 55%, transparent); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 0.88rem; }
.btn.link { background: none; border: none; color: var(--accent); padding: 0 4px; min-height: 0; font-weight: 600; }
.field { display: grid; gap: 5px; margin-bottom: 14px; }
.field > label, .field > .label { font-weight: 650; font-size: 0.9rem; }
.field .hint { color: var(--muted); font-size: 0.82rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"], input[type="search"], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 11px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
}
textarea { min-height: 96px; resize: vertical; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.switch {
  --w: 44px; position: relative; width: var(--w); height: 26px; border-radius: 99px; flex: none;
  background: var(--line-strong); border: none; cursor: pointer; padding: 0; transition: background 0.15s;
}
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.3); }
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.switch.warn[aria-checked="true"] { background: var(--bad); }
.switch:disabled { opacity: 0.5; cursor: not-allowed; }
@media (prefers-reduced-motion: reduce) { .switch, .switch::after { transition: none; } }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg button { border: none; background: none; padding: 8px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: none; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel + .panel { margin-top: 16px; }
.panel-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.panel-body { padding: 16px 18px; }
.rows > * + * { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 14px; padding: 13px 18px; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 650; }
.row .desc { color: var(--muted); font-size: 0.86rem; }
.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.cols > .panel + .panel { margin-top: 0; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.main > div { min-width: 0; }

.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 0.82rem; color: var(--muted); font-weight: 650; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: none; }
table.t td .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
table.t .cell-title { font-weight: 650; }
table.t .cell-sub { color: var(--muted); font-size: 0.85rem; }

.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 0.78rem; font-weight: 700; border: 1px solid transparent; white-space: nowrap; }
.pill.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }
.pill.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 13%, transparent); }
.pill.info { color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); }
.pill.neutral { color: var(--muted); background: color-mix(in srgb, var(--muted) 14%, transparent); }

/* The switchboard lamp: gold = live, ring = needs setup, grey = switched off. */
.lamp { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 2px solid var(--line-strong); background: transparent; }
.lamp.live { background: var(--gold); border-color: #c79a00; box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 30%, transparent); }
.lamp.off { background: var(--line-strong); border-color: var(--line-strong); }
.lamp.setup { border-style: dashed; }

.headline { display: flex; gap: 22px; flex-wrap: wrap; margin: 4px 0 18px; }
.headline .num { font-size: 2.3rem; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.headline .lbl { color: var(--muted); font-size: 0.86rem; margin-top: 4px; }
.maint { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); margin-bottom: 16px; border-left: 4px solid var(--ok); }
.maint.on { border-left-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, var(--surface)); }
.bar { height: 8px; background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.banner { padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); margin-bottom: 14px; }
.banner.ok { border-color: color-mix(in srgb, var(--ok) 50%, transparent); background: color-mix(in srgb, var(--ok) 10%, var(--surface)); }
.banner.bad { border-color: color-mix(in srgb, var(--bad) 50%, transparent); background: color-mix(in srgb, var(--bad) 9%, var(--surface)); }
.empty { padding: 36px 18px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--line), color-mix(in srgb, var(--line) 40%, var(--surface)), var(--line)); background-size: 200% 100%; animation: sk 1.2s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border: 1px solid var(--line-strong); border-radius: 99px; cursor: pointer; background: var(--surface); }
.chip:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.chip:has(input:disabled) { opacity: 0.55; cursor: not-allowed; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 180px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--ink); }
.login-card { width: min(420px, 100%); background: var(--surface); border-radius: 12px; padding: 30px 28px 26px; border-top: 5px solid var(--gold); }
.login-card h1 { margin: 18px 0 4px; }
.login-card .brand { padding: 0; }
.login-card .brand-name { color: var(--text); }
.login-card .brand-sub { color: var(--muted); }

/* ---------- dialog + toasts ---------- */
dialog { border: 1px solid var(--line-strong); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(8, 18, 36, 0.55); }
.dlg-head { padding: 18px 22px 0; }
.dlg-body { padding: 14px 22px 4px; overflow-y: auto; }
.dlg-foot { padding: 14px 22px 20px; display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: #fff; padding: 11px 14px; border-radius: var(--radius); border-left: 4px solid var(--gold); box-shadow: 0 6px 20px rgba(0,0,0,0.28); }
.toast.bad { border-left-color: var(--bad); }
.secret-box { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 1.15rem; letter-spacing: 0.04em; padding: 12px 14px; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--paper); overflow-wrap: anywhere; }

/* ---------- narrow screens ---------- */
@media (max-width: 899px) {
  .shell { display: block; }
  .side { position: fixed; z-index: 30; inset: 0 auto 0 0; width: min(290px, 86vw); height: 100dvh; transform: translateX(-102%); transition: transform 0.18s; }
  .side.open { transform: none; }
  @media (prefers-reduced-motion: reduce) { .side { transition: none; } }
  .scrim { position: fixed; inset: 0; background: rgba(8, 18, 36, 0.5); z-index: 20; }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 10; }
  .topbar .btn { background: transparent; border-color: rgba(255,255,255,0.35); color: #fff; min-height: 36px; }
  .topbar .brand-name { font-size: 1rem; }
  .main { padding-top: 20px; }
  .cols { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 1.4rem; }
  .row { padding: 12px 14px; flex-wrap: wrap; }
  .row .grow { flex: 1 1 190px; }
  .panel-head, .panel-body { padding-left: 14px; padding-right: 14px; }
  table.t th, table.t td { padding: 10px; }
}

/* ---------------------------------------------------------------- analytics */
.insight-section { margin: 0 0 30px; }
.section-title { font-size: 1.05rem; margin: 0 0 10px; letter-spacing: 0.01em; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi-num { font-size: 1.7rem; font-weight: 800; line-height: 1.05; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-label { color: var(--muted); font-size: 0.84rem; margin-top: 4px; }
.kpi-hint { color: var(--muted); font-size: 0.76rem; margin-top: 6px; border-top: 1px dashed var(--line); padding-top: 6px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.chart-card, .charts > .panel.chart-card { padding: 14px 16px; margin: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.chart-head h3 { margin: 0; font-size: 0.95rem; }
.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .col-bar { fill: var(--accent); }
.chart .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 20px; }
.tip { position: absolute; top: -6px; transform: translate(-50%, -100%); background: var(--text); color: var(--surface); font-size: 0.78rem; font-weight: 600; padding: 4px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none; }
.rank { display: grid; gap: 8px; }
.rank-row { display: grid; grid-template-columns: minmax(80px, 38%) 1fr auto; align-items: center; gap: 10px; font-size: 0.86rem; }
.rank-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-track { height: 10px; border-radius: 0 4px 4px 0; background: color-mix(in srgb, var(--line) 55%, transparent); }
.rank-bar { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.rank-value { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3ch; text-align: right; }

/* --------------------------------------------------------------------- shop */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.product { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.product-img { aspect-ratio: 4 / 3; background: linear-gradient(135deg, #25206a, #17154e); display: grid; place-items: center; color: var(--gold); font-size: 2.4rem; font-weight: 800; }
.product-img img { width: 100%; height: 100%; object-fit: cover; }
.product-body { padding: 12px 14px; display: grid; gap: 4px; }
.product-price { font-size: 1.15rem; font-weight: 800; margin: 4px 0; }
