/* Sovara governance console - styled after the Sovara Browser product page (sovarahq.com):
   flat & editorial, single green accent on ink, hairline dividers, square corners, Inter.

   Layering: pico.min.css loads first as a classless base (buttons, inputs, selects, tables,
   details/summary). This sheet themes Pico through its --pico-* variables, then adds everything
   Pico has no opinion about: the shell, tiles, panels, charts, badges and the bespoke widgets. */

/* Inter is self-hosted, not fetched from a CDN: the console has to work on air-gapped networks,
   the same constraint that keeps Pico local (see build.mjs). One variable file covers 100–900;
   italics are unused, so they are not shipped. Licence: fonts/OFL.txt (Inter v4.1). */
@font-face {
  font-family: 'Inter';
  src: url('fonts/InterVariable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f9fff8;            /* pale mint page wash (product-page background) */
  --panel: #ffffff;
  --ink: #1c1917;           /* headings + body */
  --muted: #4b4846;         /* secondary text */
  --faint: #6f6b68;         /* tertiary / axis labels - AA on the page wash */
  --line: rgba(28, 25, 23, 0.10);   /* the signature hairline */
  --line-strong: rgba(28, 25, 23, 0.20);
  --accent: #218f31;        /* Sovara green */
  --accent-deep: #1b7429;
  --accent-dark: #145b20;
  --accent-tint: #e9f7ea;   /* accent @ ~10% */
  --surface-subtle: #fbfdfb;

  /* Verdict semantics - shared with the extension overlay so the product speaks one language. */
  --allow: #218f31;   --allow-bg: #e9f7ea;
  --warn: #854f00;    --warn-bg: #fef3c7;
  --redact: #6a1b9a;  --redact-bg: #f4eefa;
  --block: #b42318;   --block-bg: #fde7e4;

  --radius: 2px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --font-sans: 'Inter', system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Code', Consolas, monospace;
}

/* ── Pico theme ────────────────────────────────────────────────────────
   Matches Pico's own `:root:not([data-theme=dark])` specificity so these win wherever they
   collide, including inside Pico's responsive font-size media queries. */
:root:not([data-theme="dark"]) {
  --pico-font-family: var(--font-sans);
  --pico-font-family-sans-serif: var(--font-sans);
  --pico-font-family-monospace: var(--font-mono);
  /* 15px base. MUST move in lockstep with `body { font: … }` below - Pico sizes its own controls
     from this and the bespoke CSS sizes everything else from that, so drift shows up as inputs
     that no longer match the text beside them. */
  --pico-font-size: 93.75%;
  --pico-line-height: 1.6;
  --pico-font-weight: 500;
  --pico-border-radius: var(--radius);
  --pico-border-width: 1px;
  --pico-outline-width: 2px;
  --pico-spacing: 1rem;
  --pico-typography-spacing-vertical: 0.75rem;

  --pico-background-color: var(--bg);
  --pico-color: var(--ink);
  --pico-muted-color: var(--muted);
  --pico-muted-border-color: var(--line);
  --pico-h1-color: var(--ink);
  --pico-h2-color: var(--ink);
  --pico-h3-color: var(--ink);
  --pico-h4-color: var(--ink);
  --pico-h5-color: var(--ink);
  --pico-h6-color: var(--muted);

  --pico-primary: var(--accent);
  --pico-primary-background: var(--accent-deep);
  --pico-primary-border: var(--accent-deep);
  --pico-primary-underline: rgba(33, 143, 49, 0.5);
  --pico-primary-hover: var(--accent-dark);
  --pico-primary-hover-background: var(--accent-dark);
  --pico-primary-hover-border: var(--accent-dark);
  --pico-primary-hover-underline: var(--accent-dark);
  --pico-primary-focus: rgba(33, 143, 49, 0.35);
  --pico-primary-inverse: #fff;

  /* Pico's "secondary" is our quiet outline button - flat, hairline, ink on panel. */
  --pico-secondary: var(--muted);
  --pico-secondary-background: var(--panel);
  --pico-secondary-border: var(--line-strong);
  --pico-secondary-hover: var(--ink);
  --pico-secondary-hover-background: var(--panel);
  --pico-secondary-hover-border: var(--ink);
  --pico-secondary-focus: rgba(33, 143, 49, 0.35);
  --pico-secondary-inverse: var(--ink);

  /* Tighter than Pico's default 0.75rem/1rem - this is a dense admin console, not a landing page. */
  --pico-form-element-spacing-vertical: 0.5rem;
  --pico-form-element-spacing-horizontal: 0.65rem;
  --pico-form-element-background-color: var(--panel);
  --pico-form-element-active-background-color: var(--panel);
  --pico-form-element-border-color: var(--line-strong);
  --pico-form-element-active-border-color: var(--accent);
  --pico-form-element-focus-color: var(--accent);
  --pico-form-element-color: var(--ink);
  --pico-form-label-font-weight: 500;

  --pico-table-border-color: var(--line);
  --pico-code-background-color: var(--bg);
  --pico-code-color: var(--ink);
  --pico-blockquote-border-color: var(--line);
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  /* Keep in lockstep with --pico-font-size above. */
  font: 15px/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

/* ── Type scale ────────────────────────────────────────────────────────
   Four levels and no more. H1 is the shell's page header; H2 labels a panel or a section; H3 a
   sub-block inside one. The tiny-uppercase treatment is no longer what a heading looks like - it
   is an explicit `.eyebrow` class for elements that are labels rather than headings. */
h1, h2, h3 { letter-spacing: -0.02em; color: var(--ink); }
h2 { font-size: 1.05rem; font-weight: 600; text-transform: none; }
h3 { font-size: 0.92rem; font-weight: 600; text-transform: none; }
.eyebrow {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted);
}

/* Tables stay denser than body copy: they are scanned, not read. */
.table-scroll table { font-size: 0.9rem; }

/* ── Shell ─────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.75rem;
  padding: 0.7rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.55rem; flex-shrink: 0; }
.brand svg { display: block; color: var(--accent); }
.brand-word { font-weight: 600; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand-tag {
  font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--accent); font-weight: 600; padding-left: 0.55rem; margin-left: 0.1rem;
  border-left: 1px solid var(--line);
}
/* Pico's `nav` is a space-between bar; the console's tabs sit tight against the brand instead.
   No overflow here: `overflow-x: auto` computes `overflow-y` from visible to auto, and the links'
   -1px bottom margin then makes the content 1px taller than the box - a scroll container at every
   width, for one pixel. Scrolling is only ever needed narrow, so it lives in the media query. */
.topbar nav { display: flex; justify-content: flex-start; gap: 0.1rem; flex: 1; margin: 0; padding: 0; }
.topbar nav a {
  padding: 0.4rem 0.8rem;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
}
.topbar nav a:hover { color: var(--ink); background: none; }
.topbar nav a.active { color: var(--accent); border-bottom-color: var(--accent); }
#sign-out { flex-shrink: 0; padding: 0.4rem 0.9rem; }

/* Sub-tab bar - rendered by the shell for sections that have children (Policy, Settings). */
.subnav {
  display: flex; justify-content: flex-start; gap: 0.25rem; margin: 0; padding: 0 1.5rem;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.subnav a {
  padding: 0.5rem 0.8rem; color: var(--muted); text-decoration: none;
  font-size: 0.95rem; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subnav a:hover { color: var(--ink); background: none; }
.subnav a.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 500; }

@media (max-width: 800px) {
  .topbar { flex-wrap: wrap; gap: 0.75rem 1rem; padding: 0.7rem 1rem; }
  .topbar nav { order: 3; flex-basis: 100%; }
  .subnav { padding: 0 1rem; }

  /* Narrow enough that the tabs genuinely run off the edge: swipe them. `overflow-y: hidden`
     is explicit so the pair stays auto/hidden rather than auto/auto, and the scrollbar chrome
     is hidden - it would sit on the hairline and read as a broken border. */
  .topbar nav, .subnav { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  .topbar nav::-webkit-scrollbar, .subnav::-webkit-scrollbar { display: none; }
}

main { padding: 1.75rem 1.5rem; max-width: 1180px; margin: 0 auto; }
/* The shell owns every page intro: one H1 and one plain-language sentence, rendered from the route
   table. Views must not repeat it. */
.page-header { margin: 0 0 1.25rem; }
.page-heading { margin: 0 0 0.3rem; font-size: 1.4rem; font-weight: 600; }
.page-heading:focus { outline: none; }
.page-intro { margin: 0; color: var(--muted); max-width: 70ch; }
.page-intro:empty { display: none; }

/* ── Sign-in ───────────────────────────────────────────────────────── */
.signin {
  max-width: 400px; margin: 12vh auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 2.25rem;
}
.signin .brand { justify-content: center; margin-bottom: 1.25rem; }
.signin h1 { margin: 0 0 0.35rem; font-size: 1.2rem; text-align: center; }
.signin .sub { margin: 0 0 1.5rem; color: var(--muted); text-align: center; font-size: 0.9rem; }
.signin label { margin: 0.9rem 0 0.3rem; font-size: 0.9rem; }
.signin button[type="submit"] { margin-top: 1.25rem; width: 100%; }
.signin details { margin-top: 0.9rem; color: var(--muted); font-size: 0.9rem; }
.signin .errors:empty { display: none; }
#signin-message { margin: 0 0 1.1rem; text-align: center; }
.sso-loading { min-height: 2.75rem; margin: 0 0 1.1rem; color: var(--muted); text-align: center; }

/* Microsoft's sign-in button styling is prescribed by their branding guidelines: white
   surface, grey border, the four-square mark to the left of the label. */
.sso-button {
  display: flex; align-items: center; justify-content: center; gap: 0.6rem;
  width: 100%; margin: 0 0 1.1rem;
  --pico-background-color: #fff; --pico-color: #5e5e5e; --pico-border-color: #8c8c8c;
  font-weight: 600;
}
.sso-button:hover { --pico-background-color: #f3f3f3; --pico-color: #5e5e5e; --pico-border-color: #8c8c8c; }
.sso-divider {
  margin: 0 0 1.1rem !important; position: relative; text-transform: uppercase;
  font-size: 0.72rem; letter-spacing: 0.08em;
}
.sso-divider::before, .sso-divider::after {
  content: ''; position: absolute; top: 50%; width: calc(50% - 1.4rem); height: 1px; background: var(--line);
}
.sso-divider::before { left: 0; }
.sso-divider::after { right: 0; }

/* ── KPI tiles ─────────────────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 1.25rem; }
.tile { background: var(--panel); padding: 1.15rem 1.25rem; display: flex; flex-direction: column; gap: 0.15rem; }
.tile-value { font-size: 1.95rem; font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; }
.tile-label { color: var(--muted); font-size: 0.82rem; }
.tile-alert .tile-value { color: var(--block); }
.tile-warn .tile-value { color: var(--warn); }

/* ── Panels ────────────────────────────────────────────────────────── */
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.35rem; margin-bottom: 1rem; }
.panels .panel { margin-bottom: 0; }  /* grid gap governs spacing inside the grid */
/* A real heading, not the old tiny-uppercase label. Flex only so a count badge can sit beside it. */
.panel h2 {
  margin: 0 0 0.85rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.panel.span-2 { grid-column: 1 / -1; }

/* ── Charts ────────────────────────────────────────────────────────── */
.chart-donut { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.donut { flex-shrink: 0; }
.donut-value { font-size: 1.6rem; font-weight: 600; fill: var(--ink); letter-spacing: -0.03em; }
.donut-label { font-size: 0.62rem; fill: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.legend { display: flex; flex-direction: column; gap: 0.5rem; min-width: 140px; }
.legend-row { display: flex; align-items: center; gap: 0.55rem; font-size: 0.88rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.legend-label { color: var(--ink); text-transform: capitalize; }
.legend-value { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }

.barlist { display: flex; flex-direction: column; gap: 0.7rem; }
.bar-row { display: grid; grid-template-columns: 8rem 1fr 2.5rem; align-items: center; gap: 0.75rem; }
.bar-label { color: var(--ink); font-size: 0.88rem; text-transform: capitalize; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; min-width: 2px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.85rem; }

.spark { display: block; width: 100%; height: auto; }
.spark-area { fill: var(--accent-tint); }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.spark-axis { fill: var(--faint); font-size: 10px; }
.spark-grid { stroke: var(--line); stroke-width: 1; }
.spark-dot { fill: var(--accent); }
.chart-empty { color: var(--muted); padding: 0.5rem 0 0.75rem; }

/* ── Tables ────────────────────────────────────────────────────────── */
/* Pico supplies the reset, borders and spacing; these are the console's own conventions. */
th, td { padding: 0.55rem 0.7rem; }
th { color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; }
tbody tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  /* `overflow-x: auto` clips the paint but a `min-width: max-content` TABLE still contributes its
     full width to the VIEWPORT's scrollable overflow in Chromium, so the whole page scrolled
     sideways (Settings, ~450px of empty space at 1280px). Paint containment stops the propagation;
     the table still scrolls inside its own box. */
  contain: paint;
}
.table-scroll:focus-visible { box-shadow: 0 0 0 var(--pico-outline-width) var(--pico-primary-focus); }
.table-scroll > table { min-width: max-content; margin-bottom: 0; border: 0; }
.events { margin-bottom: 0; }
.events thead th { background: var(--surface-subtle); }
.muted { color: var(--muted); font-size: 0.9em; }
.empty, .loading { color: var(--muted); padding: 1rem; }
.view-loading { display: grid; gap: 0.75rem; min-height: 22rem; align-content: start; }
.skeleton {
  display: block;
  background: linear-gradient(90deg, var(--line) 25%, var(--surface-subtle) 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: sovara-shimmer 1.4s ease-in-out infinite;
}
.skeleton-title { width: 12rem; height: 1.5rem; }
.skeleton-tile { height: 6rem; }
.skeleton-panel { height: 13rem; }
@keyframes sovara-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ── Badges (verdict chips - square, like the product overlay) ─────── */
.badge { padding: 0.12rem 0.5rem; border-radius: var(--radius); font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; background: var(--bg); color: var(--muted); }
.badge-block { background: var(--block-bg); color: var(--block); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-redact { background: var(--redact-bg); color: var(--redact); }
.badge-allow { background: var(--allow-bg); color: var(--allow); }
.badge-alert { background: var(--block-bg); color: var(--block); }

/* ── Forms ─────────────────────────────────────────────────────────
   Pico stretches every input/select/textarea to 100%. That is right inside a stacked .field
   and wrong everywhere the console lays controls out in a row, so those opt back out. */
.field { display: block; margin-bottom: 0.7rem; color: var(--muted); }
.field > input, .field > select, .field > textarea { margin-top: 0.3rem; margin-bottom: 0; color: var(--ink); }
.field > textarea { font: 12px/1.55 var(--font-mono); }
.check { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.45rem; font-weight: 400; }
.check input[type="checkbox"] { margin: 0; flex-shrink: 0; }
.check-fields { margin: 0 0 0.7rem 1.7rem; }

/* ── Explained settings form ───────────────────────────────────────────
   A spacious single column: label, control, and the consequence of the control. Used by Workforce
   identity, where one of the settings starts blocking every governed send in the organisation. */
.settings-form { max-width: 34rem; }
.field-group { margin-bottom: 1.35rem; }
.field-group > label { display: block; margin-bottom: 0.25rem; font-weight: 500; color: var(--ink); }
.field-group > label.check { display: flex; margin-bottom: 0.3rem; }
.field-group > input, .field-group > select { margin-bottom: 0; }
.field-help { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.88rem; max-width: 60ch; }
.consequences { margin: 0.5rem 0 0; padding: 0 0 0 1.05rem; color: var(--muted); font-size: 0.88rem; max-width: 60ch; }
.consequences li { margin: 0.2rem 0; }
.consequences strong { color: var(--ink); }

/* The acknowledgement is the switch that turns blocking on, so it gets its own bordered, tinted
   region with a visible legend rather than sitting in the run of ordinary fields. */
fieldset.required-warning {
  margin: 0 0 1.35rem; padding: 0.85rem 1rem 0.9rem;
  background: var(--warn-bg); border: 1px solid var(--warn); border-radius: var(--radius);
}
fieldset.required-warning legend {
  padding: 0 0.4rem; margin-left: -0.4rem;
  color: var(--warn); font-weight: 600; font-size: 0.88rem; width: auto;
}
fieldset.required-warning .check { margin-bottom: 0; align-items: flex-start; }
fieldset.required-warning .field-help { color: var(--warn); }

.identity-operational { margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: 0.75rem; }
.identity-operational summary { color: var(--muted); }
.identity-operational p { margin: 0.6rem 0 0; color: var(--muted); max-width: 70ch; }

.filters { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.filters input, .filters select, .filters button { width: auto; margin-bottom: 0; }
.filters select { min-width: 9rem; }

.actions { display: flex; gap: 0.75rem; align-items: center; margin-top: 0.6rem; flex-wrap: wrap; }
.actions button, .actions input, .actions select { width: auto; margin-bottom: 0; }
.pager { display: flex; gap: 0.75rem; align-items: center; margin-top: 1rem; }
/* Paging is navigation, not a primary action - quiet outline, like the row actions. */
.pager button {
  width: auto; margin-bottom: 0; padding: 0.3rem 0.8rem;
  --pico-background-color: var(--panel); --pico-border-color: var(--line-strong); --pico-color: var(--ink);
}
.pager button:hover:not(:disabled) { --pico-background-color: var(--panel); --pico-border-color: var(--ink); --pico-color: var(--ink); }

/* Row-action utilities - the compact buttons inside table cells. */
.btn-xs { width: auto; min-height: 2.75rem; margin-bottom: 0; padding: 0.35rem 0.65rem; font-size: 0.78rem; white-space: nowrap; }
.btn-outline {
  --pico-background-color: var(--panel);
  --pico-border-color: var(--line-strong);
  --pico-color: var(--ink);
}
.btn-outline:hover { --pico-background-color: var(--panel); --pico-border-color: var(--ink); --pico-color: var(--ink); }

#policy-json { width: 100%; font: 12px/1.55 var(--font-mono); padding: 0.85rem; }
.errors { color: var(--block); margin: 0.5rem 0 0; padding-left: 1.1rem; }
p.errors { padding-left: 0; }
.errors:empty { display: none; }
.hint { color: var(--muted); }
/* Beginner-oriented detail below the shell's one-line route intro: what a row means, what each term
   means. Quiet enough to skip once you know, close enough to the data to be read on the way past. */
.explainer {
  background: var(--surface-subtle); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.85rem 1.1rem; margin-bottom: 1.25rem; max-width: 78ch;
}
.explainer p { margin: 0 0 0.5rem; color: var(--muted); }
.explainer p:last-child { margin-bottom: 0; }
.explainer strong, .explainer em { color: var(--ink); }
.explainer .badge { margin-right: 0.15rem; }
.warn-banner { background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); padding: 0.65rem 0.95rem; margin-top: 1.25rem; font-weight: 500; }
.manage-billing { margin-top: 0.75rem; display: flex; align-items: center; gap: 0.6rem; }
.manage-billing button { width: auto; margin-bottom: 0; }
.view-error { padding: 1rem; display: flex; flex-direction: column; align-items: flex-start; gap: 0.6rem; }
.view-error button { width: auto; margin-bottom: 0; }

/* ── AI policy generator ───────────────────────────────────────────── */
.ai-gen { background: var(--accent-tint); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; }
.ai-gen h3 { margin: 0 0 0.35rem; color: var(--ink); }
.ai-gen .hint { margin: 0 0 0.7rem; }
.ai-gen .actions { margin-top: 0.7rem; }
#ai-org { margin-bottom: 0; resize: vertical; }
.ai-preview { margin-top: 0.7rem; }
.ai-preview summary { color: var(--muted); font-size: 0.85rem; }
.ai-preview pre { max-height: 260px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem; font: 11.5px/1.5 var(--font-mono); white-space: pre-wrap; margin: 0.5rem 0 0; color: var(--ink); }

/* ── Policy simulator ──────────────────────────────────────────────── */
.sim-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 760px) { .sim-grid { grid-template-columns: 1fr; } }
.sim-inputs { display: flex; flex-direction: column; }
.sim-advanced { margin: 0.25rem 0 0.7rem; color: var(--muted); }
.sim-result { margin-top: 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.sim-verdict { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.85rem; }
.sim-verdict .badge { font-size: 0.9rem; padding: 0.3rem 0.8rem; }
.sim-detail td:first-child { color: var(--muted); width: 10rem; }
.sim-result h3 { margin: 1.25rem 0 0.25rem; }
.trace td:first-child { font-family: var(--font-mono); }
.candidate-save { margin-top: 1rem; color: var(--muted); }
.candidate-save input { min-width: 16rem; width: auto; margin-bottom: 0; }

/* ── Detector toggle grid ─────────────────────────────────────────── */
.detector-grid { margin-bottom: 1.25rem; }
h3.detector-category { margin: 1.5rem 0 0.5rem; }
h3.detector-category:first-child { margin-top: 0; }
/* Two columns at most. `auto-fill minmax(320px, …)` fitted three or four on a wide screen, which
   turned every description into an ellipsis and made the grid unscannable. */
.detector-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.4rem; margin-bottom: 0.4rem; }
@media (max-width: 720px) { .detector-list { grid-template-columns: 1fr; } }
.detector-row {
  display: flex; align-items: flex-start; gap: 0.6rem; padding: 0.65rem 0.85rem;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
}
/* Name over description, both wrapping: the column is now wide enough that the description is
   worth reading, so it is no longer truncated. */
.detector-toggle {
  display: grid; grid-template-columns: auto 1fr; gap: 0 0.5rem; flex: 1; min-width: 0;
  margin: 0; cursor: pointer; font-weight: 400;
}
.detector-toggle input[type="checkbox"] { margin: 0; grid-row: 1 / span 2; align-self: center; flex-shrink: 0; }
.detector-name { font-size: 0.9rem; }
.detector-desc { grid-column: 2; font-size: 0.82rem; min-width: 0; }
.detector-row select { width: auto; margin-bottom: 0; align-self: center; padding: 0.15rem 1.6rem 0.15rem 0.4rem; font-size: 0.78rem; background-position: center right 0.4rem; background-size: 0.7rem auto; }

/* ── Preset cards ─────────────────────────────────────────────────── */
.preset-cards { margin-bottom: 1.25rem; }
.preset-cards h3 { margin: 0 0 0.6rem; }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.75rem; }
.preset-card {
  display: flex; flex-direction: column; gap: 0.25rem; align-items: flex-start; text-align: left;
  width: auto; margin-bottom: 0; padding: 1rem 1.15rem;
  --pico-background-color: var(--panel); --pico-border-color: var(--line); --pico-color: var(--ink);
}
.preset-card:hover { --pico-background-color: var(--panel); --pico-border-color: var(--accent); --pico-color: var(--ink); }
.preset-card strong { font-size: 0.95rem; }
.preset-card .muted { font-weight: 400; }

/* ── Terms builder ────────────────────────────────────────────────── */
.terms-builder { margin-bottom: 1rem; }
.terms-builder h2 { margin: 0 0 0.25rem; }
.term-input-row { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.5rem; }
.term-input-row input { flex: 1; min-width: 12rem; width: auto; margin-bottom: 0; }
.term-input-row button, .term-input-row select { width: auto; margin-bottom: 0; }
.term-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.term-chip {
  display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.2rem 0.35rem 0.2rem 0.5rem;
  background: var(--accent-tint); border-radius: var(--radius); font-size: 0.85rem;
}
.term-chip .chip-remove {
  width: 2.75rem; min-width: 2.75rem; height: 2.75rem; margin: -0.7rem -0.55rem -0.7rem 0;
  padding: 0; line-height: 1; font-size: 0.9rem;
  --pico-background-color: transparent; --pico-border-color: transparent; --pico-color: var(--block);
}
.term-chip .chip-remove:hover { --pico-background-color: transparent; --pico-border-color: transparent; --pico-color: var(--block); }

/* ── Policy view chrome ───────────────────────────────────────────── */
.policy-section { margin: 0 0 1.75rem; }
.policy-section + .policy-section { border-top: 1px solid var(--line); padding-top: 1.5rem; }
.policy-section > h2 { margin: 0 0 0.75rem; }
.policy-accordion > summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 600;
  padding: 0.15rem 0;
}
.policy-accordion > summary::marker { color: var(--accent); }
.policy-accordion > .accordion-body { padding-top: 1rem; }
.policy-accordion:not([open]) { margin-bottom: 1rem; }
#advanced .ai-gen { margin-bottom: 1.25rem; }
.advanced-tool { margin: 0 0 1.25rem; }
.advanced-tool + .advanced-tool { border-top: 1px solid var(--line); padding-top: 1.25rem; }
.advanced-tool h3 { margin: 0 0 0.35rem; font-size: 0.95rem; }
.json-editor-section button { width: auto; }
.json-editor-section textarea { margin-top: 0.75rem; }
.candidate-save .actions { align-items: center; }
.candidate-save input { flex: 1 1 14rem; min-width: min(100%, 14rem); margin-bottom: 0; }

/* ── Policy diff panel ────────────────────────────────────────────── */
.diff-panel { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; margin-bottom: 1rem; }
.diff-panel h3 { margin: 0 0 0.6rem; font-size: 0.85rem; font-weight: 600; }
.diff-list { list-style: none; margin: 0; padding: 0; }
.diff-list li { list-style: none; padding: 0.3rem 0; font-size: 0.88rem; border-bottom: 1px solid var(--line); }
.diff-list li:last-child { border-bottom: 0; }
.diff-added { color: var(--allow); }
.diff-removed { color: var(--block); }
.diff-changed { color: var(--warn); }
.diff-empty { color: var(--muted); margin: 0 0 1rem; }

/* ── Policy summary ────────────────────────────────────────────────
   A scannable fact table, not prose: the action leads as the same verdict chip the events table
   and simulator use, then a count, then the labels. Grid so the chips and counts line up into
   columns the eye can run down. */
.policy-summary { margin-top: 1rem; }
.summary-grid { display: grid; grid-template-columns: auto auto 1fr; gap: 0 0.85rem; }
.summary-row { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; align-items: baseline; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.summary-row:last-child { border-bottom: 0; }
.summary-row .badge { justify-self: start; }
.summary-count { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 0.85rem; color: var(--ink); text-align: right; }
/* Each label is its own quiet chip rather than text with separators: a 16-rule policy wraps over
   several lines, and any separator glyph ends up stranded at the start of a continuation line. */
.summary-items { display: flex; flex-wrap: wrap; gap: 0.3rem; font-size: 0.88rem; color: var(--ink); }
.summary-items > span {
  padding: 0.12rem 0.5rem; background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.summary-label { grid-column: 1 / 3; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.summary-value { font-size: 0.88rem; color: var(--ink); }
.summary-empty { color: var(--muted); margin: 0; }

/* Fallback for browsers without `subgrid`: the row still reads, just without column alignment. */
@supports not (grid-template-columns: subgrid) {
  .summary-row { grid-template-columns: auto auto 1fr; }
}

/* ── Setup wizard ─────────────────────────────────────────────────── */
.wizard { max-width: 640px; margin: 0 auto; }

/* Step indicator: numbered discs joined by a hairline, filled as you advance. */
.wizard-steps {
  display: flex; list-style: none; margin: 0 0 1.25rem; padding: 0;
  counter-reset: none; align-items: flex-start;
}
.wizard-steps .wizard-step {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 0.35rem; text-align: center; min-width: 0;
}
/* The connector runs from each disc back to the previous one, behind the discs. */
.wizard-steps .wizard-step::before {
  content: ''; position: absolute; top: 0.85rem; right: 50%; left: -50%;
  height: 1px; background: var(--line-strong);
}
.wizard-steps .wizard-step:first-child::before { display: none; }
.wizard-steps .wizard-step.active::before,
.wizard-steps .wizard-step.done::before { background: var(--accent); }
.wizard-disc {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  width: 1.7rem; height: 1.7rem; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--panel);
  color: var(--muted); font-size: 0.8rem; font-weight: 600;
}
.wizard-step.active .wizard-disc { border-color: var(--accent); background: var(--accent); color: #fff; }
.wizard-step.done .wizard-disc { border-color: var(--accent); background: var(--accent-tint); color: var(--accent-deep); }
.wizard-step-label { font-size: 0.75rem; color: var(--muted); }
.wizard-step.active .wizard-step-label { color: var(--ink); font-weight: 500; }
@media (max-width: 560px) { .wizard-step-label { display: none; } }

.wizard-card { padding: 1.5rem 1.6rem 1.25rem; margin-bottom: 0; }
.wizard-counter {
  margin: 0 0 0.3rem; font-size: 0.68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted);
}
.wizard-card h2 { margin: 0 0 0.3rem; font-size: 1.1rem; text-transform: none; letter-spacing: -0.02em; color: var(--ink); display: block; }
.wizard-lede { margin: 0 0 1.25rem; font-size: 0.9rem; }
.wizard-body > :last-child { margin-bottom: 0; }
.wizard-options { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.9rem; }
/* `label.` and not `.` alone: Pico's `label:has([type=checkbox])` shrinks these to fit-content,
   and that rule outranks a bare class selector. */
label.wizard-option {
  width: 100%;
  display: flex; align-items: center; gap: 0.6rem; margin: 0; padding: 0.6rem 0.75rem;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  cursor: pointer; font-weight: 400;
}
.wizard-option:hover { border-color: var(--line-strong); }
.wizard-option input[type="checkbox"], .wizard-option input[type="radio"] { margin: 0; flex-shrink: 0; }
.wizard-option.selected { border-color: var(--accent); background: var(--accent-tint); }
.wizard-nav {
  display: flex; gap: 0.75rem; align-items: center; justify-content: flex-end;
  margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line);
}
.wizard-nav button { width: auto; margin-bottom: 0; min-width: 6rem; }
.wizard-nav #wiz-back { margin-right: auto; }

/* ── Settings ─────────────────────────────────────────────────────── */
.settings-layout { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 1rem; align-items: start; }
.settings-layout .panel { margin-bottom: 0; }
tr.unread { font-weight: 600; }

.actions-spaced { margin-bottom: var(--space-4); }
.sticky-actions {
  position: sticky;
  top: 0;
  z-index: 4;
  margin: 0.75rem -0.5rem 1rem;
  padding: 0.75rem 0.5rem;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
/* Unsaved work colours the whole bar, not just the words inside it - the bar is what stays on
   screen while the admin scrolls the rules, so it has to carry the state. */
.sticky-actions[data-dirty="true"] { border-top: 2px solid var(--warn); background: color-mix(in srgb, var(--warn-bg) 60%, var(--bg)); }
.dirty-indicator { color: var(--warn); font-weight: 600; }

/* ── Rollout breakdown ────────────────────────────────────────────── */
.rollout-breakdown h3 { margin: 1.1rem 0 0.4rem; }

@media (max-width: 560px) {
  main { padding: 1.25rem 0.75rem; }
  .topbar nav::after, .subnav::after {
    content: 'Swipe for more';
    position: sticky;
    right: 0;
    align-self: center;
    padding: 0.25rem 0.4rem;
    background: var(--panel);
    color: var(--muted);
    font-size: 0.68rem;
    /* It is a hint pinned to the edge of a scroller, so it must not wrap - without this it breaks
       into three stacked words and reads as a layout fault. */
    white-space: nowrap;
    box-shadow: -0.75rem 0 0.75rem var(--panel);
  }
}
