/* Voult dashboard components (Phase 4). Tokens only: no colour literals (CI checks it).
   Loaded by layout/console.ejs, never next to Bootstrap (its .btn/.badge/.table would collide).
   Rules, markup and states: docs/design/DESIGN_SYSTEM.md; every part on screen: GET /_design. */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--t-small);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: var(--w-semibold); letter-spacing: -0.015em; line-height: 1.25; }
h1 { font-size: 1.5rem; letter-spacing: -0.025em; }
h2 { font-size: var(--t-h3); }
h3 { font-size: var(--t-ui); }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
code, kbd, pre, .mono { font-family: var(--font-mono); font-size: var(--t-code-sm); }
:focus-visible { outline: var(--focus-width) solid var(--focus); outline-offset: var(--focus-offset); border-radius: var(--radius-sm); }
::selection { background: var(--accent-bg); color: var(--text); }
.muted { color: var(--text-3); }
.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; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}

/* ---------- Buttons (R1: landing's look; dense heights for the app) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--control); padding: 0 var(--space-4);
  border: var(--border-width) solid transparent; border-radius: var(--radius);
  font: inherit; font-size: var(--t-small); font-weight: var(--w-medium);
  white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-control); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--surface); color: var(--bad); border-color: var(--border-control); }
.btn-danger:hover:not(:disabled) { background: var(--bad-bg); border-color: var(--bad); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-sm { height: var(--control-sm); padding: 0 var(--space-3); font-size: var(--t-xs); }
.btn-icon { width: var(--control); padding: 0; }
.btn-icon.btn-sm { width: var(--control-sm); }
.btn:disabled, .btn[aria-disabled='true'] { opacity: 0.55; cursor: not-allowed; }
/* Loading: aria-busy keeps the label for screen readers and shows a spinner in its place. */
.btn[aria-busy='true'] { position: relative; color: transparent; cursor: progress; }
.btn[aria-busy='true']::after {
  content: ''; position: absolute; inset: 0; margin: auto; width: 14px; height: 14px;
  border: 2px solid var(--text-3); border-top-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn-primary[aria-busy='true']::after { border-color: var(--primary-fg); border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Fields ---------- */
.field { display: grid; gap: var(--space-1); align-content: start; }
.field > label, .label { font-size: var(--t-xs); font-weight: var(--w-medium); color: var(--text-2); }
.help { font-size: var(--t-xs); color: var(--text-3); }
.error-text { font-size: var(--t-xs); color: var(--bad); }
.input, .select, .textarea {
  width: 100%; height: var(--control); padding: 0 var(--space-3);
  border: var(--border-width) solid var(--border-control); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: var(--t-small);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.textarea { height: auto; min-height: 88px; padding: var(--space-2) var(--space-3); resize: vertical; }
.input.mono { font-family: var(--font-mono); font-size: var(--t-code-sm); }
/* Password field: public/js/password-field.js wraps every password input and adds the eye button. */
.password-field { position: relative; display: block; }
.password-field .input { padding-right: 40px; }
.password-toggle { position: absolute; top: 0; right: 0; bottom: 0; width: 36px; display: grid; place-items: center; border: 0; border-radius: var(--radius); background: none; color: var(--text-3); cursor: pointer; }
.password-toggle:hover, .password-toggle[aria-pressed='true'] { color: var(--text); }
/* A provider secret typed into a text input (type=password makes browsers offer to save it): the characters are hidden. */
.masked-secret { -webkit-text-security: disc; text-security: disc; }
/* A typed confirmation: the name in its label can't be selected and copied (components.js blocks pasting it too). */
.field:has([data-confirm-match]) label strong { -webkit-user-select: none; user-select: none; }
.password-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover:not(:disabled), .select:hover:not(:disabled), .textarea:hover:not(:disabled) { border-color: var(--text-3); }
.input:focus-visible, .input[type='date']:focus-within, .select:focus-visible, .textarea:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }
.input[aria-invalid='true'], .select[aria-invalid='true'], .textarea[aria-invalid='true'] { border-color: var(--bad); }
.input[aria-invalid='true']:focus-visible { box-shadow: 0 0 0 1px var(--bad); }
.search { position: relative; display: inline-flex; align-items: center; }
.search .input { padding-left: 30px; height: var(--control-sm); font-size: var(--t-xs); min-width: 220px; }
.search svg { position: absolute; left: 10px; color: var(--text-3); pointer-events: none; }

/* Checkbox, radio: native controls, tinted. Switch: a checkbox with role="switch". */
.check { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--t-small); cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); cursor: pointer; }
.check input:disabled, .check input:disabled + span { cursor: not-allowed; opacity: 0.55; }
.switch {
  appearance: none; position: relative; flex-shrink: 0; width: 30px; height: 18px; margin: 0;
  border-radius: 999px; background: var(--border-control); cursor: pointer;
  transition: background-color var(--dur);
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-sm);
  transition: left var(--dur) var(--ease);
}
.switch:checked { background: var(--ok); }
.switch:checked::after { left: 14px; }
.switch:disabled { opacity: 0.5; cursor: not-allowed; }
.switch:focus-visible { outline-offset: 3px; border-radius: 999px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) 0; border-top: var(--border-width) solid var(--border); }
.toggle-row:first-child { border-top: 0; }
.toggle-row strong { display: block; font-weight: var(--w-medium); }
.toggle-row small { display: block; color: var(--text-3); font-size: var(--t-xs); }

/* ---------- Badges, pills, severity (R7, R8) ---------- */
.badge {
  display: inline-flex; align-items: center; padding: 1px 7px;
  border: var(--border-width) solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-3);
  font-size: var(--t-micro); font-weight: var(--w-medium); line-height: 1.6; white-space: nowrap;
}
.badge-accent { color: var(--accent); background: var(--accent-bg); border-color: var(--accent-border); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px;
  border-radius: 999px; font-size: var(--t-micro); font-weight: var(--w-medium); line-height: 1.6; white-space: nowrap;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-ok { color: var(--ok); background: var(--ok-bg); }
.pill-warn { color: var(--warn); background: var(--warn-bg); }
.pill-bad { color: var(--bad); background: var(--bad-bg); }
.pill-neutral { color: var(--text-2); background: var(--surface-3); }
.pill-accent { color: var(--accent); background: var(--accent-bg); }
/* Severity always carries its word; CRITICAL also an icon and weight. */
.sev { display: inline-flex; align-items: center; gap: 6px; padding: 1px 7px; border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: var(--t-micro); white-space: nowrap; }
.sev-low { color: var(--sev-low); background: var(--sev-low-bg); }
.sev-medium { color: var(--sev-medium); background: var(--sev-medium-bg); }
.sev-high { color: var(--sev-high); background: var(--sev-high-bg); }
.sev-critical { color: var(--sev-critical); background: var(--sev-critical-bg); font-weight: var(--w-semibold); }

/* ---------- Code ---------- */
:not(pre) > code { padding: 1px 5px; border: var(--border-width) solid var(--border); border-radius: var(--radius-sm); background: var(--code-bg); }
.codeblock { border: var(--border-width) solid var(--border); border-radius: var(--radius-lg); background: var(--code-bg); overflow: hidden; }
.codeblock-head { display: flex; align-items: center; justify-content: space-between; padding: 0 var(--space-1) 0 var(--space-3); min-height: 34px; border-bottom: var(--border-width) solid var(--border); background: var(--surface-2); font-family: var(--font-mono); font-size: var(--t-micro); color: var(--text-3); }
.codeblock pre { margin: 0; padding: var(--space-3) var(--space-4); overflow-x: auto; font-size: var(--t-code-sm); line-height: 1.75; color: var(--text); }
.codeblock .tk-k { color: var(--tk-k); } .codeblock .tk-s { color: var(--tk-s); } .codeblock .tk-f { color: var(--tk-f); }
.codeblock .tk-n { color: var(--tk-n); } .codeblock .tk-c { color: var(--tk-c); }
.copyrow { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: 3px 3px 3px var(--space-3); border: var(--border-width) solid var(--border); border-radius: var(--radius); background: var(--code-bg); font-family: var(--font-mono); font-size: var(--t-code-sm); }
.copyrow > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Key-value list ---------- */
.kv { display: grid; grid-template-columns: minmax(140px, 220px) minmax(0, 1fr); align-content: start; margin: 0; }
.kv > dt, .kv > dd { margin: 0; padding: var(--space-2) 0; border-top: var(--border-width) solid var(--border); }
.kv > dt { color: var(--text-3); }
.kv > dd { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); min-width: 0; }
.kv > dt:first-of-type, .kv > dt:first-of-type + dd { border-top: 0; }
@media (max-width: 640px) { .kv { grid-template-columns: minmax(0, 1fr); } .kv > dd { border-top: 0; padding-top: 0; } }

/* ---------- Tabs, breadcrumb (links: the URL is the state) ---------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: var(--border-width) solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: var(--space-2) var(--space-3); color: var(--text-3); font-weight: var(--w-medium); white-space: nowrap; box-shadow: inset 0 -2px 0 transparent; transition: color var(--dur-fast), box-shadow var(--dur-fast); }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a[aria-current='page'] { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.tabs .count { margin-left: 6px; color: var(--text-3); font-family: var(--font-mono); font-size: var(--t-micro); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0; padding: 0; list-style: none; font-size: var(--t-xs); color: var(--text-3); }
.crumbs li + li::before { content: '/'; margin-right: var(--space-2); color: var(--border-control); }
.crumbs a { color: var(--text-3); }
.crumbs [aria-current='page'] { color: var(--text); }

/* ---------- Menu (popover) and tooltip ---------- */
.menu[popover] {
  margin: 0; padding: var(--space-1); min-width: 180px;
  border: var(--border-width) solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  inset: auto; /* components.js places it next to the button that opened it */
}
.menu a, .menu button {
  display: flex; align-items: center; gap: var(--space-2); width: 100%;
  padding: 6px var(--space-2); border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text); font: inherit; font-size: var(--t-small); text-align: left; cursor: pointer;
}
.menu a:hover, .menu button:hover, .menu a:focus-visible, .menu button:focus-visible { background: var(--surface-3); text-decoration: none; outline: none; }
.menu .danger { color: var(--bad); }
.menu hr { margin: var(--space-1) 0; border: 0; border-top: var(--border-width) solid var(--border); }
.menu form { margin: 0; }
.menu label.check { padding: 6px var(--space-2); width: 100%; }
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: 20;
  padding: 3px 8px; border-radius: var(--radius-sm); background: var(--text); color: var(--bg);
  font-family: var(--font-sans); font-size: var(--t-micro); font-weight: var(--w-medium); white-space: nowrap; pointer-events: none;
}

/* ---------- Secret field (R8) ---------- */
.secret { display: grid; gap: var(--space-1); }
.secret .copyrow > span { letter-spacing: 0.08em; color: var(--text-2); }
.secret .help::before { content: '🔒 '; }

/* ---------- Skeleton loading ---------- */
.skeleton { display: block; height: 10px; border-radius: var(--radius-sm); background: var(--surface-3); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* ---------- Sections (R9: flat by default) and cards (real units only) ---------- */
.section { padding: var(--space-5) 0; border-top: var(--border-width) solid var(--border); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.section-head p { color: var(--text-3); font-size: var(--t-xs); }
.card { padding: var(--space-4); border: var(--border-width) solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }

/* Disclosure: a native <details> that folds a block away (Get started's stacks). Rows like a flat list; the chevron turns. */
.disclosure { border-top: var(--border-width) solid var(--border); }
.disclosure:last-of-type { border-bottom: var(--border-width) solid var(--border); }
.disclosure > summary {
  display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) 0;
  font-weight: var(--w-medium); cursor: pointer; list-style: none;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before {
  content: ''; flex-shrink: 0; width: 6px; height: 6px; margin: 0 4px 0 2px;
  border-right: 1.5px solid var(--text-3); border-bottom: 1.5px solid var(--text-3);
  transform: rotate(-45deg); transition: transform var(--dur-fast);
}
.disclosure[open] > summary::before { transform: rotate(45deg); }
.disclosure > summary:hover { color: var(--accent); }
.disclosure > summary small { margin-left: auto; color: var(--text-3); font-size: var(--t-xs); font-weight: var(--w-regular); }
.disclosure > :not(summary) { margin-bottom: var(--space-3); }

/* =================== Table system (DoD D3; partials/table.ejs) =================== */
.table-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.table-tools .spacer { flex: 1; }
.filter-chip { display: inline-flex; align-items: center; gap: 6px; height: var(--control-sm); padding: 0 var(--space-3); border: var(--border-width) solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text-2); font-size: var(--t-xs); white-space: nowrap; }
.filter-chip:hover { border-color: var(--border-control); text-decoration: none; color: var(--text); }
.filter-chip[aria-pressed='true'] { border-color: var(--accent-border); background: var(--accent-bg); color: var(--accent); }
.filter-group { display: inline-flex; align-items: center; gap: var(--space-1); }
.filter-group > span { font-size: var(--t-micro); color: var(--text-3); margin-right: 2px; }
.filter-form { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.filter-form label { display: inline-flex; align-items: center; gap: var(--space-1); }
.filter-form label > span { font-size: var(--t-micro); color: var(--text-3); }
.filter-form .input, .filter-form .select { width: auto; max-width: 100%; height: var(--control-sm); font-size: var(--t-xs); }
.table td.cell-wrap { white-space: normal; min-width: 280px; }

.bulkbar { display: none; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); padding: var(--space-1) var(--space-1) var(--space-1) var(--space-3); border: var(--border-width) solid var(--accent-border); border-radius: var(--radius); background: var(--accent-bg); font-size: var(--t-xs); }
.bulkbar.is-active { display: flex; }
.bulkbar strong { margin-right: auto; font-weight: var(--w-medium); }

.table-wrap { position: relative; /* keeps absolutely positioned cell content (sr-only labels) inside the scroller */ overflow-x: auto; border: var(--border-width) solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--t-xs); font-variant-numeric: tabular-nums; }
.table th {
  height: var(--row-compact); padding: 0 var(--space-3); text-align: left; white-space: nowrap;
  font-size: var(--t-micro); font-weight: var(--w-medium); color: var(--text-3);
  background: var(--surface-2); border-bottom: var(--border-width) solid var(--border);
}
.table th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.table th a:hover { color: var(--text); text-decoration: none; }
.table th[aria-sort='ascending'] a, .table th[aria-sort='descending'] a { color: var(--text); }
.table th .arrow { font-size: 9px; opacity: 0.8; }
.table td { height: var(--row); padding: 0 var(--space-3); border-bottom: var(--border-width) solid var(--border); white-space: nowrap; vertical-align: middle; }
.table.is-compact td { height: var(--row-compact); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color var(--dur-fast); }
.table tbody tr:hover { background: var(--surface-2); }
/* Tints are layered on the surface, so pinned (sticky) cells stay opaque and match their row. */
.table tbody tr.is-selected td { background: linear-gradient(var(--accent-bg), var(--accent-bg)), var(--surface); }
.table .num { text-align: right; }
.table .col-check { width: 36px; padding-right: 0; }
.table .col-actions { width: 44px; text-align: right; }
.table .cell-mono { font-family: var(--font-mono); font-size: var(--t-micro); color: var(--text); }
.table .cell-stack strong { display: block; font-weight: var(--w-medium); color: var(--text); }
.table .cell-stack small { display: block; max-width: 320px; overflow: hidden; text-overflow: ellipsis; color: var(--text-3); font-size: var(--t-micro); } /* a long description is cut, not a wider table (full text in its title) */
/* row.href: the first cell is a link, and its ::after covers the whole cell (td.pin is sticky, so it's the containing block). */
.table .row-link { display: block; color: inherit; text-decoration: none; }
.table .row-link::after { content: ''; position: absolute; inset: 0; }
.table .row-link:hover strong { text-decoration: underline; }
.table tbody tr:has(.row-link) td { height: calc(var(--row) + var(--space-3)); } /* a row you open is a bigger target */
.table .row-link strong { font-size: var(--t-small); }
.table .row-link:focus-visible { outline: none; }
.table .row-link:focus-visible::after { outline: var(--focus-width) solid var(--focus); outline-offset: calc(-1 * var(--focus-width)); }
.table .cell-id { display: inline-flex; align-items: center; gap: 4px; max-width: 160px; }
.table .cell-id code { overflow: hidden; text-overflow: ellipsis; border: 0; background: none; padding: 0; font-size: var(--t-micro); }
.table .cell-id button { padding: 2px 4px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-3); font-size: var(--t-micro); cursor: pointer; }
.table .cell-id button:hover { color: var(--text); background: var(--surface-3); }
.table time { color: var(--text-2); }
/* Narrow screens: scroll sideways with the first data column pinned. */
.table td.pin, .table th.pin { position: sticky; left: 0; z-index: 1; background: inherit; }
.table thead th.pin { background: var(--surface-2); }
.table tbody td.pin { background: var(--surface); }
.table tbody tr:hover td.pin { background: var(--surface-2); }
/* Revoked / disabled rows (R8): dimmed, with the reason. */
.table tr.is-revoked td { color: var(--text-3); }
.table tr.is-revoked td :is(strong, .cell-mono, time) { color: var(--text-3); }
.table tr.is-revoked time { text-decoration: line-through; }
.table .reason { display: block; font-size: var(--t-micro); color: var(--text-3); }
/* CRITICAL security rows (R8): tint, an edge marker and the label. */
.table tr.is-critical td { background: linear-gradient(var(--sev-critical-bg), var(--sev-critical-bg)), var(--surface); }
.table tr.is-critical td:first-child { box-shadow: inset 3px 0 0 var(--sev-critical); }
.table tr.is-critical:hover td { background: linear-gradient(var(--sev-critical-bg), var(--sev-critical-bg)), var(--surface-2); }
.table tr.is-critical .cell-mono { color: var(--sev-critical); font-weight: var(--w-medium); }
/* Hidden columns (column visibility) */
.table [data-col].is-hidden { display: none; }
/* Skeleton rows while loading */
.table tr.is-loading td { color: transparent; }

.table-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); margin-top: var(--space-2); font-size: var(--t-xs); color: var(--text-3); }
.pager { display: inline-flex; align-items: center; gap: var(--space-1); }
.pager a[aria-disabled='true'] { pointer-events: none; opacity: 0.45; }
.per { display: inline-flex; align-items: center; gap: var(--space-1); }
.per a { padding: 2px 6px; border-radius: var(--radius-sm); color: var(--text-3); font-family: var(--font-mono); }
.per a[aria-current='true'] { color: var(--text); background: var(--surface-3); }

/* ---------- Empty state (DoD D6; here as the table's empty row) ---------- */
.empty { display: grid; justify-items: center; gap: var(--space-2); padding: var(--space-7) var(--space-5); text-align: center; }
.empty h3 { font-size: var(--t-ui); }
.empty p { max-width: 42ch; color: var(--text-2); }
.empty .btn { margin-top: var(--space-2); }
.table td.empty-cell { height: auto; padding: 0; white-space: normal; }
.table tbody tr:hover:has(.empty-cell) { background: none; }

/* =================== Overlays and feedback (DoD D5) =================== */
/* Dialogs, confirmations and drawers are native <dialog> (showModal): focus stays inside, Esc closes,
   the page behind is inert. components.js opens them from [data-dialog-open] and returns focus. */
.dialog {
  width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 64px); padding: 0;
  border: var(--border-width) solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: var(--overlay); }
.dialog[open] { animation: dialog-in var(--dur) var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-4) 0; }
.dialog-head h2 { font-size: var(--t-ui); }
.dialog-body { display: grid; gap: var(--space-3); align-content: start; padding: var(--space-3) var(--space-4); color: var(--text-2); }
.dialog-body strong { color: var(--text); font-weight: var(--w-medium); }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-4) var(--space-4); }
.dialog-foot form { margin: 0; display: contents; }
.consequence { padding: var(--space-3); border-radius: var(--radius); background: var(--bad-bg); color: var(--bad); font-size: var(--t-xs); }
.consequence strong { color: inherit; }

.drawer {
  margin: 0 0 0 auto; width: min(440px, 100vw); height: 100vh; max-height: none; padding: 0;
  border: 0; border-left: var(--border-width) solid var(--border); border-radius: 0;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.drawer::backdrop { background: var(--overlay); }
.drawer[open] { display: flex; flex-direction: column; animation: drawer-in var(--dur) var(--ease); }
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } }
.drawer .dialog-body { flex: 1; overflow-y: auto; padding-top: var(--space-4); }
.drawer .dialog-foot { border-top: var(--border-width) solid var(--border); }

/* One-time secret reveal */
.reveal { display: grid; gap: var(--space-2); }
.reveal .copyrow { border-color: var(--warn); background: var(--warn-bg); }
.reveal .copyrow > span { color: var(--text); white-space: normal; word-break: break-all; }

/* Toasts: a polite live region; success leaves after 4 s, errors stay until closed. */
.toasts { position: fixed; right: var(--space-4); bottom: var(--space-4); z-index: 50; display: grid; gap: var(--space-2); width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: var(--space-2); padding: var(--space-3);
  border: var(--border-width) solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); font-size: var(--t-small);
  animation: toast-in var(--dur) var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.toast p { flex: 1; }
.toast .toast-icon { flex-shrink: 0; width: 18px; height: 18px; display: grid; place-items: center; border-radius: 50%; font-size: 11px; font-weight: var(--w-semibold); }
.toast-ok .toast-icon { background: var(--ok-bg); color: var(--ok); }
.toast-bad { border-color: var(--bad); }
.toast-bad .toast-icon { background: var(--bad-bg); color: var(--bad); }
.toast-info .toast-icon { background: var(--surface-3); color: var(--text-2); }
.toast button { flex-shrink: 0; padding: 0 4px; border: 0; background: none; color: var(--text-3); font-size: var(--t-ui); line-height: 1; cursor: pointer; }
.toast button:hover { color: var(--text); }

/* Banners: inline, persistent, page-level state. */
.banner { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4); border: var(--border-width) solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.banner > div { flex: 1; display: grid; gap: 2px; }
.banner strong { font-weight: var(--w-medium); }
.banner p { color: var(--text-2); font-size: var(--t-xs); }
.banner .banner-icon { flex-shrink: 0; font-family: var(--font-mono); font-weight: var(--w-semibold); }
.banner-ok { border-color: var(--ok); background: var(--ok-bg); } .banner-ok .banner-icon { color: var(--ok); }
.banner-info .banner-icon { color: var(--text-2); }
.banner-warn { border-color: var(--warn); background: var(--warn-bg); } .banner-warn .banner-icon { color: var(--warn); }
.banner-bad { border-color: var(--bad); background: var(--bad-bg); } .banner-bad .banner-icon { color: var(--bad); }

/* Empty state as its own block (outside tables). */
.empty-block { border: var(--border-width) dashed var(--border-control); border-radius: var(--radius-lg); }
.empty .empty-doc { font-size: var(--t-xs); }

/* =================== App shell (DoD E1; layout/console.ejs with `shell`) =================== */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
@media (min-width: 961px) { .shell { background: linear-gradient(to right, var(--bg-alt) var(--sidebar), var(--bg) var(--sidebar)); } }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-1);
  padding: var(--space-3) var(--space-2); border-right: var(--border-width) solid var(--border); background: var(--bg-alt);
}
.brand { display: inline-flex; align-items: center; gap: 9px; padding: var(--space-1) var(--space-2) var(--space-3); color: var(--text); font-weight: var(--w-semibold); font-size: 17px; letter-spacing: -0.02em; }
.brand:hover { text-decoration: none; }
.switcher {
  display: flex; align-items: center; gap: var(--space-2); width: 100%; padding: 6px var(--space-2);
  border: var(--border-width) solid var(--border); border-radius: var(--radius); background: var(--surface);
  color: var(--text); font: inherit; font-size: var(--t-small); text-align: left; cursor: pointer;
}
.switcher:hover { border-color: var(--border-control); }
.switcher > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher small { display: block; color: var(--text-3); font-size: var(--t-micro); }
.switcher svg { flex-shrink: 0; color: var(--text-3); }
.nav-label { padding: var(--space-3) var(--space-2) var(--space-1); color: var(--text-3); font-family: var(--font-mono); font-size: var(--t-micro); letter-spacing: 0.06em; text-transform: uppercase; }
.nav-item { display: flex; align-items: center; gap: var(--space-2); padding: 6px var(--space-2); border-radius: var(--radius); color: var(--text-2); font-size: var(--t-small); }
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item[aria-current='page'] { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 var(--border-width) var(--border); font-weight: var(--w-medium); }
.nav-item svg { flex-shrink: 0; color: var(--text-3); }
.nav-item[aria-current='page'] svg { color: var(--accent); }
.nav-item .count { margin-left: auto; color: var(--text-3); font-family: var(--font-mono); font-size: var(--t-micro); }
.nav-item .count.is-alert { color: var(--sev-high); }
.nav { display: grid; gap: 2px; margin-top: var(--space-2); }
.nav-button { width: 100%; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; }
.sidebar-foot { margin-top: auto; padding-top: var(--space-3); border-top: var(--border-width) solid var(--border); display: grid; gap: 2px; }

.shell-main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: var(--space-3);
  height: 52px; padding: 0 var(--space-5); border-bottom: var(--border-width) solid var(--border);
  background: var(--bg);
}
.topbar .search { margin-left: auto; }
.topbar .search .input { min-width: 260px; }
.topbar kbd { position: absolute; right: 8px; padding: 0 5px; border: var(--border-width) solid var(--border); border-radius: var(--radius-sm); color: var(--text-3); font-size: var(--t-micro); pointer-events: none; }
.nav-toggle { display: none; }
.page { width: 100%; max-width: var(--page); margin-inline: auto; /* centred: on a wide screen the spare space splits evenly, not all on the right */ padding: var(--space-5) var(--space-5) var(--space-8); }

@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 40; left: 0; width: min(var(--sidebar), 85vw); box-shadow: var(--shadow-lg); transform: translateX(-100%); transition: transform var(--dur) var(--ease); }
  .shell.is-nav-open .sidebar { transform: none; }
  .shell.is-nav-open::after { content: ''; position: fixed; inset: 0; z-index: 30; background: var(--overlay); }
  .nav-toggle { display: inline-flex; }
  .topbar { padding: 0 var(--space-4); }
  .topbar .search .input { min-width: 0; width: 160px; }
  .page { padding: var(--space-4) var(--space-4) var(--space-7); }
}
@media (max-width: 640px) { .topbar .crumbs, .topbar .env { display: none; } }

/* =================== Full-screen pages (Phase 5 B3; layout/console.ejs without `shell`) =================== */
/* Sign-in, register, password reset, errors: the brand, one form or message, its links, the legal links. */
.screen { display: flex; flex-direction: column; align-items: center; min-height: 100vh; padding: var(--space-7) var(--space-4) var(--space-5); }
.screen > .brand { margin-bottom: var(--space-5); padding: 0; }
.screen { position: relative; }
.screen-theme { position: absolute; top: var(--space-4); right: var(--space-4); }
.screen-card { width: 100%; max-width: 400px; padding: var(--space-6); border: var(--border-width) solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.screen-card > h1 { font-size: var(--t-h3); }
.screen-card > h1 + p { margin-top: var(--space-1); color: var(--text-3); }
.screen-card > form { display: grid; gap: var(--space-4); margin-top: var(--space-5); }
.screen-card > .banner { margin-top: var(--space-4); }
.screen-card .btn { width: 100%; }
.screen-card > .btn, .screen-card > .screen-providers { margin-top: var(--space-5); }
.screen-providers { display: grid; gap: var(--space-2); }
.screen-code { display: block; margin-bottom: var(--space-2); color: var(--text-3); font-family: var(--font-mono); font-size: var(--t-xs); }
.field-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); }
.divider { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-5); color: var(--text-3); font-size: var(--t-xs); }
.divider::before, .divider::after { content: ''; flex: 1; border-top: var(--border-width) solid var(--border); }
.divider + .screen-providers { margin-top: var(--space-4); }
.screen-foot { margin-top: var(--space-4); color: var(--text-2); }
.screen-legal { margin-top: auto; padding-top: var(--space-6); color: var(--text-3); font-size: var(--t-xs); }
.screen-legal a { color: inherit; }
@media (max-width: 480px) { .screen { padding-top: var(--space-5); } .screen-card { padding: var(--space-5) var(--space-4); } }

/* =================== Page patterns (DoD E2) =================== */
/* Page header: title, identifiers in mono, a status line, actions on the right (R6). */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-5); }
.page-header h1 { font-size: 1.5rem; }
.page-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); margin-top: var(--space-2); color: var(--text-3); font-size: var(--t-xs); }
.page-meta code { font-size: var(--t-micro); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.page-header + .tabs { margin-top: calc(-1 * var(--space-2)); margin-bottom: var(--space-5); }

/* At a glance: one strip of numbers, not a card per number (R3, R9). */
.glance { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border: var(--border-width) solid var(--border); border-radius: var(--radius-lg); background: var(--surface); margin-bottom: var(--space-5); }
.glance > a, .glance > div { display: block; padding: var(--space-3) var(--space-4); color: inherit; border-left: var(--border-width) solid var(--border); }
.glance > :first-child { border-left: 0; }
.glance > a:hover { background: var(--surface-2); text-decoration: none; }
.glance span { display: block; color: var(--text-3); font-size: var(--t-micro); }
.glance strong { display: block; margin-top: 2px; font-size: var(--t-h3); font-weight: var(--w-semibold); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.glance small { color: var(--text-3); font-size: var(--t-micro); }
.glance .is-alert strong { color: var(--sev-high); }
@media (max-width: 760px) { .glance > * { border-left: 0; border-top: var(--border-width) solid var(--border); } .glance > :first-child { border-top: 0; } }

/* Needs attention: each row says what's wrong and links to the fix (R4). */
.attention { display: grid; border: var(--border-width) solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.attention > li { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-top: var(--border-width) solid var(--border); }
.attention > li > :first-child { justify-self: start; }
@media (max-width: 640px) { .attention > li { grid-template-columns: minmax(0, 1fr); gap: var(--space-2); } }
.attention > li:first-child { border-top: 0; }
.attention > li > div { min-width: 0; }
.attention strong { display: block; font-weight: var(--w-medium); }
.attention small { color: var(--text-3); font-size: var(--t-xs); }
.attention .is-critical { box-shadow: inset 3px 0 0 var(--sev-critical); background: linear-gradient(var(--sev-critical-bg), var(--sev-critical-bg)), var(--surface); }
ul.attention, ul.feed { margin: 0; padding: 0; list-style: none; }

/* Activity feed: compact event rows (R15: event names in mono, as in the logs). */
.feed > li { display: grid; grid-template-columns: 74px minmax(0, 1fr) auto; align-items: center; gap: var(--space-3); padding: 7px 0; border-top: var(--border-width) solid var(--border); font-size: var(--t-xs); }
.feed > li:first-child { border-top: 0; }
.feed time { color: var(--text-3); font-family: var(--font-mono); font-size: var(--t-micro); }
.feed .ev { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .ev code { border: 0; background: none; padding: 0; color: var(--text); }
.feed .ev span { color: var(--text-3); }
.feed .is-critical code { color: var(--sev-critical); font-weight: var(--w-medium); }

.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: var(--space-6); }
@media (max-width: 1100px) { .split { grid-template-columns: minmax(0, 1fr); } }

/* Settings: sections of fields and toggles, one save per section (E2). */
.settings-section { display: grid; grid-template-columns: minmax(180px, 260px) minmax(0, 1fr); gap: var(--space-5); padding: var(--space-5) 0; border-top: var(--border-width) solid var(--border); }
.settings-section:first-of-type { border-top: 0; padding-top: 0; }
.settings-section > header h2 { font-size: var(--t-ui); }
.settings-section > header p { margin-top: var(--space-1); color: var(--text-3); font-size: var(--t-xs); }
.settings-section form { display: grid; gap: var(--space-3); }
.settings-save { display: flex; justify-content: flex-end; gap: var(--space-2); padding-top: var(--space-2); }
@media (max-width: 760px) { .settings-section { grid-template-columns: minmax(0, 1fr); gap: var(--space-3); } }

/* =================== Security settings (DoD D4, R8) =================== */
/* A setting that protects users looks unlike ordinary configuration: a framed panel, a shield label,
   and saving a weaker value asks first (components.js: form[data-weaken-dialog]). */
.settings-section.is-security > :not(header) { padding: var(--space-4); border: var(--border-width) solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface); box-shadow: inset 3px 0 0 var(--text); }
.security-label { display: inline-flex; align-items: center; gap: 5px; margin-bottom: var(--space-2); padding: 1px 7px 1px 5px; border: var(--border-width) solid var(--border-strong); border-radius: var(--radius-sm); color: var(--text); font-size: var(--t-micro); font-weight: var(--w-medium); }
.weakens { color: var(--warn); font-size: var(--t-micro); font-weight: var(--w-medium); }
