/* ──────────────────────────────────────────────────────────
   AI GATEWELL · v2 — enterprise security console
   Refined indigo on neutral slate. Calm, precise, trustworthy.
   ────────────────────────────────────────────────────────── */

:root {
  /* Brand — refined indigo (enterprise, restrained) */
  --brand-50:  #eef0fb;
  --brand-100: #dde0f6;
  --brand-200: #c1c6ec;
  --brand-300: #9aa2e0;
  --brand-400: #7079d4;
  --brand:     #4f57cf;
  --brand-600: #3f46b8;
  --brand-700: #333a97;
  --brand-glow:   rgba(79, 87, 207, 0.26);
  --brand-glow-2: rgba(79, 87, 207, 0.10);
  --brand-line:   rgba(79, 87, 207, 0.28);
  --brand-tint:   rgba(79, 87, 207, 0.09);

  /* Backgrounds — neutral slate (calm, professional) */
  --bg-0: #0a0b0e;
  --bg-1: #0e1015; /* App bg */
  --bg-2: #12141a; /* Surface */
  --bg-3: #171a21; /* Card */
  --bg-4: #1e222b; /* Raised */
  --bg-5: #262b35; /* Hover/active */

  /* Lines */
  --line:        rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --line-soft:   rgba(255, 255, 255, 0.05);

  /* Text — WCAG AA tuned. Ratios below are measured against --bg-1 / --bg-4
     (the lightest surface real text lands on: hovered table rows).
       --text       15.83 / 13.24
       --text-mute   8.96 /  7.50
       --text-dim    6.42 /  5.38
       --text-faint  5.55 /  4.64
     Hierarchy is preserved (text > mute > dim > faint) while every step
     clears 4.5:1 for body copy. */
  --text:      #e9eaee;
  --text-mute: #aeb2bb;
  --text-dim:  #93969d;
  --text-faint:#8a8c92;

  /* Semantic — professional, not neon.
     Two roles per hue:
       --x      → fills, dots, meter bars, icon glyphs, borders (3:1 territory)
       --x-fg   → the same hue as TEXT; tuned to clear 4.5:1 on --bg-1..--bg-4
                  *and* on its own tint composited over those surfaces
                  (e.g. .tag-blocked = --danger-fg on --danger-tint).
     Never use --x for body text; use --x-fg. */
  --safe:      #35a672;
  --safe-2:    #2c8a5e;
  --safe-fg:   #5cb78d;
  --safe-tint: rgba(53, 166, 114, 0.13);
  --safe-line: rgba(53, 166, 114, 0.30);

  --warn:      #d99a1f;
  --warn-2:    #bd851a;
  --warn-fg:   #dda63a;
  --warn-tint: rgba(217, 154, 31, 0.14);
  --warn-line: rgba(217, 154, 31, 0.30);

  --danger:    #e04b52;
  --danger-2:  #c73c43;
  --danger-fg: #e7757a;
  --danger-tint: rgba(224, 75, 82, 0.13);
  --danger-line: rgba(224, 75, 82, 0.30);

  --info:      #3d8bd4;
  --info-fg:   #5f9fdc;
  --info-tint: rgba(61, 139, 212, 0.13);
  --info-line: rgba(61, 139, 212, 0.30);

  /* Brand as text — #4f57cf is only 2.98:1 on --bg-3, so it may never carry
     text. --brand stays for fills (white-on-brand is 5.84:1); --brand-fg is
     the text-safe tint. */
  --brand-fg:  #868cde;

  /* Legacy aliases used by existing screens */
  --gold: var(--brand);
  --gold-2: var(--brand-600);
  --gold-3: var(--brand-700);
  --gold-tint: var(--brand-tint);
  --gold-line: var(--brand-line);
  --red:    var(--danger);
  --red-2:  var(--danger-2);
  --red-tint: var(--danger-tint);
  --green:  var(--safe);
  --green-2: var(--safe-2);
  --green-tint: var(--safe-tint);
  --blue:   var(--info);
  --blue-tint: var(--info-tint);

  --ink-0: var(--bg-0);
  --ink-1: var(--bg-1);
  --ink-2: var(--bg-3);
  --ink-3: var(--bg-4);

  --bg:        var(--bg-1);
  --surface:   var(--bg-2);
  --card:      var(--bg-3);
  --raised:    var(--bg-4);

  /* Type */
  --f-display: 'Geist', ui-sans-serif, -apple-system, system-ui, sans-serif;
  --f-sans:    'Geist', ui-sans-serif, -apple-system, system-ui, sans-serif;
  --f-mono:    'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Density */
  --row-h: 44px;
  --pad: 20px;
  --gap: 16px;

  /* Radii (subtle but present) */
  --r-1: 4px;
  --r-2: 6px;
  --r-3: 10px;
  --r-4: 14px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow:    0 4px 16px rgba(0, 0, 0, 0.26), 0 1px 2px rgba(0, 0, 0, 0.22);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.40);
  --shadow-brand: 0 0 0 1px var(--brand-line), 0 8px 24px rgba(79, 87, 207, 0.12);
  --shadow-brand-sm: 0 0 0 1px var(--brand-line);
}

/* Light theme */
:root[data-theme="light"] {
  --bg-0: #eceef1;
  --bg-1: #f6f7f9; /* App bg — subtle gray so white cards pop */
  --bg-2: #ffffff; /* Surface / card — white */
  --bg-3: #ffffff; /* Card — white */
  --bg-4: #f2f3f6; /* Nested raised — subtle gray */
  --bg-5: #e9ebef; /* Hover / active */
  --line:        rgba(17, 22, 38, 0.09);
  --line-strong: rgba(17, 22, 38, 0.15);
  --line-soft:   rgba(17, 22, 38, 0.05);
  --text:      #15181f;
  /* AA-tuned against the light surfaces (#f6f7f9 / #fff / #f2f3f6 / #e9ebef):
     mute 7.47+, dim 5.98+, faint 4.60+ */
  --text-mute: #454a52;
  --text-dim:  #55585e;
  --text-faint:#67696e;
  /* Semantic text roles darkened for light surfaces (all >= 4.5:1 on white
     and on their own tint) */
  --safe-fg:   #267853;
  --warn-fg:   #855e13;
  --danger-fg: #b93e44;
  --info-fg:   #2d68a0;
  --brand-fg:  #4f57cf;
  --bg:      var(--bg-1);
  --surface: var(--bg-2);
  --card:    var(--bg-3);
  --raised:  var(--bg-4);
  --brand-tint:  rgba(79, 87, 207, 0.07);
  --brand-glow-2: rgba(79, 87, 207, 0.08);
  --safe-tint: rgba(53, 166, 114, 0.11);
  --warn-tint: rgba(217, 154, 31, 0.14);
  --danger-tint: rgba(224, 75, 82, 0.10);
  --info-tint: rgba(61, 139, 212, 0.10);
  --shadow:    0 4px 16px rgba(20, 24, 40, 0.06), 0 1px 2px rgba(20, 24, 40, 0.04);
  --shadow-lg: 0 18px 50px rgba(20, 24, 40, 0.10);
}

:root[data-density="compact"] { --row-h: 36px; --pad: 14px; --gap: 12px; }
:root[data-density="comfy"]   { --row-h: 52px; --pad: 28px; --gap: 22px; }

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--f-sans);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
}

/* Very subtle neutral vignette (dark only) — no colored glow */
:root[data-theme="dark"] body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(1100px 640px at 50% -25%, rgba(255, 255, 255, 0.022), transparent 72%);
}

::selection { background: var(--brand); color: #fff; }

/* ─── Primitives ─── */
.mono   { font-family: var(--f-mono); font-feature-settings: "zero", "ss02"; font-variant-numeric: tabular-nums; }
.serif  { font-family: var(--f-display); font-weight: 500; letter-spacing: -0.01em; }
.cap    { text-transform: uppercase; letter-spacing: 0.14em; font-size: 11.5px; font-weight: 500; color: var(--text-dim); }
.cap-sm { text-transform: uppercase; letter-spacing: 0.16em; font-size: 10.5px; font-weight: 500; color: var(--text-dim); }
.num    { font-family: var(--f-display); font-weight: 500; font-feature-settings: "lnum", "tnum"; letter-spacing: -0.025em; }
.num-mono { font-family: var(--f-mono); font-feature-settings: "tnum"; font-variant-numeric: tabular-nums; }

.hr        { height: 1px; background: var(--line); border: 0; }
.hr-soft   { height: 1px; background: var(--line-soft); border: 0; }
.hr-dbl    { height: 3px; border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); background: transparent; }

/* ─── App shell ─── */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* ─── Sidebar ─── */
.sidebar {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg-1), var(--bg-1) 60%, var(--bg-2));
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  backdrop-filter: blur(20px);
}
.sb-brand {
  padding: 22px 18px 20px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.sb-brand .mark {
  flex: 0 0 32px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-700) 100%);
  border-radius: var(--r-2);
  box-shadow: 0 0 0 1px var(--brand-line), 0 4px 16px var(--brand-glow-2);
  color: #fff;
}
.sb-brand .wm   { font-family: var(--f-display); font-size: 16px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.1; }
.sb-brand .tag-pill {
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: 3px;
  font-family: var(--f-mono); font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--safe-fg);
  padding: 2px 6px; border-radius: 999px;
  background: var(--safe-tint);
  border: 1px solid var(--safe-line);
}
.sb-brand .tag-pill .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: pulse-dot 2s ease-in-out infinite; }

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 var(--safe); opacity: 1; }
  50% { box-shadow: 0 0 0 4px transparent; opacity: 0.7; }
}

.sb-section {
  padding: 18px 18px 8px;
  font-family: var(--f-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--text-faint);
}

.sb-nav { padding: 0 10px; }
.sb-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 11px;
  font-size: 13px;
  color: var(--text-mute);
  cursor: pointer;
  border-radius: var(--r-2);
  position: relative;
  user-select: none;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.sb-item:hover { color: var(--text); background: var(--bg-3); }
.sb-item .ic { width: 14px; height: 14px; opacity: 0.7; flex: 0 0 14px; transition: opacity 0.15s; }
.sb-item:hover .ic { opacity: 1; }
.sb-item .ct { margin-left: auto; font-family: var(--f-mono); font-size: 11px; color: var(--text-dim); }
.sb-item .ct.alarm { color: var(--danger-fg); }
.sb-item[data-active="true"] {
  color: var(--text);
  background: linear-gradient(90deg, var(--brand-tint), transparent 90%);
  box-shadow: inset 2px 0 0 var(--brand);
}
.sb-item[data-active="true"] .ic { opacity: 1; color: var(--brand); }

.sb-foot {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding: 14px 18px;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--text-dim);
}
.sb-foot .row { display: flex; justify-content: space-between; padding: 3px 0; }
.sb-foot .row .ok { color: var(--safe-fg); }
.sb-foot .sign-out {
  margin-top: 10px;
  display: block; width: 100%;
  text-align: left;
  border: none; background: transparent;
  color: var(--text-mute);
  font-family: var(--f-mono); font-size: 11px;
  letter-spacing: 0.06em; cursor: pointer;
  padding: 6px 0;
}
.sb-foot .sign-out:hover { color: var(--text); }

/* ─── Main / topbar ─── */
.main { min-width: 0; background: transparent; position: relative; z-index: 1; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line);
  gap: 24px;
  position: sticky; top: 0;
  background: rgba(14, 16, 21, 0.72);
  backdrop-filter: blur(20px) saturate(120%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  z-index: 5;
}
:root[data-theme="light"] .topbar { background: rgba(255, 255, 255, 0.78); }
.topbar .crumbs { font-family: var(--f-mono); font-size: 11px; color: var(--text-dim); letter-spacing: 0.12em; text-transform: uppercase; margin-bottom: 5px; }
.topbar h1 { font-family: var(--f-display); font-weight: 600; font-size: 22px; line-height: 1.1; margin: 0; letter-spacing: -0.015em; }
.topbar .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-family: var(--f-mono); font-size: 11.5px; color: var(--text-dim); letter-spacing: 0.04em; white-space: nowrap; }
.topbar .meta .status-row { display: flex; gap: 14px; align-items: center; }
.topbar .meta .ctrl-row { display: flex; gap: 6px; align-items: center; }
.topbar .meta .dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--safe);
  margin-right: 6px; vertical-align: 1px;
  box-shadow: 0 0 0 3px var(--safe-tint);
  animation: pulse-dot 2s ease-in-out infinite;
}
.topbar .clock { font-family: var(--f-mono); font-size: 12px; color: var(--text); }

/* Command-K trigger */
.cmdk-trigger {
  display: inline-flex; align-items: center; gap: 10px;
  height: 32px; padding: 0 12px 0 10px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  color: var(--text-dim);
  font-size: 12px; cursor: pointer;
  min-width: 280px;
  transition: border 0.15s, background 0.15s;
}
.cmdk-trigger:hover { border-color: var(--line-strong); background: var(--bg-4); }
.cmdk-trigger .kbd {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 2px;
  padding: 1px 5px;
  font-family: var(--f-mono); font-size: 10px;
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: 3px; color: var(--text-mute);
}

.page { padding: 28px 32px 80px; }
.page-anim { animation: fade-in 0.4s ease-out; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ─── Panels / Cards ─── */
.panel {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--r-3);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  gap: 16px;
  min-height: 56px;
}
.panel-head h3 { font-family: var(--f-display); font-weight: 600; font-size: 14px; margin: 0; letter-spacing: -0.005em; display: inline-flex; align-items: center; gap: 8px; }
.panel-head .sub { font-family: var(--f-mono); font-size: 11px; color: var(--text-dim); letter-spacing: 0.10em; text-transform: uppercase; }
.panel-body { padding: 18px; }

/* ─── KPI card ─── */
.kpi {
  border: 1px solid var(--line);
  background: var(--card);
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 8px;
  position: relative;
  border-radius: var(--r-3);
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  overflow: hidden;
}
.kpi:hover { transform: translateY(-1px); border-color: var(--line-strong); box-shadow: var(--shadow); }
.kpi .label-row { display: flex; justify-content: space-between; align-items: center; }
.kpi .num { font-size: 32px; line-height: 1.1; font-weight: 600; }
.kpi .sub { font-family: var(--f-mono); font-size: 11px; color: var(--text-dim); letter-spacing: 0.08em; text-transform: uppercase; }
.kpi .spark { height: 28px; }
.kpi .badge { font-family: var(--f-mono); font-size: 11px; padding: 2px 6px; border: 1px solid var(--line); border-radius: var(--r-1); }
.kpi.accent {
  background:
    radial-gradient(420px 200px at 100% 0%, var(--brand-glow-2), transparent 60%),
    var(--card);
  border-color: var(--brand-line);
}
.kpi.accent::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
  background: linear-gradient(180deg, var(--brand), var(--brand-700));
}

/* ─── Tag / badge ─── */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px;
  font-family: var(--f-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: var(--bg-3);
  border-radius: var(--r-1);
  height: 22px;
  text-transform: uppercase;
  font-weight: 500;
}
.tag-blocked { color: var(--danger-fg); border-color: var(--danger-line); background: var(--danger-tint); }
.tag-flagged { color: var(--warn-fg);   border-color: var(--warn-line);   background: var(--warn-tint); }
.tag-allowed { color: var(--safe-fg);   border-color: var(--safe-line);   background: var(--safe-tint); }
.tag-info    { color: var(--info-fg);   border-color: var(--info-line);   background: var(--info-tint); }
.tag-ghost   { color: var(--text-dim); border-color: var(--line); background: transparent; }
.tag-solid   { color: #fff; background: var(--brand); border-color: var(--brand); }
.tag-brand   { color: var(--brand-fg); border-color: var(--brand-line); background: var(--brand-tint); }
.tag .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  font-family: var(--f-mono); font-size: 10.5px;
  border: 1px solid var(--line); color: var(--text-mute);
  background: transparent;
  border-radius: var(--r-1);
  cursor: pointer; user-select: none;
  transition: all 0.15s;
}
.chip:hover { border-color: var(--line-strong); color: var(--text); }
.chip[data-on="true"] { background: var(--brand-tint); color: var(--brand-fg); border-color: var(--brand-line); }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px;
  padding: 0 12px;
  font-family: var(--f-sans);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: var(--bg-3);
  cursor: pointer;
  border-radius: var(--r-2);
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-4); border-color: rgba(255, 255, 255, 0.16); }
:root[data-theme="light"] .btn:hover { border-color: rgba(0, 0, 0, 0.16); }
.btn-primary {
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-600) 100%);
  color: #fff; border-color: var(--brand);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15) inset, 0 6px 16px var(--brand-glow-2);
}
.btn-primary:hover {
  background: linear-gradient(180deg, var(--brand-400) 0%, var(--brand) 100%);
  border-color: var(--brand-400);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 8px 24px var(--brand-glow);
}
.btn-ghost { border-color: var(--line); color: var(--text-mute); background: transparent; }
.btn-ghost:hover { color: var(--text); background: var(--bg-3); }
.btn-danger { color: var(--danger-fg); border-color: var(--danger-line); background: var(--danger-tint); }
.btn-danger:hover { background: rgba(255, 92, 124, 0.18); }
.btn-sm { height: 26px; padding: 0 10px; font-size: 11.5px; }
.btn-icon { width: 32px; padding: 0; justify-content: center; }

/* ─── Input ─── */
.in {
  display: flex; align-items: center; gap: 8px;
  height: 34px;
  padding: 0 11px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  color: var(--text);
  font-family: var(--f-sans);
  font-size: 13px;
  width: 100%;
  transition: border 0.15s, box-shadow 0.15s;
}
.in:hover { border-color: var(--line-strong); }
.in:focus, .in:focus-within {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}
.in input, .in select, .in textarea {
  background: transparent; border: 0; color: inherit; outline: none; font: inherit; width: 100%;
}
.in input::placeholder { color: var(--text-faint); }
.in .ic { color: var(--text-dim); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-family: var(--f-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--text-dim); font-weight: 500; }

/* ─── Table ─── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left;
  font-family: var(--f-mono);
  font-weight: 500;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  position: sticky; top: 0;
}
.tbl td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  font-family: var(--f-mono);
  font-size: 13px;
  color: var(--text-mute);
  vertical-align: middle;
}
.tbl tr { transition: background 0.12s; }
.tbl tr:hover td { background: var(--bg-4); color: var(--text); }
.tbl tr[data-selected="true"] td { background: var(--brand-tint); }
.tbl td .truncate { display: inline-block; max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.tbl td.dim { color: var(--text-dim); }
.tbl td.num { font-family: var(--f-mono); }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.new-row { animation: row-in 0.5s ease-out; }
@keyframes row-in {
  from { background: var(--brand-tint); transform: translateX(-4px); opacity: 0; }
  to   { background: transparent; transform: none; opacity: 1; }
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); background-clip: content-box; border: 2px solid transparent; }

/* ─── Grids ─── */
.row { display: flex; gap: var(--gap); }
.col { display: flex; flex-direction: column; gap: var(--gap); }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--gap); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.split-12 { display: grid; grid-template-columns: 1.55fr 1fr; gap: var(--gap); }

/* ─── Toggle ─── */
.tog {
  width: 32px; height: 18px; border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: var(--bg-2);
  position: relative; cursor: pointer; flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.tog::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px;
  background: var(--text-mute);
  border-radius: 50%;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}
.tog[data-on="true"] { background: var(--brand); border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
.tog[data-on="true"]::after { left: 16px; background: #fff; }

/* ─── Code block ─── */
pre.code {
  margin: 0;
  padding: 14px 16px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  font-family: var(--f-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text);
  overflow-x: auto;
  white-space: pre;
}
pre.code .kw { color: var(--brand-300); }
pre.code .str { color: var(--safe-fg); }
pre.code .cm { color: var(--text-dim); font-style: italic; }
pre.code .pn { color: var(--text-dim); }
pre.code .nm { color: var(--info-fg); }

/* Focus ring */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--r-1); }

/* ─── Meter ─── */
.meter { display: flex; align-items: center; gap: 10px; }
.meter .bar { flex: 1; height: 4px; background: var(--bg-2); position: relative; border-radius: 999px; overflow: hidden; }
.meter .bar > i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--brand), var(--brand-300));
  border-radius: 999px;
  transition: width 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
.meter .lbl { font-family: var(--f-mono); font-size: 11.5px; color: var(--text-mute); min-width: 28px; text-align: right; }

/* Block headers */
.block-h {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 0 0 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.block-h h2 { font-family: var(--f-display); font-weight: 600; font-size: 18px; margin: 0; letter-spacing: -0.01em; }
.block-h .meta { font-family: var(--f-mono); font-size: 11.5px; color: var(--text-dim); letter-spacing: 0.10em; text-transform: uppercase; }

/* Page-level tabs (e.g. inside Rules Engine) */
.ptabs {
  display: flex; align-items: stretch;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin: 0 0 22px;
  position: relative;
}
.ptab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 16px 13px;
  font-family: var(--f-display);
  font-size: 13px; font-weight: 500; letter-spacing: -0.005em;
  color: var(--text-dim);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  position: relative;
}
.ptab:hover { color: var(--text); background: var(--bg-3); }
.ptab[data-on="true"] {
  color: var(--text);
  border-bottom-color: var(--brand);
}
.ptab[data-on="true"]::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--brand);
  box-shadow: 0 0 12px var(--brand-glow);
}
.ptab .ct {
  font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: 1px 6px; border: 1px solid var(--line); border-radius: 3px;
}
.ptab[data-on="true"] .ct { color: var(--brand-fg); border-color: var(--brand-line); background: var(--brand-tint); }
.ptab .tag-new {
  font-family: var(--f-mono); font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 3px;
  background: var(--brand-tint); color: var(--brand-fg); border: 1px solid var(--brand-line);
}

/* Drawer */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(5, 6, 13, 0.65);
  backdrop-filter: blur(4px); z-index: 50;
  animation: fade-in 0.2s;
}
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 580px;
  background: var(--bg-1); border-left: 1px solid var(--line);
  z-index: 51; display: flex; flex-direction: column;
  box-shadow: -32px 0 80px rgba(0, 0, 0, 0.5);
  animation: drawer-in 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes drawer-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { padding: 20px 24px 16px; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 24px; }
.drawer-foot { border-top: 1px solid var(--line); padding: 14px 24px; display: flex; gap: 10px; justify-content: flex-end; background: var(--bg-2); }

/* Icon button */
.ibtn {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: transparent; color: var(--text-mute);
  cursor: pointer; border-radius: var(--r-2);
  transition: all 0.15s;
}
.ibtn:hover { color: var(--text); border-color: var(--line-strong); background: var(--bg-3); }

/* Link */
.lnk { color: var(--text); text-decoration: none; border-bottom: 1px solid var(--brand-line); padding-bottom: 1px; font-size: 13px; transition: color 0.15s, border-color 0.15s; }
.lnk:hover { color: var(--brand-fg); border-color: var(--brand); }
.lnk-mute { color: var(--text-mute); border-color: var(--line); }

/* ─── Animations ─── */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.shimmer {
  background: linear-gradient(90deg, transparent, var(--bg-5) 50%, transparent);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}

@keyframes draw-stroke {
  from { stroke-dashoffset: var(--len, 1000); }
  to   { stroke-dashoffset: 0; }
}
.draw-in {
  stroke-dasharray: var(--len, 1000);
  stroke-dashoffset: var(--len, 1000);
  animation: draw-stroke 1.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes count-up {
  from { transform: translateY(-100%); }
  to   { transform: none; }
}

/* Live pulse halo for "now" markers */
@keyframes ring-pulse {
  0%   { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(2.6); opacity: 0; }
}
.live-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px solid var(--brand);
  animation: ring-pulse 1.6s ease-out infinite;
}

/* Hover lift utility */
.lift { transition: transform 0.18s ease, box-shadow 0.18s ease; }
.lift:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

/* ─── Left-slide drawer (e.g. per-device MCP sidebar) ────────────────── */
.l-drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(5, 6, 13, 0.55);
  backdrop-filter: blur(3px);
  z-index: 60;
  animation: fade-in 0.18s ease-out;
}
.l-drawer {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: min(520px, 92vw);
  background: var(--card);
  border-right: 1px solid var(--brand-line);
  box-shadow: 24px 0 60px rgba(0, 0, 0, 0.55), inset -1px 0 0 var(--brand-line);
  z-index: 61;
  display: flex; flex-direction: column;
  animation: slide-in-l 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes slide-in-l {
  from { transform: translateX(-105%); opacity: 0.4; }
  to   { transform: translateX(0);     opacity: 1; }
}
.l-drawer-head {
  padding: 22px 22px 18px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(420px 160px at 0% 0%, var(--brand-glow-2), transparent 60%),
    var(--card);
}
.l-drawer-body { flex: 1; overflow: auto; padding: 18px 22px; }
.l-drawer-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  display: flex; justify-content: space-between; align-items: center;
}

/* Glow card variant */
.glow {
  background:
    radial-gradient(800px 320px at 0% 0%, var(--brand-glow-2), transparent 50%),
    var(--card);
}

/* Skeleton */
.skel { background: var(--bg-3); border-radius: var(--r-1); height: 12px; }
.skel.lg { height: 22px; }

/* Streaming list */
.stream-list { position: relative; }
.stream-row {
  display: grid; align-items: center;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  font-family: var(--f-mono); font-size: 12.5px;
  position: relative;
  animation: stream-in 0.5s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes stream-in {
  from { transform: translateY(-6px); opacity: 0; background: var(--brand-tint); }
  to   { transform: none; opacity: 1; background: transparent; }
}
.stream-row.new { box-shadow: inset 2px 0 0 var(--brand); }

/* Spinning glyph */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 1s linear infinite; }

/* Gradient text */
.grad-text {
  background: linear-gradient(135deg, var(--brand-200), var(--brand) 60%, var(--info));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* Subtle grid pattern overlay */
.bg-grid {
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 24px 24px;
}
.bg-dots {
  background-image: radial-gradient(circle, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* Section delimiter strip with brand corner */
.brand-corner {
  position: relative;
  overflow: hidden;
}
.brand-corner::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(380px 220px at 100% 0%, var(--brand-glow-2), transparent 65%);
}

/* Disable all animations when tweak is off */
body.no-anim *,
body.no-anim *::before,
body.no-anim *::after {
  animation-duration: 0.001s !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001s !important;
}

/* Responsive */
@media (max-width: 1280px) {
  .grid-5 { grid-template-columns: repeat(5, 1fr); gap: 12px; }
  .topbar h1 { font-size: 20px; }
}

/* ─────────────────────────────────────────────────────────
   v2 GLOBAL OVERRIDES — re-skin the entire v1 markup
   Every screen still uses Tailwind zinc/blue/amber/red/green
   utility classes. These rules remap them to v2 tokens so
   every screen automatically picks up the electric-violet
   identity without rewriting markup.
   ───────────────────────────────────────────────────────── */

/* Backgrounds */
.bg-zinc-950 { background-color: var(--bg-1) !important; }
.bg-zinc-900 { background-color: var(--bg-2) !important; }
.bg-zinc-900\/50 { background-color: rgba(18, 20, 26, 0.5) !important; }
.bg-zinc-900\/80 { background-color: rgba(18, 20, 26, 0.8) !important; }
.bg-zinc-800 { background-color: var(--bg-3) !important; }
.bg-zinc-800\/50 { background-color: rgba(20, 21, 42, 0.5) !important; }
.bg-zinc-700 { background-color: var(--bg-4) !important; }
.bg-zinc-700\/50 { background-color: rgba(28, 29, 54, 0.5) !important; }
.bg-zinc-600 { background-color: var(--bg-5) !important; }
.bg-black { background-color: var(--bg-0) !important; }

.hover\:bg-zinc-900:hover { background-color: var(--bg-2) !important; }
.hover\:bg-zinc-800:hover { background-color: var(--bg-3) !important; }
.hover\:bg-zinc-700:hover { background-color: var(--bg-4) !important; }
.hover\:bg-zinc-700\/50:hover { background-color: rgba(28, 29, 54, 0.5) !important; }
.hover\:bg-zinc-600:hover { background-color: var(--bg-5) !important; }

/* Borders */
.border-zinc-900 { border-color: var(--line-soft) !important; }
.border-zinc-800 { border-color: var(--line) !important; }
.border-zinc-700 { border-color: var(--line-strong) !important; }
.border-zinc-600 { border-color: var(--line-strong) !important; }

.hover\:border-zinc-700:hover { border-color: var(--line-strong) !important; }
.hover\:border-zinc-600:hover { border-color: var(--line-strong) !important; }

/* Text */
.text-zinc-50, .text-zinc-100, .text-white { color: var(--text) !important; }
.text-zinc-200, .text-zinc-300 { color: var(--text) !important; }
.text-zinc-400 { color: var(--text-mute) !important; }
.text-zinc-500 { color: var(--text-dim) !important; }
.text-zinc-600 { color: var(--text-faint) !important; }

.hover\:text-zinc-100:hover { color: var(--text) !important; }
.hover\:text-zinc-200:hover { color: var(--text) !important; }
.hover\:text-zinc-300:hover { color: var(--text) !important; }
.hover\:text-zinc-400:hover { color: var(--text-mute) !important; }
.hover\:text-white:hover { color: var(--text) !important; }

/* Brand accents (Tailwind blue → electric violet brand) */
.text-blue-300 { color: var(--brand-300) !important; }
.text-blue-400 { color: var(--brand-fg) !important; }
.text-blue-500 { color: var(--brand-fg) !important; }
.text-blue-600 { color: var(--brand-600) !important; }

.bg-blue-400 { background-color: var(--brand-400) !important; }
.bg-blue-500 { background-color: var(--brand) !important; }
.bg-blue-600 { background-color: var(--brand) !important; }
.bg-blue-700 { background-color: var(--brand-600) !important; }
.bg-blue-500\/10 { background-color: var(--brand-tint) !important; }
.bg-blue-500\/20 { background-color: rgba(79, 87, 207, 0.20) !important; }
.bg-blue-500\/30 { background-color: rgba(79, 87, 207, 0.30) !important; }
.bg-blue-600\/10 { background-color: var(--brand-tint) !important; }
.bg-blue-600\/20 { background-color: rgba(79, 87, 207, 0.20) !important; }

.border-blue-500, .border-blue-600 { border-color: var(--brand) !important; }
.border-blue-500\/20 { border-color: rgba(79, 87, 207, 0.20) !important; }
.border-blue-500\/30 { border-color: var(--brand-line) !important; }
.border-blue-500\/50 { border-color: rgba(79, 87, 207, 0.50) !important; }

.hover\:bg-blue-600:hover { background-color: var(--brand-600) !important; }
.hover\:bg-blue-700:hover { background-color: var(--brand-700) !important; }
.hover\:bg-blue-500\/30:hover { background-color: rgba(79, 87, 207, 0.30) !important; }
.hover\:text-blue-300:hover { color: var(--brand-300) !important; }
.hover\:text-blue-400:hover { color: var(--brand-fg) !important; }
.hover\:border-blue-500\/40:hover { border-color: rgba(79, 87, 207, 0.40) !important; }
.hover\:border-blue-500\/50:hover { border-color: rgba(79, 87, 207, 0.50) !important; }

/* Focus ring */
.focus\:border-blue-500:focus, .focus\:border-blue-600:focus { border-color: var(--brand) !important; }
.focus\:ring-blue-500\/20:focus { box-shadow: 0 0 0 3px var(--brand-tint) !important; }
.focus\:ring-blue-500:focus { box-shadow: 0 0 0 3px var(--brand-tint) !important; }

/* Purple → brand (used for semantic / AI features) */
.text-purple-300, .text-purple-400, .text-violet-300, .text-violet-400, .text-fuchsia-400 { color: var(--brand-300) !important; }
.bg-purple-500\/10, .bg-violet-500\/10 { background-color: var(--brand-tint) !important; }
.bg-purple-500\/20, .bg-violet-500\/20 { background-color: rgba(79, 87, 207, 0.20) !important; }
.border-purple-500\/30, .border-violet-500\/30 { border-color: var(--brand-line) !important; }
.focus\:border-purple-500:focus { border-color: var(--brand) !important; }
.focus\:ring-purple-500:focus { box-shadow: 0 0 0 3px var(--brand-tint) !important; }

/* Semantic — success / safe */
.text-green-300, .text-emerald-300 { color: var(--safe-fg); filter: brightness(1.15); }
.text-green-400, .text-emerald-400 { color: var(--safe-fg) !important; }
.bg-green-500, .bg-emerald-500 { background-color: var(--safe) !important; }
.bg-green-500\/10, .bg-emerald-500\/10 { background-color: var(--safe-tint) !important; }
.bg-green-500\/20, .bg-emerald-500\/20 { background-color: rgba(16, 217, 160, 0.20) !important; }
.bg-green-500\/30, .bg-emerald-500\/30 { background-color: rgba(16, 217, 160, 0.30) !important; }
.border-green-500\/20, .border-emerald-500\/20 { border-color: rgba(16, 217, 160, 0.20) !important; }
.border-green-500\/30, .border-emerald-500\/30 { border-color: var(--safe-line) !important; }
.hover\:bg-green-500\/30:hover { background-color: rgba(16, 217, 160, 0.30) !important; }
.focus\:border-emerald-500:focus { border-color: var(--safe) !important; }

/* Semantic — warning */
.text-amber-300, .text-yellow-300, .text-orange-300 { color: var(--warn-fg); filter: brightness(1.1); }
.text-amber-400, .text-yellow-400, .text-orange-400 { color: var(--warn-fg) !important; }
.bg-amber-500, .bg-yellow-500 { background-color: var(--warn) !important; }
.bg-amber-500\/10, .bg-yellow-500\/10, .bg-orange-500\/10 { background-color: var(--warn-tint) !important; }
.bg-amber-500\/20, .bg-yellow-500\/20 { background-color: rgba(255, 181, 71, 0.20) !important; }
.border-amber-500\/20, .border-yellow-500\/20 { border-color: rgba(255, 181, 71, 0.20) !important; }
.border-amber-500\/30, .border-yellow-500\/30 { border-color: var(--warn-line) !important; }

/* Semantic — danger */
.text-red-300, .text-rose-300 { color: var(--danger-fg); filter: brightness(1.1); }
.text-red-400, .text-rose-400 { color: var(--danger-fg) !important; }
.text-red-500 { color: var(--danger-fg) !important; }
.bg-red-500, .bg-rose-500 { background-color: var(--danger) !important; }
.bg-red-500\/10, .bg-rose-500\/10 { background-color: var(--danger-tint) !important; }
.bg-red-500\/20, .bg-rose-500\/20 { background-color: rgba(255, 92, 124, 0.20) !important; }
.bg-red-500\/30 { background-color: rgba(255, 92, 124, 0.30) !important; }
.border-red-500\/20, .border-rose-500\/20 { border-color: rgba(255, 92, 124, 0.20) !important; }
.border-red-500\/30, .border-rose-500\/30 { border-color: var(--danger-line) !important; }
.hover\:bg-red-500\/20:hover { background-color: rgba(255, 92, 124, 0.20) !important; }
.hover\:bg-red-500\/30:hover { background-color: rgba(255, 92, 124, 0.30) !important; }
.hover\:text-red-300:hover { color: var(--danger-fg) !important; filter: brightness(1.1); }

/* Semantic — info */
.text-cyan-400, .text-sky-400 { color: var(--info-fg) !important; }
.bg-cyan-500\/10, .bg-sky-500\/10 { background-color: var(--info-tint) !important; }
.border-cyan-500\/30, .border-sky-500\/30 { border-color: var(--info-line) !important; }

/* Borders for semantic accents that wrap rule cards & alerts */
.border-l-red-500, .border-l-rose-500 { border-left-color: var(--danger) !important; }
.border-l-amber-500, .border-l-yellow-500 { border-left-color: var(--warn) !important; }
.border-l-green-500, .border-l-emerald-500 { border-left-color: var(--safe) !important; }
.border-l-blue-500 { border-left-color: var(--brand) !important; }

/* Inputs across all screens */
input, select, textarea {
  font-family: var(--f-sans);
}
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="url"], input[type="tel"], textarea, select {
  background-color: var(--bg-2) !important;
}
input:focus, select:focus, textarea:focus {
  outline: none !important;
}

/* Tables — give every existing <table> a v2 feel */
table thead th {
  font-family: var(--f-mono) !important;
  font-size: 10.5px !important;
  letter-spacing: 0.16em !important;
  text-transform: uppercase !important;
  color: var(--text-dim) !important;
  background: var(--bg-2) !important;
  border-bottom: 1px solid var(--line) !important;
}
table tbody td {
  border-bottom: 1px solid var(--line) !important;
  vertical-align: middle;
}
table tbody tr.hover\:bg-zinc-800\/50:hover td,
table tbody tr.cursor-pointer:hover td {
  background: var(--bg-4) !important;
  color: var(--text) !important;
}

/* Buttons that use the canonical "btn btn-primary / btn-ghost" pattern */
.btn-primary { background: var(--brand) !important; color: #fff !important; border-color: var(--brand) !important; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-600) !important; border-color: var(--brand-600) !important; }

/* Rounded shells */
.rounded-md { border-radius: var(--r-2) !important; }
.rounded-lg { border-radius: var(--r-3) !important; }
.rounded-xl { border-radius: var(--r-4) !important; }
.rounded-2xl { border-radius: 16px !important; }

/* Gradient backgrounds that used to be blue → brand violet */
.bg-gradient-to-r.from-blue-600.to-blue-500,
.bg-gradient-to-r.from-blue-600.to-purple-600,
.bg-gradient-to-br.from-blue-500.to-purple-600 {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-700) 100%) !important;
}
.bg-gradient-to-br.from-blue-600.to-purple-600 {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-700) 100%) !important;
}

/* Selection rings & focus shadows on cards */
.ring-blue-500, .ring-blue-500\/50, .ring-blue-500\/30 {
  --tw-ring-color: var(--brand) !important;
}

/* Tab navigation chrome — match v2 .ptab look */
button.tab-btn[data-active="true"],
a.tab-btn[data-active="true"],
[data-active="true"].sub-tab {
  color: var(--text) !important;
  border-color: var(--brand) !important;
}

/* Cards used across screens (existing v1 vocab) */
.card, .panel-card, .stat-card {
  background: var(--card) !important;
  border-color: var(--line) !important;
  border-radius: var(--r-3) !important;
}

/* The big "stat card" tiles on each screen */
[class*="bg-zinc-900"][class*="border-zinc-800"] {
  background: var(--card) !important;
  border-color: var(--line) !important;
}

/* Pulsing live dots that already exist */
.bg-green-500.animate-pulse { background: var(--safe) !important; box-shadow: 0 0 8px var(--safe); }
.bg-red-500.animate-pulse   { background: var(--danger) !important; box-shadow: 0 0 8px var(--danger); }
.bg-amber-500.animate-pulse { background: var(--warn) !important; box-shadow: 0 0 8px var(--warn); }
.bg-blue-500.animate-pulse  { background: var(--brand) !important; box-shadow: 0 0 8px var(--brand); }

/* Brand-tinted modal/drawer backdrops */
.bg-black\/70, .bg-black\/80 { background-color: rgba(5, 6, 13, 0.78) !important; backdrop-filter: blur(6px); }

/* All headings get the display font for that techy editorial feel */
h1, h2, h3, h4 { font-family: var(--f-display); letter-spacing: -0.01em; }

/* Generic input borders inside the app */
.border.border-zinc-800 input,
.border.border-zinc-700 input,
.border.border-zinc-800 select,
.border.border-zinc-700 select { background: transparent; }

/* Selection style for sub-tab pills (Rules engine) */
.sub-tab[data-active="true"] {
  background: var(--brand-tint) !important;
  color: var(--brand-fg) !important;
  border-color: var(--brand-line) !important;
}

/* Subtle row separators in v1 lists */
.divide-y > * + * { border-color: var(--line) !important; }
.divide-zinc-800 > * + * { border-color: var(--line) !important; }

/* Pulse animation for status indicators */
@keyframes v2-pulse-ring {
  0%, 100% { box-shadow: 0 0 0 0 currentColor; opacity: 1; }
  50% { box-shadow: 0 0 0 4px transparent; opacity: 0.7; }
}

/* Better progress / meter bars */
[role="progressbar"], .progress-bar {
  background: var(--bg-2);
}

/* Tab content reveal animation */
.tab-content {
  animation: tab-fade-in 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes tab-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* Improve every modal / dialog */
.fixed.inset-0[class*="bg-black"] > div[class*="bg-zinc"] {
  background: var(--card) !important;
  border-color: var(--line-strong) !important;
  box-shadow: var(--shadow-lg);
}

/* "Empty state" rows */
.text-center.py-8, .text-center.py-12 {
  color: var(--text-dim);
}

/* Better SVG icon defaults */
svg.lucide { stroke-width: 1.5; }


/* ═══════════════════════════════════════════════════════════════════════
   ACCESSIBILITY — CONTRAST REPAIR FOR INLINE COLOURS
   index.html carries ~330 inline `style="color:var(--x)"` declarations.
   The raw semantic hues are tuned for fills / borders / dots (3:1 land) and
   fail AA as text on the near-black surfaces, so remap the TEXT role onto the
   -fg tokens. Each hue is matched only at the start of the style attribute or
   after a `;` boundary, so `background-color:var(--x)` and `border-color:…`
   are never caught. Both `color:` and Vue's rendered `color: ` are covered.
   ═══════════════════════════════════════════════════════════════════════ */
[style^="color:var(--safe)"],   [style*=";color:var(--safe)"],
[style^="color: var(--safe)"],  [style*="; color: var(--safe)"]   { color: var(--safe-fg) !important; }
[style^="color:var(--warn)"],   [style*=";color:var(--warn)"],
[style^="color: var(--warn)"],  [style*="; color: var(--warn)"]   { color: var(--warn-fg) !important; }
[style^="color:var(--danger)"], [style*=";color:var(--danger)"],
[style^="color: var(--danger)"],[style*="; color: var(--danger)"] { color: var(--danger-fg) !important; }
[style^="color:var(--info)"],   [style*=";color:var(--info)"],
[style^="color: var(--info)"],  [style*="; color: var(--info)"]   { color: var(--info-fg) !important; }
[style^="color:var(--brand)"],  [style*=";color:var(--brand)"],
[style^="color: var(--brand)"], [style*="; color: var(--brand)"]  { color: var(--brand-fg) !important; }

/* Tailwind's Play CDN sizes type in rem, and this stylesheet sets
   html { font-size: 13.5px }, so every rem-based utility renders ~16% small:
   .text-xs lands at 10.1px and .text-sm at 11.8px — and those two carry most
   of the body copy in index.html (128 + 81 uses). Restate them in px instead
   of changing the root size, which would also rescale the whole rem-based
   spacing system. */
.text-xs  { font-size: 12px !important; }
.text-sm  { font-size: 13.5px !important; }
.text-base{ font-size: 15px !important; }
/* Tailwind ships font-size and line-height in the same rule, so the leading
   has to be restated too — except where the markup picked an explicit
   leading-* utility, which must keep winning. */
.text-xs:not([class*="leading-"]),
.text-sm:not([class*="leading-"]) { line-height: 1.55 !important; }

/* Chart axis / tick labels are emitted from app.js as
   style="font:9.5px 'JetBrains Mono'". They are data labels, not decoration. */
svg text[style*="font:9.5px"], svg text[style*="font: 9.5px"],
svg text[style*="font:9px"],   svg text[style*="font: 9px"] { font-size: 10.5px !important; }

/* Minimum legible size for text that carries data rather than decoration.
   index.html hardcodes font-size:9px / 9.5px / 10px in ~100 places — status
   pills, provider labels, chart day ticks, metadata captions. All of it is
   real information, so lift it to a floor of 10.5–11px. */
[style*="font-size:9px"],  [style*="font-size:9.5px"],
[style*="font-size: 9px"], [style*="font-size: 9.5px"]  { font-size: 10.5px !important; }
[style*="font-size:10px"],  [style*="font-size:10.5px"],
[style*="font-size: 10px"], [style*="font-size: 10.5px"] { font-size: 11px !important; }

/* Label/value rows: `flex items-center justify-between` with no gap lets a
   letter-spaced caption butt straight into its value once the column narrows
   (reported as "COMPLIANCE93%"). Give every such row a floor gap — but never
   override an explicit Tailwind gap-* utility. */
.flex.items-center.justify-between:not([class*="gap-"]),
.flex.justify-between.items-center:not([class*="gap-"]) { gap: 10px; }
.flex.items-baseline.justify-between:not([class*="gap-"]) { gap: 10px; }
.block-h { gap: 12px; flex-wrap: wrap; }
.meter .lbl { padding-left: 4px; }

/* ═══════════════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET (≤ 1024px)
   ═══════════════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .grid-5, .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .split-12 { grid-template-columns: 1fr; }
  .drawer { width: min(580px, 100vw); }
  .cmdk-trigger { min-width: 0; }
}

/* ═══════════════════════════════════════════════════════════════════════
   RESPONSIVE — PHONE (≤ 767px)
   Tailwind's md:/lg: variants stop applying below 768px, so a
   `grid-cols-2 lg:grid-cols-4` KPI row degrades to two squeezed columns and
   a `grid-cols-3` row to three. Everything below stacks instead.
   ═══════════════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {

  /* ── Shell: the sidebar becomes a 56px icon rail in BOTH Vue states ──
     app.js drives w-60/w-14 via sidebarCollapsed; rather than fight it, pin
     the width and hide the label text so either state renders the same rail.
     56px of a 375px viewport is 15%, against 64% for the w-60 default. */
  .sidebar {
    width: 56px !important;
    min-width: 56px;
    max-width: 56px;
    flex: 0 0 56px;
  }
  .sb-brand {
    flex-direction: column;
    gap: 8px;
    padding: 12px 4px !important;
    justify-content: center;
  }
  .sb-brand > .flex.flex-col { display: none !important; }  /* wordmark + LIVE pill */
  .sb-brand > button { margin-left: 0 !important; }
  .sb-section { display: none !important; }
  .sb-nav { padding-left: 6px !important; padding-right: 6px !important; }
  .sb-item {
    justify-content: center;
    padding-left: 0 !important;
    padding-right: 0 !important;
    min-height: 40px;                 /* comfortable tap target */
  }
  .sb-item > span:not(.ct) { display: none !important; }
  .sb-item .ct {                       /* alert count → corner badge */
    position: absolute; top: 1px; right: 1px;
    margin-left: 0;
    font-size: 10px; line-height: 1.3;
    padding: 0 3px; border-radius: 7px;
    background: var(--danger-tint);
  }
  .sb-foot { padding: 10px 6px !important; }
  .sb-foot > div:first-child { display: none !important; }  /* Firewall / Version */
  .sb-foot .sign-out { justify-content: center; }
  .sb-foot .sign-out span { display: none !important; }

  /* ── Topbar: stack title above the status/controls cluster ── */
  .topbar {
    grid-template-columns: 1fr;
    padding: 12px 14px;
    gap: 10px;
  }
  .topbar h1 { font-size: 18px; }
  .topbar .meta {
    align-items: flex-start;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px 14px;
    white-space: normal;
  }

  /* ── Content padding ── */
  .page { padding: 16px 14px 64px; }
  .panel-head { padding: 12px 14px; flex-wrap: wrap; min-height: 0; row-gap: 8px; }
  .panel-body { padding: 14px; }
  .p-6 { padding: 14px !important; }
  .p-8 { padding: 20px !important; }
  .px-6 { padding-left: 14px !important; padding-right: 14px !important; }

  /* ── Stat / KPI cards stack to one column ── */
  .grid-5, .grid-4, .grid-3, .grid-2, .split-12 { grid-template-columns: 1fr !important; }
  .grid.grid-cols-2, .grid.grid-cols-3, .grid.grid-cols-4,
  .grid.grid-cols-5, .grid.grid-cols-6,
  .sm\:grid-cols-2, .sm\:grid-cols-3, .sm\:grid-cols-4 {
    grid-template-columns: 1fr !important;
  }
  .kpi .num { font-size: 26px; }
  .panel, .panel-body, .kpi, .main { min-width: 0; }

  /* ── Long flex rows wrap instead of overflowing ── */
  .row { flex-wrap: wrap; }
  /* index.html builds many header rows with inline `display:flex` + a fixed
     icon and a trailing action button, which starves the middle text column at
     phone width (the onboarding card wrapped "Welcome to Gatewell" onto three
     lines). Let those inline rows wrap; row-direction only, so column stacks
     are untouched. Wrapping only engages when the content would overflow. */
  [style*="display:flex"]:not([style*="flex-direction:column"]),
  [style*="display: flex"]:not([style*="flex-direction: column"]) { flex-wrap: wrap; }
  /* `flex:1;min-width:0` (used for the middle text column of those rows) lets
     the column shrink to zero, so wrapping never engages and the text collapses
     into a 90px ribbon instead. Give it a floor so the trailing action wraps
     to its own line. */
  [style*="flex:1;min-width:0"] { min-width: 150px !important; }
  /* Vue normalises static inline styles, so `flex:1;min-width:0` reaches the
     DOM as `flex: 1 1 0%; min-width: 0px`. Match both spellings. */
  [style*="flex: 1 1 0%"][style*="min-width: 0"] { min-width: 150px !important; }
  .ptabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .ptabs::-webkit-scrollbar { display: none; }
  .ptab { white-space: nowrap; }

  /* ── Data tables: scroll inside their own box rather than the page ──
     :has() lets us give the *existing* wrapper (or the panel itself, for the
     tables that ship without one) a scroll container without touching markup. */
  :is(div, section, form, li, .panel, .panel-body):has(> table) {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  table.tbl { min-width: 560px; }
  .tbl th, .tbl td { padding: 10px 10px; white-space: nowrap; }
  .tbl td .truncate { max-width: 150px; }
  pre.code { font-size: 12px; }

  /* ── Drawers / modals go full-bleed ── */
  .drawer { width: 100vw; }
  .drawer-head, .drawer-body, .drawer-foot { padding-left: 16px; padding-right: 16px; }
  .l-drawer { width: 100vw; }
}

/* ═══════════════════════════════════════════════════════════════════════
   OPT-IN: card-style stacked table rows for the densest tables.
   Add class="tbl tbl-stack" to the table and data-label="Column" to each
   <td>; below 768px each row becomes a labelled card. Purely additive —
   tables without the class keep the horizontal-scroll behaviour above.
   ═══════════════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
  table.tbl-stack { min-width: 0; display: block; }
  .tbl-stack thead { display: none; }
  .tbl-stack tbody, .tbl-stack tr, .tbl-stack td { display: block; width: 100%; }
  .tbl-stack tr {
    border: 1px solid var(--line);
    border-radius: var(--r-3);
    background: var(--card);
    margin-bottom: 10px;
    padding: 4px 2px;
  }
  .tbl-stack td {
    border-bottom: 1px solid var(--line-soft) !important;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    white-space: normal;
    text-align: right;
  }
  .tbl-stack tr td:last-child { border-bottom: 0 !important; }
  .tbl-stack td::before {
    content: attr(data-label);
    font-family: var(--f-mono);
    font-size: 10.5px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-dim);
    text-align: left;
    flex: 0 0 auto;
  }
}
