/* A&C Control Plane console. Self-hosted, no fonts or assets from elsewhere.
 * Design tokens first: change the brand by editing the variables in this block.
 * See docs/UI.md for the components and how to add a page. */

/* ---- design tokens --------------------------------------------------------- */
:root {
  /* brand (from the A&C Digital logo) */
  --brand-navy: #10243e;
  --brand-navy-2: #183454;
  --brand-teal: #2ec4b6;
  --brand-teal-ink: #0b6e66;       /* teal dark enough for text on white (5.6:1) */

  /* surfaces and text, light mode */
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --surface-3: #e6ebf1;
  --text: #142233;
  --text-muted: #556274;           /* 6.1:1 on white */
  --border: #dbe2ea;
  --border-strong: #c3ccd7;
  --link: #0b6e66;
  --focus: #0b6e66;
  --shadow: 0 1px 2px rgb(16 36 62 / 6%), 0 2px 8px rgb(16 36 62 / 5%);

  /* buttons */
  --btn-primary-bg: #10243e;
  --btn-primary-text: #ffffff;
  --btn-primary-hover: #183454;
  --btn-secondary-bg: #ffffff;
  --btn-secondary-text: #142233;
  --btn-danger-bg: #b42318;
  --btn-danger-text: #ffffff;

  /* status colours: text on its own tinted background, all >= 4.5:1 */
  --ok: #11633a;   --ok-bg: #e5f4ec;   --ok-line: #9fd5b5;
  --bad: #a3221a;  --bad-bg: #fdecea;  --bad-line: #f2b8b2;
  --warn: #7f4a00; --warn-bg: #fff3dc; --warn-line: #f0cf8e;
  --info: #1b4c8c; --info-bg: #e9f1fb; --info-line: #b5cdee;
  --changed-bg: #fff6cc;

  /* sidebar (navy in both modes) */
  --side-bg: #10243e;
  --side-text: #d9e3ee;
  --side-muted: #8fa3bb;           /* 6.2:1 on the navy */
  --side-hover: rgb(255 255 255 / 7%);
  --side-active: rgb(46 196 182 / 16%);

  /* shape and type */
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sidebar-w: 248px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1420;
    --surface: #111f30;
    --surface-2: #162739;
    --surface-3: #1d3247;
    --text: #e6edf5;
    --text-muted: #a3b2c4;         /* 7.4:1 on the surface */
    --border: #24384e;
    --border-strong: #335070;
    --link: #5fe0d2;
    --focus: #5fe0d2;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    --btn-primary-bg: #2ec4b6;
    --btn-primary-text: #0a1420;    /* 9:1 */
    --btn-primary-hover: #4fd3c6;
    --btn-secondary-bg: #162739;
    --btn-secondary-text: #e6edf5;
    --btn-danger-bg: #e5534b;
    --btn-danger-text: #0a1420;     /* 5.3:1 */
    --ok: #7ee2a8;   --ok-bg: #0f2e22;   --ok-line: #24583f;
    --bad: #ffaaa3;  --bad-bg: #3a1615;  --bad-line: #6e2a26;
    --warn: #f7cf6b; --warn-bg: #33270b; --warn-line: #66501a;
    --info: #9cc4ff; --info-bg: #12294a; --info-line: #2b4d7d;
    --changed-bg: #3d3510;
    --side-bg: #0c1a2c;
    color-scheme: dark;
  }
}

/* ---- base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 4.5rem; scroll-padding-bottom: 4.5rem; }
body { margin: 0; font: 15px/1.5 var(--font); background: var(--bg); color: var(--text); }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
h1 { font-size: 1.55rem; line-height: 1.25; margin: 0 0 .35rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: .98rem; margin: 1rem 0 .4rem; }
p { margin: 0 0 .7rem; }
code, .mono { font-family: var(--mono); font-size: .86em; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 .3em; }
pre { font-family: var(--mono); }
ul, ol { padding-left: 1.3rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.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; }
.skip { position: absolute; left: .5rem; top: -3rem; z-index: 50; background: var(--surface);
  color: var(--text); padding: .5rem .8rem; border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.skip:focus { top: .5rem; }
[hidden] { display: none !important; }

.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.2em; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- app shell: sidebar + top bar + content ------------------------------------- */
.shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
@media (min-width: 901px) { .shell { background: linear-gradient(to right, var(--side-bg) var(--sidebar-w), transparent var(--sidebar-w)); } }
.sidebar { background: var(--side-bg); color: var(--side-text); position: sticky; top: 0;
  height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.side-brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1.1rem .9rem;
  color: #fff; text-decoration: none; }
.side-brand img { width: 36px; height: 36px; border-radius: 9px; }
.side-brand strong { display: block; font-size: .98rem; line-height: 1.15; }
.side-brand span { display: block; font-size: .78rem; color: var(--side-muted); }
.nav { padding: .3rem .6rem 1.2rem; }
.nav-group { margin-top: .9rem; }
.nav-group h2 { font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--side-muted); margin: 0 0 .25rem; padding: 0 .6rem; }
.nav a { display: flex; align-items: center; gap: .65rem; padding: .45rem .6rem; margin: 1px 0;
  border-radius: 7px; color: var(--side-text); text-decoration: none; font-size: .93rem;
  border-left: 3px solid transparent; }
.nav a .icon { color: var(--side-muted); }
.nav a:hover { background: var(--side-hover); color: #fff; }
.nav a[aria-current="page"] { background: var(--side-active); color: #fff; font-weight: 600;
  border-left-color: var(--brand-teal); }
.nav a[aria-current="page"] .icon { color: var(--brand-teal); }
.nav a:focus-visible { outline-color: var(--brand-teal); }
.side-foot { margin-top: auto; padding: .8rem 1.1rem 1.1rem; font-size: .78rem; color: var(--side-muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .8rem;
  padding: .6rem 1.4rem; background: var(--surface); border-bottom: 1px solid var(--border); min-height: 56px; }
.instance { display: flex; align-items: center; gap: .45rem; min-width: 0; color: var(--text-muted);
  font-size: .88rem; }
.instance strong { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.instance .icon { color: var(--brand-teal-ink); }
.org-cards { display: grid; gap: 1rem; margin-bottom: 1rem; }
.org-card .card-head h2 { display: flex; align-items: center; gap: .45rem; }
.org-card .tiles { margin: 0; }
.org-select { display: flex; align-items: center; gap: .45rem; min-width: 0; margin: 0;
  font-size: .88rem; color: var(--text-muted); }
.org-select label { display: flex; align-items: center; gap: .35rem; margin: 0; font-weight: 400; }
.org-select .icon { color: var(--brand-teal-ink); }
.org-select select { width: auto; max-width: 16rem; min-width: 0; padding: .3rem .5rem; font-weight: 600; }
@media (max-width: 640px) { .org-select label span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); } }
.topbar .spacer { flex: 1; }
.who { display: flex; align-items: center; gap: .5rem; font-size: .88rem; color: var(--text-muted); }
.who form { margin: 0; }
.nav-toggle { display: none; }
.scrim { display: none; }
.content { width: 100%; max-width: 1280px; padding: 1.4rem 1.4rem 3rem; }
.bare .content { max-width: 440px; margin: 8vh auto 0; }
.bare-brand { display: flex; align-items: center; gap: .7rem; justify-content: center; margin-bottom: 1.2rem;
  color: var(--text); text-decoration: none; }
.bare-brand img { width: 44px; height: 44px; border-radius: 11px; }
.bare-brand strong { font-size: 1.1rem; }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; }
  .js .sidebar { position: fixed; inset: 0 auto 0 0; width: min(84vw, 300px); z-index: 40;
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: 0 0 30px rgb(0 0 0 / 35%); }
  .js .nav-open .sidebar { transform: none; }
  .js .nav-open .scrim { display: block; }
  .scrim { position: fixed; inset: 0; z-index: 30; background: rgb(5 12 22 / 50%); }
  .js .nav-toggle { display: inline-flex; }
  .topbar { padding: .5rem 1rem; }
  .content { padding: 1rem 1rem 3rem; }
  .who .who-name { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---- page header, breadcrumbs ------------------------------------------------ */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem 1rem; margin-bottom: 1.1rem; }
.page-head > div:first-child { flex: 1 1 22rem; min-width: 0; }
.page-head .lede { color: var(--text-muted); margin: 0; max-width: 72ch; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.crumbs { font-size: .85rem; margin: 0 0 .4rem; color: var(--text-muted); }
.crumbs a { color: var(--text-muted); text-decoration: none; display: inline-flex; align-items: center; gap: .25rem; }
.crumbs a:hover { color: var(--link); text-decoration: underline; }

/* ---- cards and layout grids ---------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; margin-bottom: 1rem; box-shadow: var(--shadow); min-width: 0; overflow-x: auto; }
.card > :last-child { margin-bottom: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .8rem; margin-bottom: .7rem; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }
.card-actions { margin-bottom: .7rem; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: .9rem 1.2rem 0; }
.card.narrow, .narrow { max-width: 560px; }
.grid, .cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr)); align-items: start; }
.cards-sm { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr)); }
.stack > * + * { margin-top: 1rem; }
.contents { display: contents; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.row .spacer { flex: 1; }

/* stat tiles and health cards */
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; box-shadow: var(--shadow); }
a.stat-tile { display: block; color: inherit; text-decoration: none; }
a.stat-tile:hover { border-color: var(--border-strong); }
.cards-sm + .cards-sm, .cards-sm + .cards, .cards + .card { margin-top: 1rem; }
.cards-sm > .card, .cards-sm > .contents > .card { margin-bottom: 0; }
.cards-sm.tiles { grid-template-columns: repeat(auto-fill, minmax(min(100%, 9rem), 1fr)); }
.stat-tile .label { font-size: .8rem; color: var(--text-muted); display: flex; align-items: center; gap: .4rem; }
.stat-tile .value { font-size: 1.7rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-tile .sub { font-size: .8rem; color: var(--text-muted); }
.stat { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats { display: flex; gap: 2rem; flex-wrap: wrap; }
.health { display: flex; gap: .75rem; align-items: flex-start; border-left: 4px solid var(--border-strong); }
.health.is-ok { border-left-color: var(--ok); }
.health.is-warn { border-left-color: var(--warn); }
.health.is-bad { border-left-color: var(--bad); }
.health h3 { margin: 0 0 .15rem; font-size: .95rem; }
.health p { margin: 0; font-size: .84rem; color: var(--text-muted); }
.health .state-icon { width: 1.6rem; height: 1.6rem; flex: none; }
.health.is-ok .state-icon { color: var(--ok); }
.health.is-warn .state-icon { color: var(--warn); }
.health.is-bad .state-icon { color: var(--bad); }

/* ---- tables ------------------------------------------------------------------- */
.table-wrap { overflow: auto; max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table-wrap.tall { max-height: 70vh; }
.card > .table-wrap:first-child { margin-top: 0; }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); font-size: .78rem;
  font-weight: 650; letter-spacing: .02em; color: var(--text-muted); white-space: nowrap; }
tbody tr:last-child > * { border-bottom: 0; }
tbody tr:hover > td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
tfoot th, tfoot td { background: var(--surface-2); border-top: 1px solid var(--border); border-bottom: 0; font-size: .85rem; }
th[aria-sort] .sort .icon { color: var(--link); }
button.sort { all: unset; cursor: pointer; display: inline-flex; gap: .25rem; align-items: center; }
button.sort:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
table.kv th { width: 34%; background: none; position: static; color: var(--text-muted); font-size: .85rem; white-space: normal; }
td .sub, th .sub { display: block; font-size: .8rem; color: var(--text-muted); font-weight: 400; }

/* ---- badges -------------------------------------------------------------------- */
.badge, .pill { display: inline-flex; align-items: center; gap: .25rem; padding: .05rem .5rem;
  border-radius: 999px; font-size: .76rem; font-weight: 600; line-height: 1.5; white-space: nowrap;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); vertical-align: .05em; }
.badge.ok, .pill.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
.badge.bad, .pill.bad { color: var(--bad); background: var(--bad-bg); border-color: var(--bad-line); }
.badge.warn, .pill.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.badge.info, .pill.info { color: var(--info); background: var(--info-bg); border-color: var(--info-line); }
.badge.brand { color: var(--brand-teal-ink); background: color-mix(in srgb, var(--brand-teal) 14%, var(--surface)); border-color: color-mix(in srgb, var(--brand-teal) 45%, var(--surface)); }
@media (prefers-color-scheme: dark) { .badge.brand { color: var(--link); } }
.badge .icon { width: .95em; height: .95em; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-size: .84rem; color: var(--text-muted); align-items: center; }
.legend > span { display: inline-flex; gap: .35rem; align-items: center; }

/* ---- buttons ------------------------------------------------------------------- */
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 2.35rem; padding: .45rem 1rem; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--btn-primary-bg); color: var(--btn-primary-text); font: inherit; font-weight: 600;
  font-size: .92rem; cursor: pointer; text-decoration: none; line-height: 1.2; white-space: nowrap; }
button:hover, .button:hover { background: var(--btn-primary-hover); }
button.secondary, .button.secondary { background: var(--btn-secondary-bg); color: var(--btn-secondary-text); border-color: var(--border-strong); }
button.secondary:hover, .button.secondary:hover { background: var(--surface-2); }
button.danger, .button.danger { background: var(--btn-danger-bg); color: var(--btn-danger-text); }
button.danger:hover, .button.danger:hover { filter: brightness(1.08); }
button.ghost, .button.ghost { background: transparent; color: var(--text); border-color: transparent; }
button.ghost:hover, .button.ghost:hover { background: var(--surface-2); }
button.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--link); font-weight: 500; text-decoration: underline; }
button.small, .button.small { min-height: 1.9rem; padding: .25rem .7rem; font-size: .84rem; }
button:disabled { opacity: .65; cursor: progress; }
.is-busy::before { content: ""; width: .95em; height: .95em; border-radius: 50%; border: 2px solid currentColor;
  border-right-color: transparent; animation: spin .7s linear infinite; }
span.is-busy { display: inline-flex; }
@keyframes spin { to { transform: rotate(360deg); } }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: 1rem; }
.count-badge { display: inline-flex; min-width: 1.4rem; height: 1.4rem; padding: 0 .35rem; border-radius: 999px;
  align-items: center; justify-content: center; font-size: .78rem; background: var(--brand-teal); color: var(--brand-navy); }

/* ---- forms --------------------------------------------------------------------- */
label { display: block; margin: .7rem 0; font-weight: 600; font-size: .9rem; }
.help { display: block; font-weight: 400; font-size: .82rem; color: var(--text-muted); margin-top: .2rem; }
input, select, textarea { display: block; width: 100%; margin-top: .3rem; padding: .5rem .65rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font: inherit; font-weight: 400;
  background: var(--surface); color: var(--text); min-height: 2.35rem; }
textarea { min-height: 5rem; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
input[type="checkbox"], input[type="radio"] { display: inline-block; width: 1.1rem; height: 1.1rem; min-height: 0;
  margin: 0 .4rem 0 0; vertical-align: -.15em; accent-color: var(--brand-teal-ink); }
@media (prefers-color-scheme: dark) { input[type="checkbox"], input[type="radio"] { accent-color: var(--brand-teal); } }
label.check { display: flex; flex-wrap: wrap; align-items: flex-start; gap: .1rem; font-weight: 500; }
label.check input { margin-top: .2rem; }
label.check .help { flex-basis: 100%; margin-left: 1.5rem; }
.form-row > label { align-self: flex-start; }
.inline { display: inline-flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; }
.inline label { margin: 0; }
form.inline { margin: 0; }
.form-row { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; }
.form-row > label { flex: 1 1 12rem; margin: 0; }
.search-box { position: relative; }
.search-box .icon { position: absolute; left: .65rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-box input { padding-left: 2.1rem; margin-top: 0; }
input.changed, select.changed { border-color: var(--warn); background: var(--changed-bg); }

/* ---- alerts (errors, warnings, notices) ---------------------------------------- */
.alert, p.error, .warning, .notice { display: flex; gap: .7rem; align-items: flex-start; padding: .75rem .9rem;
  border-radius: var(--radius-sm); border: 1px solid; margin: 0 0 1rem; }
.alert > .icon { margin-top: .15rem; }
.alert p { margin: 0; }
.alert p + p { margin-top: .25rem; }
.alert.bad, p.error { color: var(--bad); background: var(--bad-bg); border-color: var(--bad-line); }
.alert.warn, .warning { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.alert.info, .notice { color: var(--info); background: var(--info-bg); border-color: var(--info-line); }
.alert.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
p.error, .warning, .notice { display: block; }
.alert .title { font-weight: 650; }
.alert .next { color: var(--text); }
.alert a, .warning a, .notice a { color: inherit; font-weight: 600; }
.code-ref { font-size: .76rem; color: var(--text-muted); }
.code-ref code { font-size: .95em; }
.stat.error { color: var(--bad); }

/* empty states */
.empty { text-align: center; padding: 1.8rem 1rem; color: var(--text-muted); }
.empty .icon { width: 2rem; height: 2rem; color: var(--border-strong); margin-bottom: .4rem; }
.empty strong { display: block; color: var(--text); margin-bottom: .2rem; }
.empty p { margin: 0 auto .6rem; max-width: 46ch; }

/* ---- toasts -------------------------------------------------------------------- */
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 60; display: flex; flex-direction: column;
  gap: .5rem; width: min(26rem, calc(100vw - 2rem)); }
.toast { display: flex; gap: .6rem; align-items: flex-start; padding: .75rem .8rem .75rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid; box-shadow: 0 6px 24px rgb(16 36 62 / 18%); background: var(--surface); animation: toast-in .18s ease-out; }
.toast p { margin: 0; flex: 1; }
.toast-ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
.toast-bad { color: var(--bad); background: var(--bad-bg); border-color: var(--bad-line); }
.toast-info { color: var(--info); background: var(--info-bg); border-color: var(--info-line); }
.toast.leaving { opacity: 0; transition: opacity .2s; }
.toast-close { all: unset; cursor: pointer; font-size: 1.2rem; line-height: 1; padding: 0 .2rem; color: inherit; }
.toast-close:focus-visible { outline: 3px solid var(--focus); border-radius: 3px; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---- confirmations and disclosure ------------------------------------------------ */
details > summary { cursor: pointer; }
details.raw > summary, details.more > summary { font-size: .84rem; color: var(--link); }
details.confirm { display: inline-block; }
details.confirm > summary { list-style: none; display: inline-flex; align-items: center; gap: .35rem;
  min-height: 1.9rem; padding: .25rem .7rem; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--btn-secondary-bg); color: var(--btn-secondary-text); font-weight: 600; font-size: .84rem; }
details.confirm > summary::-webkit-details-marker { display: none; }
details.confirm > summary:hover { background: var(--surface-2); }
details.confirm[open] > summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
details.confirm .confirm-body { margin-top: .4rem; padding: .7rem .8rem; border: 1px solid var(--bad-line);
  background: var(--bad-bg); color: var(--text); border-radius: var(--radius-sm); max-width: 28rem; white-space: normal; text-align: left; }
details.confirm .confirm-body p { margin: 0 0 .5rem; font-size: .88rem; }
.danger-zone { border-color: var(--bad-line); }
.danger-zone h2 { color: var(--bad); }

/* ---- secrets (temporary passwords) ----------------------------------------------- */
.secret-box { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; padding: 1rem; margin: .8rem 0;
  border: 2px dashed var(--brand-teal-ink); border-radius: var(--radius); background: var(--surface-2); }
.secret { font-family: var(--mono); font-size: clamp(1.15rem, 4.6vw, 1.6rem); letter-spacing: .06em;
  user-select: all; word-break: break-all; flex: 1 1 14rem; color: var(--text); }
button.copied { background: var(--ok); color: #fff; }
.link-box .link-url { font-size: clamp(.9rem, 3.4vw, 1.05rem); letter-spacing: 0; }
fieldset.choices { border: 0; padding: 0; margin: .4rem 0 .8rem; }
fieldset.choices legend { padding: 0; margin-bottom: .3rem; color: var(--text-muted); }

/* ---- sidebar count (reset requests) ----------------------------------------------- */
.nav-count { margin-left: auto; display: inline-flex; }
.nav-badge { display: inline-flex; min-width: 1.35rem; height: 1.35rem; padding: 0 .35rem; border-radius: 999px;
  align-items: center; justify-content: center; font-size: .74rem; font-weight: 700;
  background: var(--brand-teal); color: var(--brand-navy); }

/* ---- tabs ------------------------------------------------------------------------ */
.tabs { display: flex; gap: .2rem; margin: 0 0 1.1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs a { padding: .5rem .85rem; color: var(--text-muted); text-decoration: none; border-bottom: 3px solid transparent;
  margin-bottom: -1px; font-weight: 500; font-size: .92rem; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--brand-teal); font-weight: 650; }

/* ---- meters, chunks, misc ----------------------------------------------------------- */
meter { width: 100%; min-width: 5rem; height: .7rem; }
.score { display: flex; align-items: center; gap: .5rem; font-family: var(--mono); font-size: .85rem; }
.score meter { flex: 1; }
.chunk { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .7rem .85rem; margin: .4rem 0 0; font-family: var(--mono); font-size: .84rem;
  max-height: 24rem; overflow: auto; color: var(--text); }
.bar { background: var(--brand-teal); height: .7rem; border-radius: 2px; display: inline-block; }
.kbd { font-family: var(--mono); font-size: .8em; padding: 0 .3em; border: 1px solid var(--border-strong); border-radius: 4px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: .7rem; padding: .55rem 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { font-size: .8rem; color: var(--text-muted); white-space: nowrap; min-width: 7.5rem; }

/* ---- access grid -------------------------------------------------------------------- */
/* scroll padding keeps a focused cell clear of the sticky first column and header */
.gridwrap { padding: 0; max-height: 72vh; overflow: auto; scroll-padding-left: 20rem; scroll-padding-top: 4rem; }
@media (max-width: 600px) { .gridwrap { scroll-padding-left: 11rem; } table.access th.rowhead { min-width: 10rem; } }
table.access th, table.access td { white-space: nowrap; text-align: center; vertical-align: middle; }
table.access th.rowhead { text-align: left; position: sticky; left: 0; z-index: 1; background: var(--surface);
  white-space: normal; min-width: 15rem; max-width: 20rem; border-right: 1px solid var(--border); }
table.access thead th { z-index: 2; }
table.access thead th.rowhead { z-index: 3; background: var(--surface-2); }
table.access th.colhead { font-size: .8rem; color: var(--text); max-width: 9.5rem; white-space: normal; font-weight: 600; }
table.access tr.public > *, table.access tr.role > * { background: var(--surface-2); }
table.access tr.public th.rowhead, table.access tr.role th.rowhead { background: var(--surface-2); }
table.access td.changed { background: var(--changed-bg); box-shadow: inset 0 0 0 2px var(--warn); }
table.access td .via { display: block; margin-top: .2rem; }
label.tick { display: inline-flex; margin: 0; font-weight: 400; align-items: center; gap: .2rem; padding: .3rem; }
label.tick input { margin: 0; width: 1.2rem; height: 1.2rem; }
.sticky-actions { position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: .7rem; align-items: center;
  padding: .7rem 0; background: linear-gradient(to top, var(--bg) 70%, transparent); }

/* ---- results (retrieval) and compare ------------------------------------------------- */
.result { border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem .95rem; margin-bottom: .7rem; background: var(--surface); }
.result.to-model { border-left: 4px solid var(--ok); }
.result-head { display: flex; flex-wrap: wrap; gap: .4rem .8rem; align-items: center; }
.rank { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 2rem; }
.result .file { font-weight: 600; overflow-wrap: anywhere; }
.compare { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 26rem), 1fr)); }

@media (max-width: 600px) {
  h1 { font-size: 1.3rem; }
  .card { padding: .9rem; }
  th, td { padding: .45rem .5rem; }
  .page-actions { width: 100%; }
}
@media print {
  .sidebar, .topbar, .toasts { display: none; }
  .shell { display: block; }
}

/* htmx loading indicators (htmx's own inline indicator styles are off for the CSP) */
.htmx-indicator { visibility: hidden; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { visibility: visible; }

/* Tables that become stacked cards on a phone: <table class="responsive"> and a
   data-label on each <td> (shown before the value; the header row is hidden). */
@media (max-width: 600px) {
  table.responsive thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { padding: .55rem .7rem; border-bottom: 1px solid var(--border); }
  table.responsive tbody tr:last-child { border-bottom: 0; }
  table.responsive td { border: 0; padding: .15rem 0; text-align: left; }
  table.responsive td[data-label]::before { content: attr(data-label); display: block; font-size: .72rem;
    font-weight: 650; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
  table.responsive td.num { text-align: left; }
  .table-wrap:has(> table.responsive) { overflow: visible; }
}

/* changed settings, result header spacing */
tr.changed > td { background: var(--changed-bg); }
.result-head .spacer { flex: 1; }
.filters { display: flex; flex-wrap: wrap; gap: .7rem; align-items: flex-end; }
.filters > label { flex: 1 1 10rem; margin: 0; }
.audit-row .when { white-space: nowrap; }
details.raw pre { margin: .3rem 0 0; }
td input[type="number"], td select { min-width: 9rem; }
/* The client console's setup page: the enrolment QR code (white behind it, so dark mode
   keeps it readable) and the recovery codes. */
.client img.qr { background: #fff; padding: .5rem; border-radius: 6px; max-width: 100%; height: auto; }
.client ol.codes { columns: 2; column-gap: 2rem; padding-left: 1.5rem; font-size: 1.05rem; }
.client ol.codes li { margin: .2rem 0; }
@media (max-width: 30rem) { .client ol.codes { columns: 1; } }
