/* components.css — styling for every component emitted by js/ui.js:
   buttons, cards, stat tiles, pills, tables, tabs, modal, drawer, toasts,
   dropzone, JSON view, sparklines, skeletons, empty states, forms, banners,
   menus, checklists, key/value lists, code blocks, progress, timers. */

/* ---- component-level tokens (a11y) ----
   Text-grade warning colour and a form-control border that meet WCAG 1.4.11
   (3:1 non-text) / 1.4.3 (4.5:1 text). --warning stays the dot/border colour;
   --border-strong stays the decorative card/table border. Same theme
   resolution as tokens.css. */
:root {
  --warning-text: #7d5c05;      /* 6.17:1 on --surface */
  --control-border: #6b7684;    /* 4.62:1 on --surface */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --warning-text: var(--warning); /* #c9950b on #161c25 = 6.35:1 */
    --control-border: #5d6e86;      /* 3.29:1 on --surface */
  }
}

:root[data-theme="dark"] {
  --warning-text: var(--warning);
  --control-border: #5d6e86;
}

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 34px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
}

.btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--muted);
}

.btn:disabled {
  opacity: 0.55;
}

.btn.primary {
  background: var(--accent-fill);
  border-color: var(--accent-fill);
  color: var(--accent-text);
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-fill-hover);
  border-color: var(--accent-fill-hover);
}

.btn.danger {
  color: var(--critical);
  border-color: var(--critical);
}

.btn.danger:hover:not(:disabled) {
  background: var(--critical-fill);
  border-color: var(--critical-fill);
  color: #fff;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
}

.btn.ghost:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: transparent;
}

.btn.sm {
  min-height: 28px;
  padding: 0 var(--sp-2);
  font-size: var(--fs-12);
}

.btn.icon-only {
  width: 34px;
  padding: 0;
}

.btn.icon-only.sm {
  width: 28px;
}

.btn.block {
  width: 100%;
}

.btn .spinner {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4) 0;
}

.card-header + .card-body {
  padding-top: var(--sp-3);
}

.card-heading {
  min-width: 0;
}

.card-title {
  font-size: var(--fs-16);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.card-subtitle {
  color: var(--muted);
  font-size: var(--fs-12);
  margin-top: 2px;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.card-body {
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}

.card.flush > .card-body {
  padding: 0;
}

.card-footer {
  border-top: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  color: var(--muted);
  font-size: var(--fs-12);
}

/* ---- stat tiles ---- */
.stat-row {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--sp-4);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "label label"
    "value spark"
    "hint hint";
  gap: var(--sp-1) var(--sp-3);
  min-width: 0;
}

.stat-label {
  grid-area: label;
  color: var(--muted);
  font-size: var(--fs-12);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  grid-area: value;
  font-size: var(--fs-26);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  min-width: 0;
  overflow-wrap: anywhere;
}

.stat-unit {
  font-size: var(--fs-14);
  color: var(--muted);
  font-weight: 500;
}

.stat-spark {
  grid-area: spark;
  align-self: end;
  color: var(--accent);
}

.stat-hint {
  grid-area: hint;
  color: var(--muted);
  font-size: var(--fs-12);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.stat-tile.good .stat-value { color: var(--good); }
.stat-tile.warning .stat-value { color: var(--warning-text); }
.stat-tile.critical .stat-value { color: var(--critical); }
.stat-tile.info .stat-value { color: var(--info); }

/* ---- pills / badges / status dots ---- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px 2px 7px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-12);
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  background: var(--neutral-soft);
  color: var(--text);
  vertical-align: middle;
}

.pill-dot,
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--neutral);
  flex: 0 0 auto;
}

.pill.good { background: var(--good-soft); }
.pill.good .pill-dot { background: var(--good); }
.pill.warning { background: var(--warning-soft); }
.pill.warning .pill-dot { background: var(--warning); }
.pill.critical { background: var(--critical-soft); }
.pill.critical .pill-dot { background: var(--critical); }
.pill.info { background: var(--info-soft); }
.pill.info .pill-dot { background: var(--info); }
.pill.accent { background: var(--accent-soft); }
.pill.accent .pill-dot { background: var(--accent); }
.pill.neutral .pill-dot { background: var(--neutral); }

.status-dot.good { background: var(--good); }
.status-dot.warning { background: var(--warning); }
.status-dot.critical { background: var(--critical); }
.status-dot.info { background: var(--info); }
.status-dot.pulse {
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.badge-count {
  display: inline-flex;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* ---- tables ---- */
.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.card-body > .table-wrap,
.card.flush .table-wrap {
  border: 0;
  border-radius: 0;
}

.card.flush .table-wrap {
  border-radius: 0 0 var(--radius-card) var(--radius-card);
}

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-14);
}

.table th,
.table td {
  padding: 9px var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table.dense th,
.table.dense td {
  padding: 6px var(--sp-3);
  font-size: var(--fs-12);
}

.table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--fs-12);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  z-index: 1;
}

.table th.sortable {
  cursor: pointer;
  user-select: none;
}

.table th.sortable:hover {
  color: var(--text);
}

.table th .th-inner {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.table th .sort-indicator {
  width: 12px;
  height: 12px;
  opacity: 0.35;
}

.table th[aria-sort="ascending"] .sort-indicator,
.table th[aria-sort="descending"] .sort-indicator {
  opacity: 1;
  color: var(--accent);
}

.table th[aria-sort="descending"] .sort-indicator {
  transform: rotate(180deg);
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr.clickable {
  cursor: pointer;
}

.table tbody tr.clickable:hover,
.table tbody tr.clickable:focus-visible {
  background: var(--surface-hover);
  box-shadow: none;
}

.table tbody tr.clickable:focus-visible td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}

.table td.num,
.table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table td.mono {
  font-family: var(--font-mono);
  font-size: var(--fs-12);
}

.table td.actions {
  text-align: right;
  white-space: nowrap;
}

.table td.truncate {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-empty td {
  padding: 0;
  border-bottom: 0;
}

.table-caption {
  padding: var(--sp-2) var(--sp-3);
  color: var(--muted);
  font-size: var(--fs-12);
  border-top: 1px solid var(--border);
}

/* ---- tabs ---- */
.tabs {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-width: 0;
}

.tablist {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
  border-radius: var(--radius-control) var(--radius-control) 0 0;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}

.tab:hover {
  color: var(--text);
  background: var(--surface-2);
}

.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tabpanel {
  min-width: 0;
}

/* ---- modal / drawer ---- */
.modal-backdrop,
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  z-index: 100;
  animation: fade-in 120ms ease;
}

.modal-backdrop {
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  width: min(560px, 100%);
  max-height: calc(100vh - 2 * var(--sp-4));
  display: flex;
  flex-direction: column;
  animation: rise 140ms ease;
}

.modal.sm { width: min(420px, 100%); }
.modal.lg { width: min(860px, 100%); }
.modal.xl { width: min(1200px, 100%); }

.modal-header,
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
}

.modal-header h2,
.drawer-header h2 {
  font-size: var(--fs-16);
}

.modal-body,
.drawer-body {
  padding: var(--sp-4);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-height: 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
}

.drawer-backdrop {
  justify-content: flex-end;
}

.drawer {
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-pop);
  width: min(560px, 100%);
  height: 100%;
  display: flex;
  flex-direction: column;
  animation: slide-in 160ms ease;
}

.drawer.lg { width: min(820px, 100%); }

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes rise {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes slide-in {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---- toasts ---- */
.toast-host {
  position: fixed;
  right: var(--sp-4);
  bottom: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 200;
  max-width: min(420px, calc(100vw - 2 * var(--sp-4)));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--neutral);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  animation: rise 140ms ease;
  overflow-wrap: anywhere;
}

.toast.good { border-left-color: var(--good); }
.toast.warning { border-left-color: var(--warning); }
.toast.critical { border-left-color: var(--critical); }
.toast.info { border-left-color: var(--info); }

.toast-text {
  flex: 1 1 auto;
}

.toast .btn.icon-only {
  margin: -6px -6px -6px 0;
}

/* ---- dropzone ---- */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-card);
  padding: var(--sp-5) var(--sp-4);
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  transition: border-color var(--ease), background var(--ease);
  background: var(--surface-2);
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.dropzone.disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

.dropzone .icon {
  color: var(--accent);
}

.dropzone-label {
  font-weight: 500;
  color: var(--text);
}

.dropzone-hint {
  font-size: var(--fs-12);
}

.dropzone-files {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  width: 100%;
  text-align: left;
}

.dropzone-file {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  font-size: var(--fs-12);
  color: var(--text);
}

/* ---- JSON view ---- */
.json-view {
  font-family: var(--font-mono);
  font-size: var(--fs-12);
  line-height: 1.55;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: var(--sp-2) var(--sp-3);
  overflow: auto;
  max-height: var(--json-max, 480px);
  white-space: pre;
}

.json-view details {
  padding-left: 0;
}

.json-view details > details,
.json-view details > .json-leaf,
.json-view details > .json-more {
  padding-left: 18px;
}

.json-view summary {
  cursor: pointer;
  list-style: none;
  display: inline-block;
  user-select: none;
}

.json-view summary::-webkit-details-marker {
  display: none;
}

.json-view summary::before {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid var(--muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  margin-right: 6px;
  transform: rotate(0deg);
  transition: transform var(--ease);
  vertical-align: 1px;
}

.json-view details[open] > summary::before {
  transform: rotate(90deg);
}

.json-view summary:focus-visible {
  box-shadow: none;
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.json-key { color: var(--json-key); }
.json-string { color: var(--json-string); }
.json-number { color: var(--json-number); }
.json-bool { color: var(--json-bool); }
.json-null { color: var(--json-null); font-style: italic; }
.json-brace { color: var(--muted); }
.json-count { color: var(--faint); margin-left: 6px; }
.json-more { color: var(--faint); font-style: italic; }
.json-view details[open] > summary .json-count,
.json-view details[open] > summary .json-close-inline {
  display: none;
}
.json-view .json-closing {
  padding-left: 0;
}

/* ---- sparklines / bars ---- */
.sparkline {
  display: block;
  width: var(--spark-w, 120px);
  height: var(--spark-h, 32px);
  overflow: visible;
}

.sparkline .spark-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.sparkline .spark-area {
  fill: currentColor;
  opacity: 0.12;
}

.sparkline .spark-dot {
  fill: currentColor;
}

.sparkline .spark-bar {
  fill: currentColor;
  opacity: 0.75;
}

.sparkline .spark-bar.last {
  opacity: 1;
}

.sparkline .spark-empty {
  stroke: var(--border-strong);
  stroke-dasharray: 2 3;
  vector-effect: non-scaling-stroke;
}

/* ---- skeleton ---- */
.skeleton {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.skeleton-line,
.skeleton-block {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--radius-control);
}

.skeleton-line {
  height: 12px;
}

.skeleton-line.short {
  width: 45%;
}

.skeleton-block {
  height: var(--skeleton-h, 80px);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- empty / error states ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-2);
  padding: var(--sp-6) var(--sp-4);
  color: var(--muted);
}

.empty-state .icon {
  color: var(--faint);
}

.empty-state.critical .icon,
.empty-state.critical .empty-title {
  color: var(--critical);
}

.empty-title {
  color: var(--text);
  font-weight: 600;
  font-size: var(--fs-16);
}

.empty-body {
  max-width: 48ch;
}

.empty-action {
  margin-top: var(--sp-2);
  display: flex;
  gap: var(--sp-2);
}

.empty-state.compact {
  padding: var(--sp-4);
}

/* ---- forms ---- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  font-size: var(--fs-12);
  font-weight: 600;
  color: var(--muted);
  display: flex;
  gap: 4px;
}

.field-label .req {
  color: var(--critical);
}

.field-hint {
  font-size: var(--fs-12);
  color: var(--muted);
}

.field-error {
  font-size: var(--fs-12);
  color: var(--critical);
}

.field.invalid .input,
.field.invalid .textarea,
.field.invalid .select {
  border-color: var(--critical);
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-control);
  color: var(--text);
  transition: border-color var(--ease);
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--muted);
}

.input:focus-visible,
.textarea:focus-visible,
.select:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input:disabled,
.textarea:disabled,
.select:disabled {
  opacity: 0.6;
  background: var(--surface-2);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--faint);
}

.textarea {
  resize: vertical;
  min-height: 96px;
  line-height: 1.5;
}

.textarea.mono,
.input.mono {
  font-family: var(--font-mono);
  font-size: var(--fs-12);
}

.textarea.tall {
  min-height: 320px;
}

.select {
  appearance: none;
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.select.sm {
  min-height: 28px;
  padding: 2px 26px 2px 8px;
  font-size: var(--fs-12);
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  user-select: none;
}

.checkbox input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.form-grid {
  display: grid;
  gap: var(--sp-3);
  grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr));
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

@media (max-width: 700px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.form-actions.end {
  justify-content: flex-end;
}

input[type="file"].visually-hidden {
  position: absolute;
}

/* ---- banners ---- */
.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-left-color: var(--neutral);
  border-radius: var(--radius-control);
  background: var(--surface-2);
}

.banner.info { border-left-color: var(--info); background: var(--info-soft); }
.banner.good { border-left-color: var(--good); background: var(--good-soft); }
.banner.warning { border-left-color: var(--warning); background: var(--warning-soft); }
.banner.critical { border-left-color: var(--critical); background: var(--critical-soft); }

.banner .icon {
  margin-top: 1px;
  flex-shrink: 0;
}

.banner.info .icon { color: var(--info); }
.banner.good .icon { color: var(--good); }
.banner.warning .icon { color: var(--warning); }
.banner.critical .icon { color: var(--critical); }

.banner-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.banner-title {
  font-weight: 600;
}

/* ---- spinner ---- */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}

.spinner-row {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--muted);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- key/value ---- */
.kv {
  display: grid;
  grid-template-columns: minmax(120px, max-content) minmax(0, 1fr);
  gap: var(--sp-1) var(--sp-4);
  margin: 0;
}

.kv dt {
  color: var(--muted);
  font-size: var(--fs-12);
  font-weight: 500;
  padding-top: 2px;
}

.kv dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.kv.inline {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
}

.kv.inline > div {
  display: flex;
  gap: var(--sp-1);
  align-items: baseline;
}

/* ---- code block ---- */
.code-block {
  font-family: var(--font-mono);
  font-size: var(--fs-12);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: var(--sp-2) var(--sp-3);
  overflow: auto;
  max-height: var(--code-max, 480px);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.code-block.prose {
  font-family: var(--font-sans);
  font-size: var(--fs-14);
}

code.inline {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
}

/* ---- checklist ---- */
.checklist {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: 6px var(--sp-2);
  border-radius: var(--radius-control);
  background: var(--surface-2);
}

.check-item .icon {
  margin-top: 2px;
}

.check-item.ok .icon { color: var(--good); }
.check-item.fail .icon { color: var(--critical); }
.check-item.unknown .icon { color: var(--muted); }

.check-label {
  flex: 1 1 auto;
  min-width: 0;
}

.check-detail {
  color: var(--muted);
  font-size: var(--fs-12);
}

/* ---- menu (dropdown) ---- */
.menu {
  position: relative;
  display: inline-block;
}

.menu-list {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  padding: var(--sp-1);
  z-index: 90;
  animation: rise 120ms ease;
}

.menu-list.left {
  right: auto;
  left: 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-control);
  text-align: left;
  color: var(--text);
  text-decoration: none;
}

.menu-item:hover {
  background: var(--surface-2);
  text-decoration: none;
}

/* Keyboard focus needs a real indicator: --surface-2 vs the menu surface is
   only ~1.1:1. An inset accent outline is 3.17:1 light / 5.4:1 dark. */
.menu-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  box-shadow: none;
  text-decoration: none;
}

.menu-item.danger {
  color: var(--critical);
}

.menu-item:disabled {
  color: var(--faint);
}

.menu-sep {
  border-top: 1px solid var(--border);
  margin: var(--sp-1) 0;
}

.menu-header {
  padding: 6px 10px;
  color: var(--muted);
  font-size: var(--fs-12);
}

/* ---- progress / timer ---- */
.progress {
  width: 100%;
  height: 6px;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-pill);
  transition: width 160ms ease;
}

.progress.indeterminate .progress-bar {
  width: 30%;
  animation: indeterminate 1.2s ease-in-out infinite;
}

@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

.timer {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: var(--fs-12);
}

/* ---- page header ---- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.page-subtitle {
  color: var(--muted);
  margin-top: 2px;
}

.page-actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

/* ---- misc ---- */
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
}

.article {
  max-width: 76ch;
  line-height: 1.6;
}

.article h3 {
  font-size: var(--fs-20);
  margin-bottom: var(--sp-3);
}

.article p {
  margin-bottom: var(--sp-3);
  white-space: pre-wrap;
}

.link-card {
  color: inherit;
}

.link-card:hover {
  text-decoration: none;
  border-color: var(--accent);
}
