/* Base: a small reset and the look of plain HTML elements, from tokens only. Replaces Pico.
   Rules here style elements and a few utility classes; components live in components.css.
   No inline styles anywhere: the CSP (deploy/unit.json) has no 'unsafe-inline' for styles. */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
}
img, svg, iframe, video { display: block; max-width: 100%; }
input, button, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* --- type */
h1, h2, h3, h4 { font-weight: var(--weight-semibold); line-height: var(--leading-tight); letter-spacing: -0.01em; overflow-wrap: anywhere; }
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }
h4 { font-size: var(--text-base); }
p, ul, ol, dl, pre, form, fieldset { overflow-wrap: anywhere; }
td { overflow-wrap: break-word; }
small { font-size: var(--text-sm); }
strong, b { font-weight: var(--weight-semibold); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-4) 0; }

a { color: var(--accent-text); text-decoration: none; text-underline-offset: 0.2em; }
a:hover { text-decoration: underline; }

code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.92em; }
code { padding: 0.1em 0.3em; border-radius: var(--radius-sm); background: var(--bg-muted); }
pre {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow: auto;
  line-height: 1.45;
}
pre code { padding: 0; background: none; }

/* --- focus: one ring everywhere, keyboard only */
:focus { outline: 2px solid transparent; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }

/* Windows high contrast and other forced-colors modes drop box-shadow focus rings and repaint
   outlines in a system colour; "outline: 2px solid transparent" (never "none") keeps them visible. */
@media (forced-colors: active) {
  :focus-visible, input:focus, select:focus, textarea:focus, .search:focus-within, .palette-input:focus-within {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }
}

::selection { background: var(--accent-subtle); color: var(--fg); }

/* --- form elements (bare; Input/Select/Field in components.js add the label, hint and error) */
input:not([type="checkbox"], [type="radio"], [type="file"], [type="range"]), select, textarea {
  display: block;
  width: 100%;
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-control);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--fg);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
}
textarea { padding: var(--space-2) var(--space-3); min-height: 6rem; resize: vertical; line-height: var(--leading); }
select {
  appearance: none;
  padding-right: var(--space-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888894' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-2) center;
  background-size: 1rem;
}
input::placeholder, textarea::placeholder { color: var(--fg-subtle); opacity: 1; }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--fg-subtle); }
input:focus-visible, select:focus-visible, textarea:focus-visible,
input:focus, select:focus, textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent);
  outline: 2px solid transparent;
}
[aria-invalid="true"] { border-color: var(--danger) !important; }
[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent) !important; }
input:disabled, select:disabled, textarea:disabled, button:disabled { cursor: not-allowed; opacity: 0.55; }
input[readonly] { background: var(--bg-subtle); }
input[type="file"] { font-size: var(--text-sm); max-width: 100%; }
input[type="file"]::file-selector-button {
  margin-right: var(--space-3);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--fg);
  cursor: pointer;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 1rem; height: 1rem; margin: 0; flex: none; }
fieldset { border: 0; padding: 0; min-width: 0; }
legend { padding: 0; font-weight: var(--weight-medium); margin-bottom: var(--space-2); }
label { cursor: default; }

/* Phones: 16px inputs so iOS does not zoom on focus */
@media (max-width: 719.98px) {
  input:not([type="checkbox"], [type="radio"], [type="file"]), select, textarea { font-size: var(--text-md); min-height: 2.5rem; }
}

/* --- tables: hairlines, no stripes, 40px rows */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { height: var(--row-height-table); padding: var(--space-1) var(--space-3); border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--fg-subtle); white-space: nowrap; }
tbody tr:hover { background: var(--bg-subtle); }
td.num, th.num { text-align: right; white-space: nowrap; }
td.nowrap, th.nowrap { white-space: nowrap; }
.strong { font-weight: var(--weight-semibold); }
.block { display: block; }

/* --- busy: aria-busy on anything shows a spinner, as Pico did */
[aria-busy="true"]::before {
  content: "";
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-right: 0.5em;
  vertical-align: -0.12em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: ds-spin 0.7s linear infinite;
  opacity: 0.7;
}
[aria-busy="true"]:empty::before { margin-right: 0; }
@keyframes ds-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { [aria-busy="true"]::before { animation-duration: 2.4s; } }

/* --- utilities (few, named for what they mean) */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.muted { color: var(--fg-muted); }
.subtle { color: var(--fg-subtle); }
.small { font-size: var(--text-sm); }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.nowrap { white-space: nowrap; }
.error { color: var(--danger-text); }
.stack > * + * { margin-top: var(--space-4); }
.stack-sm > * + * { margin-top: var(--space-2); }
