/*
 * VPS Base design system.
 *
 * 1. Tokens   - every color, space, radius and type size is a CSS variable.
 *               Light is the default; dark applies via prefers-color-scheme
 *               or [data-theme="dark"] (the header toggle). Never hard-code
 *               a color in a component: add or reuse a token.
 * 2. Base     - element defaults, focus ring, reduced motion.
 * 3. Layout   - app shell: left sidebar, mobile sheet, header, main.
 * 4. Components - one block per component; markup lives in
 *               web/templates/components.html. See documentation/design-system.md.
 *
 * Sizes: controls are 36px (--target) and small ones 32px (--target-sm)
 * with a mouse; on touch screens (pointer: coarse) both grow to 44px.
 */

/* 1. Tokens --------------------------------------------------------------- */
:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Type: 15px body, 14px for chrome (nav, buttons, labels) */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 0.9375rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;

  --target: 36px;
  --target-sm: 32px;
  --sidebar-width: 248px;
  --duration: 150ms;

  /* Neutral surfaces: cool slate, one step apart */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f0f2f5;
  --border: #e2e6eb;
  --border-strong: #c9d0d8;
  --text: #0f141a;
  --text-muted: #5b6573;
  --focus: #0d9488;

  /* Brand / primary action: VPS Base teal */
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-text: #ffffff;

  /* Status: always paired with an icon and words */
  --danger: #b42318;
  --danger-bg: #fdecea;
  --danger-border: #f4b8b2;
  --attention: #8a5a00;
  --attention-bg: #fff6db;
  --attention-border: #f0d48a;
  --success: #166534;
  --success-bg: #e7f6ec;
  --success-border: #a6dcb8;
  --info: #1d4ed8;
  --info-bg: #ebf1fe;
  --info-border: #bcccf6;

  --shadow: 0 1px 2px rgb(15 20 26 / 6%), 0 8px 24px rgb(15 20 26 / 8%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f14;
    --surface: #11161c;
    --surface-muted: #19212a;
    --border: #232c36;
    --border-strong: #35414e;
    --text: #e6ebf0;
    --text-muted: #8d99a7;
    --focus: #2dd4bf;
    --primary: #2dd4bf;
    --primary-hover: #5eead4;
    --primary-text: #042f2b;
    --danger: #ff8a7f;
    --danger-bg: #3a1714;
    --danger-border: #6b2a24;
    --attention: #f3c766;
    --attention-bg: #33280e;
    --attention-border: #5e4a17;
    --success: #4ade80;
    --success-bg: #0f2a1a;
    --success-border: #1f5134;
    --info: #8fb0ff;
    --info-bg: #15203a;
    --info-border: #2b3f6b;
    --shadow: 0 1px 2px rgb(0 0 0 / 50%), 0 8px 24px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b0f14;
  --surface: #11161c;
  --surface-muted: #19212a;
  --border: #232c36;
  --border-strong: #35414e;
  --text: #e6ebf0;
  --text-muted: #8d99a7;
  --focus: #2dd4bf;
  --primary: #2dd4bf;
  --primary-hover: #5eead4;
  --primary-text: #042f2b;
  --danger: #ff8a7f;
  --danger-bg: #3a1714;
  --danger-border: #6b2a24;
  --attention: #f3c766;
  --attention-bg: #33280e;
  --attention-border: #5e4a17;
  --success: #4ade80;
  --success-bg: #0f2a1a;
  --success-border: #1f5134;
  --info: #8fb0ff;
  --info-bg: #15203a;
  --info-border: #2b3f6b;
  --shadow: 0 1px 2px rgb(0 0 0 / 50%), 0 8px 24px rgb(0 0 0 / 40%);
  color-scheme: dark;
}

/* Fingers need room: 44px targets on touch screens. */
@media (pointer: coarse) {
  :root { --target: 44px; --target-sm: 44px; }
}

/* 2. Base ----------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--space-3); }
h1 { font-size: var(--text-xl); letter-spacing: -0.01em; }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }
p { margin: 0 0 var(--space-3); }
a { color: var(--primary); }
code, pre { font-family: var(--font-mono); font-size: var(--text-sm); }
/* Long URLs, image names and paths in running text wrap on phones. */
p code, li code, span code { overflow-wrap: anywhere; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute; left: var(--space-2); top: -100px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface); color: var(--text);
  border-radius: var(--radius-sm); z-index: 100;
}
.skip-link:focus { top: var(--space-2); }

.icon { width: 20px; height: 20px; flex: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* 3. Layout --------------------------------------------------------------- */
.shell { min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-width);
  display: flex; flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: var(--space-3);
  z-index: 40;
  transition: transform var(--duration) ease;
}

.sidebar-brand {
  display: flex; align-items: center; gap: var(--space-2);
  min-height: var(--target);
  padding: 0 var(--space-3);
  font-weight: 700;
  color: var(--text); text-decoration: none;
  margin-bottom: var(--space-2);
}
.sidebar-brand .icon { color: var(--primary); }

/* Groups are split by a hairline above their first item (li.nav-group),
   no headings: the lists are short. */
/* Only the links scroll on short screens; brand and health stay put. */
.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; overflow-y: auto; }
.nav-bottom { margin-top: auto; padding-top: var(--space-2); }
.nav-group { border-top: 1px solid var(--border); margin-top: var(--space-2); padding-top: var(--space-2); }
.nav-link {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--target);
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--text-muted); text-decoration: none;
}
.nav-link .icon { width: 18px; height: 18px; }
.nav-link:hover { background: var(--surface-muted); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--surface-muted); color: var(--text); font-weight: 600; }
.nav-link[aria-current="page"] .icon { color: var(--primary); }

/* Sidebar footer: live server health, links to Monitoring. */
.health {
  margin-top: auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-3);
  min-height: var(--target);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border);
  font-size: var(--text-xs); color: var(--text-muted); text-decoration: none;
}
.health:hover { color: var(--text); }
.health-item { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.nav-link[aria-disabled="true"] { opacity: 0.55; pointer-events: none; }
.nav-soon { margin-left: auto; font-size: var(--text-xs); }

.scrim {
  display: none;
  position: fixed; inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 30;
}

.header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-2) var(--space-6);
  margin-left: var(--sidebar-width);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
/* Where you are: server / page. The server name hides on phones. */
.context { list-style: none; display: flex; align-items: center; gap: var(--space-2); margin: 0; padding: 0; min-width: 0; font-size: var(--text-sm); }
.context li { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.context li + li::before { content: "/"; color: var(--border-strong); }
.context-server { color: var(--text-muted); }
.context [aria-current="page"] { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.header .menu-button { display: none; } /* beats .btn's display, declared later */

.main {
  margin-left: var(--sidebar-width);
  padding: var(--space-6);
}
/* Content is centred in the space next to the sidebar, not pinned left. */
.main > * { max-width: 1280px; margin-inline: auto; }

@media (max-width: 767px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow); }
  .shell[data-nav-open="true"] .sidebar { transform: none; }
  .shell[data-nav-open="true"] .scrim { display: block; }
  .header, .main { margin-left: 0; }
  .header { padding: var(--space-2) var(--space-4); }
  .main { padding: var(--space-4); }
  .header .menu-button { display: inline-flex; }
  .context .context-server { display: none; }
  .context li + li::before { content: none; }
}

.stack { display: grid; gap: var(--space-4); }
.stack-tight { display: grid; gap: var(--space-1); } /* a line and its note */
/* Grid and flex children default to min-width: auto, which lets one long
   line (a CLI command, a table) widen the whole page on phones. */
.stack > *, .row > * { min-width: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }

/* 4. Components ----------------------------------------------------------- */

/* Status dot: always next to words (Live, Failed, CPU 12%). */
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-muted); }
.dot-success { background: var(--success); }
.dot-attention { background: var(--attention); }
.dot-danger { background: var(--danger); }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.card > :last-child { margin-bottom: 0; }

/* Button: one .btn-primary per screen (the one clear next action) */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--target); min-width: var(--target);
  padding: 0 var(--space-4);
  font: inherit; font-weight: 600; font-size: var(--text-sm);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none;
  transition: background var(--duration) ease;
}
.btn:hover { background: var(--surface-muted); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn-danger:hover { filter: brightness(1.08); background: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-icon { padding: 0; width: var(--target); }
.btn-sm { min-height: var(--target-sm); min-width: var(--target-sm); padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn-sm.btn-icon { width: var(--target-sm); padding: 0; }
.btn .htmx-indicator { display: none; }
.btn.htmx-request .htmx-indicator { display: inline-block; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* Set by app.js on the button that submitted a form, until the answer. */
.is-busy { pointer-events: none; cursor: progress; }
button.is-busy::before {
  content: ""; flex: none; width: 14px; height: 14px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
button.is-busy > .icon:first-child, button.is-busy .htmx-indicator { display: none; }
.btn-done { border-color: var(--success); }
.btn-done .icon { color: var(--success); }

/* Field: label + input + hint + inline error slot (filled by htmx OOB swap) */
.field { display: grid; gap: var(--space-1); }
.field-label { font-weight: 600; font-size: var(--text-sm); }
.field-hint { color: var(--text-muted); font-size: var(--text-sm); margin: 0; }
.input {
  min-height: var(--target);
  width: 100%;
  padding: 0 var(--space-3);
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
textarea.input { padding: var(--space-3); min-height: 120px; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: var(--text-sm); margin: 0; }
.field-error:empty { display: none; }

/* Alert: inline, persistent message. Variants pair color + icon + words. */
.alert {
  display: flex; gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--info-border);
  background: var(--info-bg); color: var(--text);
}
.alert .icon { color: var(--info); margin-top: 2px; }
.alert-title { font-weight: 600; margin: 0 0 var(--space-1); }
.alert p:last-child { margin-bottom: 0; }
.alert-danger { background: var(--danger-bg); border-color: var(--danger-border); }
.alert-danger .icon { color: var(--danger); }
.alert-attention { background: var(--attention-bg); border-color: var(--attention-border); }
.alert-attention .icon { color: var(--attention); }
.alert-success { background: var(--success-bg); border-color: var(--success-border); }
.alert-success .icon { color: var(--success); }

/* Toast: transient result, stacked in #toasts (aria-live region) */
/* Top right, under the header: at the bottom they'd cover the Save button
   in a card's footer. */
.toasts {
  position: fixed; right: var(--space-4); top: 68px;
  display: grid; gap: var(--space-2);
  width: min(420px, calc(100vw - 2 * var(--space-4)));
  z-index: 60;
  /* The container never blocks taps on the page; only toasts do. */
  pointer-events: none;
}
.toasts > * { pointer-events: auto; }
.toast {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}
.toast p { margin: 0 0 var(--space-1); }
.toast-body { flex: 1; min-width: 0; }
.toast-ref { color: var(--text-muted); font-size: var(--text-xs); font-family: var(--font-mono); }
.toast-danger { border-left-color: var(--danger); }
.toast-danger .icon { color: var(--danger); }
.toast-success { border-left-color: var(--success); }
.toast-success .icon { color: var(--success); }
.toast-attention { border-left-color: var(--attention); }
.toast-attention .icon { color: var(--attention); }
.toast-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }

/* Badge: short status label, e.g. the access-mode badge in the header */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: 28px;
  padding: 0 var(--space-3);
  border-radius: 999px;
  font-size: var(--text-xs); font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-muted); color: var(--text-muted);
  white-space: nowrap;
}
.badge .icon { width: 14px; height: 14px; }
.badge-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success); }
.badge-attention { background: var(--attention-bg); border-color: var(--attention-border); color: var(--attention); }
.badge-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
a.badge { min-height: var(--target); text-decoration: none; }

/* Table: wraps in .table-wrap so wide tables scroll instead of the page.
   position: relative contains absolutely positioned children (e.g. a
   .visually-hidden header label), which would otherwise widen the page. */
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
.table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: var(--text-sm); }
.table th, .table td { text-align: left; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.table th { font-weight: 600; color: var(--text-muted); background: var(--surface-muted); }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* CLI block: "show the command" - every action shows its CLI equivalent */
.cli {
  display: flex; align-items: center; gap: var(--space-2); max-width: 100%; min-width: 0;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding-left: var(--space-3);
}
.cli-label { color: var(--text-muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; }
.cli code { flex: 1; min-width: 0; overflow-x: auto; white-space: pre; padding: var(--space-3) 0; }

/* Empty state: explains what's missing and offers the one next action */
.empty {
  display: grid; justify-items: center; gap: var(--space-2);
  text-align: center;
  padding: var(--space-8) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text-muted);
}
.empty-tile { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg); color: var(--text); }
.empty-tile .icon { width: 20px; height: 20px; }
.empty h2 { color: var(--text); font-size: var(--text-md); margin: var(--space-2) 0 0; }
.empty p { margin: 0; max-width: 46ch; }

/* Skeleton: content-shaped placeholder for meaningful waits */
.skeleton {
  display: block;
  height: 1em;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-muted), var(--border), var(--surface-muted));
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
.skeleton + .skeleton { margin-top: var(--space-2); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Dialog: consequential actions; .dialog-typed requires typing a word */
.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text);
  padding: var(--space-6);
  width: min(480px, calc(100vw - 2 * var(--space-4)));
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgb(0 0 0 / 50%); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-6); }

/* Definition list for key/value details */
.details { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-6); margin: 0; }
.details dt { color: var(--text-muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }

/* Diff: line-by-line comparison (history, file editor) */
.diff { margin: 0; padding: var(--space-3) 0; overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.diff-line { display: block; padding: 0 var(--space-4); white-space: pre; }
.diff-add { background: var(--success-bg); color: var(--success); }
.diff-del { background: var(--danger-bg); color: var(--danger); }
.diff-same { color: var(--text-muted); }

/* Log viewer: untrusted service output, one line per entry, scrolls sideways
   instead of widening the page. */
.log { margin: 0; padding: var(--space-3) 0; max-height: 32rem; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.log-line { display: block; padding: 0 var(--space-4); white-space: pre; }
.log-line time { color: var(--text-muted); }
.log-level { display: inline-block; min-width: 7ch; font-weight: 600; }
.log-error { background: var(--danger-bg); color: var(--danger); }
.log-warning { background: var(--attention-bg); color: var(--attention); }
.log-debug { color: var(--text-muted); }
.log-stderr { background: var(--danger-bg); color: var(--danger); }

/* Security checklist: one card per check, badge before the title. */
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-4); }
.checklist-title { font-size: 1.05rem; margin: 0; }
/* Dashboard "Get started": the same list, with a progress bar; done steps
   shrink to their title. .badge-neutral is the plain badge, named. */
.setup-progress { inline-size: 100%; block-size: 0.5rem; }
.setup-step-done .checklist-title { color: var(--text-muted); font-weight: 500; }
.badge-neutral { background: var(--surface-muted); color: var(--text-muted); }

/* Disk usage: native <meter> (no inline widths under the CSP) and a
   breadcrumb of the folder being measured. */
.meter { inline-size: 8rem; max-inline-size: 100%; block-size: 0.75rem; vertical-align: middle; }
.crumbs { display: flex; flex-wrap: wrap; gap: var(--space-1); list-style: none; margin: 0; padding: 0; }
.crumbs li + li::before { content: "/"; margin-inline-end: var(--space-1); color: var(--text-muted); }
.crumbs a { display: inline-flex; align-items: center; min-block-size: 44px; padding-inline: var(--space-1); }

/* Processes: long command lines are cut in the table (full text on the
   detail page); facts are a two-column list. */
.cmd { display: inline-block; max-inline-size: 28rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.cmd-full { white-space: pre-wrap; word-break: break-all; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); margin: 0; }
.facts dt { color: var(--text-muted); }
.facts dd { margin: 0; min-inline-size: 0; }

/* Compose editor: monospace, no wrapping (YAML indentation matters), and
   policy findings as an icon list. */
.findings { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }
.findings li { display: flex; gap: var(--space-2); align-items: flex-start; color: var(--danger); }
.findings li p { margin: 0; color: var(--text); }
.limits { margin: 0; padding-inline-start: var(--space-5); display: grid; gap: var(--space-1); }

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

/* Error page (rendered by internal/httperr) */
.error-page { max-width: 560px; margin: 10vh auto; padding: var(--space-4); }
.error-ref { color: var(--text-muted); font-family: var(--font-mono); font-size: var(--text-sm); }

/* Steps: visible progress for multi-step flows (setup wizard) */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }
.step { display: flex; align-items: center; gap: var(--space-2); color: var(--text-muted); font-size: var(--text-sm); }
.step-num {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--border); font-weight: 600;
}
.step-num .icon { width: 16px; height: 16px; }
.step-current { color: var(--text); font-weight: 600; }
.step-current .step-num { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.step-done .step-num { background: var(--success-bg); border-color: var(--success-border); color: var(--success); }

/* Radio/checkbox groups */
.choices { border: 0; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.choices legend { margin-bottom: var(--space-2); }

/* Pick list: one choice from a short list of named things (repositories).
   Each row is a full-width radio card; the checked one is outlined. */
.pick-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.pick { display: flex; align-items: center; gap: var(--space-3); min-height: 56px; padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); cursor: pointer; }
.pick:hover { border-color: var(--text-muted); }
.pick:has(input:checked) { border-color: var(--primary); background: var(--surface-muted); box-shadow: inset 0 0 0 1px var(--primary); }
.pick:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.pick input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--primary); }
.pick-body { display: grid; gap: 2px; min-width: 0; }
.pick-title { overflow-wrap: anywhere; }
.pick-meta { color: var(--text-muted); font-size: 0.9rem; }

/* Checkbox with label: the whole row is the 44px target */
.check { display: flex; align-items: flex-start; gap: var(--space-3); min-height: var(--target); cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--primary); }

/* Recovery codes and QR code */
.codes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: var(--space-2); }
.codes code { display: block; padding: var(--space-2) var(--space-3); background: var(--surface-muted); border-radius: var(--radius-sm); text-align: center; letter-spacing: 0.05em; }
.qr { display: block; width: 240px; max-width: 100%; height: auto; background: #fff; padding: var(--space-2); border-radius: var(--radius-md); image-rendering: pixelated; }

/* Auth pages (setup, login): centered single card */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--space-4); }
.auth .card { width: min(440px, 100%); }

/* Charts (inline SVG from the server; see the "chart" component) */
.chart-grid-layout { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); }
.chart-card { margin: 0; }
.chart-card h3 { margin: 0; font-size: var(--text-md); }
.chart-card p { margin: 0; }
.chart { display: block; width: 100%; height: 160px; }
.chart-rule { stroke: var(--border); stroke-width: 1; }
.chart-area { fill: var(--info-bg); }
.chart-line { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; }
.chart-axis { display: flex; justify-content: space-between; gap: var(--space-2); font-size: var(--text-xs); }
summary { padding-block: 12px; cursor: pointer; } /* 44px target */

/* Tabs: links that switch a form or view without JavaScript (a page per
   tab). The current one is marked with aria-current, not only by color. */
.tabs { display: flex; flex-wrap: wrap; gap: var(--space-1); list-style: none; margin: 0; padding: 0; border-bottom: 1px solid var(--border); }
/* One row that scrolls sideways on phones instead of wrapping. */
.tabs-scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
.tabs-scroll .tab { white-space: nowrap; }
.tab { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--space-3); color: var(--text-muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { color: var(--text); font-weight: 600; border-bottom-color: var(--primary); }

/* Narrow inputs for numbers in table rows (limits). */
.input-narrow { inline-size: 7rem; }

/* 5. Design v2 components ------------------------------------------------- *
 * Markup conventions are documented in documentation/design-system.md and
 * shown on /dev/components. No component needs JavaScript to work; app.js
 * only adds keyboard shortcuts (/ to search, arrow keys in comboboxes).     */

/* Keyboard hint chip */
.kbd {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  font: 600 var(--text-xs)/1 var(--font-mono); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg);
}

/* Toolbar: search, filters, one primary action on the right */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-left: auto; }
.search { position: relative; flex: 1 1 240px; min-width: 0; }
.search > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.search .input { padding-left: 36px; padding-right: 44px; }
.search .kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.search .input:focus + .kbd { display: none; }
select.input { padding-right: var(--space-8); }

/* List rows: icon tile, title, one meta line, one trailing action */
.rows { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); min-width: 0; }
/* No overflow: hidden here, or row menus get clipped; round the hover
   background of the first and last rows instead. */
.rows > li:first-child > .row-item { border-top-left-radius: calc(var(--radius-lg) - 1px); border-top-right-radius: calc(var(--radius-lg) - 1px); }
.rows > li:last-child > .row-item { border-bottom-left-radius: calc(var(--radius-lg) - 1px); border-bottom-right-radius: calc(var(--radius-lg) - 1px); }
.rows > li + li { border-top: 1px solid var(--border); }
.row-item { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); min-height: 60px; padding: var(--space-3) var(--space-4); color: inherit; text-decoration: none; }
a.row-item:hover { background: var(--surface-muted); }
a.row-item:focus-visible { outline-offset: -2px; }
.row-tile { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg); color: var(--text); }
.row-tile .icon { width: 18px; height: 18px; }
.row-main { display: grid; gap: 2px; flex: 1 1 12rem; min-width: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-title code { font-size: inherit; }
.row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-3); color: var(--text-muted); font-size: var(--text-sm); }
.row-meta > span { display: inline-flex; align-items: center; gap: 6px; }
.row-meta .icon { width: 14px; height: 14px; }
.row-end { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; flex: none; }
.row-end > .icon { color: var(--text-muted); }

/* Settings card: one decision per card; the footer holds the hint, the
   command and Save. */
.setting { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.setting-body { display: grid; gap: var(--space-4); padding: var(--space-5); }
.setting-body > h2 { margin: 0; font-size: var(--text-lg); }
.setting-desc { margin: calc(-1 * var(--space-3)) 0 0; color: var(--text-muted); }
.setting-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3);
  min-height: 60px; padding: var(--space-2) var(--space-5);
  border-top: 1px solid var(--border); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: var(--bg); color: var(--text-muted); font-size: var(--text-sm);
}
.setting-foot > p { margin: 0; flex: 1 1 14rem; }
.setting-foot > .btn:last-child, .setting-foot > form:last-child { margin-left: auto; }
.setting-danger { border-color: var(--danger-border); }
.setting-danger .setting-foot { background: var(--danger-bg); border-top-color: var(--danger-border); color: var(--text); }

/* "Show command": the CLI equivalent, folded away until asked for */
.show-cli > summary { display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--target); padding: 0; color: var(--text-muted); cursor: pointer; }
.show-cli > summary .icon { width: 16px; height: 16px; }
.show-cli[open] { flex-basis: 100%; order: 9; }
.show-cli[open] > summary { color: var(--text); }

/* Sheet: a dialog docked to the right for add/edit flows; full screen on
   phones. Opens with data-dialog-open like any dialog. */
.sheet {
  inset: 0 0 0 auto; margin: 0;
  width: min(520px, 100vw); height: 100dvh; max-height: none; max-width: 100vw;
  padding: 0; border: 0; border-left: 1px solid var(--border);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.sheet[open] { display: flex; flex-direction: column; }
.sheet::backdrop { background: rgb(0 0 0 / 50%); }
.sheet > form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border); }
.sheet-head h2 { margin: 0; font-size: var(--text-lg); }
.sheet-body { display: grid; align-content: start; gap: var(--space-4); padding: var(--space-5); overflow-y: auto; flex: 1; }
.sheet-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); background: var(--bg); }

/* Segmented control: 2-4 radio options in a pill */
.segmented { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg); }
.segmented label { display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--target); padding: 0 var(--space-4); border-radius: var(--radius-sm); color: var(--text-muted); font-size: var(--text-sm); cursor: pointer; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented label:has(input:checked) { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 1px; }

/* Progress: a multi-step run (deploy). Each step is a <details> holding its
   log; state classes pair an icon with the step's words. */
.progress { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; }
.progress > li + li { border-top: 1px solid var(--border); }
.progress summary, .progress .progress-row { display: flex; align-items: center; gap: var(--space-3); min-height: 52px; padding: 0 var(--space-4); list-style: none; cursor: pointer; }
.progress .progress-row { cursor: default; }
.progress summary::-webkit-details-marker { display: none; }
.progress summary::after { content: ""; width: 8px; height: 8px; border: solid var(--text-muted); border-width: 0 2px 2px 0; transform: rotate(-45deg); margin-left: var(--space-2); transition: transform var(--duration) ease; }
.progress details[open] > summary::after { transform: rotate(45deg); }
.progress-name { font-weight: 600; }
.progress-note { color: var(--text-muted); font-size: var(--text-sm); }
.progress-time { margin-left: auto; color: var(--text-muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.progress .log { border-width: 1px 0 0; border-radius: 0; max-height: 20rem; }
.progress .is-pending { color: var(--text-muted); }
.progress .is-pending .progress-name { font-weight: 400; }
.progress .is-done > .icon, .progress .is-done .progress-state { color: var(--success); }
.progress .is-failed > .icon, .progress .is-failed .progress-state { color: var(--danger); }
.progress .is-waiting > .icon, .progress .is-waiting .progress-state { color: var(--attention); }
.progress .is-running .progress-state { color: var(--primary); }
.progress-state { display: inline-grid; place-items: center; width: 20px; height: 20px; flex: none; }
.progress-state .icon { width: 20px; height: 20px; }
.progress-state .spinner { width: 16px; height: 16px; }

/* Next steps: compact checklist with a count; only the current step gets
   a button, done steps are struck through. */
.count { display: inline-grid; place-items: center; min-width: 32px; height: 22px; padding: 0 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg); color: var(--text-muted); font-size: var(--text-xs); font-weight: 600; font-variant-numeric: tabular-nums; }
.next-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.next-step { display: flex; align-items: center; gap: var(--space-3); min-height: var(--target); padding: 2px var(--space-2); border-radius: var(--radius-md); font-size: var(--text-sm); }
.next-step > .icon { width: 16px; height: 16px; flex: none; color: var(--text-muted); }
.next-step > span { flex: 1; min-width: 0; }
.next-step > span > a { color: var(--text); text-decoration: none; }
.next-step > span > a:hover { text-decoration: underline; }
.next-step > .btn { flex: none; }
.next-step > span > a { display: inline-flex; align-items: center; min-height: var(--target-sm); }
.next-step-done { background: transparent; color: var(--text-muted); }
.next-step-done > span { text-decoration: line-through; }
.next-step-done > .icon { color: var(--success); }
.next-step-current { background: var(--surface-muted); font-weight: 600; }
.next-step-current > .icon { color: var(--primary); }

/* Copyable value inside tables (DNS records) */
.copy-value { display: inline-flex; align-items: center; gap: var(--space-1); font-family: var(--font-mono); font-size: var(--text-sm); overflow-wrap: anywhere; }
.copy-value .btn-icon { min-height: var(--target); }


/* Menu: a <details> popover of links (row actions, "New"). app.js closes
   it on an outside click or Escape. */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + var(--space-1)); z-index: 30;
  min-width: 240px; margin: 0; padding: var(--space-1); list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow);
}
.menu-list a, .menu-list button {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  min-height: var(--target); padding: 0 var(--space-3);
  border: 0; border-radius: var(--radius-sm); background: none;
  font: inherit; font-size: var(--text-sm); color: var(--text); text-decoration: none; cursor: pointer;
}
.menu-list a:hover, .menu-list button:hover { background: var(--surface-muted); }
.menu-list .icon { width: 16px; height: 16px; color: var(--text-muted); }
.menu > summary .icon:last-child { width: 14px; height: 14px; }

/* Overview (mission control): apps grid + a side column */
.toolbar-title { margin: 0; }
.section-label { margin: 0; font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.mission { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: var(--space-6); align-items: start; }
.mission-side { gap: var(--space-4); }
@media (max-width: 1023px) { .mission { grid-template-columns: minmax(0, 1fr); } }
.mission-more { margin-left: auto; font-weight: 500; color: var(--text-muted); }
.mission-more .icon { width: 14px; height: 14px; }
.mission-foot { margin: var(--space-2) 0 0; font-size: var(--text-xs); }

/* auto-fit: one or two apps share the row instead of leaving it empty. */
.app-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-3); }
.app-card {
  display: grid; gap: var(--space-3); min-height: 120px; padding: var(--space-4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  color: inherit; text-decoration: none; transition: border-color var(--duration) ease;
}
.app-card:hover { border-color: var(--border-strong); }
.app-card-head { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.app-card .row-meta { min-width: 0; }
.app-card .row-meta > span { min-width: 0; overflow-wrap: anywhere; }
.status { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; font-size: var(--text-sm); flex: none; }
.first-app { justify-items: start; }
.first-app .rows { width: 100%; }

.gauges { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: grid; gap: var(--space-1); }
.gauge { display: grid; grid-template-columns: 6rem 1fr 3rem; align-items: center; gap: var(--space-3); min-height: 32px; font-size: var(--text-sm); }
.gauge-label { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); }
.gauge-value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.spark { width: 100%; height: 24px; }
.spark .chart-line { stroke-width: 1.5; }

.problem-list, .activity-list { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: grid; gap: var(--space-3); }
.problem { display: flex; gap: var(--space-3); font-size: var(--text-sm); }
.problem > .icon { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.problem p { margin: 0; }
.problem .btn { margin-top: var(--space-2); }
.problem-title { font-weight: 600; }
.problem-danger > .icon { color: var(--danger); }
.problem-attention > .icon { color: var(--attention); }
.problem-info > .icon { color: var(--info); }
.activity-list li { display: grid; grid-template-columns: 8px 1fr; column-gap: var(--space-3); align-items: baseline; font-size: var(--text-sm); }
.activity-list .dot { align-self: center; }
.activity-list time { grid-column: 2; font-size: var(--text-xs); }

/* App context: the sidebar lists the app's sections; the header crumb
   switches apps. */
.nav-back { color: var(--text-muted); }
.nav-heading { margin: var(--space-3) var(--space-3) var(--space-1); font-weight: 700; overflow-wrap: anywhere; }
.nav[aria-label] { flex: 1; }
.menu-left .menu-list { left: 0; right: auto; }
.menu-sep { border-top: 1px solid var(--border); margin-top: var(--space-1); padding-top: var(--space-1); }
.menu-list a[aria-current="page"] { font-weight: 600; }
.menu-list a[aria-current="page"] .icon { color: var(--primary); }
.context-switch { min-height: var(--target); padding: 0 var(--space-2); font-weight: 600; gap: var(--space-1); }
.context-switch .icon { width: 14px; height: 14px; color: var(--text-muted); }
/* On desktop the sidebar has the sections; the tab row is for phones,
   where the sidebar is a sheet. */
.app-tabs { margin-bottom: var(--space-4); }
@media (min-width: 768px) { .app-tabs { display: none; } }

/* Page header: title + one sentence on the left, the primary on the right */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.page-head h2, .page-head h1 { margin: 0 0 var(--space-1); }
.page-head p { margin: 0; }

/* A row opened for editing in place: the form sits under the row. */
.row-edit { padding: var(--space-4); border-top: 1px solid var(--border); background: var(--bg); }
.row-edit-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); }
.row-edit-foot .btn-danger, .row-edit-foot .btn-remove { margin-right: auto; }

/* Destructive menu item: red and last, after a divider */
.menu-list form { margin: 0; }
.menu-list .menu-danger { color: var(--danger); }
.menu-list .menu-danger .icon { color: var(--danger); }

/* Row status tile tints and an aligned middle column */
.row-tile-success { color: var(--success); }
.row-tile-danger { color: var(--danger); }
.row-tile-attention { color: var(--attention); }
.row-col { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-sm); }
.row-col .icon { width: 14px; height: 14px; }
@media (max-width: 767px) { .row-col { display: none; } }

/* Pill: a short label on a row ("Current", "Production") */
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; background: var(--info-bg); color: var(--info); font-size: var(--text-xs); font-weight: 600; }

/* Advanced options folded inside a form */
.advanced { border-top: 1px solid var(--border); padding-top: var(--space-2); }
.advanced > summary { display: inline-flex; align-items: center; min-height: var(--target); color: var(--text-muted); cursor: pointer; font-size: var(--text-sm); }
.advanced[open] > summary { color: var(--text); margin-bottom: var(--space-3); }
/* display: inline-flex drops the native marker; draw one so these read as
   something to open, not as plain text. */
.advanced > summary::before {
  content: ""; flex: none; width: 6px; height: 6px; margin-right: var(--space-2);
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform 0.15s;
}
.advanced[open] > summary::before { transform: rotate(45deg); }

/* Segmented links: pick one of a few views that are their own URLs */
.segmented-links { display: inline-flex; flex-wrap: wrap; gap: 2px; margin: 0; padding: 3px; list-style: none; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg); }
.segmented-links a { display: inline-flex; align-items: center; min-height: var(--target-sm); padding: 0 var(--space-3); border-radius: var(--radius-sm); color: var(--text-muted); font-size: var(--text-sm); text-decoration: none; }
.segmented-links a:hover { color: var(--text); }
.segmented-links a[aria-current="page"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }
.log-tall { max-height: 70vh; }
/* .log-plain: plain text (a command's output) rather than .log-line rows. */
.log-plain { padding-inline: var(--space-4); }
.menu-list button .muted { margin-left: auto; font-size: var(--text-xs); }
.row-title a { color: var(--text); text-decoration: none; }
.row-title a:hover { text-decoration: underline; }

.pill .icon { width: 12px; height: 12px; margin-right: 4px; }
.pill-attention { background: var(--attention-bg); color: var(--attention); }
.section-row { margin-bottom: var(--space-2); }
.pill-danger { background: var(--danger-bg); color: var(--danger); }
.setting-foot-field { flex: 1 1 14rem; }
.setting-foot-field .field-label { font-size: var(--text-xs); }
details.row-edit > summary { cursor: pointer; min-height: var(--target-sm); display: inline-flex; align-items: center; font-size: var(--text-sm); font-weight: 600; }
details.row-edit[open] > summary { margin-bottom: var(--space-2); }
.rows.checklist { display: block; gap: 0; }
.row-meter { width: 120px; } @media (max-width: 767px) { .row-meter { width: 64px; } }
.menu-wide { min-width: 320px; max-width: min(420px, calc(100vw - 32px)); }
.menu-item-body { display: grid; gap: 2px; text-align: left; padding: var(--space-1) 0; }
.menu-item-body .muted { font-size: var(--text-xs); white-space: normal; }
.menu-list button:has(.menu-item-body) { min-height: auto; padding-block: var(--space-2); }
.empty .row { justify-content: center; }

/* Get started (side column): the current step gets room; its button sits
   under its title instead of squeezing it. */
#setup .next-step-current { flex-wrap: wrap; padding: var(--space-3); }
#setup .next-step-current > span { flex: 1 1 100%; }
#setup .next-step-current > .btn { margin-left: calc(16px + var(--space-3)); }
#setup .next-steps { gap: var(--space-1); }

/* 6-digit code (component "otp-cells"): six bordered cells under one
   transparent input. Without JS (no .otp-ready) it's a plain monospace
   input; .otp-free (a recovery code being typed) shows the input again. */
.otp { position: relative; display: flex; inline-size: 100%; max-inline-size: 308px; } /* 6 × 44px cells and their gaps */
.input-otp { font: 600 var(--text-lg)/1 var(--font-mono); letter-spacing: 0.3em; min-height: 52px; }
.otp-cells { display: none; gap: var(--space-2); inline-size: 100%; }
.otp-cells > span {
  display: grid; place-items: center; flex: 1 1 0; min-inline-size: 0; block-size: 52px; /* up to 44px wide, narrower on a small card */
  font: 600 var(--text-xl)/1 var(--font-mono); color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  transition: border-color var(--duration), box-shadow var(--duration);
}
.otp-cells > span:nth-child(4) { margin-inline-start: var(--space-3); } /* 3 + 3, like the app shows it */
.otp-ready:not(.otp-free) .otp-cells { display: flex; }
.otp-ready:not(.otp-free) .input-otp {
  position: absolute; inset: 0; inline-size: 100%; block-size: 100%; min-height: 0; z-index: 1;
  color: transparent; caret-color: transparent; background: transparent; border: 0; outline: 0;
  font-size: 1px; letter-spacing: 0; /* nothing visible, but still the real field */
}
.otp-ready .input-otp::selection { background: transparent; }
.otp-ready.otp-focus .otp-cells > [data-active] { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.otp-ready.otp-focus .otp-cells > [data-active]:empty::after { content: ""; inline-size: 2px; block-size: 1.5rem; background: var(--text); animation: otp-caret 1s steps(1) infinite; }
@keyframes otp-caret { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .otp-cells > span { transition: none; } .otp-cells > span::after { animation: none !important; } }
.otp:has([aria-invalid="true"]) .otp-cells > span { border-color: var(--danger); }
@media (pointer: coarse) { .otp-cells > span { block-size: 56px; } }

/* Jumping to a section (#domains, ?section=x#x) scrolls smoothly and stops
   below the sticky header instead of under it. */
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
[id] { scroll-margin-top: 72px; }

/* Pager: newer and older pages of a long list. */
.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.live-note { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.segmented-links { max-width: 100%; overflow-x: auto; flex-wrap: nowrap; }
.chart-grid-wide { grid-template-columns: 1fr; }

/* App overview: checklist and observability cards in a row; the checklist
   panel is a side sheet with a card per step. */
.sheet > .sheet-inner { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.overview-row { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); align-items: start; }
.card-title-row { justify-content: space-between; margin: 0; font-size: var(--text-md); }
.card-title-row h2 { margin: 0; font-size: var(--text-md); }
.card-link { display: inline-flex; align-items: center; gap: var(--space-1); color: var(--text); text-decoration: none; }
.card-link:hover { text-decoration: underline; }
.card-link .icon { width: 14px; height: 14px; color: var(--text-muted); }
.spark-rows { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.spark-rows a { display: grid; grid-template-columns: minmax(0, 1fr) 5rem auto; align-items: center; gap: var(--space-3); min-height: var(--target); padding: 0 var(--space-2); margin: 0 calc(-1 * var(--space-2)); border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-size: var(--text-sm); }
.spark-rows a:hover { background: var(--bg); }
.spark-name { display: inline-flex; align-items: center; gap: var(--space-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spark-value { color: var(--text-muted); font-variant-numeric: tabular-nums; text-align: right; }
.check-cards { display: grid; gap: var(--space-3); margin: 0; padding: 0; list-style: none; }
.check-card { display: grid; grid-template-columns: auto 1fr; gap: var(--space-3); padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.check-card h3 { margin: 0; font-size: var(--text-md); }
.check-card p { margin: 0; }
.check-card-done { background: var(--success-bg); border-color: transparent; }
.check-card-done h3 { text-decoration: line-through; text-decoration-color: var(--text-muted); }
.check-more > summary { cursor: pointer; width: fit-content; font-size: var(--text-sm); color: var(--text-muted); }
.check-more p { margin-top: var(--space-2); font-size: var(--text-sm); }
.check-card form { margin: 0; }
.pill-success { background: var(--success-bg); color: var(--success); }
.next-step-link { display: inline-flex; align-items: center; gap: var(--space-1); color: inherit; text-decoration: none; }
.next-step-link:hover { text-decoration: underline; }
.next-step-link .icon { width: 14px; height: 14px; }
@media (min-width: 1100px) { .overview-row { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr); } }
.spark-rows a { grid-template-columns: minmax(0, 1fr) minmax(3rem, 4rem) auto; }
.spark-value { white-space: nowrap; }

/* Production card: title and state with the actions on the right, facts
   in columns, how to update it in the footer. */
.prod-card { display: grid; gap: var(--space-4); }
.prod-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
.prod-head h2 { margin: 0; }
.prod-actions form { margin: 0; }
.prod-facts { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); margin: 0; }
.prod-facts dt { margin-bottom: var(--space-1); color: var(--text-muted); font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.prod-facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.prod-facts .icon { width: 14px; height: 14px; vertical-align: -2px; margin-right: 4px; color: var(--text-muted); }
.prod-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); padding-top: var(--space-3); border-top: 1px solid var(--border); }
.prod-foot p { margin: 0; }
.pill .dot { margin-right: 6px; }
.dot-info { background: var(--text-muted); }
/* A check's fix, inset under its row. */
/* minmax(0, …): a long command scrolls instead of widening the page. */
.check-fix { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-2); padding: 0 var(--space-4) var(--space-4) calc(var(--space-4) + 36px + var(--space-3)); }
.check-fix > summary { cursor: pointer; width: fit-content; min-height: var(--target-sm); display: inline-flex; align-items: center; font-size: var(--text-sm); font-weight: 600; }
.check-fix p { margin: 0; }
@media (max-width: 640px) { .check-fix { padding-left: var(--space-4); } }
.check-fix > summary { list-style: none; gap: var(--space-1); }
.check-fix > summary::-webkit-details-marker { display: none; }
.check-fix > summary::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); margin-right: 6px; transition: transform .15s; }
.check-fix[open] > summary::before { transform: rotate(45deg); }
@media (prefers-reduced-motion: reduce) { .check-fix > summary::before { transition: none; } }

/* Code editor: a textarea with a line-number gutter and a status bar,
   like an IDE pane. The gutter shows only once app.js has numbered it. */
.code-editor { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); overflow: hidden; }
.code-editor:has(.code-area:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.code-body { display: flex; min-height: 16rem; }
.code-gutter, .code-area { font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.6; padding: var(--space-3) 0; margin: 0; }
.code-gutter { display: none; flex: none; min-width: 3.5ch; padding-inline: var(--space-3) var(--space-2); overflow: hidden; white-space: pre; text-align: right; color: var(--text-muted); background: var(--bg); border-right: 1px solid var(--border); user-select: none; font-variant-numeric: tabular-nums; }
[data-code-ready] .code-gutter { display: block; }
.code-area { flex: 1; min-width: 0; padding-inline: var(--space-3); border: 0; outline: 0; resize: vertical; white-space: pre; overflow: auto; overflow-wrap: normal; tab-size: 2; background: transparent; color: var(--text); caret-color: var(--primary); }
.code-status { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); padding: var(--space-1) var(--space-3); border-top: 1px solid var(--border); background: var(--bg); color: var(--text-muted); font-size: var(--text-xs); font-family: var(--font-mono); }
.code-help { margin-left: auto; font-family: var(--font-sans, inherit); }
[aria-invalid="true"].code-area { background: var(--danger-bg); }
.error-empty h1 { margin: 0; font-size: var(--text-lg); }

/* Get started on the Overview: one row per step, the next one highlighted. */
.setup-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }
.setup-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: var(--space-3); border-radius: var(--radius-md); }
.setup-row-next { background: var(--surface-muted); }
.setup-mark { display: grid; place-items: center; width: 24px; flex: none; color: var(--text-muted); }
.setup-row-done .setup-mark { color: var(--success); }
.setup-row-next .setup-mark { color: var(--primary); }
.setup-row-done .row-title { color: var(--text-muted); font-weight: 500; }

/* Read-only file view with line numbers, like the code editor. The numbers
   are generated content, so copying the text leaves them out. */
.code-view {
  margin: 0; padding: var(--space-3) 0; overflow: auto; max-height: 32rem;
  background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.6; counter-reset: line;
}
.code-view code { display: block; min-width: max-content; }
.code-line { display: block; padding-right: var(--space-4); white-space: pre; counter-increment: line; }
.code-line::before {
  content: counter(line); display: inline-block; width: 3.5em; padding-right: var(--space-3); margin-right: var(--space-3);
  text-align: right; color: var(--text-muted); border-right: 1px solid var(--border); user-select: none;
}
