/* =============================================================================
   components.css: shared components (spec B4). Legacy BEM names (.btn, .card,
   .form-input, .data-table …) are restyled here so legacy views pick up the
   new look where it is safe.
   ========================================================================== */
@layer components {

/* ---------------------------------------------------------------- icon */
.icon { width: 1.5rem; height: 1.5rem; flex: none; display: inline-block; vertical-align: middle; fill: none; stroke: currentColor; }
.icon--sm { width: 1.125rem; height: 1.125rem; }

/* ---------------------------------------------------------------- button */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--control-h); padding: 0 1.25rem;
  border: var(--border-w-control) solid transparent; border-radius: var(--radius-button);
  font: inherit; font-size: var(--text-base); font-weight: var(--weight-semibold); line-height: var(--leading-tight);
  text-align: center; text-decoration: none; white-space: normal;
  cursor: pointer; box-shadow: none; transform: none;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  background: var(--color-surface); color: var(--color-action);
  border-color: var(--color-action);
}
.btn .icon, .btn svg { width: 1.25rem; height: 1.25rem; flex: none; }
.btn:hover { transform: none; }
.btn--primary { background: var(--color-action); border-color: var(--color-action); color: var(--color-on-action); box-shadow: var(--shadow-button); }
.btn--primary:hover:not([aria-disabled="true"]):not(:disabled) { background: var(--color-action-hover); border-color: var(--color-action-hover); color: var(--color-on-action); }
.btn--primary:active:not([aria-disabled="true"]):not(:disabled) { background: var(--color-action-active); border-color: var(--color-action-active); }
/* Secondary = a white button with a visible 1.5 px control edge (Pinnat). */
.btn--secondary { background: var(--color-surface); border-color: var(--color-border-control); color: var(--color-text); }
.btn--secondary:hover:not([aria-disabled="true"]):not(:disabled) { background: var(--color-surface-sunken); color: var(--color-text); border-color: var(--color-text-2); }
.btn--quiet, .btn--ghost {
  background: transparent; border-color: transparent; color: var(--color-link);
  text-decoration: underline; text-underline-offset: .18em; padding: 0 var(--space-2);
  min-height: var(--control-h-min);
}
.btn--ghost { text-decoration: none; color: var(--color-text); }
.btn--quiet:hover, .btn--ghost:hover { background: var(--color-surface-sunken); color: var(--color-action-hover); }
.btn--danger { background: var(--color-danger-action); border-color: var(--color-danger-action); color: #fff; }
.btn--danger:hover:not([aria-disabled="true"]):not(:disabled) { background: #8F1C13; border-color: #8F1C13; color: #fff; }
.btn--success, .btn--accent { background: var(--color-action); border-color: var(--color-action); color: var(--color-on-action); }
.btn--warning { background: var(--status-attn-bg); border-color: var(--status-attn-line); color: var(--status-attn-fg); }
.btn--lg { min-height: var(--control-h-lg); padding: 0 1.5rem; font-size: var(--text-base); }
.btn--sm { min-height: var(--control-h-min); padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn--block { display: flex; width: 100%; }
@media (max-width: 35.99rem) {
  .btn--primary.btn--flow, .card--next .btn--primary { min-height: var(--control-h-lg); }
}
.btn:disabled, .btn[aria-disabled="true"] {
  cursor: not-allowed; opacity: 1; box-shadow: none;
  background: var(--color-surface-sunken); border-color: var(--color-border-subtle); color: var(--color-text-muted);
}
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"]::before {
  content: ""; width: 1.1em; height: 1.1em; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .8s linear infinite;
}
.btn.is-loading { color: transparent; }
.btn__reason { display: block; margin-top: var(--space-2); font-size: var(--text-sm); color: var(--color-text-muted); }
@keyframes spin { to { transform: rotate(360deg); } }

.back-link {
  display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: var(--control-h-min); padding-right: var(--space-2);
  color: var(--color-link); font-weight: var(--weight-semibold); text-decoration: underline; text-underline-offset: .18em;
}
.back-link .icon { width: 1.25rem; height: 1.25rem; }

/* ---------------------------------------------------------------- card */
.card {
  position: relative;
  background: var(--color-surface); border: 0;
  border-radius: var(--radius-card); padding: var(--space-5); box-shadow: var(--shadow-card);
}
@media (max-width: 35.99rem) { .card { padding: var(--space-4); } }
.legacy-view .card { padding: 0; box-shadow: var(--shadow-card); }
.card + .card { margin-top: var(--space-4); }
.card__title { margin: 0 0 var(--space-2); font-family: var(--font-heading); font-size: var(--text-md); font-weight: var(--weight-bold); line-height: var(--leading-tight); }
.card__eyebrow {
  display: inline-flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2);
  font-family: var(--font-ui); font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text-2);
}
.card__link { color: inherit; text-decoration: none; }
.card__link::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.card:has(.card__link):hover .card__title { text-decoration: underline; }
.card__link:focus-visible { outline: none; }
.card:has(.card__link:focus-visible) { outline: var(--focus-ring); outline-offset: var(--focus-offset); }
.card--next {
  border-radius: var(--radius-sheet); padding: var(--space-6); box-shadow: var(--shadow-card);
}
.card--next .card__title { font-size: var(--text-lg); font-weight: var(--weight-bold); letter-spacing: -.01em; margin-bottom: var(--space-3); }
@media (max-width: 35.99rem) {
  .card--next { padding: var(--space-5); }
}

/* ---------------------------------------------------------------- status pill */
/* Status tag: a filled tint with 6 px corners, no border and no dashes (never a pill; the class name stays). */
.pill {
  display: inline-flex; align-items: center; gap: .375rem;
  min-height: 1.875rem; padding: .125rem .625rem .125rem .4375rem;
  border-radius: var(--radius-tile); border: 0;
  font-size: var(--text-sm); font-weight: var(--weight-semibold); line-height: 1.2; white-space: nowrap;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.pill__icon { width: 1.125rem; height: 1.125rem; }
.pill--ok        { background: var(--status-ok-bg); color: var(--status-ok-fg); }
.pill--wait      { background: var(--color-surface-sunken); color: var(--status-wait-fg); }
.pill--problem   { background: var(--status-problem-solid); color: #fff; }
.pill--unreached { background: var(--status-unreached-bg); color: var(--status-unreached-fg); }
/* Paper notice (display only, Facade::paperPending): the waiting family, never amber (ENR-17) */
.pill--paper     { background: var(--color-surface-sunken); color: var(--status-wait-fg); }
.pill--none      { background: var(--status-none-bg); color: var(--status-none-fg); }
.pill--attn      { background: var(--status-attn-bg); color: var(--status-attn-fg); }

/* ---------------------------------------------------------------- apartment tile */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(6.75rem, 1fr)); gap: var(--space-2); }
@media (max-width: 35.99rem) { .tiles { grid-template-columns: repeat(auto-fill, minmax(5.75rem, 1fr)); } }
.tile {
  position: relative;
  display: flex; flex-direction: column; justify-content: space-between; gap: .125rem;
  min-width: 6.75rem; min-height: 4.75rem; padding: .375rem .5rem;
  border-radius: var(--radius-tile); border: 2px solid transparent;
  color: var(--color-text); text-decoration: none;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
@media (max-width: 35.99rem) { .tile { min-width: 5.75rem; min-height: 4rem; } }
.tile__number { font-family: var(--font-ui); font-size: var(--text-base); font-weight: var(--weight-semibold); line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile__state { display: flex; align-items: center; gap: .25rem; font-size: var(--text-xs); font-weight: var(--weight-semibold); line-height: 1.15; }
.tile__icon { width: 1rem; height: 1rem; }
/* Two-word states ("Ei tavoitettu", "Tiedot puuttuvat"): the long second word gets the full tile width on its own line instead of running over the border
   (a break inside the word only as the last resort, e.g. with enlarged text). */
.tile--unreached .tile__state, .tile--none .tile__state, .tile--paper .tile__state { display: block; }
.tile--unreached .tile__state, .tile--none .tile__state { overflow-wrap: anywhere; }
.tile--unreached .tile__icon, .tile--none .tile__icon, .tile--paper .tile__icon { display: inline-block; vertical-align: -.2em; margin-right: .25rem; }
.tile__dots { font-size: var(--text-xs); letter-spacing: .1em; line-height: 1; }
.tile__markers { position: absolute; top: .25rem; right: .25rem; display: flex; gap: .125rem; }
.tile__marker .icon { width: 1rem; height: 1rem; }
/* Windows of the drawing: tested = solid Kuusi (white text 9.5:1); waiting = white with a grey ring;
   not reached = white with the amber ring; problem = solid red; no detectors = a grey fill. An outline only means "not tested yet". */
.tile--ok        { background: var(--color-action); border-color: var(--color-action); color: var(--color-on-action); }
.tile--wait      { background: var(--color-surface); border-color: var(--status-wait-line); color: var(--status-wait-fg); }
.tile--paper     { background: var(--color-surface); border-color: var(--status-wait-line); color: var(--status-wait-fg); }
.tile--paper .tile__state { hyphens: manual; overflow-wrap: anywhere; }
.tile--problem   { background: var(--status-problem-solid); border-color: var(--status-problem-solid); color: #fff; }
.tile--unreached { background: var(--color-surface); border: 3px solid var(--status-unreached-line); padding: calc(.375rem - 1px) calc(.5rem - 1px); color: var(--status-unreached-fg); }
.tile--none      { background: var(--draw-none-fill); border-color: var(--draw-none-fill); color: var(--status-none-fg); }
.tile:hover { border-width: 3px; padding: calc(.375rem - 1px) calc(.5rem - 1px); }
.tile:hover .tile__number { text-decoration: underline; }
.tile[aria-current="true"], .tile[aria-current="page"] { outline: 3px solid var(--color-text); outline-offset: 2px; }
/* Phones: tighter padding, and tiles at least 5.75rem wide so the longest state word ("tavoitettu", "puuttuvat":
   75 px at the 15 px floor) fits inside the border: three tiles a row on most phones (324–423 px), four from 424 px. */
@media (max-width: 35.99rem) {
  .tile { padding: .375rem; }
  .tile--unreached, .tile:hover { padding: calc(.375rem - 1px); }
  .tile__state { display: block; font-size: var(--text-xs); }
  .tile__state .tile__icon { display: block; margin-bottom: .125rem; }
  .tile__icon { width: 1rem; height: 1rem; }
}

/* ---------------------------------------------------------------- list rows */
.rows { margin: 0; padding: 0; list-style: none; background: var(--color-surface); border: 0; border-radius: var(--radius-card); box-shadow: var(--shadow-card); overflow: hidden; }
.rows > li + li, .rows > .row + .row { border-top: 1px solid var(--color-border-subtle); }
.row {
  position: relative;
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 3.5rem; padding: var(--space-3) var(--space-4);
  color: var(--color-text); text-decoration: none;
}
a.row:hover, .row--link:hover { background: var(--color-surface-sunken); }
a.row:hover .row__title { text-decoration: underline; }
.row__main { flex: 1 1 auto; min-width: 0; }
.row__title { display: block; font-size: var(--text-base); font-weight: var(--weight-semibold); line-height: var(--leading-tight); overflow-wrap: anywhere; }
.row__meta { display: block; font-size: var(--text-sm); color: var(--color-text-muted); overflow-wrap: anywhere; }
.row__chevron { width: 1.25rem; height: 1.25rem; color: var(--color-text-muted); flex: none; }
.row__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); flex: none; }
.row[aria-selected="true"], .row:has(> .row__check input:checked) { background: var(--color-surface-selected); }
.row__check { display: inline-flex; align-items: center; justify-content: center; min-width: var(--control-h-min); min-height: var(--control-h-min); margin: calc(var(--space-2) * -1) 0; }
.row__check input { width: 1.25rem; height: 1.25rem; accent-color: var(--color-action); }
@media (max-width: 35.99rem) {
  .row--stack { flex-wrap: wrap; }
  .row--stack .row__actions { width: 100%; }
  .row--stack .row__actions .btn { flex: 1 1 auto; }
}

/* ---------------------------------------------------------------- table */
.table, .data-table { width: 100%; border-collapse: collapse; font-size: 1rem; background: var(--color-surface); }
.table th, .data-table th {
  text-align: left; font-size: var(--text-sm); font-weight: var(--weight-semibold);
  text-transform: none; letter-spacing: 0; color: var(--color-text);
  padding: var(--space-3) var(--space-3); border-bottom: 2px solid var(--color-border-subtle); background: var(--color-surface);
}
.table td, .data-table td { padding: var(--space-3); border-bottom: 1px solid var(--color-border-subtle); vertical-align: top; }
.table th button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: .25rem; font-weight: var(--weight-semibold); min-height: var(--control-h-min); }
.table th button:focus-visible { outline: var(--focus-ring); outline-offset: var(--focus-offset); }
.table th[aria-sort="ascending"] button::after { content: "▲"; font-size: .7em; }
.table th[aria-sort="descending"] button::after { content: "▼"; font-size: .7em; }
/* Wrap tables in .table-wrap: below 40rem of wrapper width each row becomes a label/value card.
   (Not a container on .main__inner: layout containment would re-anchor legacy position:fixed modals.) */
.table-wrap { container: table / inline-size; overflow-x: auto; border: 0; border-radius: var(--radius-card); background: var(--color-surface); box-shadow: var(--shadow-card); }
@container table (max-width: 40rem) {
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-subtle); }
  .table td { border: 0; padding: var(--space-1) 0; display: grid; grid-template-columns: minmax(7rem, 40%) 1fr; gap: var(--space-3); }
  .table td[data-label]::before { content: attr(data-label); font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text-muted); }
  .table td:not([data-label]) { display: block; }
}

/* ---------------------------------------------------------------- fields */
.field { margin: 0 0 var(--space-5); max-width: 36rem; }
.field--wide { max-width: none; }
.field__label, .form-label { display: block; margin-bottom: var(--space-1); font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text); }
.field__hint, .form-hint { display: block; margin: 0 0 var(--space-2); font-size: var(--text-sm); color: var(--color-text-muted); }
.input, .field input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), .field select, .field textarea, .form-input {
  display: block; width: 100%; min-height: var(--control-h);
  padding: .625rem .875rem; font: inherit; font-size: var(--text-base); line-height: 1.4;
  color: var(--color-text); background: var(--color-surface);
  border: var(--border-w-control) solid var(--color-border-control); border-radius: var(--radius-control);
  box-shadow: none;
}
.field textarea, textarea.form-input, textarea.input { min-height: 7rem; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus, .form-input:focus {
  border-color: var(--color-focus); box-shadow: inset 0 0 0 1px var(--color-focus); outline: var(--focus-ring); outline-offset: var(--focus-offset);
}
.input::placeholder, .field input::placeholder, .form-input::placeholder { color: var(--color-text-muted); opacity: 1; }
[aria-invalid="true"], .form-input--error { border-color: var(--status-problem-fg) !important; box-shadow: inset 0 0 0 1px var(--status-problem-fg); }
.input:disabled, .field input:disabled, .field select:disabled, .form-input:disabled { background: var(--color-surface-sunken); color: var(--color-text-muted); cursor: not-allowed; }
.input[readonly], .field input[readonly] { background: var(--color-surface-sunken); }
.field__error, .form-error {
  display: flex; align-items: flex-start; gap: var(--space-1); margin-top: var(--space-1);
  font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--status-problem-fg);
}
.field__error .icon { width: 1.125rem; height: 1.125rem; margin-top: .1em; }
.error-summary {
  margin: 0 0 var(--space-5); padding: var(--space-4) var(--space-5);
  border: 1px solid var(--status-problem-fg); box-shadow: inset 0 0 0 1px var(--status-problem-fg); border-radius: var(--radius-card);
  background: var(--status-problem-bg); color: var(--color-text);
}
.error-summary:focus { outline: var(--focus-ring); outline-offset: var(--focus-offset); }
.error-summary__title { margin: 0 0 var(--space-2); font-size: var(--text-md); font-weight: var(--weight-bold); color: var(--status-problem-fg); }
.error-summary ul { margin: 0; padding-left: 1.25rem; }
.error-summary a { color: var(--status-problem-fg); font-weight: var(--weight-semibold); }

/* checkbox / radio choice tiles */
fieldset.choices { border: 0; margin: 0 0 var(--space-5); padding: 0; min-width: 0; }
.choices > legend { padding: 0; margin-bottom: var(--space-2); font-size: var(--text-base); font-weight: var(--weight-semibold); }
.choices__list { display: grid; gap: var(--space-2); }
@media (min-width: 36rem) { .choices__list--row { grid-auto-flow: column; grid-auto-columns: 1fr; } }
.choice {
  position: relative;
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 3.5rem; padding: var(--space-3) var(--space-4);
  border: var(--border-w-control) solid var(--color-border-control); border-radius: var(--radius-control);
  background: var(--color-surface); cursor: pointer; font-weight: var(--weight-semibold);
}
.choice input { width: 1.375rem; height: 1.375rem; flex: none; margin: 0; accent-color: var(--color-action); }
.choice:hover { border-color: var(--color-action); }
.choice:has(input:checked) { border: var(--border-w-strong) solid var(--color-action); padding: calc(var(--space-3) - .5px) calc(var(--space-4) - .5px); background: var(--color-surface-selected); }
.choice:has(input:focus-visible) { outline: var(--focus-ring); outline-offset: var(--focus-offset); }
.choice__hint { display: block; font-weight: var(--weight-regular); font-size: var(--text-sm); color: var(--color-text-muted); }

/* building-type picture tiles (partials/type_tiles.php, ENR-32): 2 × 2 at every
   width, the radio at the top right so the label gets the whole width, a small
   filled drawing that turns Kuusi when picked */
.type-tiles__list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
.type-tile.choice {
  flex-direction: column; align-items: stretch; gap: .5rem; min-height: 0;
  --td-b: var(--draw-ground); --td-r: var(--draw-type-roof); --td-w: var(--draw-wait-fill); --td-g: var(--draw-ground);
}
.type-tile.choice:has(input:checked) { --td-b: var(--color-action); --td-r: var(--color-action-active); --td-w: var(--color-brand-tint); }
.type-tile input { position: absolute; top: var(--space-3); right: var(--space-3); }
.type-tile__art { display: block; width: 4.5rem; height: 2.75rem; max-width: calc(100% - 2rem); }
.type-tile__art .b { fill: var(--td-b); } .type-tile__art .r { fill: var(--td-r); } .type-tile__art .w { fill: var(--td-w); } .type-tile__art .g { fill: var(--td-g); }
.type-tile__label { display: block; min-width: 0; font-size: var(--text-base); font-weight: var(--weight-semibold); line-height: 1.3; overflow-wrap: break-word; hyphens: manual; }
.type-tiles__hint { margin: 0 0 var(--space-3); }

/* "Miten tieto saatiin?" (partials/method_pick.php): compact chips, one row when they fit */
fieldset.method-pick { margin: 0; }
.method-pick > legend { font-size: var(--text-sm); margin-bottom: var(--space-1); }
.method-pick__hint { margin: 0 0 var(--space-2); }
.method-pick:has(input:checked) .method-pick__hint--first { display: none; }
.method-pick__list { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.method-pick .choice { flex: 0 1 auto; min-height: var(--control-h-min); padding: var(--space-2) var(--space-3); gap: var(--space-2); font-size: var(--text-sm); }
.method-pick .choice:has(input:checked) { padding: calc(var(--space-2) - .5px) calc(var(--space-3) - .5px); }
.method-pick .choice input { width: 1.25rem; height: 1.25rem; }
.method-pick.is-attention { outline: 3px solid var(--status-attn-line); outline-offset: 4px; border-radius: var(--radius-control); }
@media (max-width: 35.99rem) { .method-pick .choice { flex: 1 1 100%; } }

/* ---------------------------------------------------------------- inline edit */
.inline-edit { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); max-width: 100%; }
.inline-edit__value {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: var(--control-h-min); padding: 0 var(--space-2); margin-left: calc(var(--space-2) * -1);
  border: 1px solid transparent; border-radius: var(--radius-control); background: none;
  font: inherit; color: var(--color-text); cursor: pointer; text-align: left; overflow-wrap: anywhere;
}
.inline-edit__value .icon { width: 1.125rem; height: 1.125rem; color: var(--color-action); }
.inline-edit__value:hover { border-color: var(--color-border-control); background: var(--color-surface); }
.inline-edit__empty { color: var(--color-text-muted); font-style: italic; }
.inline-edit__form { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); width: 100%; }
.inline-edit__form .input { flex: 1 1 14rem; width: auto; }
.inline-edit__error { width: 100%; }
.inline-edit__saved { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--status-ok-fg); }

/* ---------------------------------------------------------------- toasts */
#toasts {
  position: fixed; z-index: var(--z-toast);
  left: var(--gutter); right: var(--gutter); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--space-3));
  display: flex; flex-direction: column; gap: var(--space-2); align-items: stretch;
  pointer-events: none;
}
@media (min-width: 56.25rem) { #toasts { left: calc(var(--rail-w) + var(--gutter)); right: auto; bottom: var(--space-5); width: min(28rem, calc(100vw - var(--rail-w) - 2 * var(--gutter))); } }
#toasts .toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: var(--space-3);
  min-width: 0; width: auto; max-width: 100%; margin: 0; position: static;
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  background: var(--color-text); color: var(--color-text-inverse);
  border: 0; border-radius: var(--radius-card); box-shadow: var(--shadow-overlay);
  font-size: var(--text-base); line-height: 1.35;
  animation: toast-in var(--dur) var(--ease-out) both;
}
#toasts .toast.is-leaving { animation: toast-out var(--dur-fast) var(--ease-in) both; }
#toasts .toast--error { background: var(--status-problem-solid); }
#toasts .toast__icon { width: 1.375rem; height: 1.375rem; flex: none; margin-top: .05em; }
#toasts .toast__msg { flex: 1 1 auto; min-width: 0; padding-top: .15em; overflow-wrap: anywhere; }
#toasts .toast__action {
  flex: none; min-height: var(--control-h-min); padding: 0 var(--space-3); margin: -.35rem 0;
  border: 2px solid currentColor; border-radius: var(--radius-control); background: transparent; color: inherit;
  font: inherit; font-weight: var(--weight-bold); text-decoration: none; display: inline-flex; align-items: center; cursor: pointer;
}
#toasts .toast__action:hover { background: rgb(255 255 255 / .12); }
#toasts .toast__close {
  flex: none; display: inline-flex; align-items: center; min-height: var(--control-h-min); padding: 0 var(--space-2); margin: -.5rem -.25rem -.5rem 0;
  border: 0; background: none; color: inherit; cursor: pointer; border-radius: var(--radius-control);
  font: inherit; font-size: var(--text-sm); text-decoration: underline; text-underline-offset: .18em;
}
#toasts .toast__close:hover { background: rgb(255 255 255 / .12); }
html:not(.js) .js-only { display: none !important; }
#toasts .toast form { display: contents; }
#toasts :focus-visible { outline-color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes toast-out { to { opacity: 0; } }

/* ---------------------------------------------------------------- banners */
.banner {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border-radius: var(--radius-card); border: 0;
  background: var(--color-surface);
}
.banner:focus { outline: var(--focus-ring); outline-offset: var(--focus-offset); }
.banner__icon { width: 1.5rem; height: 1.5rem; flex: none; margin-top: .1em; }
.banner__body { flex: 1 1 auto; min-width: 0; padding-top: .15em; }
.banner__title { font-weight: var(--weight-bold); }
.banner__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.banner__actions form { display: inline; margin: 0; }
.banner__close {
  flex: none; display: inline-flex; align-items: center; min-height: var(--control-h-min); padding: 0 var(--space-2); margin: -.35rem -.25rem -.35rem 0;
  border: 0; background: none; color: var(--color-text); cursor: pointer; border-radius: var(--radius-control);
  font: inherit; font-size: var(--text-sm); text-decoration: underline; text-underline-offset: .18em;
}
.banner__close:hover { background: var(--color-surface-sunken); color: var(--color-text); }
.banner--done  { background: var(--status-ok-bg); }
.banner--done .banner__icon { color: var(--status-ok-fg); }
.banner--info  { background: var(--color-surface); box-shadow: var(--shadow-card); }
.banner--info .banner__icon { color: var(--status-wait-fg); }
.banner--warn  { background: var(--status-attn-bg); }
.banner--warn .banner__icon { color: var(--status-attn-fg); }
.banner--error { background: var(--status-problem-bg); box-shadow: inset 0 0 0 1.5px var(--status-problem-fg); }
.banner--error .banner__icon { color: var(--status-problem-fg); }

/* ---------------------------------------------------------------- empty state */
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
  padding: var(--space-7) var(--space-4); text-align: center;
}
.empty-state__icon { width: 3rem; height: 3rem; color: var(--color-text-muted); opacity: .7; margin: 0; }
.empty-state__text { margin: 0; max-width: 32rem; font-size: var(--text-md); line-height: var(--leading-tight); }
.empty-state__actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: var(--space-3); margin-top: var(--space-2); }

/* ---------------------------------------------------------------- dialog / sheet */
dialog.dialog, dialog.sheet, dialog.picker {
  border: 0; padding: 0; color: var(--color-text); background: var(--color-surface);
  box-shadow: var(--shadow-overlay);
}
dialog.dialog { width: min(32rem, calc(100vw - 2rem)); border-radius: var(--radius-sheet); margin: auto; } /* the legacy reset zeroes the margin that centres a modal */
dialog::backdrop { background: rgb(16 24 40 / .45); }
dialog[open] { animation: dialog-in var(--dur) var(--ease-out); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px); } }
.dialog__inner { padding: var(--space-5); }
.dialog__head { display: flex; align-items: flex-start; gap: var(--space-3); margin-bottom: var(--space-3); }
.dialog__title { flex: 1 1 auto; margin: 0; font-family: var(--font-heading); font-size: var(--text-lg); font-weight: var(--weight-bold); line-height: var(--leading-tight); }
.dialog__body { margin: 0 0 var(--space-5); }
.dialog__actions { display: flex; flex-wrap: wrap-reverse; justify-content: flex-end; gap: var(--space-3); }
@media (max-width: 35.99rem) { .dialog__actions .btn { flex: 1 1 100%; } }
.dialog__close {
  flex: none; display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: var(--control-h-min); padding: 0 var(--space-2); margin: -.5rem -.5rem 0 0;
  border: 0; border-radius: var(--radius-control); background: none; color: var(--color-text); font: inherit; font-size: var(--text-sm); font-weight: var(--weight-semibold); cursor: pointer;
}
.dialog__close:hover { background: var(--color-surface-sunken); }
.dialog__close .icon { width: 1.25rem; height: 1.25rem; }
dialog.sheet {
  margin: auto 0 0; width: 100%; max-width: 100%; max-height: 90vh; max-height: 90dvh;
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0; overflow: auto;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 56.25rem) {
  dialog.sheet { margin: 0 0 0 auto; width: 28rem; height: 100vh; height: 100dvh; max-height: none; border-radius: var(--radius-sheet) 0 0 var(--radius-sheet); }
}
/* inert fallback when <dialog> is not supported */
.dialog-fallback[open], .dialog-fallback.is-open { display: block; position: fixed; inset: 0; margin: auto; z-index: 90; height: fit-content; }

/* ---------------------------------------------------------------- popover menu */
.menu-pop {
  position: fixed; inset: auto; top: calc(var(--topbar-h) - .25rem); right: var(--gutter); left: auto; bottom: auto; margin: 0;
  width: min(20rem, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100vh - var(--topbar-h) - 1rem); overflow: auto;
  padding: var(--space-2); border: 0; border-radius: var(--radius-card);
  background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-overlay);
}
.menu-pop:not(:popover-open):not(.is-open) { display: none; }
.menu-pop__head { padding: var(--space-2) var(--space-3) var(--space-3); border-bottom: 1px solid var(--color-border-subtle); margin-bottom: var(--space-2); }
.menu-pop__name { display: block; font-weight: var(--weight-bold); overflow-wrap: anywhere; }
.menu-pop__sub { display: block; font-size: var(--text-sm); color: var(--color-text-muted); overflow-wrap: anywhere; }
.menu-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.menu-list__sep { height: 1px; background: var(--color-border-subtle); margin: var(--space-2) 0; }
.menu-item {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  min-height: var(--control-h); padding: var(--space-2) var(--space-3);
  border: 0; border-radius: var(--radius-control); background: none;
  color: var(--color-text); font: inherit; font-weight: var(--weight-semibold); text-align: left; text-decoration: none; cursor: pointer;
}
.menu-item .icon { width: 1.375rem; height: 1.375rem; color: var(--color-text-muted); }
.menu-item:hover { background: var(--color-surface-sunken); }
.menu-item:hover span { text-decoration: underline; }
.menu-item__value { margin-left: auto; font-weight: var(--weight-regular); font-size: var(--text-sm); color: var(--color-text-muted); }
.menu-list form { margin: 0; }

/* ---------------------------------------------------------------- picker */
dialog.picker {
  margin: calc(var(--topbar-h) + .5rem) auto auto; width: min(40rem, calc(100vw - 2rem));
  max-height: min(36rem, calc(100vh - var(--topbar-h) - 2rem)); border-radius: var(--radius-sheet); overflow: hidden;
}
dialog.picker[open] { display: flex; flex-direction: column; }
@media (max-width: 56.24rem) {
  dialog.picker { margin: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
}
.picker__bar { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3); border-bottom: 1px solid var(--color-border-subtle); }
.picker__bar .icon { color: var(--color-text-muted); }
.picker__input { flex: 1 1 auto; min-width: 0; min-height: var(--control-h); border: 0; padding: 0 var(--space-2); font: inherit; font-size: var(--text-md); background: transparent; }
.picker__input:focus { outline: none; }
.picker__bar:focus-within { box-shadow: inset 0 -3px 0 var(--color-focus); }
.picker__list { margin: 0; padding: var(--space-2); list-style: none; overflow-y: auto; flex: 1 1 auto; }
.picker__group { padding: var(--space-3) var(--space-3) var(--space-1); font-size: var(--text-sm); font-weight: var(--weight-bold); color: var(--color-text-muted); }
.picker__option {
  display: flex; flex-direction: column; justify-content: center; min-height: var(--control-h);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-control);
  color: var(--color-text); text-decoration: none; cursor: pointer;
}
.picker__option[aria-selected="true"], .picker__option:hover { background: var(--color-surface-selected); }
.picker__option[aria-selected="true"] { box-shadow: inset 0 0 0 2px var(--color-action); }
.picker__name { font-weight: var(--weight-semibold); }
.picker__sub { font-size: var(--text-sm); color: var(--color-text-muted); }
.picker__empty { padding: var(--space-5) var(--space-3); color: var(--color-text-muted); }
.picker__foot { padding: var(--space-2) var(--space-4); border-top: 1px solid var(--color-border-subtle); font-size: var(--text-xs); color: var(--color-text-muted); }

/* ---------------------------------------------------------------- progress */
.progress-wrap { display: flex; flex-direction: column; gap: var(--space-1); }
.progress__label { font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.progress { position: relative; height: 12px; border-radius: var(--radius-tile); background: var(--color-surface-sunken); border: 0; box-shadow: inset 0 0 0 1px rgb(26 34 37/.08); overflow: hidden; }
.progress__bar { display: block; height: 100%; background: var(--status-ok-line); border-radius: inherit; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.progress--striped .progress__bar { background: repeating-linear-gradient(45deg, var(--status-ok-line) 0 6px, var(--status-ok-fg) 6px 12px); }

/* ---------------------------------------------------------------- tabs (register) */
.tabs { display: flex; gap: var(--space-1); margin: 0 0 var(--space-5); padding: 0; list-style: none; border-bottom: 2px solid var(--color-border-subtle); overflow-x: auto; }
.tabs__link {
  position: relative; display: inline-flex; align-items: center; min-height: var(--control-h); padding: 0 var(--space-4);
  color: var(--color-text-muted); font-weight: var(--weight-semibold); text-decoration: none; white-space: nowrap;
}
.tabs__link:hover { color: var(--color-text); text-decoration: underline; }
.tabs__link[aria-current="page"] { color: var(--color-action-active); }
.tabs__link[aria-current="page"] { color: var(--color-text); }
.tabs__link[aria-current="page"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 3px; border-radius: 2px; background: var(--color-action); }

/* ---------------------------------------------------------------- filter chips */
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0 0 var(--space-4); padding: 0; list-style: none; }
.chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: var(--control-h-min); padding: 0 var(--space-4);
  border: var(--border-w-control) solid var(--color-border-control); border-radius: var(--radius-control);
  background: var(--color-surface); color: var(--color-text); font-weight: var(--weight-semibold); text-decoration: none; cursor: pointer; font: inherit; font-weight: var(--weight-semibold);
}
.chip:hover { border-color: var(--color-action); }
.chip[aria-pressed="true"], .chip[aria-current="true"], .chip[aria-current="page"] { background: var(--color-action); border-color: var(--color-action); color: var(--color-on-action); }
.chip[aria-pressed="true"] .chip__count, .chip[aria-current="true"] .chip__count, .chip[aria-current="page"] .chip__count { color: inherit; }
.chip__count { font-family: var(--font-ui); font-size: var(--text-sm); font-variant-numeric: tabular-nums; color: var(--color-text-muted); font-weight: var(--weight-regular); }

/* ---------------------------------------------------------------- batch bar */
.batchbar {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--space-2)); z-index: 15;
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3);
  margin-top: var(--space-4); padding: var(--space-3) var(--space-4);
  background: var(--color-text); color: var(--color-text-inverse); border-radius: var(--radius-card); box-shadow: var(--shadow-overlay);
}
@media (min-width: 56.25rem) { .batchbar { bottom: var(--space-4); } }
.batchbar[hidden] { display: none; }
.batchbar__count { font-weight: var(--weight-bold); margin-right: auto; }
.batchbar .btn--secondary { background: transparent; color: #fff; border-color: #fff; }
.batchbar .btn--quiet { color: #fff; }

/* ---------------------------------------------------------------- skeleton */
.skeleton { display: block; height: 1rem; border-radius: var(--radius-tile); background: linear-gradient(90deg, var(--color-surface-sunken) 25%, #F7F6F3 50%, var(--color-surface-sunken) 75%); background-size: 200% 100%; animation: skeleton 1.2s ease-in-out infinite; }
@keyframes skeleton { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---------------------------------------------------------------- page header */
.page-header { margin: 0 0 var(--space-5); }
.page-header__eyebrow { display: block; margin-bottom: var(--space-2); font-family: var(--font-ui); font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text-2); }
.page-header__row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--space-3) var(--space-4); }
.page-header__title { flex: 1 1 18rem; margin: 0; font-family: var(--font-display); font-stretch: var(--display-wdth); font-size: var(--text-xl); font-weight: var(--weight-bold); letter-spacing: var(--tracking-display); line-height: var(--leading-display); text-wrap: balance; }
.page-header__title:focus { outline: none; }
.page-header__title:focus-visible { outline: var(--focus-ring); outline-offset: 4px; }
.page-header__lede { margin: var(--space-3) 0 0; font-size: var(--text-lead); line-height: 1.45; color: var(--color-text-2); max-width: var(--measure); }
.page-header__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.page-header .back-link { margin-bottom: var(--space-2); }

/* ---------------------------------------------------------------- misc */
.section { margin-top: var(--space-6); }
.section__title { margin: 0 0 var(--space-3); font-family: var(--font-heading); font-size: var(--text-lg); font-weight: var(--weight-bold); line-height: var(--leading-tight); }
.prose { max-width: var(--measure); }
.prose p + p { margin-top: var(--space-3); }
.muted { color: var(--color-text-muted); }
.kbd, kbd.kbd { font: inherit; font-size: var(--text-xs); border: 1px solid var(--color-border-control); border-radius: var(--radius-tile); padding: 0 .35rem; }

/* ---------------------------------------------------------------- menu segmented (text size) */
.menu-item--form { cursor: default; flex-wrap: wrap; }
.menu-item--form:hover { background: none; }
.menu-item--form:hover span { text-decoration: none; }
.menu-seg { display: inline-flex; margin-left: auto; border: var(--border-w-control) solid var(--color-border-control); border-radius: var(--radius-control); overflow: hidden; }
.menu-seg__btn { min-height: var(--control-h-min); padding: 0 var(--space-3); border: 0; background: var(--color-surface); color: var(--color-text); font: inherit; font-size: var(--text-sm); font-weight: var(--weight-semibold); cursor: pointer; }
.menu-seg__btn + .menu-seg__btn { border-left: 1px solid var(--color-border-control); }
.menu-seg__btn--large { font-size: var(--text-base); }
.menu-seg__btn[aria-pressed="true"] { background: var(--color-surface-selected); color: var(--color-action-active); box-shadow: inset 0 -3px 0 var(--color-action); }
.menu-seg__btn:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- detector test row */
.alarm-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4);
  padding: var(--space-3) 0; border-top: 1px solid var(--color-border-subtle);
}
.alarm-row:first-child { border-top: 0; }
.alarm-row__main { flex: 1 1 14rem; min-width: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.alarm-row__name { font-weight: var(--weight-semibold); overflow-wrap: anywhere; }
.alarm-row__markers { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); }
.alarm-row__markers:empty { display: none; }
.alarm-row__marker { display: inline-flex; align-items: center; gap: .25rem; font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--status-attn-fg); }
.alarm-row__marker .icon { width: 1.125rem; height: 1.125rem; }
.alarm-row__marker--problem { color: var(--status-problem-fg); }
.alarm-row__marker--quiet { color: var(--status-none-fg); }
.alarm-row__result { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); font-size: var(--text-sm); }
.alarm-row--pass .alarm-row__result-text { color: var(--status-ok-fg); font-weight: var(--weight-semibold); }
.alarm-row--fail .alarm-row__result-text { color: var(--status-problem-fg); font-weight: var(--weight-semibold); }
.alarm-row__result--none { color: var(--color-text-muted); }
.alarm-row__void { display: inline; margin: 0; }
.alarm-row__form { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0; }
.alarm-row__btn { min-height: var(--control-h); }
.alarm-row__btn--fail { border-color: var(--status-problem-fg); color: var(--status-problem-fg); }
.alarm-row__btn--fail:hover:not([aria-disabled="true"]):not(:disabled) { background: var(--status-problem-bg); color: var(--status-problem-fg); border-color: var(--status-problem-fg); }
@media (max-width: 35.99rem) {
  .alarm-row__form { width: 100%; }
  .alarm-row__btn { flex: 1 1 0; min-height: var(--control-h-lg); }
}


/* ---------------------------------------------------------------- stepper (talot spec 3.2, partials/stepper.php)
   A −/+ number field: 11 rem wide, the control height, a 1.5 px edge, 12 px
   corners, square buttons with a 2.6 px minus / plus in Kuusi. Without JS the
   buttons are hidden and the field is a plain number field. */
.stepper {
  display: inline-flex; align-items: stretch; width: 11rem; max-width: 100%; min-height: var(--control-h); box-sizing: border-box;
  border: var(--border-w-control) solid var(--color-border-control); border-radius: var(--radius-control);
  background: var(--color-surface); overflow: hidden;
}
.stepper__btn { flex: 0 0 var(--control-h); display: grid; place-items: center; border: 0; padding: 0; background: transparent; color: var(--color-action); cursor: pointer; }
.stepper__btn svg { width: 1.25rem; height: 1.25rem; }
.stepper__btn:hover { background: var(--color-surface-selected); }
.stepper__btn:disabled { color: var(--color-border-control); opacity: .55; cursor: default; background: transparent; }
.stepper__btn:focus-visible { outline: var(--focus-ring); outline-offset: -3px; }
.stepper__input {
  flex: 1 1 auto; min-width: 0; width: 100%; border: 0; padding: 0; text-align: center; background: transparent; color: var(--color-text);
  font: inherit; font-size: var(--text-base); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums;
}
.stepper__input:focus { outline: none; }
.stepper input.stepper__input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) { min-height: 0; height: auto; border: 0; border-radius: 0; box-shadow: none; background: transparent; padding: 0; }
.stepper input.stepper__input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):is(:hover, :focus, :focus-visible) { border: 0; box-shadow: none; outline: none; }
.stepper:focus-within { outline: var(--focus-ring); outline-offset: var(--focus-offset); }
.stepper:has(.stepper__btn:focus-visible) { outline: none; }
.stepper:has([aria-invalid="true"]) { border-color: var(--status-problem-solid); }
html:not(.js) .stepper__btn { display: none; }

/* building groups (talot spec 3.1, partials/building_groups.php): group 1 has
   no box, groups 2–4 are white cards with "Poista"; a used type's tile hides */
.bf-group { margin: 0 0 var(--space-5); padding: 0; border: 0; min-width: 0; }
.bf-group > .field:last-child { margin-bottom: 0; }
.bf-group:focus { outline: none; }
.bf-group--extra { padding: var(--space-5); border-radius: var(--radius-card); background: var(--color-surface); box-shadow: var(--shadow-card); }
/* narrow phones: the card's padding gives the 2 × 2 tiles back their label width (360 px) */
@media (max-width: 24rem) { .bf-group--extra { padding-inline: var(--space-4); } }
.bf-group__head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin: 0 0 var(--space-3); }
.bf-group__title { margin: 0; font-size: var(--text-base); font-weight: var(--weight-semibold); line-height: 1.3; }
.bf-group__remove {
  display: inline-flex; align-items: center; min-height: var(--control-h-min); border: 0; padding: 0 .25rem; background: none;
  color: var(--color-action); font: inherit; font-size: var(--text-base); font-weight: var(--weight-semibold);
  text-decoration: underline; text-underline-offset: .2em; cursor: pointer;
}
.bf-group__remove:focus-visible { outline: var(--focus-ring); outline-offset: var(--focus-offset); border-radius: 4px; }
.bf-group .bf-types { margin: 0 0 var(--space-5); padding: 0; border: 0; min-width: 0; }
.bf-add { margin: 0 0 var(--space-6); }
.bf-add .btn { display: inline-flex; align-items: center; gap: .5rem; }
.bf-add .btn svg { width: 1.125rem; height: 1.125rem; }
.bf-add .field__hint { margin: var(--space-2) 0 0; }
.type-tile[hidden] { display: none; }
html.js [data-su-off] { display: none; }
/* the form's default button (Enter never presses "Poista" or "Lisää") */
.bf-default { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
}
