/* Archie Voice Hub.
 * UI chrome uses a teal accent; the blue series colour is reserved for data marks, so controls never read as data.
 * Light and dark are chosen separately (not inverted); every text token is WCAG AA on page, surface and surface-2.
 */
:root {
  color-scheme: light;
  --page: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --ink: #18212c;
  --ink-2: #465161;
  --muted: #5c6878;
  --line: #dde2e8;
  --grid: #e6eaef;
  --axis: #c3cad3;
  --accent: #0b6b62;
  --accent-hover: #08574f;
  --accent-ink: #0a5f57;
  --accent-tint: #e3f1ee;
  --on-accent: #ffffff;
  --series-1: #2a78d6;
  --track: #e8eef7;
  --bubble-bot: #e9f0f8;
  --good: #0ca30c;
  --good-ink: #0b6b1f;
  --serious: #ec835a;
  --serious-ink: #9a4419;
  --critical: #d03b3b;
  --critical-ink: #b42828;
  --critical-tint: #fbeaea;
  --notice: #fff6dd;
  --notice-line: #ecd9a0;

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --r-panel: 12px;
  --r-control: 8px;
  --sidebar: 248px;
  font-family: var(--font-ui);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0e1318;
    --surface: #151b22;
    --surface-2: #1c242d;
    --ink: #e8edf2;
    --ink-2: #b6c0cc;
    --muted: #909cab;
    --line: #27313c;
    --grid: #222b35;
    --axis: #36414d;
    --accent: #4cc3b2;
    --accent-hover: #6fd3c4;
    --accent-ink: #6fd3c4;
    --accent-tint: #16302d;
    --on-accent: #0e1318;
    --series-1: #3987e5;
    --track: #1d2836;
    --bubble-bot: #1a2633;
    --good-ink: #5cc96a;
    --serious-ink: #f0a07c;
    --critical-ink: #ef7b7b;
    --critical-tint: #2e1a1c;
    --notice: #2b2614;
    --notice-line: #4d4322;
  }
}

/* --- base ------------------------------------------------------------------ */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page); color: var(--ink); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--accent-ink); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }
code { font-family: var(--font-mono); font-size: 0.86em; }
h1, h2, h3 { font-family: var(--font-display); color: var(--ink); letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0; font-weight: 650; }
h2 { font-size: 1.1rem; line-height: 1.3; margin: 0 0 0.75rem; font-weight: 620; }
h3 { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; font-weight: 620; }
p { margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; font-weight: 400; margin: 0.3rem 0 0; }
.num, .tabular { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip {
  position: absolute; left: 1rem; top: -3rem; z-index: 100; padding: 0.5rem 0.9rem;
  background: var(--accent); color: var(--on-accent); border-radius: var(--r-control); text-decoration: none;
}
.skip:focus { top: 1rem; }

/* --- brand ----------------------------------------------------------------- */
.brand { display: inline-flex; align-items: center; gap: 0.55rem; color: var(--ink); text-decoration: none; }
.brand .glyph { width: 26px; height: 26px; flex: none; }
.glyph rect { fill: var(--accent); }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; line-height: 1.1; }
.brand-name span { display: block; font-weight: 500; font-size: 0.8rem; color: var(--muted); letter-spacing: 0; }

/* --- app layout ------------------------------------------------------------ */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
  padding: 1.25rem 0.9rem 1rem; background: var(--surface); border-right: 1px solid var(--line);
}
.sidebar .brand { padding: 0 0.5rem; }
.org-name {
  margin: 1.1rem 0.5rem 1.25rem; padding: 0.55rem 0.7rem; border-radius: var(--r-control);
  background: var(--surface-2); font-size: 0.875rem; font-weight: 600; color: var(--ink);
}
.org-name small { display: block; font-weight: 400; color: var(--muted); font-size: 0.78rem; }
.nav-group { margin: 0 0 1.1rem; }
.nav-group h2 {
  font-family: var(--font-ui); font-size: 0.78rem; font-weight: 600; color: var(--muted);
  margin: 0 0.6rem 0.3rem; letter-spacing: 0;
}
.nav-group ul { list-style: none; margin: 0; padding: 0; }
.nav-group a {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0.6rem; border-radius: var(--r-control);
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.nav-group a svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-group a:hover { background: var(--surface-2); color: var(--ink); }
.nav-group a[aria-current="page"] { background: var(--accent-tint); color: var(--accent-ink); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 0.9rem 0.5rem 0; border-top: 1px solid var(--line); display: grid; gap: 0.35rem; }
.sidebar-foot .who { display: block; color: var(--ink); text-decoration: none; font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.sidebar-foot .who small { display: block; font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.sidebar-foot .who:hover small { color: var(--accent-ink); }

.mobile-bar { display: none; }
main.content { padding: 2rem 2.5rem 4rem; max-width: 1240px; width: 100%; }

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .mobile-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; position: sticky; top: 0; z-index: 20;
    padding: 0.7rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line);
  }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar > .brand { display: none; }
  .org-name { margin-top: 0; }
  /* With JS the menu folds away behind the Menu button; without JS it simply stays open */
  .js .sidebar { display: none; }
  .js body.nav-open .sidebar, body.nav-open .sidebar { display: flex; }
  main.content { padding: 1.25rem 1rem 3rem; }
}

/* --- page header ----------------------------------------------------------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem 2rem; flex-wrap: wrap; margin: 0 0 1.5rem; }
.page-head .intro { margin: 0.4rem 0 0; color: var(--ink-2); max-width: 62ch; }
.page-head .actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 0.3rem; margin: 0 0 0.75rem; color: var(--muted); text-decoration: none; font-size: 0.9rem; }
.back:hover { color: var(--accent-ink); }

/* --- panels ---------------------------------------------------------------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel);
  padding: 1.25rem 1.4rem; margin: 0 0 1.25rem;
}
.panel > :last-child { margin-bottom: 0; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem 1rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.panel-head h2 { margin: 0; }
.panel-head p { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.9rem; flex-basis: 100%; max-width: 75ch; }
.panel.flush { padding: 0; overflow: hidden; }
.panel.flush .panel-head { padding: 1.1rem 1.4rem 0; }
.table-wrap { overflow-x: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.grid-2 > .panel { margin: 0; }
.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.25rem; align-items: start; }
.detail-layout > aside .panel:last-child { margin-bottom: 0; }
@media (max-width: 1100px) { .grid-2, .detail-layout { grid-template-columns: 1fr; } }

/* --- messages -------------------------------------------------------------- */
.flash, .notice, .errors, .callout {
  display: flex; gap: 0.7rem; align-items: flex-start; padding: 0.75rem 1rem; border-radius: var(--r-control);
  margin: 0 0 1.25rem; border: 1px solid var(--line); background: var(--surface);
}
.flash .icon, .errors .icon, .notice .icon, .callout .icon { flex: none; margin-top: 0.1rem; }
.flash { border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
.flash .icon { color: var(--good-ink); }
.notice { background: var(--notice); border-color: var(--notice-line); }
.errors { background: var(--critical-tint); border-color: color-mix(in srgb, var(--critical) 45%, var(--line)); color: var(--ink); }
.errors .icon { color: var(--critical-ink); }
.errors strong { display: block; color: var(--critical-ink); }
.errors ul { margin: 0.2rem 0 0; padding-left: 1.1rem; }
.callout { background: var(--accent-tint); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.icon { display: inline-block; width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* --- empty states ---------------------------------------------------------- */
.empty { text-align: left; padding: 1.75rem 1.4rem; }
.empty h3 { margin: 0 0 0.3rem; font-size: 1rem; }
.empty p { margin: 0 0 0.8rem; color: var(--ink-2); max-width: 60ch; }
.empty p:last-child { margin-bottom: 0; }
td.empty-cell { padding: 1.5rem 1.4rem; color: var(--muted); }

/* --- dashboard ------------------------------------------------------------- */
.summary {
  font-family: var(--font-display); font-size: 1.6rem; line-height: 1.3; font-weight: 560; letter-spacing: -0.015em;
  margin: 0 0 1.5rem; max-width: 34ch; color: var(--ink);
}
.summary .tabular { font-weight: 650; }
@media (max-width: 600px) { .summary { font-size: 1.3rem; } h1 { font-size: 1.5rem; } }
.kpi-strip {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0 0 1.25rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden;
}
.kpi { padding: 1rem 1.2rem 1.1rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0; }
.kpi:nth-child(4n) { border-right: 0; }
.kpi:nth-last-child(-n + 4) { border-bottom: 0; }
.kpi dt { color: var(--ink-2); font-size: 0.875rem; font-weight: 500; }
.kpi dd { margin: 0; }
.kpi .value { display: block; font-family: var(--font-display); font-size: 1.85rem; font-weight: 650; line-height: 1.2; margin-top: 0.2rem; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.kpi .note { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 0.15rem; }
.kpi.secondary .value { font-size: 1.35rem; }
@media (max-width: 1000px) {
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(4n) { border-right: 1px solid var(--line); }
  .kpi:nth-child(2n) { border-right: 0; }
  .kpi:nth-last-child(-n + 4) { border-bottom: 1px solid var(--line); }
  .kpi:nth-last-child(-n + 2) { border-bottom: 0; }
}

/* --- charts ---------------------------------------------------------------- */
figure.panel { margin-left: 0; margin-right: 0; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .axis { stroke: var(--axis); stroke-width: 1; }
svg.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; font-family: var(--font-ui); }
svg.chart .value-label { fill: var(--ink-2); font-size: 11px; font-weight: 600; font-family: var(--font-ui); }
svg.chart .bar, svg.hbar .bar { fill: var(--series-1); }
svg.chart .hit { fill: transparent; cursor: default; }
svg.chart .hit:hover, svg.chart .hit:focus-visible { fill: var(--ink); fill-opacity: 0.05; outline: none; }
svg.hbar { display: block; max-width: 100%; }
svg.hbar .track { fill: var(--track); }
.table-view { margin-top: 0.75rem; }
.table-view summary { cursor: pointer; color: var(--ink-2); font-size: 0.9rem; }
.table-view table { margin-top: 0.5rem; max-width: 320px; }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; padding: 0.35rem 0.6rem; border-radius: 6px;
  background: var(--ink); color: var(--surface); font-size: 0.85rem; white-space: nowrap;
}

/* --- tables ---------------------------------------------------------------- */
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.data thead th { font-size: 0.8rem; color: var(--muted); font-weight: 600; border-bottom-color: var(--line); white-space: nowrap; }
table.data tbody tr:last-child > * { border-bottom: 0; }
table.data th[scope="row"] { font-weight: 500; }
table.data .num { text-align: right; white-space: nowrap; }
table.data .nowrap { white-space: nowrap; }
table.data .secondary-text { display: block; color: var(--muted); font-size: 0.82rem; }
table.bars td.bar-cell { width: 38%; min-width: 110px; }
.panel table.data th:first-child, .panel table.data td:first-child { padding-left: 0; }
.panel table.data th:last-child, .panel table.data td:last-child { padding-right: 0; }
.panel.flush table.data th:first-child, .panel.flush table.data td:first-child { padding-left: 1.4rem; }
.panel.flush table.data th:last-child, .panel.flush table.data td:last-child { padding-right: 1.4rem; }
.panel.flush table.data thead th { padding-top: 0.75rem; }
table.rows tbody tr:hover { background: var(--surface-2); }
table.rows a.row-link { font-weight: 600; text-decoration: none; color: var(--ink); }
table.rows a.row-link:hover { color: var(--accent-ink); text-decoration: underline; }
.args { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; }
.args .arg b { font-weight: 500; color: var(--muted); margin-right: 0.3rem; }
.row-actions { white-space: nowrap; text-align: right; }

dl.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.5rem 1.25rem; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
dl.stack-facts { margin: 0; display: grid; gap: 0.75rem; }
dl.stack-facts dt { color: var(--muted); font-size: 0.82rem; }
dl.stack-facts dd { margin: 0.1rem 0 0; overflow-wrap: anywhere; }

/* --- status: always icon + label, never colour alone ----------------------- */
.status { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.875rem; white-space: nowrap; color: var(--ink); }
.status .dot {
  display: inline-grid; place-items: center; width: 1.15rem; height: 1.15rem; border-radius: 50%;
  font-size: 0.7rem; font-weight: 700; color: #fff; line-height: 1; flex: none;
}
.status-good .dot { background: var(--good); }
.status-serious .dot { background: var(--serious); color: #2b1307; }
.status-critical .dot { background: var(--critical); }
.status-idle .dot, .status-pending .dot { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--axis); }
.status-info .dot { background: var(--accent-tint); color: var(--accent-ink); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.status-critical { color: var(--critical-ink); }
.status-serious { color: var(--serious-ink); }
.status-pending { color: var(--muted); }
.pill {
  display: inline-block; font-size: 0.78rem; font-weight: 500; padding: 0.08rem 0.55rem; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; vertical-align: middle;
}
.pill.accent { background: var(--accent-tint); color: var(--accent-ink); border-color: transparent; }

/* --- call detail ----------------------------------------------------------- */
.call-title { display: flex; align-items: center; gap: 0.5rem 1rem; flex-wrap: wrap; }
.call-facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; margin: 0 0 1.25rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden;
}
.call-facts div { padding: 0.8rem 1.1rem; border-right: 1px solid var(--line); }
.call-facts div:last-child { border-right: 0; }
.call-facts dt { color: var(--muted); font-size: 0.82rem; }
.call-facts dd { margin: 0.1rem 0 0; font-family: var(--font-display); font-weight: 620; font-size: 1.05rem; overflow-wrap: anywhere; }

.thread { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.9rem; }
.msg { display: grid; gap: 0.25rem; max-width: min(80%, 60ch); }
.msg .who { font-size: 0.8rem; color: var(--muted); display: flex; gap: 0.6rem; align-items: baseline; flex-wrap: wrap; }
.msg .who b { color: var(--ink-2); font-weight: 600; }
.msg .bubble { padding: 0.65rem 0.95rem; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-user { justify-self: start; }
.msg-user .bubble { background: var(--surface-2); border-top-left-radius: 4px; }
.msg-assistant { justify-self: end; }
.msg-assistant .who { justify-content: flex-end; }
.msg-assistant .bubble { background: var(--bubble-bot); border-top-right-radius: 4px; }
.msg .flag { color: var(--serious-ink); }
.event {
  justify-self: center; display: flex; align-items: flex-start; gap: 0.6rem; max-width: 90%;
  padding: 0.5rem 0.85rem; border: 1px dashed var(--axis); border-radius: var(--r-control); font-size: 0.875rem; color: var(--ink-2);
}
.event .icon { width: 16px; height: 16px; margin-top: 0.15rem; color: var(--muted); }
.event strong { color: var(--ink); font-weight: 600; }
.event > div { display: grid; gap: 0.1rem; }
.event .query { color: var(--ink); }
.event .event-meta { color: var(--muted); font-size: 0.82rem; }
.event .args { margin-top: 0.15rem; }
.event-error { border-color: color-mix(in srgb, var(--critical) 50%, var(--line)); }
.event-error .icon { color: var(--critical-ink); }
.handoff { white-space: pre-wrap; background: var(--surface-2); border-radius: var(--r-control); padding: 0.6rem 0.8rem; margin: 0.25rem 0 0; }
.error-list { margin: 0; padding-left: 1.1rem; color: var(--critical-ink); }
.error-list code { overflow-wrap: anywhere; }

/* --- forms ----------------------------------------------------------------- */
.field { display: grid; gap: 0.3rem; align-content: start; }
.field > label, label.field-label { font-weight: 600; font-size: 0.9rem; color: var(--ink); }
.field .hint { margin: 0; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"], select, textarea {
  display: block; width: 100%; padding: 0.55rem 0.7rem; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--axis); border-radius: var(--r-control);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:not([type="checkbox"]):not([type="radio"]), select { height: 2.5rem; }
input[type="search"] { -webkit-appearance: none; appearance: none; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
input[type="number"] { display: inline-block; width: 6.5rem; }
textarea { resize: vertical; font-family: var(--font-mono); font-size: 0.9em; line-height: 1.5; }
input.code-input { font-family: var(--font-mono); font-size: 1.35rem; letter-spacing: 0.25em; text-align: center; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset[disabled] { opacity: 0.75; }
.check { display: grid; grid-template-columns: auto 1fr; gap: 0.1rem 0.65rem; align-items: start; font-weight: 500; }
.check input { margin: 0.25rem 0 0; width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
.check .hint { grid-column: 2; }
.stack { display: grid; gap: 1.1rem; }
.narrow-form { max-width: 440px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem 1.25rem; align-items: start; }
.form-grid .wide, .form-grid .check, .form-grid .form-actions { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.filters { display: flex; flex-wrap: wrap; gap: 0.9rem 1rem; align-items: end; }
.filters .field { min-width: 160px; flex: 1 1 160px; }
.filters .field.grow { flex: 1 1 240px; }
.filters .field > label { font-size: 0.82rem; }
form.inline { display: inline-flex; align-items: center; gap: 0.5rem; margin: 0; flex-wrap: wrap; }
form.inline select { display: inline-block; width: auto; padding: 0.35rem 0.5rem; }
.inline-setting { display: flex; align-items: center; gap: 0.6rem 0.9rem; flex-wrap: wrap; margin-top: 1.25rem; padding-top: 1.1rem; border-top: 1px solid var(--grid); }
.inline-setting label { font-weight: 600; font-size: 0.9rem; }
.inline-setting .hint { flex-basis: 100%; }

/* --- buttons --------------------------------------------------------------- */
button, .button {
  font: inherit; font-weight: 600; font-size: 0.925rem; cursor: pointer; border-radius: var(--r-control);
  padding: 0.55rem 1.05rem; border: 1px solid transparent; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem; line-height: 1.3;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
button.primary, .button.primary { background: var(--accent); color: var(--on-accent); }
button.primary:hover, .button.primary:hover { background: var(--accent-hover); }
button.secondary, .button.secondary { background: var(--surface); color: var(--ink); border-color: var(--axis); }
button.secondary:hover, .button.secondary:hover { background: var(--surface-2); border-color: var(--muted); }
button.danger, .button.danger { background: var(--critical); color: #fff; }
button.danger:hover { background: var(--critical-ink); }
button.small, .button.small { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
button.link { background: none; border: 0; padding: 0; color: var(--accent-ink); font-weight: 500; text-decoration: underline; text-underline-offset: 0.15em; }
button.block, .button.block { width: 100%; }
button.ghost { background: none; color: var(--ink-2); border-color: transparent; }
button.ghost:hover { background: var(--surface-2); color: var(--ink); }

/* --- disclosure, confirmation and menus ------------------------------------ */
details > summary { cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
details.item { border-top: 1px solid var(--grid); }
details.item:first-of-type { border-top: 0; }
details.item > summary {
  list-style: none; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.25rem 1rem; align-items: center;
  padding: 0.9rem 0;
}
details.item > summary .title { font-weight: 600; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
details.item > summary .sub { grid-column: 1; color: var(--muted); font-size: 0.875rem; overflow-wrap: anywhere; }
details.item > summary .toggle { grid-row: 1 / span 2; grid-column: 2; color: var(--accent-ink); font-size: 0.875rem; font-weight: 600; }
details.item[open] > summary .toggle .when-closed, details.item:not([open]) > summary .toggle .when-open { display: none; }
details.item > .item-body { padding: 0 0 1.25rem; }
details.add > summary {
  list-style: none; display: inline-flex; align-items: center; gap: 0.45rem; margin-top: 0.75rem;
  font-weight: 600; font-size: 0.925rem; color: var(--accent-ink); padding: 0.5rem 0.9rem;
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: var(--r-control);
}
details.add > summary:hover { background: var(--accent-tint); }
details.add[open] > summary { margin-bottom: 1rem; }
details.add > .item-body { padding: 1.1rem 1.2rem; border: 1px solid var(--line); border-radius: var(--r-panel); background: var(--page); }

details.confirm { display: inline-block; }
details.confirm > summary {
  list-style: none; display: inline-flex; align-items: center; font-weight: 600; font-size: 0.85rem;
  color: var(--critical-ink); padding: 0.3rem 0.65rem; border-radius: var(--r-control); border: 1px solid transparent;
}
details.confirm > summary:hover { background: var(--critical-tint); }
details.confirm[open] > summary { color: var(--muted); }
details.confirm .confirm-body {
  margin-top: 0.5rem; padding: 0.75rem 0.9rem; border-radius: var(--r-control); background: var(--critical-tint);
  border: 1px solid color-mix(in srgb, var(--critical) 35%, var(--line)); display: grid; gap: 0.6rem; max-width: 360px;
  text-align: left; white-space: normal;
}
details.confirm .confirm-body p { margin: 0; font-size: 0.9rem; }

details.menu { position: relative; display: inline-block; }
details.menu > summary {
  list-style: none; padding: 0.3rem 0.65rem; border-radius: var(--r-control); border: 1px solid var(--axis);
  font-size: 0.85rem; font-weight: 600; color: var(--ink); background: var(--surface);
}
details.menu > summary:hover { background: var(--surface-2); }
details.menu .menu-body {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 15; min-width: 230px; padding: 0.4rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel);
  box-shadow: 0 10px 30px color-mix(in srgb, var(--ink) 14%, transparent); display: grid; gap: 0.25rem;
}
details.menu .menu-body form { display: block; }
details.menu .menu-body button { width: 100%; justify-content: flex-start; }
details.menu .menu-body .confirm { width: 100%; }
details.menu .menu-body .confirm > summary { width: 100%; }

.segmented { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.segmented a { padding: 0.3rem 0.85rem; text-decoration: none; color: var(--ink-2); border-radius: 7px; font-size: 0.875rem; font-weight: 500; white-space: nowrap; }
.segmented a:hover { color: var(--ink); }
.segmented a[aria-current] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px color-mix(in srgb, var(--ink) 12%, transparent); }
.pagination { display: flex; gap: 0.75rem; align-items: center; justify-content: space-between; padding: 0.8rem 1.4rem; border-top: 1px solid var(--grid); font-size: 0.9rem; }
.pagination .spacer { flex: 1; }
.result-count { color: var(--muted); font-size: 0.9rem; margin: 0; }

/* --- public pages (login, invite, 2FA) ------------------------------------- */
.public { min-height: 100vh; display: grid; place-items: start center; padding: 9vh 1rem 3rem; }
.public-inner { width: 100%; max-width: 420px; }
.public .brand { margin: 0 0 1.75rem; }
.public .brand .glyph { width: 32px; height: 32px; }
.public .brand-name { font-size: 1.2rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 2rem; }
.card h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.card .lede { color: var(--ink-2); margin-bottom: 1.4rem; }
.card-foot { margin: 1.25rem 0 0; font-size: 0.9rem; color: var(--muted); }
.public-note { margin: 1.25rem 0 0; color: var(--muted); font-size: 0.85rem; text-align: center; }
.public.wide .public-inner { max-width: 640px; }

/* --- 2FA ------------------------------------------------------------------- */
.mfa-setup { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 2rem; align-items: start; }
@media (max-width: 700px) { .mfa-setup { grid-template-columns: 1fr; } .mfa-setup .qr { max-width: 220px; } }
.qr svg { width: 100%; height: auto; background: #fff; padding: 12px; border-radius: var(--r-panel); border: 1px solid var(--line); display: block; }
.secret { word-break: break-all; user-select: all; }
ol.steps { margin: 0 0 1.25rem; padding-left: 1.25rem; display: grid; gap: 0.4rem; }
.codes { list-style: none; padding: 0; margin: 0 0 1.25rem; display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
.codes li { background: var(--surface-2); border-radius: var(--r-control); padding: 0.45rem 0.7rem; text-align: center; }
.codes code { font-size: 1rem; letter-spacing: 0.04em; }

/* --- key reveal ------------------------------------------------------------ */
.key-reveal { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin: 0.5rem 0; }
.key-reveal code { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-control); padding: 0.45rem 0.7rem; }

dl.roles { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.25rem; margin: 0; font-size: 0.9rem; }
dl.roles dt { font-weight: 600; }
dl.roles dd { margin: 0; color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media (forced-colors: active) {
  svg.chart .bar, svg.hbar .bar { fill: CanvasText; }
  .glyph rect { fill: CanvasText; }
  .status .dot { border: 1px solid CanvasText; }
  .nav-group a[aria-current="page"] { outline: 2px solid Highlight; }
  .segmented a[aria-current] { outline: 2px solid Highlight; }
}

/* --- list toolbars (inside flush panels) ----------------------------------- */
.pad { padding: 1.1rem 1.4rem; }
form.filters.pad { border-bottom: 1px solid var(--grid); background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); }
.toolbar { display: flex; align-items: baseline; justify-content: space-between; gap: 0.25rem 1rem; flex-wrap: wrap; padding-bottom: 0.4rem; }
.toolbar .hint { margin: 0; }

/* Row menus must not be clipped by the table's scroll container */
@media (min-width: 1000px) {
  .panel.flush:has(details.menu), .panel.flush:has(details.menu) .table-wrap { overflow: visible; }
}
@media (max-width: 999px) {
  details.menu .menu-body { position: static; box-shadow: none; margin-top: 0.4rem; min-width: 0; }
}

/* --- knowledge gaps -------------------------------------------------------- */
.gap-status { margin: 0 0 1rem; flex-wrap: wrap; }
.segmented .count { margin-left: 0.3rem; font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 500; }
.row-actions form { display: inline; }
.row-actions form + form { margin-left: 0.25rem; }
table.gaps th[scope="row"] { font-weight: 600; }
details.examples { margin-top: 0.3rem; font-weight: 400; }
details.examples summary { cursor: pointer; color: var(--ink-2); font-size: 0.85rem; width: max-content; }
details.examples ul { margin: 0.35rem 0 0; padding-left: 1.1rem; font-size: 0.875rem; }
details.examples li + li { margin-top: 0.2rem; }

/* --- analysis (call detail) ------------------------------------------------ */
.analysis-summary { margin: 0 0 0.9rem; font-size: 0.975rem; line-height: 1.55; max-width: 70ch; }
.analysis-facts { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 0.9rem; padding: 0; list-style: none; }
.analysis-facts li { padding: 0.2rem 0.65rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 0.85rem; }
.analysis-facts li strong { font-weight: 600; }
.unanswered { margin: 0; padding-left: 1.1rem; }
.unanswered li + li { margin-top: 0.3rem; }
.unanswered .muted { font-size: 0.85rem; }
dl.facts.compact { margin-top: 1rem; padding-top: 0.9rem; border-top: 1px solid var(--line); }
