/* =========================================================================
   لوحة البوّاب — gatekeeper console

   This file has three parts, in order:
     1. TOKENS + PRIMITIVES  — shared by both designs (colour, type, buttons)
     2. PHONE DESIGN         — @media (max-width: 999px): cards, bottom tabs,
                               finger-sized targets, one column
     3. DESKTOP DESIGN       — @media (min-width: 1000px): its own layout —
                               dense tables, two-pane pages, mouse-sized rows

   The two designs are separate on purpose. Nothing in part 3 is part 2 with
   bigger numbers, and nothing in part 2 is part 3 squeezed.

   Colour carries meaning and never decorates:
     emerald = allowed / live · rose = blocked · amber = waiting · sky = trusted
   ========================================================================= */

/* Self-hosted so it works under the panel's strict CSP and offline. */
@font-face {
  font-family: 'Cairo';
  font-style: normal;
  font-weight: 400 800;      /* variable file: one download covers every weight */
  font-display: swap;
  src: url('fonts/cairo-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC4, U+10EFC-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42, U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}
@font-face {
  font-family: 'Cairo';
  font-style: normal;
  font-weight: 400 800;      /* variable file: one download covers every weight */
  font-display: swap;
  src: url('fonts/cairo-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Cairo';
  font-style: normal;
  font-weight: 400 800;      /* variable file: one download covers every weight */
  font-display: swap;
  src: url('fonts/cairo-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* =========================================================================
   1. TOKENS + PRIMITIVES
   ========================================================================= */
:root {
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --t: 140ms cubic-bezier(.4, 0, .2, 1);

  --font: "Cairo", -apple-system, "SF Arabic", "Segoe UI", "Noto Sans Arabic", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;

  --tap: 44px;
  --topbar-h: 56px;
  --tabbar-h: 60px;

  /* One type scale. Every size in the phone design is one of these six. */
  --fs-hero: 28px;     /* the single number that matters on a screen */
  --fs-title: 20px;    /* page title */
  --fs-section: 16px;  /* card title */
  --fs-body: 15px;     /* sentences, list titles */
  --fs-meta: 13px;     /* secondary line, timestamps */
  --fs-micro: 11.5px;  /* chips, tab labels */

  /* One spacing scale: 4-point steps only. */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px;

  /* Three radii, by role. */
  --r-chip: 8px; --r-card: 12px; --r-pill: 999px;
}

[data-theme="dark"] {
  --ink: #0C131B;
  --surface: #141F2B;
  --raised: #1B2836;
  --line: #253647;
  --line-soft: #1E2C3B;
  --text: #E9F0F6;
  --muted: #92A5B8;
  --dim: #64798D;

  --allow: #2BD576;
  --allow-ink: #0B3D24;
  --block: #FF5A6E;
  --block-ink: #4A1119;
  --wait: #FFB020;
  --wait-ink: #4A3006;
  --trust: #4CC2FF;
  --trust-ink: #0A3A54;

  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .3);
}

[data-theme="light"] {
  --ink: #F2F5F8;
  --surface: #FFFFFF;
  --raised: #F7FAFC;
  --line: #DCE5EE;
  --line-soft: #E8EEF4;
  --text: #10202E;
  --muted: #55697C;
  --dim: #8398AC;

  --allow: #0F9D58;
  --allow-ink: #D6F5E4;
  --block: #D42B45;
  --block-ink: #FBE0E4;
  --wait: #B26A00;
  --wait-ink: #FCEFD6;
  --trust: #0B78BE;
  --trust-ink: #DAEEFB;

  --shadow: 0 10px 30px rgba(16, 32, 46, .10);
  --shadow-sm: 0 1px 4px rgba(16, 32, 46, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* `clip` on the body alone. `overflow: hidden` on html+body turns the body into
   a scroll container and Android Chrome then refuses to pan it by touch —
   the wheel still worked, the finger did not. */
body { overflow-x: clip; }

/* A `display` rule on a component beats the hidden attribute, and an invisible
   full-screen overlay would swallow every tap. Keep hidden meaning hidden. */
[hidden] { display: none !important; }

body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, .tab, .line, label { touch-action: manipulation; }  /* no double-tap zoom */

h1, h2, h3, h4 { margin: 0; line-height: 1.3; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

/* Latin ids and numbers must not flip inside Arabic text */
code, .ltr { font-family: var(--mono); direction: ltr; unicode-bidi: isolate; }
code {
  font-size: 12.5px;
  background: var(--raised);
  border: 1px solid var(--line-soft);
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--muted);
}
.num { font-variant-numeric: tabular-nums; }
svg.ic { flex: none; display: block; }

input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="search"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  transition: border-color var(--t);
}
input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible { outline: 2px solid var(--trust); outline-offset: 2px; }
input::placeholder { color: var(--dim); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform var(--t), background var(--t), border-color var(--t), opacity var(--t);
}
.btn:hover { border-color: var(--dim); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.block { width: 100%; }
.btn.primary { background: var(--allow); border-color: var(--allow); color: #04240F; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--block); border-color: var(--block); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; border-color: transparent; color: var(--block); }
.btn.trust { background: transparent; border-color: var(--trust); color: var(--trust); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm); border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background var(--t), color var(--t);
}
.icon-btn:hover { background: var(--raised); color: var(--text); }
/* The two survivors of the top bar are a pair, so they wear the same shape —
   one bordered pill each, not one boxed and one bare. */
#langBtn, #themeBtn {
  height: 36px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--r-chip);
}
#langBtn { font-size: 12.5px; font-weight: 800; letter-spacing: .02em; width: auto; min-width: 44px; }
#themeBtn { width: 36px; padding: 0; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* State chips: the colour is the state */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 8px;
  font-size: 12px; font-weight: 700; line-height: 1.7;
  background: var(--raised); color: var(--muted); border: 1px solid transparent;
  white-space: nowrap;
}
.chip.allow { background: var(--allow-ink); color: var(--allow); }
.chip.block { background: var(--block-ink); color: var(--block); }
.chip.wait { background: var(--wait-ink); color: var(--wait); }
.chip.trust { background: var(--trust-ink); color: var(--trust); }

/* Toggle: track reads 27px, the target is the full row height */
.switch { position: relative; display: inline-block; width: 46px; height: var(--tap); flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.switch span {
  position: absolute; inset-inline: 0; top: 50%; height: 27px; margin-top: -13.5px;
  background: var(--raised); border: 1px solid var(--line);
  border-radius: 999px; transition: background var(--t), border-color var(--t);
}
.switch span::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px;
  width: 19px; height: 19px; border-radius: 50%; background: var(--dim);
  transition: transform var(--t), background var(--t);
}
.switch input:checked + span { background: color-mix(in oklab, var(--allow) 22%, transparent); border-color: var(--allow); }
.switch input:checked + span::after { background: var(--allow); transform: translateX(-19px); }
[dir="ltr"] .switch input:checked + span::after { transform: translateX(19px); }
.switch input:focus-visible + span { outline: 2px solid var(--trust); outline-offset: 2px; }

.dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--dim);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--dim) 25%, transparent);
}
.dot.live { background: var(--allow); box-shadow: 0 0 0 3px color-mix(in oklab, var(--allow) 25%, transparent); }
.dot.warn { background: var(--wait); box-shadow: 0 0 0 3px color-mix(in oklab, var(--wait) 25%, transparent); }
.dot.down { background: var(--block); box-shadow: 0 0 0 3px color-mix(in oklab, var(--block) 25%, transparent); }

.empty {
  display: grid; gap: 6px; place-items: center; text-align: center;
  padding: 26px 16px; color: var(--muted);
  border: 1px dashed var(--line); border-radius: var(--r);
}
.empty strong { color: var(--text); font-size: 15px; }

.log {
  background: var(--ink); border: 1px solid var(--line-soft); border-radius: var(--r-sm);
  padding: 12px; max-height: 60vh; overflow: auto;
  font-family: var(--mono); font-size: 12px; direction: ltr; text-align: left;
  white-space: pre-wrap; word-break: break-word;
}

/* Shown for the first tick so a refresh never flashes the login form */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--ink); z-index: 80; color: var(--muted); }

/* Login is one design at both sizes: a single centred card.
   Everything here is sized from the top of the card down — the old one was a
   fixed-gap grid, so a short form left a slab of empty card under the button. */
.login {
  min-height: 100dvh; display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(90% 60% at 50% -15%, color-mix(in oklab, var(--allow) 12%, transparent), transparent 70%),
    var(--ink);
}
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 28px 24px 22px;
  box-shadow: var(--shadow);
  display: grid; gap: 16px; align-content: start;
}

/* The mark, the name and the line under it are one block, centred — three
   left-aligned items with even gaps read as a list, not as an identity. */
.login-head { display: grid; justify-items: center; gap: 8px; text-align: center; margin-bottom: 2px; }
.login-mark {
  width: 56px; height: 56px; display: grid; place-items: center;
  border-radius: 17px; color: var(--allow);
  background: color-mix(in oklab, var(--allow) 12%, var(--raised));
  border: 1px solid color-mix(in oklab, var(--allow) 28%, var(--line));
  margin-bottom: 2px;
}
.login-card h1 { font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.login-sub { color: var(--muted); font-size: 13.5px; line-height: 1.5; }

.field { display: grid; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input { min-height: 46px; padding: 10px 14px; font-size: 15px; }
.field input:focus { border-color: var(--allow); outline: none; }

/* password field + its reveal button */
.input-wrap { position: relative; display: block; }
.input-wrap input { width: 100%; padding-inline-end: 46px; }
.peek {
  position: absolute; inset-block: 0; inset-inline-end: 4px; margin: auto;
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 0; background: transparent; color: var(--dim); cursor: pointer;
  border-radius: var(--r-chip);
}
.peek:hover { color: var(--text); }
.peek[aria-pressed="true"] { color: var(--allow); }

.login-card .btn { min-height: 48px; padding: 0 16px; font-size: 15px; margin-top: 2px; }
/* reserves its line only when it has something to say */
.error-text { color: var(--block); font-size: 13px; line-height: 1.5; }
.error-text:empty { display: none; }

.login-foot {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--dim); font-size: 11.5px;
  padding-top: 12px; border-top: 1px solid var(--line-soft);
}

.toast-wrap { position: fixed; z-index: 60; display: grid; gap: 8px; pointer-events: none; }
.toast {
  background: var(--raised); color: var(--text);
  border: 1px solid var(--line); border-inline-start: 3px solid var(--allow);
  border-radius: var(--r-sm); padding: 11px 14px; font-size: 14px;
  box-shadow: var(--shadow); max-width: 440px;
  opacity: 0; transform: translateY(8px); transition: opacity var(--t), transform var(--t);
}
.toast.show { opacity: 1; transform: none; }
.toast.error { border-inline-start-color: var(--block); }

.sheet-wrap { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.55); display: grid; justify-items: center; }
.sheet { background: var(--surface); border: 1px solid var(--line); display: grid; gap: 12px; }
.sheet h3 { font-size: 17px; }
.sheet p { color: var(--muted); font-size: 14px; white-space: pre-line; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }

.brand {
  display: inline-grid; place-items: center; border-radius: 10px;
  background: var(--raised); color: var(--allow); flex: none;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}



/* Group picker row: fixed columns so names, counts and chips line up down the
   list instead of each row finding its own shape. */
.group-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto 12px;
  align-items: center; gap: var(--sp-3);
  width: 100%; min-height: 60px; padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--line-soft); border-radius: var(--r-card);
  background: var(--surface); color: inherit; text-align: start; cursor: pointer;
  font: inherit;
  transition: border-color var(--t), background var(--t);
}
.group-row:hover { border-color: var(--dim); }
.group-count {
  justify-self: start; min-width: 52px; text-align: center;
  background: var(--wait-ink); color: var(--wait);
  font-weight: 800; font-size: var(--fs-meta); line-height: 1.9;
  border-radius: var(--r-chip);
}
.group-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-body); }
.group-chips { display: flex; gap: var(--sp-1); }
.group-go { color: var(--dim); font-size: 18px; line-height: 1; }
[dir="ltr"] .group-go { transform: scaleX(-1); }


/* --- الأرقام: مبدّل الرقم في الشريط، وورقة الباركود ----------------------- */
/* The number picker is one pill — light, name, chevron — sized to its name and
   no larger. All three controls in the bar share this height, so the row reads
   as one set of controls instead of a title next to two boxes. */
.bot-pill {
  display: flex; align-items: center; gap: var(--sp-2);
  flex: 0 1 auto; min-width: 0;
  height: 36px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--r-chip);
  background: var(--raised); color: var(--muted);
}
.bot-pill .dot { flex: none; }
.bot-pill .caret { flex: none; opacity: .8; }
select.bot-switch {
  flex: 0 1 auto; min-width: 0;
  border: 0; background: transparent; color: var(--text);
  font: inherit; font-weight: 700; font-size: var(--fs-meta);
  padding: 0; height: 100%;
  appearance: none; -webkit-appearance: none;
  white-space: nowrap; text-overflow: ellipsis; cursor: pointer;
}
/* No ring on tap. :focus-visible is no help here — Chrome counts a tap on a
   <select> as keyboard-ish focus because it opens a listbox — so the outline
   goes entirely and focus shows as a neutral shift of the pill itself. Still
   visible to whoever is tabbing, never a blue line under a thumb. */
select.bot-switch:focus,
select.bot-switch:focus-visible { outline: none; box-shadow: none; }
.bot-pill:focus-within { background: var(--surface); border-color: var(--dim); }

/* an identifier we could not turn into a phone number: readable, but clearly
   not the same thing as a number */
.dim { color: var(--dim); }

.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;
}

.card.is-current { border-color: var(--trust); }
.actions-grid.one { grid-template-columns: minmax(0, 1fr); }

.qr-frame {
  display: grid; place-items: center;
  background: #fff; border-radius: var(--r-card); padding: 12px;
}
.qr-frame img { width: 100%; max-width: 260px; height: auto; display: block; }
.qr-note { text-align: center; }

/* =========================================================================
   2. PHONE DESIGN  (max-width: 999px)
   One column. Six type sizes, one 4-point spacing scale, three radii.
   Every value below comes from a token — no one-off numbers.
   ========================================================================= */
@media (max-width: 999px) {
  body { font-size: var(--fs-body); }

  /* iOS Safari zooms the page when a focused field is under 16px. */
  input[type="text"], input[type="search"], input[type="password"],
  input[type="number"], select, textarea { font-size: 16px; }

  .app {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: calc(var(--topbar-h) + env(safe-area-inset-top)) 1fr;
    grid-template-areas: "top" "main";
    min-height: 100dvh;
  }

  /* ---------- top bar ---------- */
  .topbar {
    grid-area: top;
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: var(--sp-2);
    padding: env(safe-area-inset-top) max(var(--sp-3), env(safe-area-inset-right)) 0 max(var(--sp-3), env(safe-area-inset-left));
    height: calc(var(--topbar-h) + env(safe-area-inset-top));
    background: color-mix(in oklab, var(--ink) 92%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line-soft);
  }
  .brand { display: none; }
  .status { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: var(--sp-2); overflow: hidden; }
  .status strong {
    color: var(--text); font-weight: 600; font-size: var(--fs-meta);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
  }
  .topbar-actions { display: flex; align-items: center; gap: 2px; flex: none; }
  .icon-btn { width: 36px; height: 36px; border-radius: var(--r-chip); }
  #langBtn, #themeBtn { height: 36px; }
  #langBtn { min-width: 40px; }
  .bot-pill { max-width: 62%; }

  /* ---------- page canvas ---------- */
  .main { grid-area: main; min-width: 0; }
  .view {
    padding: var(--sp-4) max(var(--sp-4), env(safe-area-inset-right))
             calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--sp-6))
             max(var(--sp-4), env(safe-area-inset-left));
    display: grid; gap: var(--sp-3); align-content: start;
    grid-template-columns: minmax(0, 1fr);
    animation: rise var(--t);
  }
  @keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

  .page-head { display: grid; gap: var(--sp-1); margin-bottom: var(--sp-1); }
  .page-head h2 { font-size: var(--fs-title); font-weight: 800; }
  .page-head p { color: var(--muted); font-size: var(--fs-meta); }

  .card {
    background: var(--surface); border: 1px solid var(--line-soft);
    border-radius: var(--r-card); padding: var(--sp-4);
    display: grid; gap: var(--sp-3); grid-template-columns: minmax(0, 1fr);
  }
  .card h3 { font-size: var(--fs-section); font-weight: 700; }
  .card-sub { color: var(--muted); font-size: var(--fs-meta); }

  /* ---------- controls ---------- */
  .btn {
    min-height: var(--tap); padding: 0 var(--sp-4);
    font-size: var(--fs-body); font-weight: 600; border-radius: var(--r-chip);
  }
  .btn.small { min-height: 38px; padding: 0 var(--sp-3); font-size: var(--fs-meta); }
  input[type="text"], input[type="search"], input[type="password"], input[type="number"], select, textarea {
    min-height: var(--tap); padding: 0 var(--sp-3); border-radius: var(--r-chip);
  }
  textarea { padding: var(--sp-3); }
  .chip { font-size: var(--fs-micro); padding: 3px var(--sp-2); border-radius: var(--r-chip); }

  .row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
  .row.between { justify-content: space-between; }
  .grow { flex: 1; min-width: 0; }
  .actions-grid { display: grid; gap: var(--sp-2); grid-template-columns: 1fr 1fr; }
  .actions-grid .btn { width: 100%; min-width: 0; }
  .actions-grid .span-2 { grid-column: 1 / -1; }

  /* ---------- metrics: one hero number, three supporting ---------- */
  .grid.metrics { display: grid; gap: var(--sp-2); grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric {
    background: var(--surface); border: 1px solid var(--line-soft);
    border-radius: var(--r-card); padding: var(--sp-3);
    display: grid; gap: 2px; align-content: start;
  }
  .metric .label { color: var(--muted); font-size: var(--fs-micro); }
  .metric .value { font-size: var(--fs-title); font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.15; }
  .metric.hero {
    grid-column: 1 / -1; padding: var(--sp-3) var(--sp-4);
    grid-template-columns: 1fr auto; align-items: baseline; gap: var(--sp-3);
  }
  .metric.hero .label { font-size: var(--fs-body); }
  .metric.hero .value { font-size: var(--fs-hero); }
  .metric.allow .value { color: var(--allow); }
  .metric.block .value { color: var(--block); }
  .metric.wait .value { color: var(--wait); }
  .metric.trust .value { color: var(--trust); }

  /* ---------- fact list: label + value, never chips ---------- */
  .facts { display: grid; gap: 0; }
  .fact {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
    min-height: 40px; border-bottom: 1px solid var(--line-soft);
  }
  .fact:last-child { border-bottom: 0; }
  .fact .k { color: var(--muted); font-size: var(--fs-meta); }
  .fact .v { font-size: var(--fs-body); font-weight: 600; font-variant-numeric: tabular-nums; }

  /* ---------- gate card ---------- */
  .grid.cards { display: grid; gap: var(--sp-3); grid-template-columns: minmax(0, 1fr); }
  .gate { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--r-card); overflow: hidden; }
  .gate.is-open { border-color: color-mix(in oklab, var(--allow) 35%, var(--line)); }
  .gate-top { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4); }
  .gate-queue {
    flex: none; width: 58px; text-align: center;
    background: var(--raised); border-radius: var(--r-chip); padding: var(--sp-2) 0;
  }
  .gate-queue b { display: block; font-size: var(--fs-section); font-weight: 800; font-variant-numeric: tabular-nums; color: var(--wait); line-height: 1.2; }
  .gate-queue.is-empty b { color: var(--dim); }
  .gate-queue span { font-size: var(--fs-micro); color: var(--muted); }
  .gate-id { min-width: 0; display: grid; gap: var(--sp-1); }
  .gate-id h4 { font-size: var(--fs-body); font-weight: 700; overflow-wrap: anywhere; }
  .gate-chips { display: flex; gap: var(--sp-1); flex-wrap: wrap; }
  .gate-switches { display: grid; border-top: 1px solid var(--line-soft); padding: 0 var(--sp-4); }
  .switch-row {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
    min-height: 46px; border-bottom: 1px solid var(--line-soft);
  }
  .switch-row:last-child { border-bottom: 0; }
  .switch-row span { font-size: var(--fs-body); color: var(--text); }
  .gate-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4) var(--sp-4); }
  .gate-actions .btn { width: 100%; }

  /* ---------- rows: one line of identity, one line of context ---------- */
  .list { display: grid; gap: var(--sp-2); grid-template-columns: minmax(0, 1fr); }
  /* One request = one line high. A 1,600-long queue cannot afford card-sized rows. */
  .req {
    display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3);
    border: 1px solid var(--line-soft); border-radius: var(--r-card); background: var(--surface);
    min-height: 62px;
  }
  .req.checked { border-color: var(--trust); }
  .req-main { min-width: 0; flex: 1; display: grid; gap: 1px; }
  .req-main .who {
    font-family: var(--mono); direction: ltr; unicode-bidi: isolate;
    font-size: var(--fs-body); font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;   /* never slide under the state chip */
  }
  .req > .chip { flex: none; }
  .req-main .where {
    display: flex; align-items: center; gap: var(--sp-2); min-width: 0;
    font-size: var(--fs-meta); color: var(--muted);
  }
  .req-main .where-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .req-actions { display: flex; gap: var(--sp-2); flex: none; }
  .req-actions .btn { min-height: 38px; padding: 0 var(--sp-3); }

  /* Four filters = two tidy rows. A scrolling strip cut the last one in half
     and read as broken, which is worse than the space it saved. */
  .filters { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
  .filters .btn { width: 100%; min-height: 40px; padding: 0 var(--sp-2); }
  .check { width: 22px; height: 22px; accent-color: var(--trust); flex: none; }

  .line {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
    padding: var(--sp-3); border: 1px solid var(--line-soft); border-radius: var(--r-card);
    background: var(--surface); min-height: var(--tap);
  }
  .line .meta {
    color: var(--muted); font-size: var(--fs-meta);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .line .ltr { overflow-wrap: anywhere; }

  .empty { padding: var(--sp-6) var(--sp-4); border-radius: var(--r-card); }
  .empty strong { font-size: var(--fs-body); }

  /* ---------- bottom tabs ---------- */
  .tabbar {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 40;
    display: grid; grid-auto-flow: column;
    background: color-mix(in oklab, var(--surface) 96%, transparent);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line-soft);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tab {
    transition: color var(--t);
    display: grid; justify-items: center; align-content: center; gap: 3px;
    height: var(--tabbar-h);
    border: 0; background: transparent; cursor: pointer;
    color: var(--dim); font-size: var(--fs-micro); font-weight: 600; position: relative;
  }
  .tab .tab-icon { display: grid; place-items: center; width: 22px; height: 22px; }
  .tab .tab-icon svg { width: 21px; height: 21px; }
  .tab.active { color: var(--allow); }
  .tab-badge {
    position: absolute; top: 4px; inset-inline-end: 14%;
    background: var(--wait); color: #2A1A00; font-size: 10px; font-weight: 800;
    line-height: 1; padding: 2px 5px; border-radius: var(--r-pill);
    font-variant-numeric: tabular-nums;
    border: 2px solid var(--surface);   /* keeps it legible over the icon edge */
  }

  .toast-wrap { inset-inline: var(--sp-3); bottom: calc(var(--tabbar-h) + var(--sp-4)); justify-items: center; }
  .toast { font-size: var(--fs-body); border-radius: var(--r-card); }

  .sheet-wrap { align-items: end; }
  .sheet {
    width: 100%; border-radius: var(--r-card) var(--r-card) 0 0;
    padding: var(--sp-5) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom));
    gap: var(--sp-3); animation: slideUp var(--t);
  }
  @keyframes slideUp { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
  .sheet h3 { font-size: var(--fs-section); }
  .sheet p { font-size: var(--fs-body); }
  .sheet-actions .btn { min-height: var(--tap); }

  /* Desktop-only building blocks stay out of the phone entirely */
  .split, .table-wrap, .toolbar { display: contents; }
  .desktop-only { display: none !important; }
}


/* =========================================================================
   3. DESKTOP DESIGN  (min-width: 1000px)
   Its own layout: a top bar with inline tabs, a 1240px working area,
   two-pane pages, and dense tables built for a mouse and a keyboard.
   ========================================================================= */
@media (min-width: 1000px) {
  :root { --tap: 36px; --topbar-h: 60px; }
  body { font-size: 14px; }

  .app {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) auto 1fr;
    grid-template-areas: "top" "nav" "main";
    min-height: 100dvh;
  }

  .topbar {
    grid-area: top;
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 14px;
    padding: 0 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--line-soft);
  }
  .brand { width: 32px; height: 32px; }
  .status { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); flex: 1; }
  .status strong { color: var(--text); font-weight: 600; font-size: 13.5px; }
  .bot-pill { max-width: 320px; height: 34px; }
  select.bot-switch { font-size: 13px; }
  .icon-btn { width: 34px; height: 34px; }
  #langBtn, #themeBtn { height: 32px; }        /* mouse-sized on desktop only */
  #langBtn { min-width: 40px; }
  #themeBtn { width: 34px; }

  /* Tabs live inline under the header, centred over the working area */
  .tabbar {
    grid-area: nav;
    position: sticky; top: var(--topbar-h); z-index: 25;
    display: flex; gap: 2px; align-items: center;
    padding: 0 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--line-soft);
  }
  .tab {
    display: inline-flex; align-items: center; gap: 7px;
    height: 42px; padding: 0 14px;
    border: 0; background: transparent; cursor: pointer;
    color: var(--muted); font-size: 13.5px; font-weight: 600;
    border-bottom: 2px solid transparent;
    transition: color var(--t), border-color var(--t);
  }
  .tab:hover { color: var(--text); }
  .tab .tab-icon { font-size: 13px; opacity: .8; }
  .tab.active { color: var(--text); border-bottom-color: var(--allow); }
  .tab-badge {
    background: var(--wait-ink); color: var(--wait);
    font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
    font-variant-numeric: tabular-nums;
  }

  .main { grid-area: main; min-width: 0; }
  .view {
    padding: 22px 28px 40px;
    max-width: 1240px; margin: 0 auto; width: 100%;
    display: grid; gap: 16px; align-content: start;
    grid-template-columns: minmax(0, 1fr);
  }

  .page-head { display: flex; align-items: baseline; gap: 12px; }
  .page-head h2 { font-size: 19px; }
  .page-head p { color: var(--muted); font-size: 13px; }

  .card {
    background: var(--surface); border: 1px solid var(--line-soft);
    border-radius: var(--r); padding: 16px 18px;
    display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr);
  }
  .card h3 { font-size: 14.5px; }
  .card-sub { color: var(--muted); font-size: 12.5px; }

  .btn { min-height: 34px; padding: 0 13px; font-size: 13px; border-radius: 8px; }
  .btn.small { min-height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
  input[type="text"], input[type="search"], input[type="password"], input[type="number"], select, textarea {
    min-height: 34px; padding: 6px 11px; font-size: 13px; border-radius: 8px;
  }
  .switch { width: 40px; height: 34px; }
  .switch span { height: 22px; margin-top: -11px; }
  .switch span::after { width: 16px; height: 16px; top: 2px; }
  .switch input:checked + span::after { transform: translateX(-16px); }

  .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .row.between { justify-content: space-between; }
  .grow { flex: 1; min-width: 0; }
  .actions-grid { display: flex; gap: 8px; flex-wrap: wrap; }
  .actions-grid .span-2 { order: -1; }

  /* KPI strip: four to six numbers on one line */
  .grid.metrics { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid.cards.two { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }

  /* fact list — the phone rules live in the phone block, so the desktop
     design states its own instead of inheriting a layout it never saw */
  .facts { display: grid; gap: 0; }
  .fact {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    min-height: 34px; border-bottom: 1px solid var(--line-soft);
  }
  .fact:last-child { border-bottom: 0; }
  .fact .k { color: var(--muted); font-size: 12.5px; }
  .fact .v { font-weight: 600; font-variant-numeric: tabular-nums; }
  .metric {
    background: var(--surface); border: 1px solid var(--line-soft);
    border-radius: var(--r); padding: 13px 16px; display: grid; gap: 2px;
  }
  .metric .label { color: var(--muted); font-size: 12px; }
  .metric .value { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
  .metric.allow .value { color: var(--allow); }
  .metric.block .value { color: var(--block); }
  .metric.wait .value { color: var(--wait); }
  .metric.trust .value { color: var(--trust); }

  /* Two-pane pages: filters on one side, work on the other */
  .split { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 16px; align-items: start; }
  .split-side { display: grid; gap: 12px; align-content: start; position: sticky; top: calc(var(--topbar-h) + 52px); }

  /* Dense table — the desktop's main data surface */
  .table-wrap {
    background: var(--surface); border: 1px solid var(--line-soft);
    border-radius: var(--r); overflow: hidden;
  }
  table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
  table.data thead th {
    /* not sticky: a page-scrolled table would float its header over the rows */
    background: var(--raised); color: var(--muted);
    font-weight: 600; font-size: 12px; text-align: start;
    padding: 9px 14px; border-bottom: 1px solid var(--line-soft); white-space: nowrap;
  }
  table.data tbody td { padding: 8px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
  table.data tbody tr:last-child td { border-bottom: 0; }
  table.data tbody tr { transition: background var(--t); }
  table.data tbody tr:hover { background: var(--raised); }
  table.data tbody tr.checked { background: color-mix(in oklab, var(--trust) 8%, transparent); }
  table.data td.tight { width: 1%; white-space: nowrap; }
  table.data td.actions { text-align: end; white-space: nowrap; }
  table.data td.actions .btn + .btn { margin-inline-start: 6px; }
  table.data .who { font-family: var(--mono); direction: ltr; unicode-bidi: isolate; }
  table.data .sub { color: var(--muted); font-size: 12px; }
  .check { width: 16px; height: 16px; accent-color: var(--trust); }

  /* A sticky action bar for bulk work on a long table */
  .toolbar {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; background: var(--surface);
    border: 1px solid var(--line-soft); border-radius: var(--r);
    position: sticky; top: calc(var(--topbar-h) + 46px); z-index: 6;
  }

  .list { display: grid; gap: 6px; grid-template-columns: minmax(0, 1fr); }
  .line {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 8px 12px; border: 1px solid var(--line-soft); border-radius: var(--r-sm);
    background: var(--surface); min-height: 38px;
  }
  .line .meta { color: var(--muted); font-size: 12px; }

  .toast-wrap { bottom: 22px; inset-inline: auto 22px; justify-items: end; }

  /* Confirmation is a centred dialog, not a sheet */
  .sheet-wrap { align-items: center; }
  .sheet { width: min(480px, 92vw); border-radius: var(--r-lg); padding: 22px; box-shadow: var(--shadow); }

  /* Phone-only building blocks never render here */
  .gate, .phone-only { display: none !important; }
}
