/* Mitra Cafe Super Admin console. Tokens first; dark mode redefines them. */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e1e4ea;
  --border-strong: #c9ced8;
  --text: #15171c;
  --text-2: #4a4f5c;
  --muted: #6b7180;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fb;
  --focus: #2a78d6;
  --series: #2a78d6;
  --good: #0a7d0a;
  --good-soft: #e3f5e3;
  --warn: #8a5a00;
  --warn-soft: #fff3d6;
  --bad: #b42323;
  --bad-soft: #fde7e7;
  --info: #1e5fae;
  --info-soft: #e6f0fb;
  --neutral-soft: #eceef2;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111214;
    --surface: #1a1b1e;
    --surface-2: #212226;
    --border: #2e3036;
    --border-strong: #42454d;
    --text: #f2f3f5;
    --text-2: #c3c6ce;
    --muted: #9599a3;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --accent-soft: #1b2c44;
    --focus: #6aa6ee;
    --series: #3987e5;
    --good: #5fd35f;
    --good-soft: #15301a;
    --warn: #f7c04a;
    --warn-soft: #3a2e10;
    --bad: #ff7b7b;
    --bad-soft: #3d1a1a;
    --info: #8dbcf3;
    --info-soft: #1b2c44;
    --neutral-soft: #2a2c31;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111214;
  --surface: #1a1b1e;
  --surface-2: #212226;
  --border: #2e3036;
  --border-strong: #42454d;
  --text: #f2f3f5;
  --text-2: #c3c6ce;
  --muted: #9599a3;
  --accent: #3987e5;
  --accent-soft: #1b2c44;
  --focus: #6aa6ee;
  --series: #3987e5;
  --good: #5fd35f;
  --good-soft: #15301a;
  --warn: #f7c04a;
  --warn-soft: #3a2e10;
  --bad: #ff7b7b;
  --bad-soft: #3d1a1a;
  --info: #8dbcf3;
  --info-soft: #1b2c44;
  --neutral-soft: #2a2c31;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  overflow-x: hidden;
}
a { color: var(--accent); }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
code, pre, .mono { font-family: var(--mono); font-size: 0.85em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.noscript { padding: 2rem; }

/* ---------- shell ---------- */
.app { min-height: 100vh; }
.skip {
  position: absolute; left: 8px; top: -48px; z-index: 50;
  background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: var(--radius-sm);
}
.skip:focus { top: 8px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.brand small { color: var(--muted); font-weight: 500; }
.topbar .spacer { flex: 1; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 18ch; }
.countdown {
  font-variant-numeric: tabular-nums; font-size: 0.85rem; color: var(--text-2);
  background: var(--neutral-soft); border-radius: 999px; padding: 2px 10px; white-space: nowrap;
}
.countdown.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.menu-btn { display: none; }

.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.sidenav {
  border-right: 1px solid var(--border); background: var(--surface);
  padding: 12px 8px; position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto;
}
.sidenav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sidenav a {
  display: block; padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--text-2); text-decoration: none; font-weight: 500;
}
.sidenav a:hover { background: var(--surface-2); color: var(--text); }
.sidenav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidenav .nav-count {
  float: right; min-width: 1.6em; text-align: center; font-size: 0.75rem; font-weight: 700;
  background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: 0 6px;
}

main { padding: 24px; min-width: 0; max-width: 1280px; width: 100%; }
main:focus { outline: none; }

@media (max-width: 860px) {
  .menu-btn { display: inline-flex; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidenav {
    position: fixed; top: 56px; left: 0; bottom: 0; width: 240px; z-index: 15; height: auto;
    transform: translateX(-100%); transition: transform 0.15s ease; box-shadow: var(--shadow);
  }
  .sidenav.open { transform: none; }
  main { padding: 16px; }
  .who-name { display: none; }
  .brand small { display: none; }
}

/* ---------- page furniture ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 20px; }
.page-head h1 { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.page-head .sub { color: var(--muted); font-size: 0.9rem; width: 100%; }
.crumbs { font-size: 0.85rem; margin-bottom: 6px; }
.section { margin-top: 28px; }
.section > h2 { margin-bottom: 10px; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }
.section-head h2 { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stack { display: grid; gap: 12px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; min-width: 0;
}
.card h2, .card h3 { margin-bottom: 10px; }
.grid { display: grid; gap: 14px; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }

.stat { display: grid; gap: 4px; }
.stat .label { color: var(--text-2); font-size: 0.85rem; font-weight: 500; }
.stat .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat .hint { color: var(--muted); font-size: 0.8rem; }
a.stat { color: inherit; text-decoration: none; }
a.stat:hover .value { color: var(--accent); }

/* proportional bars (tenants per plan, capacity) */
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(70px, 120px) minmax(0, 1fr) 4ch; gap: 10px; align-items: center; font-size: 0.9rem; }
.bar-track { height: 10px; border-radius: 999px; background: var(--neutral-soft); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--series); min-width: 2px; }
.bar-fill.warn { background: #fab219; }
.bar-fill.bad { background: #d03b3b; }
.capacity { display: grid; gap: 4px; min-width: 120px; }
.capacity .bar-track { height: 8px; }

/* signups chart */
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--series); }
.chart .hit { fill: transparent; }
.chart .hit:hover + .bar, .chart g:hover .bar { opacity: 0.75; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart-tip { min-height: 1.4em; font-size: 0.85rem; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-2); background: var(--surface-2); white-space: nowrap; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { color: var(--muted); font-size: 0.8rem; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.load-more { display: flex; justify-content: center; margin-top: 14px; }

dl.kv { display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: 6px 16px; margin: 0; font-size: 0.92rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.chips + dl.kv { margin-top: 16px; }

pre.json {
  margin: 6px 0 0; padding: 10px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto;
}
details > summary { cursor: pointer; color: var(--accent); font-size: 0.85rem; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  padding: 1px 8px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  background: var(--neutral-soft); color: var(--text-2);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.warn::before { border-radius: 1px; transform: rotate(45deg); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.bad::before { border-radius: 1px; }
.badge.info { background: var(--info-soft); color: var(--info); }

/* ---------- forms & buttons ---------- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 0.9rem; line-height: 1.2;
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.06); background: var(--accent); }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.danger:hover { filter: brightness(1.06); background: var(--bad); }
button.ghost { border-color: transparent; background: transparent; }
button.small, .btn.small { padding: 5px 10px; font-size: 0.82rem; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 500; }
button.link:hover { text-decoration: underline; background: none; }

label { font-weight: 500; font-size: 0.88rem; color: var(--text-2); }
.field { display: grid; gap: 5px; min-width: 0; }
.field .help { font-size: 0.8rem; color: var(--muted); font-weight: 400; }
input, select, textarea {
  font: inherit; font-size: 0.95rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 8px 10px; width: 100%; min-width: 0;
}
textarea { min-height: 80px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); }
input:user-invalid, textarea:user-invalid { border-color: var(--bad); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { flex: 1 1 180px; }
.filters .actions { display: flex; gap: 8px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.error-text { color: var(--bad); font-size: 0.88rem; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a {
  padding: 8px 14px; color: var(--text-2); text-decoration: none; font-weight: 600; font-size: 0.9rem;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }

/* overrides editor */
.ovr-table td { vertical-align: middle; }
.ovr-table select { width: auto; min-width: 9rem; }
.ovr-table input[type="number"] { width: 8rem; }
.ovr-changed td { background: var(--warn-soft) !important; }
.tri { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.tri label { display: inline-flex; align-items: center; padding: 5px 10px; cursor: pointer; font-size: 0.82rem; border-left: 1px solid var(--border-strong); color: var(--text-2); }
.tri label:first-child { border-left: 0; }
.tri input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tri input:checked + span { font-weight: 700; color: var(--accent); }
.tri label:has(input:checked) { background: var(--accent-soft); }
.tri label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: -2px; }

.feature-list { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 0.8rem; padding: 2px 8px; border-radius: 999px; background: var(--neutral-soft); color: var(--text-2); }
.chip.on { background: var(--good-soft); color: var(--good); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { margin-bottom: 18px; font-size: 1.1rem; }
.login-card form { display: grid; gap: 14px; }
.login-card .note { font-size: 0.8rem; color: var(--muted); margin-top: 14px; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 32px));
  box-shadow: 0 10px 40px rgb(0 0 0 / 25%);
}
dialog::backdrop { background: rgb(10 12 16 / 55%); }
dialog form { padding: 20px; display: grid; gap: 14px; }
dialog .dialog-msg { color: var(--text-2); white-space: pre-line; }
dialog .form-actions { margin-top: 4px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); font-size: 0.9rem;
}
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }
.toast.warn { border-left-color: #fab219; }

.panel-msg { padding: 28px; text-align: center; color: var(--muted); }
.panel-msg.error { color: var(--bad); }
.loading::after { content: "Loading..."; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (forced-colors: active) {
  .bar-fill, .chart .bar { forced-color-adjust: none; background: CanvasText; fill: CanvasText; }
}
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
