/* One restrained palette, defined once in light and inverted once in dark.
   Colour is spent only on status; everything structural is neutral. */
:root {
  color-scheme: light dark;
  --bg: #faf9f8;
  --panel: #ffffff;
  --sunken: #f5f4f2;
  --line: #e7e4e0;
  --line-soft: #efedea;
  --ink: #1a1917;
  --ink-2: #57534e;
  --muted: #8b857e;
  --accent: #1a1917;
  --accent-ink: #ffffff;
  --focus: #7c8cf8;
  --ok: #4a7c59;
  --warn: #8a6a2f;
  --off: #9a948c;
  --bad: #a1544a;
  --shadow: 0 1px 2px rgba(26, 25, 23, .04), 0 8px 24px -12px rgba(26, 25, 23, .12);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131315;
    --panel: #1a1a1d;
    --sunken: #202024;
    --line: #2e2e34;
    --line-soft: #26262b;
    --ink: #eceae7;
    --ink-2: #b5b0aa;
    --muted: #8a857e;
    --accent: #eceae7;
    --accent-ink: #131315;
    --focus: #8fa0ff;
    --ok: #7fb08f;
    --warn: #c39a55;
    --off: #7c7770;
    --bad: #d08b80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  height: 52px; padding: 0 24px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 13px; font-weight: 600; letter-spacing: -0.005em; }
.brand .sep { color: var(--muted); margin: 0 7px; font-weight: 400; }
.brand .area { color: var(--muted); font-weight: 500; }
.who { margin-left: auto; font-size: 12.5px; color: var(--muted); }

/* Environment switch: two segments, the live one filled. Dev is outlined
   rather than a different hue — the signal is "which one is solid", which
   survives both themes and colour-blindness. */
.envswitch { display: inline-flex; gap: 2px; padding: 2px; margin-left: 14px;
             background: var(--sunken); border: 1px solid var(--line); border-radius: 8px; }
.envswitch button {
  font: inherit; font-size: 12px; letter-spacing: 0.02em;
  padding: 3px 10px; border: 0; border-radius: 6px;
  /* The inactive segment is quieter than the live one but still plainly
     readable: misreading which environment you are in is the one mistake
     this control exists to prevent, so it does not get --muted. */
  background: none; color: var(--ink-2); cursor: pointer;
}
.envswitch button:hover { color: var(--ink); background: var(--panel); }
.envswitch button[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink);
}
/* On dev the whole bar carries a marker, so the difference is visible even
   from the corner of the eye. */
body[data-env="dev"] .topbar { box-shadow: inset 0 -2px 0 var(--warn); }

/* ---- page ---- */
main { max-width: 1120px; margin: 0 auto; padding: 32px 24px 64px; }
.page-head { margin-bottom: 24px; }
h1 { margin: 0 0 6px; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.lede { margin: 0; color: var(--ink-2); max-width: 62ch; }

/* ---- stats ---- */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 24px;
}
.stat { background: var(--panel); padding: 14px 16px; }
.stat dt { font-size: 11.5px; font-weight: 500; color: var(--muted);
           text-transform: uppercase; letter-spacing: 0.07em; margin: 0 0 4px; }
.stat dd { margin: 0; font-size: 22px; font-weight: 550; letter-spacing: -0.02em;
           font-variant-numeric: tabular-nums; }
.stat dd small { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 3px; }

/* ---- panel + table ---- */
.panel { background: var(--panel); border: 1px solid var(--line);
         border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 12px;
              padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 13.5px; font-weight: 600; }
.panel-head .count { color: var(--muted); font-weight: 400; }
.panel-head .spacer { margin-left: auto; }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 11px 16px; white-space: nowrap;
         border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
th { font-size: 11.5px; font-weight: 500; color: var(--muted);
     text-transform: uppercase; letter-spacing: 0.07em; background: var(--sunken); }
tbody tr:last-child > td { border-bottom: 0; }
tbody tr:hover > td { background: color-mix(in srgb, var(--sunken) 60%, transparent); }
td.code { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
          font-size: 13px; letter-spacing: 0.03em; }
td.num { font-variant-numeric: tabular-nums; }
td.note { white-space: normal; min-width: 180px; max-width: 280px; color: var(--ink-2); }
td.dim { color: var(--muted); }
td.actions { text-align: right; padding-left: 8px; padding-right: 12px; }

/* Seat meter: the number is the fact, the bar is the glance. <progress>
   rather than a hand-built bar — it carries the value in an attribute, so
   nothing here needs an inline style the CSP would have to allow. */
progress.meter { -webkit-appearance: none; appearance: none; border: 0;
                 width: 54px; height: 3px; margin-left: 8px; vertical-align: middle;
                 border-radius: 2px; background: var(--line); overflow: hidden; }
progress.meter::-webkit-progress-bar { background: var(--line); }
progress.meter::-webkit-progress-value { background: var(--ink-2); border-radius: 2px; }
progress.meter::-moz-progress-bar { background: var(--ink-2); border-radius: 2px; }

.status { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.active { color: var(--ok); }
.status.exhausted { color: var(--warn); }
.status.expired { color: var(--off); }
.status.revoked { color: var(--bad); }

/* ---- buttons ---- */
button {
  font: inherit; cursor: pointer; border-radius: 7px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 6px 12px; transition: background .12s, border-color .12s, color .12s;
}
button:hover { background: var(--sunken); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { opacity: .88; }
button.ghost { border-color: transparent; background: none; color: var(--muted);
               padding: 4px 6px; font-size: 12.5px; }
button.ghost:hover { background: var(--sunken); color: var(--ink); }
button.ghost.bad:hover { color: var(--bad); }
.actions button + button { margin-left: 2px; }

/* ---- states ---- */
.state { padding: 44px 16px; text-align: center; color: var(--muted); }
.state strong { display: block; color: var(--ink-2); font-weight: 550; margin-bottom: 4px; }

tr.redemptions > td { background: var(--sunken); white-space: normal; padding: 14px 16px 16px; }
.redemptions h3 { margin: 0 0 8px; font-size: 11.5px; font-weight: 500; color: var(--muted);
                  text-transform: uppercase; letter-spacing: 0.07em; }
.redemptions ul { margin: 0; padding: 0; list-style: none;
                  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 4px 20px; }
.redemptions li { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
                  font-size: 12.5px; color: var(--ink-2); }
.redemptions li span { color: var(--muted); font-family: inherit; }
.redemptions .meta { color: var(--ink-2); font-size: 13px; margin-bottom: 12px; }
.redemptions h3 + .meta { margin-top: -2px; }

/* ---- dialogs (native <dialog>, no library) ---- */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0;
  background: var(--panel); color: var(--ink); box-shadow: var(--shadow);
  width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(26, 25, 23, .32); backdrop-filter: blur(2px); }
dialog h2 { margin: 0; padding: 16px 18px 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
dialog .hint { margin: 6px 18px 0; color: var(--ink-2); font-size: 13px; }
dialog .body { padding: 14px 18px 4px; display: grid; gap: 12px; }
dialog footer { display: flex; justify-content: flex-end; gap: 8px;
                padding: 14px 18px; margin-top: 8px; border-top: 1px solid var(--line-soft); }
.field { display: grid; gap: 5px; }
.field > span { font-size: 12px; color: var(--muted); }
.field .help { font-size: 12px; color: var(--muted); }
input {
  font: inherit; width: 100%; padding: 8px 10px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
input::placeholder { color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---- toast ---- */
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 20;
  max-width: min(380px, calc(100vw - 40px));
  padding: 11px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel);
  box-shadow: var(--shadow); font-size: 13px;
}
.toast.err { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); color: var(--bad); }
.toast.ok { color: var(--ink-2); }

@media (max-width: 620px) {
  main { padding: 24px 14px 48px; }
  .topbar { padding: 0 14px; }
}
