/* =============================================================
   amaru-treasury dashboard — single stylesheet.

   AN AGENT-REPLACEABLE FILE.
   This file is the *only* surface controlling the visual style.
   Markup classes are stable; an agent can rewrite this file to
   alter the look without ever touching the PureScript or HTML.

   Theming surface
   ---------------
   Everything that varies between light/dark is a Material 3
   "sys color" custom property (`--md-sys-color-*`) defined on
   `:root`. To produce an alternate theme, override these only —
   do not hard-code hex values inside element rules.

   Class taxonomy used by App.purs and JsonView.purs
   -------------------------------------------------
     #app                                root grid container
     .topbar, .topbar__title             top bar (title + theme btn)
     .site-header__eyebrow               small uppercase URL line
     .site-header__title                 main h1
     .site-header__lede                  intro paragraph
     .scope-grid                         responsive grid of cards
     .scope-card                         scope card surface
       .scope-card__title                h2 of the card
       .scope-card__slug                 short slug under title
       .scope-card__loading              "Loading…" placeholder
       .scope-card__error                error text
     .stat-grid                          3-col stat row inside card
     .stat-tile                          one stat tile
       .stat-tile__value                 big number
       .stat-tile__label                 small upper-case label
     .kv__value                          monospace value text (kv row)
     .kv__value--link                    same, but inside an <a>-like row
     .site-footer                        footer
       .site-footer__links               clustered links cell
       .site-footer__build               build-identity cell
   JSON viewer (JsonView.purs)
     details.json-block + .json-body     outer wrapper around JSON
     .v-node + .v-summary + .v-meta      one collapsible object/array
     .v-object, .v-array                 nested grid / list
     .v-key                              object key
     .v-null, .v-bool, .v-num, .v-str    primitive types
     .v-txid, .v-addr, .v-policy         linked, resolved values
   ============================================================= */

:root {
  color-scheme: light dark;
  font-family: "Roboto Flex", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-optical-sizing: auto;
  --app-shell-max: 1280px;
  --app-radius: 8px;
  --app-shadow: 0 18px 45px rgb(29 27 32 / 0.09);
  --app-shadow-dark: 0 20px 55px rgb(0 0 0 / 0.35);
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:root,
:root[data-theme="light"] {
  --md-sys-color-primary: #006a70;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #b8eef2;
  --md-sys-color-on-primary-container: #002022;
  --md-sys-color-secondary: #735b00;
  --md-sys-color-tertiary: #6750a4;
  --md-sys-color-surface: #fffdf8;
  --md-sys-color-surface-container-low: #ffffff;
  --md-sys-color-surface-container: #f0f4f1;
  --md-sys-color-surface-container-high: #e6ece8;
  --md-sys-color-on-surface: #1b1d1b;
  --md-sys-color-surface-variant: #dce6e2;
  --md-sys-color-on-surface-variant: #48514e;
  --md-sys-color-outline: #707a76;
  --md-sys-color-outline-variant: #c0cbc6;
  --md-sys-color-background: #f6f8f4;
  --md-sys-color-on-background: #1b1d1b;
  --md-sys-color-error: #b3261e;
  --app-hero-tint: rgb(0 106 112 / 0.1);
  --app-rule: rgb(112 122 118 / 0.34);
}
:root[data-theme="dark"] {
  --md-sys-color-primary: #78dce2;
  --md-sys-color-on-primary: #00363a;
  --md-sys-color-primary-container: #004f54;
  --md-sys-color-on-primary-container: #9cf0f5;
  --md-sys-color-secondary: #e0c15f;
  --md-sys-color-tertiary: #d0bcff;
  --md-sys-color-surface: #181c19;
  --md-sys-color-surface-container-low: #1f2421;
  --md-sys-color-surface-container: #252b27;
  --md-sys-color-surface-container-high: #303833;
  --md-sys-color-on-surface: #e2e9e4;
  --md-sys-color-surface-variant: #3f4945;
  --md-sys-color-on-surface-variant: #c0cbc6;
  --md-sys-color-outline: #8a948f;
  --md-sys-color-outline-variant: #3f4945;
  --md-sys-color-background: #111512;
  --md-sys-color-on-background: #e2e9e4;
  --md-sys-color-error: #ffb4ab;
  --app-hero-tint: rgb(120 220 226 / 0.11);
  --app-rule: rgb(138 148 143 / 0.34);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --md-sys-color-primary: #78dce2;
    --md-sys-color-on-primary: #00363a;
    --md-sys-color-primary-container: #004f54;
    --md-sys-color-on-primary-container: #9cf0f5;
    --md-sys-color-secondary: #e0c15f;
    --md-sys-color-tertiary: #d0bcff;
    --md-sys-color-surface: #181c19;
    --md-sys-color-surface-container-low: #1f2421;
    --md-sys-color-surface-container: #252b27;
    --md-sys-color-surface-container-high: #303833;
    --md-sys-color-on-surface: #e2e9e4;
    --md-sys-color-surface-variant: #3f4945;
    --md-sys-color-on-surface-variant: #c0cbc6;
    --md-sys-color-outline: #8a948f;
    --md-sys-color-outline-variant: #3f4945;
    --md-sys-color-background: #111512;
    --md-sys-color-on-background: #e2e9e4;
    --md-sys-color-error: #ffb4ab;
    --app-hero-tint: rgb(120 220 226 / 0.11);
    --app-rule: rgb(138 148 143 / 0.34);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html {
  min-width: 320px;
  text-rendering: optimizeLegibility;
}
html, body { margin: 0; }
body {
  /* #289 slice H — shorter hero tint (was 360px) so the
     gradient doesn't bleed into the first scope card. */
  background:
    linear-gradient(180deg, var(--app-hero-tint), transparent 220px),
    var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  min-height: 100dvh;
}
code, pre {
  font-family: "Roboto Mono", ui-monospace, monospace;
}
a {
  color: var(--md-sys-color-primary);
}

#app {
  width: min(100%, var(--app-shell-max));
  margin: 0 auto;
  /* #289 slice H — slimmer outer padding so the hero +
     status row + first scope card all fit in the first
     viewport fold. */
  padding: 16px 28px 28px;
}
#app > div {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
@media (max-width: 600px) {
  #app { padding: 12px 14px 20px; }
  #app > div { gap: 10px; }
}
noscript {
  display: block;
  padding: 24px;
  text-align: center;
  color: var(--md-sys-color-on-surface-variant);
}

/* ---------- Top bar ---------- */
/* #289 slice A — the topbar must fit at every viewport from
   320 px up.  Flex-wrap is the picked pattern (rather than a
   hamburger drawer): the link set is short (View / Operate /
   Books) and the theme-toggle stays reachable when the nav
   wraps to its own row on narrow viewports.  `min-width:0`
   on the children lets the brand truncate cleanly when the
   row is still single-line on borderline widths. */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  min-height: 44px;
}
.topbar__brand {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar__theme-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--app-radius);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    color 0.12s ease;
}
.topbar__theme-btn:hover {
  border-color: var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-container);
}
.topbar__theme-btn md-icon {
  font-size: 20px;
}
.topbar__title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--md-sys-color-on-surface);
  font-weight: 650;
}
md-text-button {
  --md-text-button-label-text-color: var(--md-sys-color-primary);
  --md-text-button-container-shape: var(--app-radius);
  font-weight: 650;
}

/* ---------- Site header ---------- */
/* #289 slice H — compact hero.  The page used to lead with
   a 60-pt display-medium heading + a 16-pt lede on a
   centered-stack layout that pushed the per-scope cards
   below the first viewport fold on both desktop and
   mobile.  The new layout keeps the brand + lede but on a
   single visual band: smaller heading, smaller lede,
   tighter padding, no decorative gap.  Per-scope cards
   land in the first 800 px (desktop) / 700 px (mobile). */
.site-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding: 4px 0 0 0;
}
.site-header__eyebrow {
  color: var(--md-sys-color-on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 700;
}
.site-header__title {
  margin: 0;
  color: var(--md-sys-color-on-background);
  font-weight: 700;
}
.site-header__lede {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  max-width: 64ch;
  font-weight: 500;
}
.site-header md-chip-set {
  justify-content: center;
}
md-chip-set {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
md-assist-chip {
  --md-assist-chip-container-shape: var(--app-radius);
  --md-assist-chip-label-text-color: var(--md-sys-color-on-surface);
  --md-assist-chip-outline-color: var(--app-rule);
  --md-assist-chip-container-height: 36px;
}

/* ---------- #289 slice E — dashboard status row ---------- */
/* Plain flex row above the totals strip + scope grid.
   Tip + refresh sit on the left; one chip per scope on
   the right.  Wraps to two visual lines on narrow viewports
   (mobile-390 puts the chips on row 2). */
.status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  padding: 8px 12px;
  background: var(--md-sys-color-surface-container-lowest, transparent);
  border: 1px solid var(--md-sys-color-outline-variant, #44474e);
  border-radius: var(--app-radius);
  font: 500 12px/1.2 "Roboto Mono", ui-monospace, monospace;
  color: var(--md-sys-color-on-surface-variant);
}
.status-row__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  align-items: center;
}
.status-row__pair {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.status-row__label {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  opacity: 0.75;
}
.status-row__value {
  /* #289 slice H — chain-tip slot and the refreshed clock
     are critical operational numerics; use the strongest
     on-surface token + heavier weight for AAA contrast. */
  color: var(--md-sys-color-on-background);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.status-row__scopes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}
.scope-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--app-radius);
  border: 1px solid var(--md-sys-color-outline-variant, #44474e);
  font-size: 11px;
  line-height: 1.2;
}
.scope-chip__name {
  font-weight: 700;
  letter-spacing: 0.02em;
}
.scope-chip__state {
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.08em;
  opacity: 0.85;
}
.scope-chip[data-state="fresh"] {
  background: var(--md-sys-color-surface-container-low, #1c1f24);
  color: var(--md-sys-color-on-surface);
}
.scope-chip[data-state="stale"] {
  background: var(--md-sys-color-tertiary-container, #ffdc9d);
  color: var(--md-sys-color-on-tertiary-container, #261901);
  border-color: var(--md-sys-color-tertiary, #7b5800);
}
.scope-chip[data-state="partial"] {
  background: var(--md-sys-color-error-container, #ffdad6);
  color: var(--md-sys-color-on-error-container, #410002);
  border-color: var(--md-sys-color-error, #ba1a1a);
}

@media (max-width: 600px) {
  .status-row__scopes {
    margin-left: 0;
    width: 100%;
  }
  .status-row {
    font-size: 11px;
  }
}

/* ---------- #289 slice F — dashboard copy rows ---------- */
/* Per-scope rows that show a long string (treasury bech32,
   script hash, future txids).  Truncated display sits next
   to a sibling copy icon-button so the operator can grab
   the full value with one click — no jumping to a separate
   panel.  The button flips to a check glyph for ~1 s on
   success, and an inline "Copy failed" caption appears
   below the row for ~3 s if the browser denies the write
   (private browsing / non-HTTPS / focus policy). */
.copy-row {
  display: grid;
  grid-template-columns: minmax(8rem, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant, #44474e);
  font-family: "Roboto Mono", ui-monospace, monospace;
  font-size: 13px;
}
.copy-row:last-child {
  border-bottom: 0;
}
.copy-row__label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface);
}
.copy-row__value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--md-sys-color-on-surface);
  text-decoration: none;
}
a.copy-row__value {
  color: var(--md-sys-color-primary);
  text-decoration: underline;
}
a.copy-row__value:hover {
  filter: brightness(1.1);
}
.copy-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--md-sys-color-outline-variant, #44474e);
  border-radius: var(--app-radius);
  background: var(--md-sys-color-surface-container, #22252b);
  color: var(--md-sys-color-on-surface);
  font: 600 16px/1 "Roboto Mono", ui-monospace, monospace;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.copy-icon-btn md-icon {
  font-size: 20px;
}
.copy-icon-btn:hover {
  border-color: var(--md-sys-color-outline);
}
.copy-icon-btn[data-state="copied"] {
  background: var(--md-sys-color-primary-container, #b8d4d6);
  color: var(--md-sys-color-on-primary-container, #002022);
  border-color: var(--md-sys-color-primary, #006a70);
}
.copy-icon-btn[data-state="failed"] {
  background: var(--md-sys-color-error-container, #ffdad6);
  color: var(--md-sys-color-on-error-container, #410002);
  border-color: var(--md-sys-color-error, #ba1a1a);
}
.copy-row__failed {
  grid-column: 2 / -1;
  font-size: 11px;
  font-family: "Roboto Flex", system-ui, sans-serif;
  letter-spacing: 0.02em;
  color: var(--md-sys-color-error, #ba1a1a);
}

@media (max-width: 600px) {
  .site-header__title {
    font-size: 32px;
    line-height: 1.08;
  }
  .site-header__lede {
    font-size: 15px;
    line-height: 1.35;
  }
  .copy-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .copy-row__label {
    grid-column: 1 / -1;
  }
  .copy-row__value {
    grid-column: 1;
  }
  .copy-icon-btn {
    grid-column: 2;
    grid-row: 2;
  }
  .copy-row__failed {
    grid-column: 1 / -1;
  }
}

/* ---------- Totals strip ---------- */
.totals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--app-radius);
}
.totals__tile {
  min-width: 0;
}
.totals__value {
  font-family: "Roboto Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  /* #289 slice H — total ADA / USDM / UTxOs are critical
     operational numerics.  Force the strongest text token
     against the totals-strip surface for AAA contrast
     (≥ 7:1). */
  color: var(--md-sys-color-on-background);
  font-weight: 600;
  overflow-wrap: anywhere;
}
.totals__label {
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 700;
  color: var(--md-sys-color-on-surface-variant);
}

/* ---------- Scope grid ---------- */
.scope-grid {
  display: grid;
  grid-template-columns: repeat(
    auto-fit,
    minmax(min(100%, 440px), 1fr)
  );
  gap: 18px;
  margin-top: 8px;
}

/* ---------- Scope card ---------- */
.scope-card {
  --scope-accent: var(--md-sys-color-primary);
  --md-elevated-card-container-color: var(--md-sys-color-surface-container-low);
  --md-elevated-card-container-shape: var(--app-radius);
  padding: 22px;
  display: block;
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow);
  overflow: hidden;
  position: relative;
}
:root[data-theme="dark"] .scope-card {
  box-shadow: var(--app-shadow-dark);
}
.scope-card::before {
  content: "";
  display: block;
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--scope-accent);
}
.scope-grid > .scope-card:nth-child(1) { --scope-accent: #006a70; }
.scope-grid > .scope-card:nth-child(2) { --scope-accent: #8f5f00; }
.scope-grid > .scope-card:nth-child(3) { --scope-accent: #5865c9; }
.scope-grid > .scope-card:nth-child(4) { --scope-accent: #7d5260; }
.scope-grid > .scope-card:nth-child(5) { --scope-accent: #486a20; }
:root[data-theme="dark"] .scope-grid > .scope-card:nth-child(1) { --scope-accent: #78dce2; }
:root[data-theme="dark"] .scope-grid > .scope-card:nth-child(2) { --scope-accent: #e0c15f; }
:root[data-theme="dark"] .scope-grid > .scope-card:nth-child(3) { --scope-accent: #c3c8ff; }
:root[data-theme="dark"] .scope-grid > .scope-card:nth-child(4) { --scope-accent: #efb8c8; }
:root[data-theme="dark"] .scope-grid > .scope-card:nth-child(5) { --scope-accent: #aad47b; }
.scope-card > * {
  position: relative;
}
.scope-card__head {
  margin-bottom: 14px;
}
.scope-card__body {
  display: block;
}
.scope-card__weight {
  height: 4px;
  width: calc(var(--share, 0) * 100%);
  background: var(--scope-accent);
  border-radius: 2px;
  margin: 0 0 14px 0;
  transition: width 0.4s ease;
}
.scope-card__title {
  margin: 0 0 2px 0;
  font-weight: 650;
}
.scope-card__slug {
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 18px;
  font-size: 12px;
  font-family: "Roboto Mono", ui-monospace, monospace;
}
.scope-card__loading {
  color: var(--md-sys-color-on-surface-variant);
}
.scope-card__error {
  color: var(--md-sys-color-error);
}

/* ---------- Stat tiles inside the card ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}
.stat-tile {
  min-width: 0;
  padding: 12px;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
  border: 1px solid rgb(112 122 118 / 0.16);
  border-radius: var(--app-radius);
}
.stat-tile__value {
  font-family: "Roboto Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  /* #289 slice H — per-scope balances are the most
     glanced-at numbers on the page; force the strongest
     contrast against the stat-tile surface (AAA). */
  color: var(--md-sys-color-on-background);
  font-weight: 600;
  overflow-wrap: anywhere;
}
.stat-tile__label {
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
}

/* ---------- kv list (one row in md-list) ---------- */
md-list {
  background: transparent;
  border-block: 1px solid var(--app-rule);
  padding: 6px 0;
  margin: 0 0 12px 0;
}
md-list-item {
  --md-list-list-item-container-color: transparent;
  --md-list-list-item-hover-state-layer-color: var(--md-sys-color-primary);
  --md-list-list-item-label-text-color: var(--md-sys-color-on-surface);
  --md-list-list-item-supporting-text-color: var(--md-sys-color-on-surface-variant);
  --md-list-list-item-one-line-container-height: 60px;
  --md-list-list-item-two-line-container-height: 68px;
  border-radius: var(--app-radius);
}
.kv__value {
  font-family: "Roboto Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.kv__value--link {
  color: var(--md-sys-color-primary);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* ---------- Site footer ---------- */
.site-footer {
  color: var(--md-sys-color-on-surface-variant);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  padding: 16px 0 6px 0;
  border-top: 1px solid var(--app-rule);
}
.site-footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.site-footer__build {
  font-family: "Roboto Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

/* JSON tree styling lives in `json-tree.css`, shipped by
   the browser-json-tree flake input. */

/* ---------- #310 tx audit view ---------- */
.audit-page {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.audit-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 4px;
}
.audit-header__title {
  margin: 0;
  color: var(--md-sys-color-on-background);
  font-weight: 700;
}
.audit-header__lede {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  max-width: 72ch;
}
.audit-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--app-radius);
  background: var(--md-sys-color-surface-container-low);
}
.audit-field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
}
.audit-field__input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--app-radius);
  padding: 8px 10px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font: 500 14px/1.2 "Roboto Flex", system-ui, sans-serif;
}
.audit-field__input:focus {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 1px;
}
.audit-controls__actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.audit-btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--app-radius);
  padding: 0 12px;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  font-weight: 700;
  cursor: pointer;
}
.audit-btn--primary {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-color: var(--md-sys-color-primary);
}
.audit-btn md-icon {
  font-size: 20px;
}
.audit-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(480px, 0.85fr);
  gap: 14px;
  align-items: start;
}
.audit-panel,
.audit-detail {
  min-width: 0;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--app-radius);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--app-shadow);
}
:root[data-theme="dark"] .audit-panel,
:root[data-theme="dark"] .audit-detail {
  box-shadow: var(--app-shadow-dark);
}
.audit-panel {
  overflow: hidden;
}
.audit-detail {
  padding: 16px;
}
.audit-detail h2 {
  margin: 0 0 12px 0;
}
.audit-state {
  padding: 18px;
  color: var(--md-sys-color-on-surface-variant);
}
.audit-state__title {
  color: var(--md-sys-color-on-surface);
  font-weight: 750;
  margin-bottom: 4px;
}
.audit-state p {
  margin: 0;
  overflow-wrap: anywhere;
}
.audit-table-wrap {
  overflow-x: auto;
}
.audit-table-meta {
  display: flex;
  justify-content: flex-end;
  padding: 10px 12px 0;
  color: var(--md-sys-color-on-surface-variant);
  font: 700 11px/1.2 "Roboto Mono", ui-monospace, monospace;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.audit-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 14px;
}
.audit-table th,
.audit-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  text-align: left;
  vertical-align: middle;
}
.audit-table th {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.audit-table tr[data-selected="true"] td {
  background: color-mix(in srgb, var(--md-sys-color-primary) 12%, transparent);
}
.audit-link-btn {
  max-width: 28ch;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--md-sys-color-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.audit-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--app-radius);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  font: 700 12px/1.2 "Roboto Mono", ui-monospace, monospace;
}
.audit-detail__kv {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr);
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.audit-detail__kv span {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.audit-detail__kv code {
  overflow-wrap: anywhere;
  color: var(--md-sys-color-on-surface);
}
/* #338 SB1 — truncated hash/address value + inline copy button
   inside an audit detail kv row. */
.audit-copy {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.audit-copy code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--md-sys-color-on-surface);
}
.audit-copy .copy-icon-btn {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
}
.audit-detail__body {
  margin-top: 14px;
}
.audit-detail__section {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--app-radius);
  background: var(--md-sys-color-surface-container);
}
.audit-detail__section h3 {
  margin: 0 0 8px 0;
  color: var(--md-sys-color-on-surface);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.audit-detail__section ul {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.audit-detail__section li {
  overflow-wrap: anywhere;
  color: var(--md-sys-color-on-surface);
  font-size: 12px;
  line-height: 1.35;
}
.audit-detail__empty {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
}
.audit-output-card {
  gap: 8px;
  padding: 10px;
}
.audit-output-card__badges {
  min-width: 0;
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
.audit-output-card__summary {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(9rem, 0.6fr);
  gap: 8px 12px;
  align-items: center;
}
.audit-output-field {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.audit-output-field__label,
.audit-output-chip__label {
  flex: 0 0 auto;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.audit-output-field__value {
  min-width: 0;
  color: var(--md-sys-color-on-surface);
}
.audit-output-card .audit-copy {
  gap: 4px;
}
.audit-output-card .audit-copy .copy-icon-btn {
  width: 26px;
  height: 26px;
}
.audit-output-card .audit-copy .copy-icon-btn md-icon {
  font-size: 17px;
}
.audit-output-card__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.audit-output-chip {
  min-width: 0;
  max-width: 100%;
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--app-radius);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  font-size: 12px;
  line-height: 1.2;
}
.audit-output-chip code {
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--md-sys-color-on-surface);
}

@media (max-width: 900px) {
  .audit-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .audit-layout {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 520px) {
  .audit-controls {
    grid-template-columns: 1fr;
  }
  .audit-controls__actions {
    align-items: stretch;
  }
  .audit-btn {
    flex: 1 1 0;
  }
  .audit-output-card__summary {
    grid-template-columns: 1fr;
  }
  .audit-output-field {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }
  .audit-detail__kv {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}

/* #289 slice A — tighten topbar chrome on phones so the
   three nav links + brand + theme button can share a single
   wrapped row (or two narrow rows) without horizontal
   overflow at 320 px. */
@media (max-width: 600px) {
  .topbar {
    gap: 6px 10px;
    padding-top: 4px;
    padding-bottom: 4px;
  }
  .topbar__brand {
    font-size: 16px;
    line-height: 1.1;
  }
  .topbar__nav {
    gap: 2px;
    flex-wrap: wrap;
  }
  .topbar__nav-link {
    padding: 4px 8px;
  }
  .topbar__theme-btn {
    margin-left: auto;
  }
}

@media (max-width: 700px) {
  .topbar {
    align-items: flex-start;
  }
  .site-header__title {
    margin-top: 4px;
  }
  .scope-grid {
    gap: 16px;
  }
  .scope-card {
    padding: 20px 14px 16px;
  }
  .stat-grid {
    gap: 6px;
  }
  .stat-tile {
    padding: 10px 8px;
  }
  md-list-item {
    --md-list-list-item-two-line-container-height: 64px;
  }
  .site-footer {
    gap: 10px;
  }
}

/* #338 SB3 / SB1 — phone layout at ≤390px.  Per-scope stat
   tiles drop to a 2-up grid (3-up is too cramped), and the
   audit results table stops forcing a 680px scroll-strip:
   each row stacks its cells so the operator can read history
   without horizontal scrolling. */
@media (max-width: 390px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .audit-table {
    min-width: 0;
  }
  .audit-table thead {
    display: none;
  }
  .audit-table,
  .audit-table tbody,
  .audit-table tr,
  .audit-table td {
    display: block;
    width: 100%;
  }
  .audit-table tr {
    padding: 6px 0;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
  }
  .audit-table td {
    padding: 4px 12px;
    border-bottom: 0;
  }
}

/* ---------- repeated form rows ----------
   Kept in sync with style-build.css for removable row sets
   on /operate: rationale references and contingency
   destinations. */
.repeated-row-list,
.destination-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.repeated-row-list__actions {
  display: flex;
  justify-content: flex-start;
  padding-top: 2px;
}
.repeated-row-card,
.destination-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--app-radius);
  background: var(--md-sys-color-surface-container);
}
.repeated-row-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.repeated-row-card__title {
  font-family: "Roboto Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
}
.repeated-row-card__fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}
.reference-card__fields {
  grid-template-columns:
    minmax(0, 2fr) minmax(0, 1fr) minmax(0, 2fr);
}
.destination-card__fields {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.repeated-row-card__remove {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  white-space: nowrap;
}
.repeated-row-card__remove md-icon {
  font-size: 18px;
  line-height: 1;
}
@media (max-width: 600px) {
  .repeated-row-card__head { align-items: flex-start; }
  .repeated-row-card__fields,
  .reference-card__fields,
  .destination-card__fields { grid-template-columns: 1fr; }
  .repeated-row-card__remove { align-self: flex-start; }
  .repeated-row-list__actions .btn { width: 100%; }
}
