/* BAB Gate Tracker: shared styles. Light and dark follow the device setting. */
:root {
  --bg: #F4F3F1; --panel: #FFFFFF; --panel-2: #FAF9F7; --ink: #1B1A18; --muted: #66625C; --line: #E0DDD7;
  --accent: #B8400E; --accent-ink: #FFFFFF; --accent-soft: #FBE9DD;
  --ok: #17753A; --ok-soft: #DDF2E3; --bad: #B3261E; --bad-soft: #FAE3E0; --warn: #8A5A00; --warn-soft: #FDEFC8;
  --info: #1F5FA8; --info-soft: #E0ECFA;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110; --panel: #1B1A18; --panel-2: #211F1D; --ink: #EFECE7; --muted: #A39E96; --line: #33302C;
    --accent: #F0894A; --accent-ink: #1C0E04; --accent-soft: #3B2414;
    --ok: #57C781; --ok-soft: #14311F; --bad: #F2867C; --bad-soft: #3B1B18; --warn: #E9B24C; --warn-soft: #382C10;
    --info: #7FB2F0; --info-soft: #16283D;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 20px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--accent); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px 56px; }
.narrow { max-width: 440px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.stack { display: grid; gap: 12px; }
.stack-lg { display: grid; gap: 20px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.row > .grow { flex: 1 1 160px; min-width: 0; }
.between { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; }
.cols { display: grid; gap: 20px; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); align-items: start; }
@media (max-width: 820px) { .cols { grid-template-columns: minmax(0, 1fr); } }

.topbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding: 14px 0; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand b { font-size: 18px; letter-spacing: -.01em; }
.brand span { color: var(--muted); font-size: 13px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card > h2, .card > h3 { margin-bottom: 4px; }
.card .lead { color: var(--muted); font-size: 13px; margin-bottom: 12px; max-width: 70ch; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%; min-width: 0; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn { font: inherit; font-weight: 600; background: var(--accent); color: var(--accent-ink); border: 1px solid transparent; border-radius: 8px; padding: 9px 14px; cursor: pointer; text-decoration: none; display: inline-block; text-align: center; white-space: nowrap; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { display: block; width: 100%; }

.list { display: grid; gap: 6px; }
.item { display: flex; gap: 8px; align-items: center; justify-content: space-between; width: 100%; text-align: left; font: inherit; color: var(--ink); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; cursor: pointer; min-width: 0; }
.item > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.item small { display: block; color: var(--muted); }
.item[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.plain { background: var(--line); color: var(--ink); }

.note { border-radius: 8px; padding: 10px 12px; font-size: 14px; background: var(--info-soft); color: var(--ink); overflow-wrap: anywhere; }
.note.warn { background: var(--warn-soft); }
.note.bad { background: var(--bad-soft); }
.note.ok { background: var(--ok-soft); }
.note b.mono { font-size: 14px; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { font: inherit; font-weight: 600; background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); padding: 8px 12px; cursor: pointer; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

.scroll { overflow-x: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
td.wrapcell { white-space: normal; }
.empty { color: var(--muted); text-align: center; padding: 22px 10px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi b { display: block; font-size: 30px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 13px; color: var(--muted); }
.kpi.main { background: var(--accent-soft); border-color: transparent; }
.kpi.main b { color: var(--accent); }
.meter { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.meter.warn i { background: var(--warn); } .meter.bad i { background: var(--bad); }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; border-bottom: 1px solid var(--line); }
.chart .col { flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.chart .bar { width: 42%; max-width: 26px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bar.e { background: var(--accent); } .bar.x { background: var(--muted); }
.axis { display: flex; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 4px; }
.axis span { flex: 1 1 0; min-width: 0; text-align: center; overflow: hidden; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }

.qrbox { background: #fff; border-radius: 8px; padding: 6px; width: 180px; max-width: 100%; line-height: 0; border: 1px solid var(--line); }
.qrbox svg { width: 100%; height: auto; display: block; }
.linkbox { font-family: var(--mono); font-size: 13px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; overflow-wrap: anywhere; user-select: all; }

.toasts { position: fixed; left: 0; right: 0; bottom: 16px; display: grid; justify-items: center; gap: 8px; pointer-events: none; z-index: 50; padding: 0 16px; }
.toast { background: var(--ink); color: var(--bg); border-radius: 8px; padding: 9px 14px; font-size: 14px; max-width: 520px; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); }
.toast.bad { background: var(--bad); color: #fff; }
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: grid; place-items: center; padding: 16px; z-index: 40; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; width: 100%; max-width: 420px; display: grid; gap: 14px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- print sheet ---------- */
.tags { display: flex; flex-wrap: wrap; gap: 3mm; }
.tag { width: var(--tag, 32mm); padding: 1mm; text-align: center; background: #fff; color: #000; border: 0.2mm dashed #9a9a9a; break-inside: avoid; page-break-inside: avoid; }
.tags.nocut .tag { border-color: transparent; }
.tag svg { width: 100%; height: auto; display: block; }
.tag b { display: block; font: 700 4.2mm/1.15 var(--font); }
.tag span { display: block; font: 2.3mm/1.3 var(--mono); letter-spacing: .02em; }
@media print {
  .noprint { display: none !important; }
  body { background: #fff; }
  .wrap { max-width: none; padding: 0; }
  @page { margin: 8mm; }
}

/* ---------- gate scanner (always dark: venues are dark and it saves battery) ---------- */
body.gate {
  --bg: #0E0E0D; --panel: #1A1917; --panel-2: #23211F; --ink: #F3F0EB; --muted: #A8A39B; --line: #37342F;
  --accent: #F0894A; --accent-ink: #1C0E04; --accent-soft: #3B2414;
  --ok: #57C781; --ok-soft: #14311F; --bad: #F2867C; --bad-soft: #3B1B18; --warn: #E9B24C; --warn-soft: #382C10;
  --info: #7FB2F0; --info-soft: #16283D;
  color-scheme: dark;
}
body.gate .wrap { max-width: 520px; padding-bottom: 40px; }
.g-head { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 0; }
.g-head .who { min-width: 0; }
.g-head .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-head .who span { color: var(--muted); font-size: 13px; }
.g-count { text-align: right; white-space: nowrap; }
.g-count b { font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; }
.g-count span { display: block; color: var(--muted); font-size: 12px; }
.g-count.full b { color: var(--bad); }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.modes button { font: inherit; font-weight: 700; padding: 12px 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); cursor: pointer; }
.modes button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.cam { position: relative; background: #000; border-radius: 14px; overflow: hidden; aspect-ratio: 4 / 3; max-width: 100%; }
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam .aim { position: absolute; inset: 12% 22%; border: 3px solid rgba(255, 255, 255, .75); border-radius: 14px; pointer-events: none; }
.cam .cam-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 18px; color: #fff; background: rgba(0, 0, 0, .72); font-size: 14px; }
.cam .torch { position: absolute; right: 8px; bottom: 8px; }
.result { border-radius: 14px; padding: 16px 14px; text-align: center; min-height: 112px; display: grid; align-content: center; gap: 4px; border: 2px solid var(--line); background: var(--panel); }
.result .big { font-size: 30px; font-weight: 800; letter-spacing: -.01em; line-height: 1.1; }
.result .sub { font-size: 15px; }
.result.ok { background: #0F5C2C; border-color: #57C781; color: #fff; }
.result.exit { background: #164A86; border-color: #7FB2F0; color: #fff; }
.result.warn { background: #7A5200; border-color: #E9B24C; color: #fff; }
.result.bad { background: #8E1C16; border-color: #F2867C; color: #fff; }
.result.idle { color: var(--muted); }
.result.old { opacity: .55; }
.recent { display: grid; gap: 4px; font-size: 13px; }
.recent div { display: flex; gap: 8px; justify-content: space-between; padding: 6px 10px; border-radius: 8px; background: var(--panel); }
@media (prefers-reduced-motion: no-preference) { .result { transition: background-color .12s, border-color .12s, opacity .4s; } }
