/* CorpProfit console, in the Regnum design language.
 *
 * The class vocabulary is unchanged on purpose. Every page and every page
 * script names the same things it always did -- `panel`, `stat`, `pill`,
 * `hazard`, `gate-item` -- and only what they look like has moved. A restyle
 * that also renames is two changes at once, and the second one breaks pages
 * silently: a stylesheet cannot tell you that `.notice` became `.banner`
 * somewhere it was still being written.
 *
 * What came from Regnum: the warm ground, the near-black ink, the lime
 * accent, Bricolage Grotesque over Geist, generous radii, and the habit of
 * separating surfaces by colour rather than by drawing boxes around them.
 *
 * What this console keeps, because it is an operations desk and not a
 * marketing site:
 *
 *   - The verdict colours stay load-bearing. `pass`, `hold` and `block` are
 *     the whole vocabulary of a guardrail panel, and they are read at a
 *     glance by somebody deciding whether to arm an order.
 *   - Numbers are monospaced and tabular everywhere. A column of rupee
 *     figures that does not align is a column nobody scans.
 *   - Density is switchable. This desk is read on a laptop at arm's length
 *     and on a phone one-handed, and one spacing does not serve both.
 */

:root {
  color-scheme: light;

  /* Surfaces, warm rather than blue-grey. */
  --ground: #eeece6;
  --surface: #ffffff;
  --surface-muted: #eeece6;
  --track: #e7e4dc;
  --nav-hover: #e4e1d9;
  --line: #ddd9d0;
  --line-subtle: #eeece6;

  --ink: #16181d;
  --ink-2: #3a3d44;
  --ink-muted: #5b5f68;
  --ink-subtle: #6b6f78;

  --action: #16181d;
  --on-action: #ffffff;
  --accent: #c6f432;
  --on-accent: #16181d;

  /* Verdicts. Named for what a guardrail says, not for a colour: the panel
     that uses them is the one an operator reads before arming an order. */
  --pass: #15803d;
  --pass-soft: #dcfce7;
  --on-pass-soft: #14532d;
  --hold: #d97706;
  --hold-soft: #fef3c7;
  --on-hold-soft: #92400e;
  --block: #b42318;
  --block-soft: #fee4e2;
  --on-block-soft: #912018;
  --note: #0f766e;
  --note-soft: #ccfbf1;
  --on-note-soft: #134e4a;

  --focus: #0f766e;
  --scrim: rgba(22, 24, 29, 0.45);

  --shadow-card: 0 1px 2px rgba(22, 24, 29, 0.04);
  --shadow-popover: 0 20px 60px rgba(22, 24, 29, 0.18);
  --shadow-dialog: 0 30px 80px rgba(22, 24, 29, 0.25);
  --shadow-toast: 0 10px 30px rgba(22, 24, 29, 0.22);

  --font-display: 'Bricolage Grotesque', Georgia, serif;
  --sans: Geist, -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-2xl: 20px;
  --r-3xl: 24px;

  /* Density, switchable at runtime from the top bar. `--density-gap` is
     named in the markup, so it keeps its name. */
  --density-padding: 18px;
  --density-gap: 12px;
  --density-text-sm: 13px;
  --density-text-xs: 11px;
  --density-cell-py: 12px;
  --density-cell-px: 16px;
  --density-row: 1.45;

  --bar-h: 52px;
}

/* Dark, twice: once for a system preference the operator has not overridden,
   and once for an explicit choice. The guard on the first is what lets the
   second win. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --ground: #111214;
    --surface: #1b1d22;
    --surface-muted: #25282e;
    --track: #2c2f36;
    --nav-hover: #25282e;
    --line: #33363d;
    --line-subtle: #25282e;
    --ink: #f2f1ec;
    --ink-2: #cfd0d4;
    --ink-muted: #a3a6ae;
    --ink-subtle: #8c9099;
    --action: #f2f1ec;
    --on-action: #16181d;
    --pass: #4ade80;
    --pass-soft: #0f2e1b;
    --on-pass-soft: #86efac;
    --hold: #f59e0b;
    --hold-soft: #3a2a08;
    --on-hold-soft: #fcd34d;
    --block: #f97066;
    --block-soft: #3d1512;
    --on-block-soft: #fda29b;
    --note: #2dd4bf;
    --note-soft: #0f3b37;
    --on-note-soft: #99f6e4;
    --focus: #2dd4bf;
    --scrim: rgba(0, 0, 0, 0.6);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --ground: #111214;
  --surface: #1b1d22;
  --surface-muted: #25282e;
  --track: #2c2f36;
  --nav-hover: #25282e;
  --line: #33363d;
  --line-subtle: #25282e;
  --ink: #f2f1ec;
  --ink-2: #cfd0d4;
  --ink-muted: #a3a6ae;
  --ink-subtle: #8c9099;
  --action: #f2f1ec;
  --on-action: #16181d;
  --pass: #4ade80;
  --pass-soft: #0f2e1b;
  --on-pass-soft: #86efac;
  --hold: #f59e0b;
  --hold-soft: #3a2a08;
  --on-hold-soft: #fcd34d;
  --block: #f97066;
  --block-soft: #3d1512;
  --on-block-soft: #fda29b;
  --note: #2dd4bf;
  --note-soft: #0f3b37;
  --on-note-soft: #99f6e4;
  --focus: #2dd4bf;
  --scrim: rgba(0, 0, 0, 0.6);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3);
}

:root[data-density='compact'] {
  --density-padding: 12px;
  --density-gap: 8px;
  --density-cell-py: 7px;
  --density-cell-px: 10px;
  --density-row: 1.3;
}

:root[data-density='spacious'] {
  --density-padding: 24px;
  --density-gap: 18px;
  --density-cell-py: 16px;
  --density-cell-px: 20px;
  --density-row: 1.6;
}

/* --------------------------------------------------------------------------
 * Base
 * ------------------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ground);
  color: var(--ink);
  font: 400 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.4px;
  color: var(--ink);
}

h1 {
  font-size: 26px;
  line-height: 1.15;
}

h2 {
  font-size: 19px;
}

h3 {
  font-size: 16px;
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

ul,
ol,
dl {
  margin: 0;
  padding: 0;
  list-style: none;
}

dd {
  margin: 0;
}

figure {
  margin: 0;
}

::selection {
  background: color-mix(in srgb, var(--accent) 60%, transparent);
  color: var(--ink);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

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

.hidden {
  display: none !important;
}

/* --------------------------------------------------------------------------
 * Typographic helpers
 * ------------------------------------------------------------------------ */

.mute {
  color: var(--ink-muted);
}

.dim {
  color: var(--ink-2);
  font-size: var(--density-text-sm);
  line-height: 1.5;
}

.sm {
  font-size: var(--density-text-sm);
}

.sub {
  display: block;
  font-size: var(--density-text-xs);
  color: var(--ink-muted);
  margin-top: 2px;
}

.hint {
  font-size: var(--density-text-xs);
  font-weight: 400;
  color: var(--ink-subtle);
  letter-spacing: 0;
  text-transform: none;
}

.nowrap {
  white-space: nowrap;
}

/* Numbers are monospaced and tabular wherever they appear. A column of rupee
   figures that does not align is a column nobody reads down. */
.num,
.mono,
.money,
td.num,
th.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.num,
td.num,
th.num {
  text-align: right;
}

.money .rupee {
  color: var(--ink-muted);
  margin-right: 1px;
}

.pos {
  color: var(--pass);
}

.neg {
  color: var(--block);
}

.symbol {
  font-family: var(--mono);
  font-size: var(--density-text-xs);
  letter-spacing: 0.4px;
  color: var(--ink-muted);
}

/* --------------------------------------------------------------------------
 * Top bar and navigation
 * ------------------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--bar-h);
  padding: 0 16px;
}

.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--line);
  flex: none;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  flex: none;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: var(--r-sm);
  background: var(--action);
  color: var(--on-action);
  display: grid;
  place-items: center;
  font: 700 13px var(--font-display);
}

.brand-name {
  font: 700 14px var(--font-display);
  letter-spacing: -0.2px;
}

.brand-name span {
  color: var(--ink-muted);
  font-weight: 500;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.topnav::-webkit-scrollbar {
  display: none;
}

.topnav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.topnav a:hover {
  background: var(--nav-hover);
  color: var(--ink);
}

.topnav a[aria-current='page'] {
  background: var(--action);
  color: var(--on-action);
}

.topnav a .icon,
.topnav a[aria-current='page'] .icon {
  width: 15px;
  height: 15px;
}

.topnav .count {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--block);
  color: #fff;
}

.bottomnav {
  display: none;
}

/* --------------------------------------------------------------------------
 * Hazard band: the one thing that must never be missed.
 * ------------------------------------------------------------------------ */

.hazard {
  background: var(--block-soft);
  color: var(--on-block-soft);
  font-size: var(--density-text-sm);
  padding: 8px 16px;
  border-bottom: 1px solid color-mix(in srgb, var(--block) 30%, transparent);
}

.hazard b {
  font-weight: 600;
}

.hazard[hidden] {
  display: none;
}

/* --------------------------------------------------------------------------
 * Page frame
 * ------------------------------------------------------------------------ */

.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 16px 72px;
  display: flex;
  flex-direction: column;
  gap: var(--density-gap);
}

.page-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.page-head p {
  margin-top: 6px;
  max-width: 78ch;
  color: var(--ink-muted);
  font-size: var(--density-text-sm);
  line-height: 1.55;
}

.page-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  gap: var(--density-gap);
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.grid.cols-2 {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.grid.cols-3 {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.grid.cols-4 {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.grid + .grid,
.grid + .panel,
.panel + .panel,
.panel + .grid {
  margin-top: var(--density-gap);
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--density-gap);
}

.spacer {
  margin-left: auto;
}

/* --------------------------------------------------------------------------
 * Panels and cards
 * ------------------------------------------------------------------------ */

.panel {
  background: var(--surface);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.panel > header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px var(--density-padding);
  border-bottom: 1px solid var(--line-subtle);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.2px;
}

.panel > header .spacer {
  margin-left: auto;
}

.panel-body {
  padding: var(--density-padding);
  display: flex;
  flex-direction: column;
  gap: var(--density-gap);
}

.stat {
  background: var(--surface);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow-card);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.stat-label {
  font-size: var(--density-text-xs);
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--ink-subtle);
}

.stat-value {
  font: 600 26px/1.15 var(--font-display);
  letter-spacing: -0.6px;
  font-variant-numeric: tabular-nums;
}

.stat-note {
  font-size: var(--density-text-xs);
  color: var(--ink-muted);
}

.stat-note.pass {
  color: var(--pass);
}

.stat-note.hold {
  color: var(--hold);
}

.stat-note.block {
  color: var(--block);
}

/* --------------------------------------------------------------------------
 * Tables
 * ------------------------------------------------------------------------ */

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--density-text-sm);
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left;
  font-size: var(--density-text-xs);
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--ink-subtle);
  padding: 12px var(--density-cell-px);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: var(--density-cell-py) var(--density-cell-px);
  border-bottom: 1px solid var(--line-subtle);
  vertical-align: middle;
  line-height: var(--density-row);
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: var(--surface-muted);
}

td .sub {
  color: var(--ink-muted);
}

td.id {
  font-family: var(--mono);
  font-size: var(--density-text-xs);
  color: var(--ink-muted);
}

.empty {
  padding: 32px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ink-muted);
}

.empty strong {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--ink);
}

/* --------------------------------------------------------------------------
 * Definition lists and the ledger
 * ------------------------------------------------------------------------ */

.defs {
  display: grid;
  gap: 1px;
  background: var(--line-subtle);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.def {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--surface);
}

.def dt {
  flex: 0 0 200px;
  font-size: var(--density-text-sm);
  color: var(--ink-muted);
}

.def dd {
  flex: 1;
  min-width: 0;
  font-size: var(--density-text-sm);
}

.def dd.unknown {
  color: var(--hold);
  font-style: italic;
}

.ledger {
  display: flex;
  flex-direction: column;
}

.ledger-row {
  display: flex;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-subtle);
}

.ledger-row:last-child {
  border-bottom: 0;
}

.ledger-when {
  flex: 0 0 130px;
  font-family: var(--mono);
  font-size: var(--density-text-xs);
  color: var(--ink-muted);
}

.ledger-what strong {
  font-weight: 600;
}

.ledger-what .detail {
  display: block;
  font-size: var(--density-text-xs);
  color: var(--ink-muted);
  margin-top: 2px;
}

/* --------------------------------------------------------------------------
 * Buttons
 * ------------------------------------------------------------------------ */

.btn,
.btn-primary,
.btn-quiet,
.btn-danger,
.btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--action);
  color: var(--on-action);
  font: 500 13px var(--sans);
  white-space: nowrap;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s, background 0.15s;
}

.btn:hover,
.btn-primary:hover,
.btn-danger:hover {
  filter: brightness(0.88);
}

button:hover {
  filter: brightness(0.95);
}

.btn:active,
.btn-primary:active,
.btn-quiet:active,
.btn-sm:active {
  transform: translateY(1px);
}

.btn-quiet {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

.btn-quiet:hover {
  background: var(--surface-muted);
  filter: none;
}

.btn-danger {
  background: var(--block);
  color: #fff;
}

.btn-sm {
  height: 30px;
  padding: 0 11px;
  font-size: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

.btn-sm:hover {
  background: var(--surface-muted);
  filter: none;
}

button:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}

.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--nav-hover);
  color: var(--ink);
}

.icon-btn .icon,
.icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.kbd {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 9px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--surface-muted);
  color: var(--ink-muted);
  font: 500 11px var(--mono);
  cursor: pointer;
}

.kbd:hover {
  background: var(--track);
  color: var(--ink);
}

.kbd .icon {
  width: 13px;
  height: 13px;
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  height: 28px;
  padding: 0 11px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--ink-2);
  font: 500 12px var(--sans);
  cursor: pointer;
}

.chip:hover {
  background: var(--track);
}

.chip[aria-pressed='true'] {
  background: var(--action);
  color: var(--on-action);
}

.density-picker {
  display: inline-flex;
  padding: 2px;
  border-radius: var(--r-sm);
  background: var(--surface-muted);
  gap: 2px;
}

.density-picker button {
  height: 26px;
  min-width: 26px;
  padding: 0 7px;
  border: 0;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--ink-muted);
  font: 500 11px var(--sans);
  cursor: pointer;
}

.density-picker button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-card);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.switch input {
  appearance: none;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--track);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}

.switch input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  transition: transform 0.15s;
}

.switch input:checked {
  background: var(--pass);
}

.switch input:checked::after {
  transform: translateX(16px);
}

/* --------------------------------------------------------------------------
 * Form controls
 * ------------------------------------------------------------------------ */

input,
select,
textarea {
  font: 400 14px var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  height: 40px;
  padding: 0 12px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent);
}

input::placeholder,
textarea::placeholder {
  color: var(--ink-subtle);
}

textarea {
  height: auto;
  min-height: 84px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.5;
}

input[type='number'],
input[type='date'] {
  font-family: var(--mono);
}

input[type='search'] {
  border-radius: 999px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > label {
  font-size: var(--density-text-sm);
  font-weight: 500;
  color: var(--ink-2);
}

.field > .help {
  font-size: var(--density-text-xs);
  color: var(--ink-subtle);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar .spacer {
  margin-left: auto;
}

.toolbar input[type='search'],
.toolbar select {
  height: 34px;
  width: auto;
  min-width: 140px;
  font-size: var(--density-text-sm);
}

/* --------------------------------------------------------------------------
 * Status: pills, notices, toasts
 * ------------------------------------------------------------------------ */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font: 600 11px/14px var(--sans);
  white-space: nowrap;
  background: var(--surface-muted);
  color: var(--ink-2);
}

.pill.pass {
  background: var(--pass-soft);
  color: var(--on-pass-soft);
}

.pill.hold {
  background: var(--hold-soft);
  color: var(--on-hold-soft);
}

.pill.block {
  background: var(--block-soft);
  color: var(--on-block-soft);
}

.pill.note {
  background: var(--note-soft);
  color: var(--on-note-soft);
}

.pill.muted {
  background: var(--surface-muted);
  color: var(--ink-subtle);
}

.notice {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-lg);
  background: var(--surface-muted);
  color: var(--ink-2);
  font-size: var(--density-text-sm);
  line-height: 1.55;
}

.notice strong {
  color: var(--ink);
}

.notice.pass {
  background: var(--pass-soft);
  color: var(--on-pass-soft);
}

.notice.hold {
  background: var(--hold-soft);
  color: var(--on-hold-soft);
}

.notice.block {
  background: var(--block-soft);
  color: var(--on-block-soft);
}

.notice.note {
  background: var(--note-soft);
  color: var(--on-note-soft);
}

.state-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font: 600 11px var(--sans);
  background: var(--surface-muted);
  color: var(--ink-2);
}

.state-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
}

.topbar[data-state='paused'] .state-pill {
  background: var(--block-soft);
  color: var(--on-block-soft);
}

.topbar[data-state='readonly'] .state-pill {
  background: var(--hold-soft);
  color: var(--on-hold-soft);
}

.topbar[data-state='armed'] .state-pill {
  background: var(--pass-soft);
  color: var(--on-pass-soft);
}

.topbar[data-state='armed'] .state-dot {
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.clock {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-muted);
}

.freshness {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--density-text-xs);
  color: var(--ink-muted);
}

.freshness-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--ink-subtle);
}

.freshness-dot.live {
  background: var(--pass);
}

.freshness-dot.recent {
  background: var(--hold);
}

.freshness-dot.stale {
  background: var(--block);
}

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 15px;
  border-radius: var(--r-lg);
  background: var(--ink);
  color: var(--ground);
  font-size: var(--density-text-sm);
  box-shadow: var(--shadow-toast);
  max-width: 380px;
}

.toast.pass {
  background: var(--pass);
  color: #fff;
}

.toast.block {
  background: var(--block);
  color: #fff;
}

/* --------------------------------------------------------------------------
 * The guardrail gate
 * ------------------------------------------------------------------------ */

.grid.gate {
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
}

.gate-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.gate-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--line-subtle);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.gate-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 13px;
  background: var(--surface);
}

.gate-item:hover {
  background: var(--surface-muted);
}

.gate-glyph {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  flex: none;
  margin-top: 1px;
  background: var(--surface-muted);
  color: var(--ink-subtle);
}

.gate-item[data-verdict='pass'] .gate-glyph {
  background: var(--pass-soft);
  color: var(--on-pass-soft);
}

.gate-item[data-verdict='hold'] .gate-glyph {
  background: var(--hold-soft);
  color: var(--on-hold-soft);
}

.gate-item[data-verdict='block'] .gate-glyph {
  background: var(--block-soft);
  color: var(--on-block-soft);
}

.gate-name {
  font-size: var(--density-text-sm);
  font-weight: 500;
}

.gate-sub,
.gate-detail {
  font-size: var(--density-text-xs);
  color: var(--ink-muted);
  margin-top: 2px;
}

.gate-verdict {
  margin-left: auto;
  font: 600 11px var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink-subtle);
}

.gate-verdict[data-verdict='pass'] {
  color: var(--pass);
}

.gate-verdict[data-verdict='hold'] {
  color: var(--hold);
}

.gate-verdict[data-verdict='block'] {
  color: var(--block);
}

/* --------------------------------------------------------------------------
 * Brokers
 * ------------------------------------------------------------------------ */

.broker-grid {
  display: grid;
  gap: var(--density-gap);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.broker,
button.broker {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 5px;
  height: auto;
  padding: 14px;
  border: 0;
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
  cursor: pointer;
}

button.broker:hover {
  background: var(--surface-muted);
  filter: none;
}

button.broker:focus-visible {
  outline: 2px solid var(--focus);
}

.broker[aria-disabled='true'] {
  opacity: 0.55;
  cursor: not-allowed;
}

.broker-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
}

.broker-note {
  font-size: var(--density-text-xs);
  color: var(--ink-muted);
  line-height: 1.45;
}

/* --------------------------------------------------------------------------
 * Dialogs
 * ------------------------------------------------------------------------ */

dialog {
  border: 0;
  padding: 0;
  border-radius: var(--r-xl);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-dialog);
  width: min(560px, calc(100vw - 32px));
}

dialog::backdrop {
  background: var(--scrim);
  backdrop-filter: blur(2px);
}

dialog header {
  padding: 16px var(--density-padding);
  border-bottom: 1px solid var(--line-subtle);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
}

dialog .panel-body {
  gap: 14px;
}

dialog footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px var(--density-padding);
  border-top: 1px solid var(--line-subtle);
}

dialog.palette {
  width: min(560px, calc(100vw - 32px));
  margin-top: 12vh;
}

dialog.palette input {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  height: 52px;
  font-size: 15px;
}

dialog.palette input:focus {
  box-shadow: none;
  border-color: var(--focus);
}

.palette-list {
  max-height: 50vh;
  overflow-y: auto;
  padding: 6px;
}

.palette-list a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  font-size: var(--density-text-sm);
  color: var(--ink-2);
}

.palette-list a:hover,
.palette-list a.active {
  background: var(--surface-muted);
  color: var(--ink);
}

.palette-list a .icon,
.palette-list a.active .icon {
  width: 15px;
  height: 15px;
  color: var(--ink-muted);
}

.palette-list .where {
  margin-left: auto;
  font-size: var(--density-text-xs);
  color: var(--ink-subtle);
}

.cmdline {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--ink);
  color: var(--ground);
  padding: 12px 14px;
  border-radius: var(--r-md);
  overflow-x: auto;
  white-space: pre;
}

.mfa-qr {
  display: grid;
  place-items: center;
  padding: 14px;
  background: #fff;
  border-radius: var(--r-md);
}

/* --------------------------------------------------------------------------
 * Sign-in
 * ------------------------------------------------------------------------ */

.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.auth-aside {
  background: var(--ink);
  color: var(--ground);
  padding: 44px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.auth-mark {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font: 700 15px var(--font-display);
}

.auth-mark span {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--on-accent);
  display: grid;
  place-items: center;
}

.auth-claim {
  font: 600 32px/1.2 var(--font-display);
  letter-spacing: -0.8px;
  max-width: 18ch;
}

.auth-facts {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-fact {
  display: flex;
  gap: 10px;
  font-size: var(--density-text-sm);
  color: color-mix(in srgb, var(--ground) 72%, transparent);
  line-height: 1.5;
}

.auth-fact i {
  font-style: normal;
  color: var(--accent);
}

.auth-form-wrap {
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

.auth-form {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-form h1 {
  font-size: 24px;
}

.auth-form p.lede {
  color: var(--ink-muted);
  font-size: var(--density-text-sm);
  line-height: 1.55;
}

.auth-form .btn-primary {
  width: 100%;
}

/* --------------------------------------------------------------------------
 * Loading
 * ------------------------------------------------------------------------ */

.sk {
  background: linear-gradient(90deg, var(--track) 25%, var(--surface-muted) 37%, var(--track) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: var(--r-xs);
  height: 12px;
}

@keyframes shimmer {
  to {
    background-position: -135% 0;
  }
}

/* --------------------------------------------------------------------------
 * Small screens: the nav moves to the bottom, where a thumb is.
 * ------------------------------------------------------------------------ */

@media (max-width: 860px) {
  .topnav,
  .topbar-divider {
    display: none;
  }

  .bottomnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: block;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .bottomnav div {
    display: flex;
    justify-content: space-around;
    padding: 5px 4px;
  }

  .bottomnav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 9px;
    border-radius: var(--r-sm);
    font-size: 10px;
    font-weight: 500;
    color: var(--ink-muted);
  }

  .bottomnav a .icon {
    width: 19px;
    height: 19px;
  }

  .bottomnav a[aria-current='page'] {
    color: var(--ink);
  }

  .bottomnav a[aria-current='page'] .icon {
    color: var(--ink);
  }

  .auth {
    grid-template-columns: 1fr;
  }

  .auth-aside {
    display: none;
  }

  .main {
    padding-bottom: 92px;
  }

  .def dt {
    flex: 0 0 100%;
  }

  .ledger-when {
    flex: 0 0 96px;
  }
}

/* --------------------------------------------------------------------------
 * Print: a compliance officer's copy.
 * ------------------------------------------------------------------------ */

@page {
  margin: 14mm;
}

@media print {
  .topbar,
  .bottomnav,
  .toasts,
  .page-actions,
  .toolbar {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .panel,
  .stat {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }
}
