/*
 * SmartPeak back office: components and layout.
 * Uses only --sp-* tokens from tokens.css. Mobile-first: 640px (cards -> table,
 * sheet -> dialog) and 900px (tab bar -> side rail). See docs/reference/design-components.md.
 */
@layer tokens, base, layout, components, utilities;
/* Layered, so the bare element rules in tokens.css (a, h1…) never beat a component class. */
@import url("/css/tokens-1462b50fcfac6544a7aac1c000d9e0d9.css") layer(tokens);

@layer base {
  html { scroll-padding-top: calc(var(--sp-topbar-h) + var(--sp-space-6)); }
  @media (max-width: 899px) {
    html { scroll-padding-bottom: calc(var(--sp-tabbar-h) + env(safe-area-inset-bottom) + var(--sp-space-6)); }
  }
  body { min-height: 100dvh; }
  button, input, select, textarea { font: inherit; color: inherit; }
  svg.icon { width: 1.25rem; height: 1.25rem; flex: none; }
  body:has(dialog[open]) { overflow: hidden; }
}

/* ── App shell ─────────────────────────────────────────────────────── */
@layer layout {
  .skip-link {
    position: absolute; left: var(--sp-space-6); top: -100px; z-index: var(--sp-z-toast);
    padding: var(--sp-space-4) var(--sp-space-6); border-radius: var(--sp-radius-pill);
    background: var(--sp-action); color: var(--sp-on-action);
  }
  .skip-link:focus-visible { top: var(--sp-space-4); }

  .shell { min-height: 100dvh; }

  .nav {
    position: fixed; inset: auto 0 0 0; z-index: var(--sp-z-nav);
    background: var(--sp-nav-bg); color: var(--sp-nav-fg);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  .nav :focus-visible { outline-color: var(--sp-focus-on-dark); }
  .nav__link:focus-visible { outline-offset: -4px; }
  .nav__brand, .nav__user { display: none; }
  .nav__list {
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
    margin: 0; padding: 0; list-style: none;
  }
  .nav__link {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: var(--sp-space-1); min-height: var(--sp-tabbar-h);
    color: var(--sp-nav-fg-muted); text-decoration: none;
    font-size: var(--sp-text-2xs); font-weight: var(--sp-weight-medium);
  }
  .nav__link span { overflow-wrap: anywhere; text-align: center; }
  button.nav__link { width: 100%; border: 0; background: none; cursor: pointer; }
  .nav__link[aria-current], .nav__link[data-active] { color: var(--sp-nav-fg); box-shadow: inset 0 3px 0 var(--sp-accent-mark); }
  @media (forced-colors: active) {
    .nav__link[aria-current], .nav__link[data-active] { border-top: 3px solid Highlight; }
  }
  /* A phone shows the entries marked onPhone plus "Meer"; the rest open as a sheet above the bar. */
  @media (max-width: 899px) { .nav__extra { display: none; } }
  .nav-more {
    position: fixed; inset: auto 0 calc(var(--sp-tabbar-h) + env(safe-area-inset-bottom)) 0;
    width: auto; margin: 0; padding: var(--sp-space-4) max(var(--sp-space-4), env(safe-area-inset-right)) var(--sp-space-4) max(var(--sp-space-4), env(safe-area-inset-left));
    border: 0; border-radius: var(--sp-radius-m) var(--sp-radius-m) 0 0;
    background: var(--sp-nav-bg); color: var(--sp-nav-fg);
  }
  .nav-more::backdrop { background: rgb(0 0 0 / 0.35); }
  .nav-more__list { display: grid; gap: var(--sp-space-1); margin: 0; padding: 0; list-style: none; }
  .nav-more__link {
    display: flex; align-items: center; gap: var(--sp-space-5); min-height: var(--sp-hit); padding: 0 var(--sp-space-5);
    border-radius: var(--sp-radius-s); color: var(--sp-nav-fg-muted); text-decoration: none; font-weight: var(--sp-weight-medium);
  }
  .nav-more__link[aria-current] { color: var(--sp-nav-fg); background: var(--sp-nav-active-bg); }
  .nav-more__link:focus-visible { outline-color: var(--sp-focus-on-dark); outline-offset: -3px; }

  .topbar {
    position: sticky; top: 0; z-index: var(--sp-z-sticky);
    display: flex; align-items: center; gap: var(--sp-space-5);
    min-height: var(--sp-topbar-h);
    padding: var(--sp-space-4) max(var(--sp-gutter), env(safe-area-inset-right)) var(--sp-space-4) max(var(--sp-gutter), env(safe-area-inset-left));
    background: color-mix(in srgb, var(--sp-canvas) 92%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--sp-border);
  }
  @media (max-height: 500px) { .topbar { position: static; } }
  .topbar__title { font-size: var(--sp-text-xl); font-stretch: var(--sp-stretch-display); }
  .topbar__actions { margin-left: auto; display: flex; gap: var(--sp-space-4); align-items: center; }

  .main {
    max-width: var(--sp-wrap); margin: 0 auto;
    padding: var(--sp-space-7) max(var(--sp-gutter), env(safe-area-inset-right))
             calc(var(--sp-tabbar-h) + var(--sp-space-9) + env(safe-area-inset-bottom))
             max(var(--sp-gutter), env(safe-area-inset-left));
  }

  @media (min-width: 900px) {
    .shell { display: grid; grid-template-columns: var(--sp-rail-w) minmax(0, 1fr); }
    .nav {
      position: sticky; inset: 0 auto auto 0; height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
      display: flex; flex-direction: column; padding: var(--sp-space-7) var(--sp-space-5);
    }
    .nav__more { display: none; }
    .nav__brand {
      display: flex; align-items: center; gap: var(--sp-space-4);
      padding: 0 var(--sp-space-4) var(--sp-space-8);
      color: var(--sp-nav-fg); text-decoration: none;
      font-weight: var(--sp-weight-bold); font-stretch: var(--sp-stretch-display); font-size: var(--sp-text-lg);
    }
    .nav__brand img { width: 28px; height: 28px; }
    .nav__list { display: flex; flex-direction: column; gap: var(--sp-space-2); }
    .nav__link {
      flex-direction: row; justify-content: flex-start; gap: var(--sp-space-5);
      min-height: var(--sp-hit); padding: 0 var(--sp-space-5); border-radius: var(--sp-radius-s);
      font-size: var(--sp-text-md);
    }
    @media (hover: hover) {
      .nav__link:hover { color: var(--sp-nav-fg); background: var(--sp-nav-active-bg); }
    }
    .nav__link[aria-current] {
      background: var(--sp-nav-active-bg); box-shadow: inset 3px 0 0 var(--sp-accent-mark);
    }
    .nav__link:focus-visible { outline-offset: var(--sp-focus-offset); }
    .nav__user {
      display: flex; flex-direction: column; gap: var(--sp-space-4); margin-top: auto;
      padding: var(--sp-space-6) var(--sp-space-4) 0; border-top: 1px solid var(--sp-nav-active-bg);
      color: var(--sp-nav-fg-muted); font-size: var(--sp-text-sm);
    }
    .nav__dev { color: var(--sp-nav-fg-muted); }
    .main { padding-bottom: var(--sp-space-11); }
    /* The rail carries brand, title context and logout on wide screens. */
    .topbar { display: none; }
  }

  .page-head { display: flex; flex-wrap: wrap; align-items: end; gap: var(--sp-space-5); margin-bottom: var(--sp-space-8); }
  .page-head h1 { font-size: var(--sp-text-2xl); font-stretch: var(--sp-stretch-display); }
  .page-head p { margin: var(--sp-space-3) 0 0; color: var(--sp-text-muted); }
  .page-head__actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: var(--sp-space-4); }

  .stack { display: grid; gap: var(--sp-space-8); }
  /* auto-fill, not auto-fit: two fields keep their column width instead of each taking half the page.
     The row gap is the gap of a form, so wrapped rows and separate grids have the same rhythm. */
  .grid-auto { display: grid; gap: var(--sp-space-7) var(--sp-space-6); grid-template-columns: repeat(auto-fill, minmax(min(15rem, 100%), 1fr)); align-items: start; }
  .grid-auto > .field--full { grid-column: 1 / -1; }
  /* Two fields that belong together (gepland | gedaan): side by side down to a narrow phone. */
  .pair { display: grid; gap: var(--sp-space-5); grid-template-columns: repeat(auto-fit, minmax(min(9rem, 100%), 1fr)); align-items: start; }
  /* In a grid the gap spaces the parts; the browser's own margins on a paragraph or list would come
     on top of it and make the spacing uneven between cards. */
  :is(.stack, .stack-tight, .block, .form, .fieldset, .choices) > :is(p, ul, ol) { margin: 0; }
}

@layer components {
  /* ── Buttons (pill, like the site) ───────────────────────────────── */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-space-4);
    min-height: var(--sp-control-h); padding: 0 var(--sp-space-7);
    border: 1px solid transparent; border-radius: var(--sp-radius-pill);
    font-weight: var(--sp-weight-semibold); font-size: var(--sp-text-md);
    text-decoration: none; cursor: pointer; text-align: center; padding-block: var(--sp-space-2);
    transition: background-color var(--sp-dur) var(--sp-ease-out), transform var(--sp-dur-fast) var(--sp-ease-out);
    position: relative;
  }
  /* Fine pointers get 36px buttons; this keeps a 44px hit area around them. */
  .btn::after { content: ""; position: absolute; inset: 50% 50%; min-width: var(--sp-hit); min-height: var(--sp-hit); transform: translate(-50%, -50%); }
  @media (pointer: coarse) { .btn::after { display: none; } }
  .btn:active { transform: scale(var(--sp-press-scale)); }
  .btn--primary { background: var(--sp-action); color: var(--sp-on-action); }
  .btn--primary:hover { background: var(--sp-action-hover); }
  .btn--accent { background: var(--sp-accent); color: var(--sp-on-accent); }
  .btn--accent:hover { background: var(--sp-accent-hover); }
  .btn--secondary { background: var(--sp-surface); color: var(--sp-text); border-color: var(--sp-border-strong); }
  .btn--secondary:hover { border-color: var(--sp-border-ink); }
  .btn--ghost { background: transparent; color: inherit; }
  .btn--ghost:hover { background: var(--sp-surface-hover); }
  .btn--danger { background: var(--sp-danger); color: var(--sp-on-danger); }
  .btn--icon { padding: 0; width: var(--sp-control-h); }
  .btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
  .nav .btn--ghost:hover { background: var(--sp-nav-active-bg); }

  /* ── Card ────────────────────────────────────────────────────────── */
  .card {
    background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: var(--sp-radius-m);
    padding: var(--sp-space-7); box-shadow: var(--sp-shadow-1);
  }
  .card > h2 { font-size: var(--sp-text-lg); margin-bottom: var(--sp-space-5); }
  /* A card that is a grid spaces its title with the gap, not with a margin on top of it. */
  .card:is(.stack, .stack-tight, .block, .form) > h2 { margin-bottom: 0; }

  /* ── Blocks: cards side by side, each with a title and at most one action ── */
  .blocks { display: grid; gap: var(--sp-space-6); grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr)); align-items: start; }
  .block { display: grid; gap: var(--sp-space-6); align-content: start; min-width: 0; container-type: inline-size; }
  .block--wide { grid-column: 1 / -1; }
  .block__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--sp-space-3) var(--sp-space-5); }
  .block__head h2 { font-size: var(--sp-text-lg); margin: 0; }
  .block__action { position: relative; display: inline-flex; align-items: center; min-height: var(--sp-control-h); font-size: var(--sp-text-sm); font-weight: var(--sp-weight-medium); }
  .block__action::after { content: ""; position: absolute; inset: 50% 50%; min-width: var(--sp-hit); min-height: var(--sp-hit); transform: translate(-50%, -50%); }
  @media (pointer: coarse) { .block__action::after { display: none; } }
  .section-title { font-size: var(--sp-text-xl); margin-bottom: var(--sp-space-5); }

  /* ── Board: projects per phase, from 900 px; under it the list stays ── */
  .view-switch { display: none; }
  .board { display: none; }
  @media (min-width: 900px) {
    .view-switch { display: inline-flex; gap: var(--sp-space-2); padding: var(--sp-space-2); border: 1px solid var(--sp-border); border-radius: var(--sp-radius-pill); }
    .view-switch__item {
      display: inline-flex; align-items: center; min-height: var(--sp-hit); padding: 0 var(--sp-space-6);
      border-radius: var(--sp-radius-pill); color: var(--sp-text); text-decoration: none; font-weight: var(--sp-weight-medium);
    }
    .view-switch__item[aria-current="page"] { background: var(--sp-action); color: var(--sp-on-action); }
    .results--board .results__list { display: none; }
    .board {
      display: grid; grid-auto-flow: column; grid-auto-columns: minmax(15rem, 1fr); gap: var(--sp-space-5);
      overflow-x: auto; padding-bottom: var(--sp-space-5); align-items: start;
    }
    .board:focus-visible { outline: var(--sp-focus-width) solid var(--sp-focus); outline-offset: var(--sp-focus-offset); }
  }
  .board__column { background: var(--sp-surface-sunken); border-radius: var(--sp-radius-m); padding: var(--sp-space-5); min-width: 0; border-top: 4px solid var(--column-accent, var(--sp-border-strong)); }
  .board__column[data-phase="nieuw"] { --column-accent: var(--sp-phase-nieuw-dot); }
  .board__column[data-phase="bezoek"] { --column-accent: var(--sp-phase-bezoek-dot); }
  .board__column[data-phase="offerte"] { --column-accent: var(--sp-phase-offerte-dot); }
  .board__column[data-phase="uitvoering"] { --column-accent: var(--sp-phase-uitvoering-dot); }
  .board__column[data-phase="afgesloten"] { --column-accent: var(--sp-phase-afgesloten-dot); }
  .board__title { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-space-3); font-size: var(--sp-text-md); margin: 0 0 var(--sp-space-5); }
  .board__count { font-size: var(--sp-text-sm); color: var(--sp-text-muted); font-weight: var(--sp-weight-medium); }
  .board__empty { margin: 0; font-size: var(--sp-text-sm); }
  .board__cards { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-space-4); }
  .board-card {
    position: relative; display: grid; gap: var(--sp-space-3); background: var(--sp-surface); border: 1px solid var(--sp-border);
    border-radius: var(--sp-radius-s); padding: var(--sp-space-5); box-shadow: var(--sp-shadow-1); font-size: var(--sp-text-sm); min-width: 0;
  }
  .board-card__title { font-size: var(--sp-text-sm); margin: 0; overflow-wrap: anywhere; }
  .board-card__title .row-link { color: var(--sp-text); font-weight: var(--sp-weight-semibold); }
  .board-card__meta { margin: 0; color: var(--sp-text-muted); display: flex; flex-wrap: wrap; gap: 0 var(--sp-space-4); }
  .board-card__next { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-space-3); }
  .board-card__menu > summary { display: inline-flex; align-items: center; min-height: var(--sp-hit); cursor: pointer; color: var(--sp-link); font-weight: var(--sp-weight-medium); }
  .board-card__menu[open] { display: grid; gap: var(--sp-space-4); }
  .board-card__menu a { display: inline-flex; align-items: center; min-height: var(--sp-hit); }

  .warning-chips { list-style: none; margin: var(--sp-space-3) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--sp-space-3); }
  .warning-chips .chip { position: relative; text-decoration: none; font-size: var(--sp-text-xs); }
  .warning-chips .chip::before { display: none; }
  .warning-chips .chip .icon { width: 1em; height: 1em; }
  .attention-item { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-space-3) var(--sp-space-4); }
  .attention-item .icon { color: var(--sp-warning); }
  .attention-item a { display: inline-flex; align-items: center; min-height: var(--sp-hit); }

  /* ── Phase / status chip ─────────────────────────────────────────── */
  .chip {
    display: inline-flex; align-items: center; gap: var(--sp-space-3);
    padding: var(--sp-space-2) var(--sp-space-5); border-radius: var(--sp-radius-pill);
    max-width: 100%; font-size: var(--sp-text-xs); line-height: var(--sp-leading-snug);
    background: var(--chip-bg); color: var(--chip-fg);
  }
  .chip::before { content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--chip-dot); }
  .chip strong { font-weight: var(--sp-weight-semibold); }
  .chip[data-phase="nieuw"]      { --chip-bg: var(--sp-phase-nieuw-bg); --chip-fg: var(--sp-phase-nieuw-fg); --chip-dot: var(--sp-phase-nieuw-dot); }
  .chip[data-phase="bezoek"]     { --chip-bg: var(--sp-phase-bezoek-bg); --chip-fg: var(--sp-phase-bezoek-fg); --chip-dot: var(--sp-phase-bezoek-dot); }
  .chip[data-phase="offerte"]    { --chip-bg: var(--sp-phase-offerte-bg); --chip-fg: var(--sp-phase-offerte-fg); --chip-dot: var(--sp-phase-offerte-dot); }
  .chip[data-phase="uitvoering"] { --chip-bg: var(--sp-phase-uitvoering-bg); --chip-fg: var(--sp-phase-uitvoering-fg); --chip-dot: var(--sp-phase-uitvoering-dot); }
  .chip[data-phase="afgesloten"] { --chip-bg: var(--sp-phase-afgesloten-bg); --chip-fg: var(--sp-phase-afgesloten-fg); --chip-dot: var(--sp-phase-afgesloten-dot); }
  .chip[data-phase="verloren"]   { --chip-bg: var(--sp-phase-verloren-bg); --chip-fg: var(--sp-phase-verloren-fg); --chip-dot: var(--sp-phase-verloren-dot); }
  .chip[data-phase="onbekend"]   { --chip-bg: var(--sp-surface-sunken); --chip-fg: var(--sp-text-muted); --chip-dot: var(--sp-border-strong); }
  .chip[data-check="ok"]   { --chip-bg: var(--sp-success-soft); --chip-fg: var(--sp-on-success-soft); --chip-dot: var(--sp-success); }
  .chip[data-check="warn"] { --chip-bg: var(--sp-warning-soft); --chip-fg: var(--sp-on-warning-soft); --chip-dot: var(--sp-warning); }
  .chip[data-check="no"]   { --chip-bg: var(--sp-danger-soft); --chip-fg: var(--sp-on-danger-soft); --chip-dot: var(--sp-danger); }
  .chip[data-check="none"] { --chip-bg: var(--sp-surface-sunken); --chip-fg: var(--sp-text-muted); --chip-dot: var(--sp-border-strong); }
  .chip-row { display: flex; flex-wrap: wrap; gap: var(--sp-space-3); margin: 0; padding: 0; list-style: none; }
  .checklist { display: grid; gap: var(--sp-space-3); margin: 0; padding: 0; list-style: none; }
  .checklist li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--sp-space-5); padding: var(--sp-space-3) 0; border-top: 1px solid var(--sp-border); }
  /* A long file name without spaces wraps instead of pushing the button off a 320 px screen. */
  .checklist li > :first-child { min-width: 0; overflow-wrap: anywhere; }
  .energy-file-name { overflow-wrap: anywhere; }
  .checklist li:first-child { border-top: 0; }

  /* ── Data table -> cards under 640px of its container ────────────── */
  .table-wrap {
    container-type: inline-size;
    background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: var(--sp-radius-m);
    overflow-x: auto;
  }
  .table { width: 100%; border-collapse: collapse; font-size: var(--sp-text-sm); }
  .table th {
    text-align: left; font-weight: var(--sp-weight-semibold); color: var(--sp-text-muted);
    background: var(--sp-surface-sunken); font-size: var(--sp-text-xs);
    text-transform: uppercase; letter-spacing: var(--sp-tracking-caps);
    padding: var(--sp-space-4) var(--sp-space-6);
  }
  .table td { padding: var(--sp-space-4) var(--sp-space-6); border-top: 1px solid var(--sp-border); height: var(--sp-row-h); }
  .table .num { text-align: right; white-space: nowrap; }
  /* transform makes the row the containing block for the link overlay, also in Safari. */
  .table tbody tr { position: relative; transform: scale(1); }
  @media (hover: hover) { .table tbody tr:hover { background: var(--sp-surface-hover); } }
  .table .row-link { color: var(--sp-text); font-weight: var(--sp-weight-semibold); text-decoration: none; }
  .table .row-link::after { content: ""; position: absolute; inset: 0; }
  .table .row-link:focus-visible { outline: none; }
  .table .row-link:focus-visible::after {
    outline: var(--sp-focus-width) solid var(--sp-focus); outline-offset: -3px; border-radius: var(--sp-radius-xs);
  }
  .table .subline { display: block; color: var(--sp-text-subtle); font-size: var(--sp-text-xs); }
  .table .subline--warning { color: var(--sp-on-danger-soft); font-weight: var(--sp-weight-medium); }
  .table .row-action { position: relative; z-index: 1; }
  .table tfoot th, .table tfoot td { padding: var(--sp-space-4) var(--sp-space-6); border-top: 2px solid var(--sp-border-strong); font-weight: var(--sp-weight-semibold); }
  .table .cell-label { display: none; }
  .table caption {
    caption-side: top; text-align: left; padding: var(--sp-space-4) var(--sp-space-6);
    font-weight: var(--sp-weight-semibold); color: var(--sp-text);
  }
  /* A row header (the label of a figure, a period, a capacity) reads like a cell, not a column title. */
  .table tbody th[scope="row"] {
    text-transform: none; letter-spacing: normal; background: none; color: var(--sp-text);
    font-size: var(--sp-text-sm); border-top: 1px solid var(--sp-border); height: var(--sp-row-h);
  }
  /* A comment on a quote: one line of text across the row, without amounts. */
  .table td.cell-text { white-space: normal; color: var(--sp-text); }

  @container (max-width: 959px) {
    .table [data-col="secondary"] { display: none; }
  }
  @container (max-width: 639px) {
    .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .table, .table tbody, .table tr, .table td { display: block; }
    .table tr {
      display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-space-3) var(--sp-space-5);
      padding: var(--sp-space-6); border-top: 1px solid var(--sp-border);
    }
    .table tbody tr:first-child { border-top: 0; }
    .table td { padding: 0; border: 0; height: auto; }
    .table td.num { text-align: left; white-space: normal; }
    .table td[data-col="action"] { grid-column: 2; grid-row: 1; }
    /* A cell of running text (a reason) takes the whole width of the card. */
    .table td[data-col="wide"] { grid-column: 1 / -1; }
    /* Without an action the title takes the first row and the figures share two even columns, so a
       long amount never squeezes the title on a phone. */
    .table tbody tr:not(:has(> td[data-col="action"])) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .table tbody tr:not(:has(> td[data-col="action"])) > td:first-child { grid-column: 1 / -1; }
    .table tfoot { display: block; }
    .table tfoot td:empty { display: none; }
    .table .cell-label { display: inline; margin-right: var(--sp-space-2); color: var(--sp-text-muted); }
    .table caption { display: block; padding: var(--sp-space-5) var(--sp-space-6) 0; }
    .table tbody th[scope="row"] { display: block; grid-column: 1 / -1; padding: 0; border: 0; height: auto; }
    /* Hidden in the narrow table to save width; a card has room, so it comes back with its label. */
    .table [data-col="secondary"] { display: block; }
  }

  /* ── Forms ───────────────────────────────────────────────────────── */
  /* Forms use the width of the page; --narrow is for a short form on its own (a comment, a login). */
  .form { display: grid; gap: var(--sp-space-7); }
  .form--narrow { max-width: 40rem; }
  /* A field on a row of its own (a description, a name) stays readable on a wide screen. */
  :is(.form, .fieldset, .card) > .field { max-width: 48rem; }
  /* An address (Straat, Nummer, Bus, Postcode, Gemeente): street wide, number and box narrow. */
  .address-lookup { position: relative; max-width: 40rem; margin-bottom: var(--sp-space-6); }
  .address-lookup__list {
    position: absolute; z-index: 5; left: 0; right: 0; margin: var(--sp-space-2) 0 0; padding: var(--sp-space-2) 0; list-style: none;
    background: var(--sp-surface); border: 1px solid var(--sp-border-strong); border-radius: var(--sp-radius-s); box-shadow: var(--sp-shadow-1);
  }
  .address-lookup__list [role="option"] { display: flex; align-items: center; min-height: var(--sp-hit); padding: 0 var(--sp-space-5); cursor: pointer; }
  .address-lookup__list [role="option"][aria-selected="true"] { background: var(--sp-surface-hover); outline: 2px solid var(--sp-focus); outline-offset: -2px; }
  @media (hover: hover) { .address-lookup__list [role="option"]:hover { background: var(--sp-surface-hover); } }
  .address-grid { display: grid; gap: var(--sp-space-7) var(--sp-space-6); grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; max-width: 64rem; }
  .address-grid > .field:first-child { grid-column: 1 / -1; }
  @media (min-width: 62.5em) {
    .address-grid { grid-template-columns: minmax(0, 3fr) minmax(0, 6rem) minmax(0, 6rem) minmax(0, 7rem) minmax(0, 2fr); }
    .address-grid > .field:first-child { grid-column: auto; }
  }
  /* align-content: start, so a field next to a taller one keeps its label, input and hint together. */
  .field { display: grid; gap: var(--sp-space-3); align-content: start; }
  .field label { font-weight: var(--sp-weight-medium); font-size: var(--sp-text-sm); }
  .field__hint { color: var(--sp-text-subtle); font-size: var(--sp-text-xs); }
  .field__error { display: flex; gap: var(--sp-space-3); align-items: center; color: var(--sp-on-danger-soft); font-size: var(--sp-text-sm); }
  .field__error .icon { color: var(--sp-danger); width: 1rem; height: 1rem; }
  .input {
    width: 100%; min-height: var(--sp-control-h); padding: 0 var(--sp-space-5);
    background: var(--sp-surface); border: 1px solid var(--sp-border-strong); border-radius: var(--sp-radius-s);
    font-size: var(--sp-text-control);
  }
  .input:hover { border-color: var(--sp-border-ink); }
  /* A file input keeps its button inside the box and its file name on one shortened line, so it
     never sticks out of a narrow card or sheet. */
  .input[type="file"] {
    display: block; min-width: 0; max-width: 100%; padding: var(--sp-space-2);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: var(--sp-text-sm); line-height: calc(var(--sp-control-h) - 2 * var(--sp-space-2) - 2px);
  }
  .input[type="file"]::file-selector-button {
    min-height: calc(var(--sp-control-h) - 2 * var(--sp-space-2) - 2px); margin-right: var(--sp-space-4);
    padding: 0 var(--sp-space-5); border: 1px solid var(--sp-border-strong); border-radius: var(--sp-radius-pill);
    background: var(--sp-surface-sunken); color: inherit; font: inherit; font-weight: var(--sp-weight-semibold); cursor: pointer;
  }
  .input[type="file"]:hover::file-selector-button { background: var(--sp-surface-hover); }
  /* Own chevron with room to its right; the native one sits against the border on macOS. */
  select.input:not([multiple]) {
    appearance: none; padding-right: calc(var(--sp-space-5) + 1.5rem);
    background-image:
      linear-gradient(45deg, transparent 50%, var(--sp-text-muted) 50%),
      linear-gradient(135deg, var(--sp-text-muted) 50%, transparent 50%);
    background-position: right calc(var(--sp-space-5) + 0.3125rem) center, right var(--sp-space-5) center;
    background-size: 0.3125rem 0.3125rem; background-repeat: no-repeat;
  }
  @media (forced-colors: active) {
    select.input:not([multiple]) { appearance: auto; background-image: none; }
    /* The red inset line is gone in forced colours: a thicker border says "error" instead. */
    .input[aria-invalid="true"] { border-width: 2px; }
  }
  .input[aria-invalid="true"] { border-color: var(--sp-danger); box-shadow: inset 0 0 0 1px var(--sp-danger); }
  .input:disabled, .input[readonly] { background: var(--sp-surface-sunken); color: var(--sp-text-muted); }
  .input:disabled { cursor: not-allowed; }
  /* A unit after the value (A, kW, Wp, € ex btw) or before it (€): the wrapper is the box, so its
     border, hover, error and focus ring go around value and unit together, never through the unit. */
  .input-affix {
    display: flex; align-items: stretch; min-width: 0;
    background: var(--sp-surface); border: 1px solid var(--sp-border-strong); border-radius: var(--sp-radius-s);
  }
  .input-affix:hover { border-color: var(--sp-border-ink); }
  .input-affix .input {
    flex: 1 1 auto; min-width: 0; min-height: calc(var(--sp-control-h) - 2px);
    border: 0; border-radius: 0; background: transparent; box-shadow: none;
    text-align: right; font-variant-numeric: tabular-nums;
  }
  .input-affix .input:focus-visible { outline: none; }
  .input-affix:has(.input:focus-visible) { outline: var(--sp-focus-width) solid var(--sp-focus); outline-offset: var(--sp-focus-offset); }
  /* Outside the border: an inset line would be covered by the unit's background. */
  .input-affix:has(.input[aria-invalid="true"]) { border-color: var(--sp-danger); box-shadow: 0 0 0 1px var(--sp-danger); }
  .input-affix:has(.input:disabled, .input[readonly]) { background: var(--sp-surface-sunken); }
  .input-affix:has(.input:disabled) { cursor: not-allowed; }
  .input-affix__unit {
    display: flex; align-items: center; flex: none; padding: 0 var(--sp-space-5);
    border-left: 1px solid var(--sp-border); border-radius: 0 calc(var(--sp-radius-s) - 1px) calc(var(--sp-radius-s) - 1px) 0;
    background: var(--sp-surface-sunken); color: var(--sp-text-muted); font-size: var(--sp-text-sm); white-space: nowrap;
  }
  .input-affix__unit:first-child {
    border-left: 0; border-right: 1px solid var(--sp-border); border-radius: calc(var(--sp-radius-s) - 1px) 0 0 calc(var(--sp-radius-s) - 1px);
  }
  @media (forced-colors: active) {
    .input-affix:has(.input:focus-visible) { outline-color: CanvasText; }
    .input-affix:has(.input[aria-invalid="true"]) { border-width: 2px; }
  }
  .fieldset { margin: 0; padding: 0; border: 0; display: grid; gap: var(--sp-space-3); align-content: start; min-width: 0; }
  .fieldset legend { margin-bottom: var(--sp-space-3); font-weight: var(--sp-weight-semibold); font-size: var(--sp-text-sm); }
  .textarea { min-height: 6rem; padding: var(--sp-space-4) var(--sp-space-5); resize: vertical; }
  /* Disclosure (<details class="disclosure">): a part or an action that opens on demand. The summary
     is a button with a chevron that turns when it opens, so it reads as clickable; the same in every
     place. A yes/no that reveals options is a checkbox with data-show-if instead. */
  .disclosure { min-width: 0; }
  .disclosure > summary {
    display: inline-flex; align-items: center; gap: var(--sp-space-4); max-width: 100%;
    min-height: var(--sp-control-h); padding: var(--sp-space-2) var(--sp-space-6);
    border: 1px solid var(--sp-border-strong); border-radius: var(--sp-radius-pill); background: var(--sp-surface);
    color: var(--sp-text); font-size: var(--sp-text-sm); font-weight: var(--sp-weight-semibold);
    list-style: none; cursor: pointer;
  }
  .disclosure > summary::-webkit-details-marker { display: none; }
  .disclosure > summary::after {
    content: ""; flex: none; width: 0.4375rem; height: 0.4375rem; margin-top: -0.25rem;
    border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg);
    transition: transform var(--sp-dur) var(--sp-ease-out);
  }
  .disclosure[open] > summary::after { margin-top: 0.25rem; transform: rotate(225deg); }
  @media (hover: hover) { .disclosure > summary:hover { border-color: var(--sp-border-ink); background: var(--sp-surface-hover); } }
  .disclosure[open] > summary { margin-bottom: var(--sp-space-5); }
  .disclosure > :not(summary) + :not(summary) { margin-top: var(--sp-space-5); }
  .form__actions { display: flex; flex-wrap: wrap; gap: var(--sp-space-4); }
  /* A yes / no / not checked question: the third answer keeps "not checked" apart from "no".
     Legend, control, hint and error are spaced like the label, input, hint and error of a field, so
     a question next to a field lines up with it. */
  .choices { margin: 0; padding: 0; border: 0; min-width: 0; display: grid; gap: var(--sp-space-3); justify-items: start; align-content: start; }
  .choices legend { padding: 0; margin-bottom: var(--sp-space-3); font-weight: var(--sp-weight-medium); font-size: var(--sp-text-sm); }
  /* Segmented control: one choice out of a few short options (Ja · Nee · Niet nagekeken). */
  .segmented {
    display: inline-flex; flex-wrap: wrap; gap: var(--sp-space-1); padding: var(--sp-space-1);
    border: 1px solid var(--sp-border-strong); border-radius: var(--sp-radius-m); background: var(--sp-surface);
  }
  /* The options are lower than a control by the padding and border, so the whole control is as high
     as an input next to it. */
  .segmented label {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    min-height: calc(var(--sp-control-h) - 2 * var(--sp-space-1) - 2px); padding: 0 var(--sp-space-6); border-radius: var(--sp-radius-s);
    font-size: var(--sp-text-sm); cursor: pointer;
  }
  .segmented input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
  /* 44px hit area on fine pointers too, only vertically so it never covers the next option. */
  .segmented label::after { content: ""; position: absolute; inset: min(-4px, calc((100% - var(--sp-hit)) / 2)) 0; }
  @media (hover: hover) { .segmented label:hover { background: var(--sp-surface-hover); } }
  .segmented label:has(:checked) { background: var(--sp-action); color: var(--sp-on-action); font-weight: var(--sp-weight-semibold); }
  .segmented label:has(:focus-visible) { outline: var(--sp-focus-width) solid var(--sp-focus); outline-offset: var(--sp-focus-offset); }
  @media (forced-colors: active) {
    .segmented label:has(:checked) { forced-color-adjust: none; background: Highlight; color: HighlightText; }
    .segmented label:has(:focus-visible) { outline: 3px solid CanvasText; outline-offset: 2px; }
  }
  /* Checkboxes in even columns, also when a label wraps. */
  /* Searchable multi-select with pills (data-multiselect in app.js). */
  .multiselect { display: grid; gap: var(--sp-space-3); }
  .multiselect__box { position: relative; }
  .pill-list { display: flex; flex-wrap: wrap; gap: var(--sp-space-3); margin: 0; padding: 0; list-style: none; }
  .pill {
    display: inline-flex; align-items: center; gap: var(--sp-space-1); padding-left: var(--sp-space-5);
    background: var(--sp-surface-selected); border: 1px solid var(--sp-border-strong); border-radius: var(--sp-radius-pill);
    font-size: var(--sp-text-sm); overflow-wrap: anywhere;
  }
  .pill__remove {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    min-width: var(--sp-hit); min-height: var(--sp-hit); padding: 0; border: 0; border-radius: var(--sp-radius-pill);
    background: transparent; color: var(--sp-text-muted); font-size: var(--sp-text-md); cursor: pointer;
  }
  @media (hover: hover) { .pill__remove:hover { color: var(--sp-text); background: var(--sp-surface-hover); } }
  .multiselect__list {
    position: absolute; left: 0; right: 0; top: calc(100% + var(--sp-space-2)); z-index: var(--sp-z-overlay);
    max-height: 16rem; overflow-y: auto; margin: 0; padding: var(--sp-space-2) 0; list-style: none;
    background: var(--sp-surface); border: 1px solid var(--sp-border-strong); border-radius: var(--sp-radius-s); box-shadow: var(--sp-shadow-2);
  }
  .multiselect__list [role="option"] { display: flex; align-items: center; min-height: var(--sp-hit); padding: 0 var(--sp-space-5); cursor: pointer; }
  .multiselect__list [role="option"].is-active { background: var(--sp-surface-selected); outline: 2px solid var(--sp-focus); outline-offset: -2px; }
  @media (hover: hover) { .multiselect__list [role="option"]:hover { background: var(--sp-surface-hover); } }
  .multiselect__empty { margin: var(--sp-space-2) 0 0; color: var(--sp-text-muted); font-size: var(--sp-text-sm); }
  .check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(13rem, 100%), 1fr)); column-gap: var(--sp-space-6); align-items: start; }
  .check-grid .check { align-items: flex-start; padding-block: var(--sp-space-3); }
  .check-grid .check input { margin-top: 0.1em; }
  .check-grid .check .subline { display: block; color: var(--sp-text-subtle); font-size: var(--sp-text-xs); }
  /* Choice cards: one choice out of two or three that each need a sentence of explanation. */
  .choice-cards { display: grid; gap: var(--sp-space-4); grid-template-columns: repeat(auto-fit, minmax(min(16rem, 100%), 1fr)); }
  .choice-card {
    position: relative; display: grid; gap: var(--sp-space-2); align-content: start;
    padding: var(--sp-space-5) var(--sp-space-6) var(--sp-space-5) calc(var(--sp-space-6) + 1.75rem);
    border: 1px solid var(--sp-border-strong); border-radius: var(--sp-radius-m); background: var(--sp-surface); cursor: pointer;
  }
  .choice-card input { position: absolute; left: var(--sp-space-6); top: calc(var(--sp-space-5) + 0.1em); width: 1.25rem; height: 1.25rem; margin: 0; accent-color: var(--sp-accent); }
  .choice-card__title { font-weight: var(--sp-weight-semibold); font-size: var(--sp-text-sm); }
  .choice-card__hint { color: var(--sp-text-muted); font-size: var(--sp-text-xs); }
  @media (hover: hover) { .choice-card:hover { background: var(--sp-surface-hover); } }
  .choice-card:has(:checked) { border-color: var(--sp-accent); box-shadow: inset 0 0 0 1px var(--sp-accent); background: var(--sp-accent-soft); }
  .choice-card:has(:focus-visible) { outline: var(--sp-focus-width) solid var(--sp-focus); outline-offset: var(--sp-focus-offset); }
  @media (forced-colors: active) { .choice-card:has(:checked) { outline: 3px solid Highlight; } }
  /* The live line under the price fields, with its one action. */
  .price-preview { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-space-4) var(--sp-space-6); padding: var(--sp-space-5) var(--sp-space-6); border-radius: var(--sp-radius-m); background: var(--sp-surface-sunken); }
  .price-preview p { margin: 0; flex: 1 1 20rem; font-variant-numeric: tabular-nums; }
  .inverter { padding-top: var(--sp-space-5); border-top: 1px solid var(--sp-border); }
  .inverter:first-of-type { padding-top: 0; border-top: 0; }
  /* Composition form: one row per requirement. The live check replaces these rows; without scroll
     anchoring the browser does not jump to keep a node in view that was just replaced. */
  .composition-form { overflow-anchor: none; }
  /* Repeatable rows (data-rows in app.js): a legend with the row's name and its remove button. */
  .rows { display: grid; gap: var(--sp-space-6); }
  .rows--nested { gap: var(--sp-space-4); padding-left: var(--sp-space-6); border-left: 2px solid var(--sp-border); }
  .row__legend { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: var(--sp-space-5); }
  .row__remove { min-height: var(--sp-control-h); padding-inline: var(--sp-space-5); font-size: var(--sp-text-sm); color: var(--sp-link); }
  .pv-string legend { font-weight: var(--sp-weight-medium); }
  .grid-auto--dense { grid-template-columns: repeat(auto-fill, minmax(min(9rem, 100%), 1fr)); gap: var(--sp-space-5); }
  .h-sub { margin: 0; font-size: var(--sp-text-md); font-weight: var(--sp-weight-semibold); }

  /* ── Callout ─────────────────────────────────────────────────────── */
  .callout {
    display: flex; gap: var(--sp-space-5); padding: var(--sp-space-6);
    border-radius: var(--sp-radius-m); background: var(--callout-bg); color: var(--callout-fg);
  }
  .callout .icon { color: var(--callout-icon); margin-top: 1px; }
  /* Straight on the page (not in a stack): space a callout, card or KPI row from what follows. */
  :is(.main, #project-results) > :is(.callout, .card, .kpis) { margin-bottom: var(--sp-space-7); }
  .callout p { margin: 0; }
  .callout[data-variant="info"]    { --callout-bg: var(--sp-info-soft); --callout-fg: var(--sp-on-info-soft); --callout-icon: var(--sp-info); }
  .callout[data-variant="warning"] { --callout-bg: var(--sp-warning-soft); --callout-fg: var(--sp-on-warning-soft); --callout-icon: var(--sp-warning); }
  .callout[data-variant="danger"]  { --callout-bg: var(--sp-danger-soft); --callout-fg: var(--sp-on-danger-soft); --callout-icon: var(--sp-danger); }
  .callout[data-variant="success"] { --callout-bg: var(--sp-success-soft); --callout-fg: var(--sp-on-success-soft); --callout-icon: var(--sp-success); }

  /* ── Empty state ─────────────────────────────────────────────────── */
  .empty {
    max-width: 36rem; padding: var(--sp-space-8);
    border: 1px dashed var(--sp-border-strong); border-radius: var(--sp-radius-m); background: var(--sp-surface);
  }
  .empty :is(h2, h3) { font-size: var(--sp-text-lg); }
  .empty p { margin: var(--sp-space-4) 0 var(--sp-space-7); color: var(--sp-text-muted); }

  /* ── Dialog: bottom sheet on phones, centred above 640px ─────────── */
  .sheet {
    width: 100%; max-width: 100%; max-height: 85dvh; margin: auto 0 0; padding: 0;
    border: 0; border-radius: var(--sp-radius-l) var(--sp-radius-l) 0 0;
    background: var(--sp-surface); color: var(--sp-text); box-shadow: var(--sp-shadow-3);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sheet::backdrop { background: var(--sp-scrim); }
  .sheet[open] {
    display: flex; flex-direction: column; overscroll-behavior: contain;
    animation: sheet-in var(--sp-dur-slow) var(--sp-ease-out);
  }
  .sheet__head {
    display: flex; align-items: center; gap: var(--sp-space-5);
    padding: var(--sp-space-6) var(--sp-space-7); border-bottom: 1px solid var(--sp-border);
  }
  .sheet__head h2 { font-size: var(--sp-text-lg); }
  .sheet__head .btn { margin-left: auto; }
  .sheet__body { flex: 1; min-height: 0; padding: var(--sp-space-7); overflow-y: auto; }
  .sheet__foot { display: flex; justify-content: flex-end; gap: var(--sp-space-4); padding: var(--sp-space-6) var(--sp-space-7); border-top: 1px solid var(--sp-border); }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
  @media (min-width: 640px) {
    .sheet { max-width: 26rem; margin: auto; border-radius: var(--sp-radius-l); }
    .sheet--wide { max-width: 40rem; }
  }

  /* ── Toast ───────────────────────────────────────────────────────── */
  .toasts {
    position: fixed; z-index: var(--sp-z-toast);
    left: max(var(--sp-space-6), env(safe-area-inset-left)); right: max(var(--sp-space-6), env(safe-area-inset-right));
    bottom: calc(var(--sp-tabbar-h) + var(--sp-space-5) + env(safe-area-inset-bottom));
    display: grid; gap: var(--sp-space-4); pointer-events: none;
  }
  .toast {
    display: flex; align-items: center; gap: var(--sp-space-5); pointer-events: auto;
    padding: var(--sp-space-5) var(--sp-space-7); border-radius: var(--sp-radius-pill);
    background: var(--sp-surface-inverse); color: var(--sp-text-inverse); box-shadow: var(--sp-shadow-2);
    transition: opacity var(--sp-dur) var(--sp-ease-out), translate var(--sp-dur) var(--sp-ease-out);
  }
  @starting-style { .toast { opacity: 0; translate: 0 8px; } }
  .toast .icon { color: var(--sp-toast-action); }
  .toast :focus-visible { outline-color: var(--sp-text-inverse); }
  .toast__close { margin-left: auto; color: inherit; }
  .toast[data-variant="danger"] .icon, .toast[data-variant="warning"] .icon { color: var(--sp-warning); }
  @media (min-width: 900px) {
    .toasts { left: auto; right: var(--sp-space-8); bottom: var(--sp-space-8); max-width: 28rem; }
  }

  /* ── KPI tiles ───────────────────────────────────────────────────── */
  .kpis { display: grid; gap: var(--sp-space-6); grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr)); margin: 0; }
  .kpi { min-width: 0; background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: var(--sp-radius-m); padding: var(--sp-space-6); }
  .kpi dt { color: var(--sp-text-muted); font-size: var(--sp-text-xs); }
  .kpi dd { margin: var(--sp-space-3) 0 0; overflow-wrap: anywhere; font-size: var(--sp-text-3xl); font-weight: var(--sp-weight-bold); font-stretch: var(--sp-stretch-display); font-variant-numeric: tabular-nums; line-height: var(--sp-leading-tight); }
  .kpi__range { display: block; margin-top: var(--sp-space-3); font-size: var(--sp-text-xs); font-weight: var(--sp-weight-regular); color: var(--sp-text-subtle); font-stretch: var(--sp-stretch-body); }

  /* ── Login ───────────────────────────────────────────────────────── */
  .login { min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-gutter); }
  .login__card {
    width: min(100%, 26rem); background: var(--sp-surface); border-radius: var(--sp-radius-l);
    padding: var(--sp-space-9); box-shadow: var(--sp-shadow-2);
    position: relative; overflow: hidden;
  }
  .login__card::before { content: ""; position: absolute; inset: 0 0 auto; height: 6px; background: var(--sp-brand-gradient); }
  .login__card h1 { font-size: var(--sp-text-2xl); font-stretch: var(--sp-stretch-display); margin-bottom: var(--sp-space-4); }
  .login__card > p { color: var(--sp-text-muted); margin: 0 0 var(--sp-space-8); }
  .login__card .btn { width: 100%; }

  /* ── Swatches (style guide only) ─────────────────────────────────── */
  .swatches { display: grid; gap: var(--sp-space-4); grid-template-columns: repeat(auto-fill, minmax(min(9rem, 100%), 1fr)); }
  .swatch { border: 1px solid var(--sp-border); border-radius: var(--sp-radius-s); overflow: hidden; font-size: var(--sp-text-xs); }
  .swatch__color { height: 3rem; background: var(--swatch); }
  .swatch code { display: block; padding: var(--sp-space-3) var(--sp-space-4); font-family: var(--sp-font-mono); }
  .swatch[data-token="canvas"] { --swatch: var(--sp-canvas); }
  .swatch[data-token="surface"] { --swatch: var(--sp-surface); }
  .swatch[data-token="action"] { --swatch: var(--sp-action); }
  .swatch[data-token="accent"] { --swatch: var(--sp-accent); }
  .swatch[data-token="accent-mark"] { --swatch: var(--sp-accent-mark); }
  .swatch[data-token="link"] { --swatch: var(--sp-link); }
  .swatch[data-token="warning"] { --swatch: var(--sp-warning); }
  .swatch[data-token="danger"] { --swatch: var(--sp-danger); }
  .swatch[data-token="gradient"] { --swatch: var(--sp-brand-gradient); }
}

@layer components {
  /* ── Project list filters ────────────────────────────────────────── */
  .filters {
    display: grid; gap: var(--sp-space-6); margin-bottom: var(--sp-space-7);
    padding: var(--sp-space-6); background: var(--sp-surface);
    border: 1px solid var(--sp-border); border-radius: var(--sp-radius-m);
  }
  @media (min-width: 900px) {
    .filters { grid-template-columns: minmax(16rem, 22rem) 1fr; align-items: end; }
    .filters .check { grid-column: 1 / -1; }
  }
  .filters__phases { display: flex; flex-wrap: wrap; gap: var(--sp-space-3); margin: 0; padding: 0; border: 0; }
  .filters__phases legend { width: 100%; margin-bottom: var(--sp-space-3); font-weight: var(--sp-weight-medium); font-size: var(--sp-text-sm); }
  .phase-option { position: relative; }
  .phase-option input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
  .phase-option span {
    display: inline-flex; align-items: center; gap: var(--sp-space-3); min-height: var(--sp-control-h);
    padding: 0 var(--sp-space-6); border: 1px solid var(--sp-border-strong); border-radius: var(--sp-radius-pill);
    font-size: var(--sp-text-sm); background: var(--sp-surface);
  }
  .phase-option[data-phase] span::before { content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--dot); }
  .phase-option[data-phase="nieuw"] { --dot: var(--sp-phase-nieuw-dot); }
  .phase-option[data-phase="bezoek"] { --dot: var(--sp-phase-bezoek-dot); }
  .phase-option[data-phase="offerte"] { --dot: var(--sp-phase-offerte-dot); }
  .phase-option[data-phase="uitvoering"] { --dot: var(--sp-phase-uitvoering-dot); }
  .phase-option[data-phase="afgesloten"] { --dot: var(--sp-phase-afgesloten-dot); }
  .phase-option input:checked + span { background: var(--sp-action); color: var(--sp-on-action); border-color: var(--sp-action); font-weight: var(--sp-weight-semibold); }
  .phase-option input:checked + span::before { box-shadow: 0 0 0 2px var(--sp-on-action); }
  .phase-option input:focus-visible + span { outline: var(--sp-focus-width) solid var(--sp-focus); outline-offset: var(--sp-focus-offset); }
  .check { display: inline-flex; align-items: center; gap: var(--sp-space-4); min-height: var(--sp-hit); font-size: var(--sp-text-sm); cursor: pointer; }
  .check input { width: 1.25rem; height: 1.25rem; accent-color: var(--sp-accent); }
  .results-count { margin: 0 0 var(--sp-space-4); color: var(--sp-text-muted); font-size: var(--sp-text-sm); }
  .load-more { display: flex; justify-content: center; margin-top: var(--sp-space-7); }

  .flags { display: flex; gap: var(--sp-space-2); margin: 0; padding: 0; list-style: none; position: relative; z-index: 1; }
  .flag { display: inline-flex; color: var(--flag); }
  .flag[data-variant="danger"] { --flag: var(--sp-danger); }
  .flag[data-variant="warning"] { --flag: var(--sp-warning); }
  .flag[data-variant="info"] { --flag: var(--sp-info); }

  /* ── Project hub ─────────────────────────────────────────────────── */
  .hub-head { display: grid; gap: var(--sp-space-4); margin-bottom: var(--sp-space-7); }
  .breadcrumb { font-size: var(--sp-text-sm); }
  .breadcrumb a { display: inline-flex; align-items: center; min-height: var(--sp-hit-dense); }
  .hub-head h1 { font-size: var(--sp-text-2xl); font-stretch: var(--sp-stretch-display); }
  .hub-head__meta { display: flex; flex-wrap: wrap; gap: var(--sp-space-2) var(--sp-space-6); margin: 0; color: var(--sp-text-muted); }
  .hub-head__meta a { display: inline-flex; align-items: center; min-height: var(--sp-hit-dense); }
  .hub-head__status { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-space-5); }

  .phase-rail { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--sp-space-2); margin: var(--sp-space-3) 0 0; padding: 0; list-style: none; }
  .phase-rail li { display: grid; gap: var(--sp-space-2); font-size: var(--sp-text-xs); color: var(--sp-text-subtle); }
  .phase-rail li::before { content: ""; height: 6px; border-radius: var(--sp-radius-pill); background: var(--sp-surface-sunken); }
  .phase-rail li[data-state="done"]::before { background: var(--sp-accent); }
  .phase-rail li[data-state="current"]::before { background: var(--sp-brand-gradient); }
  .phase-rail li[data-state="lost"]::before { background: var(--sp-danger); }
  .phase-rail li[data-state="current"], .phase-rail li[data-state="lost"] { color: var(--sp-text); font-weight: var(--sp-weight-semibold); }
  @media (max-width: 639px) {
    .phase-rail li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  }

  .tabs {
    display: flex; gap: var(--sp-space-2); overflow-x: auto; scrollbar-width: none;
    margin-bottom: var(--sp-space-7); border-bottom: 1px solid var(--sp-border);
  }
  .tabs::-webkit-scrollbar { display: none; }
  @media (max-width: 639px) {
    /* Hint that more tabs scroll in from the right. */
    .tabs { mask-image: linear-gradient(to right, #000 85%, transparent); }
  }
  .tabs__tab {
    flex: none; display: inline-flex; align-items: center; min-height: var(--sp-hit); padding: 0 var(--sp-space-6);
    color: var(--sp-text-muted); text-decoration: none; font-weight: var(--sp-weight-medium);
    border-bottom: 3px solid transparent; margin-bottom: -1px;
  }
  .tabs__tab[aria-current="page"] { color: var(--sp-text); border-bottom-color: var(--sp-accent); font-weight: var(--sp-weight-semibold); }
  @media (hover: hover) { .tabs__tab:hover { color: var(--sp-text); } }
  .tabs__tab:focus-visible { outline-offset: -3px; }
  /* The children of a menu group: tabs at the top of their pages, on every screen (ADR-41). */

  /* Sections of a long form as tabs (data-tabs in app.js); stays in view while scrolling. */
  .tabs--sticky { position: sticky; top: 0; z-index: var(--sp-z-sticky); background: var(--sp-canvas); }
  @media (max-width: 899px) { .tabs--sticky { top: var(--sp-topbar-h); } }
  @media (max-height: 500px) { .tabs--sticky { position: static; } }
  /* Save and cancel of a long form, always at hand: above the tab bar on a phone. The page keeps
     room below (scroll-padding) so the bar never covers a focused field (WCAG 2.4.11). */
  .action-bar {
    position: sticky; bottom: 0; z-index: var(--sp-z-sticky);
    display: flex; flex-wrap: wrap; gap: var(--sp-space-4); margin-top: var(--sp-space-7);
    padding: var(--sp-space-5) 0; background: var(--sp-canvas); border-top: 1px solid var(--sp-border);
  }
  @media (max-width: 899px) { .action-bar { bottom: calc(var(--sp-tabbar-h) + env(safe-area-inset-bottom)); } }
  @media (max-height: 500px) { .action-bar { position: static; } }
  html:has(.tabs--sticky) { scroll-padding-top: calc(var(--sp-topbar-h) + var(--sp-hit) + var(--sp-space-6)); }
  @media (min-width: 900px) { html:has(.tabs--sticky) { scroll-padding-top: calc(var(--sp-hit) + var(--sp-space-6)); } }
  html:has(.action-bar) { scroll-padding-bottom: calc(var(--sp-control-h) + var(--sp-space-11)); }
  @media (max-width: 899px) {
    html:has(.action-bar) { scroll-padding-bottom: calc(var(--sp-tabbar-h) + env(safe-area-inset-bottom) + var(--sp-control-h) + var(--sp-space-11)); }
  }
  /* A low screen: the save bar is no longer sticky, but the fixed tab bar below 900px still is. */
  @media (max-height: 500px) { html:has(.action-bar) { scroll-padding-bottom: 0; } }
  @media (max-height: 500px) and (max-width: 899px) {
    html:has(.action-bar) { scroll-padding-bottom: calc(var(--sp-tabbar-h) + env(safe-area-inset-bottom) + var(--sp-space-6)); }
  }
  .action-bar__note { flex-basis: 100%; margin: 0; color: var(--sp-on-warning-soft); font-size: var(--sp-text-sm); font-weight: var(--sp-weight-medium); }
  .tabs__tab[aria-current="true"] { color: var(--sp-text); border-bottom-color: var(--sp-accent); font-weight: var(--sp-weight-semibold); }
  .tabs__count { margin-left: var(--sp-space-3); color: var(--sp-on-danger-soft); font-weight: var(--sp-weight-semibold); }

  .facts { display: grid; gap: var(--sp-space-5) var(--sp-space-8); grid-template-columns: repeat(auto-fit, minmax(min(10rem, 100%), 1fr)); margin: 0; }
  .facts dt { color: var(--sp-text-muted); font-size: var(--sp-text-xs); }
  .facts dd { margin: var(--sp-space-1) 0 0; overflow-wrap: anywhere; }
  .facts--compact { gap: var(--sp-space-4) var(--sp-space-7); }
  /* Label left, value right in a narrow block; stacked again on a phone. */
  .facts--stack { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .facts--stack > div { display: grid; grid-template-columns: minmax(7rem, 2fr) minmax(0, 3fr); gap: var(--sp-space-5); padding: var(--sp-space-4) 0; border-top: 1px solid var(--sp-border); }
  .facts--stack > div:first-child { border-top: 0; padding-top: 0; }
  .facts--stack dt { font-size: var(--sp-text-sm); }
  .facts--stack dd { margin: 0; }
  @container (max-width: 22rem) {
    .facts--stack > div { grid-template-columns: minmax(0, 1fr); gap: var(--sp-space-1); }
  }
  .prewrap { white-space: pre-wrap; margin: 0; }
  .todo-list { display: grid; gap: var(--sp-space-4); }

  .inverters, .configs, .comments { display: grid; gap: var(--sp-space-5); margin: 0; padding: 0; list-style: none; }
  .inverters li, .configs li { display: grid; gap: var(--sp-space-1); }
  .inverters span, .configs span { color: var(--sp-text-muted); font-size: var(--sp-text-sm); }
  .configs code { font-family: var(--sp-font-mono); font-size: var(--sp-text-sm); }
  .photo-grid { display: grid; gap: var(--sp-space-4); grid-template-columns: repeat(auto-fill, minmax(min(8.5rem, 100%), 1fr)); margin: 0; padding: 0; list-style: none; }
  .photo-tile { display: grid; gap: var(--sp-space-2); color: var(--sp-text-muted); text-decoration: none; font-size: var(--sp-text-xs); }
  .photo-tile img {
    width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--sp-radius-s);
    background: var(--sp-surface-sunken); outline: 1px solid rgb(0 0 0 / 0.08); outline-offset: -1px;
  }
  .photo-tile:focus-visible { outline-offset: var(--sp-focus-offset); }
  .photo { display: grid; gap: var(--sp-space-2); align-content: start; min-width: 0; }
  .photo__meta { margin: 0; color: var(--sp-text-muted); font-size: var(--sp-text-xs); overflow-wrap: anywhere; }
  .photo__meta strong { display: block; color: var(--sp-text); font-weight: var(--sp-weight-medium); }
  .photo__meta .subline { display: block; }
  /* Links to the groups of a long list (photos, documents): touch targets of 44 px. */
  .jump-links a {
    display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--sp-space-5);
    border: 1px solid var(--sp-border); border-radius: var(--sp-radius-pill); font-size: var(--sp-text-sm);
  }
  .serials { display: grid; gap: var(--sp-space-3); margin: 0; padding: 0; list-style: none; }
  .serial {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-space-3) var(--sp-space-5);
    padding: var(--sp-space-5) var(--sp-space-6); background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: var(--sp-radius-m);
  }
  .serial > div { display: grid; gap: var(--sp-space-1); min-width: 0; }
  .serial__value { font-family: var(--sp-font-mono); font-size: var(--sp-text-md); overflow-wrap: anywhere; }
  .serial__meta { color: var(--sp-text-muted); font-size: var(--sp-text-sm); }
  .photo-errors { display: grid; gap: var(--sp-space-2); margin: 0; padding: 0; list-style: none; color: var(--sp-danger); font-size: var(--sp-text-sm); }
  .offer__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-space-3); }
  .offer--inactive { opacity: 0.75; }
  .photo-view { position: relative; width: fit-content; max-width: 100%; margin: 0; }
  .photo-view img { display: block; max-width: 100%; height: auto; border-radius: var(--sp-radius-s); }
  .photo-view .photo-view__overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
  .files { display: grid; gap: var(--sp-space-4); margin: 0; padding: 0; list-style: none; }
  .file {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-space-5);
    padding: var(--sp-space-6); background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: var(--sp-radius-m);
  }
  .file .subline { display: block; color: var(--sp-text-subtle); font-size: var(--sp-text-xs); }
  .comment { padding: var(--sp-space-6); background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: var(--sp-radius-m); }
  .history { display: grid; gap: var(--sp-space-5); margin: 0; padding: 0; list-style: none; }
  .history__item { display: grid; gap: var(--sp-space-2); padding-left: var(--sp-space-5); border-left: 2px solid var(--sp-border); }
  .history__item--back { border-left-color: var(--sp-warning); }
  .history__item p { margin: 0; }
  .history__what { display: flex; flex-wrap: wrap; gap: var(--sp-space-3); align-items: baseline; }
  .history__reason { font-size: var(--sp-text-sm); }
  .history__meta { color: var(--sp-text-muted); font-size: var(--sp-text-xs); }
  .comment__meta { margin: 0 0 var(--sp-space-3); color: var(--sp-text-muted); font-size: var(--sp-text-sm); }
  /* ── Ter goedkeuring (ADR-12): what changes, old → new, and one tap to decide ── */
  .pending-changes { display: grid; gap: var(--sp-space-5); margin: 0; padding: 0; list-style: none; }
  .pending-change { min-width: 0; border-left: 4px solid var(--sp-accent-mark); }
  .pending-change[data-mark="terug"], .pending-change[data-mark="afsluiten"] { border-left-color: var(--sp-warning); }
  .pending-change[data-state="vervallen"] { border-left-color: var(--sp-warning); }
  .pending-change[data-state="weg"] { border-left-color: var(--sp-danger); }
  .pending-change[data-state="toegepast"], .pending-change[data-state="afgewezen"] { border-left-color: var(--sp-border-strong); }
  .pending-change p { margin: 0; }
  .pending-change__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--sp-space-3); }
  .pending-change__meta { color: var(--sp-text-muted); font-size: var(--sp-text-sm); overflow-wrap: anywhere; }
  .pending-change__meta a { display: inline-flex; align-items: center; min-height: var(--sp-hit-dense); }
  @media (pointer: coarse) { .pending-change__meta a { min-height: var(--sp-hit); } }
  .pending-change__label { color: var(--sp-text-muted); font-size: var(--sp-text-sm); }
  .pending-change__why { color: var(--sp-text-muted); font-size: var(--sp-text-sm); }
  .pending-change__decision { font-weight: var(--sp-weight-medium); }
  .pending-change__remarks { display: grid; gap: var(--sp-space-2); margin: 0; padding: 0; list-style: none; font-size: var(--sp-text-sm); }
  .pending-change__remarks li { display: flex; align-items: flex-start; gap: var(--sp-space-3); }
  .pending-change__remarks .icon { flex: none; margin-top: 0.15em; color: var(--sp-accent-mark); }
  .pending-change__photo { margin: 0; display: grid; gap: var(--sp-space-2); justify-items: start; max-width: 100%; }
  /* Room reserved before the photo has loaded, so the buttons below never jump. */
  .pending-change__photo img { display: block; width: min(100%, 20rem); height: auto; aspect-ratio: 4 / 3; object-fit: contain; background: var(--sp-surface-sunken); border-radius: var(--sp-radius-xs); border: 1px solid var(--sp-border); }
  .pending-change__photo a { display: grid; gap: var(--sp-space-2); }
  .pending-change__photo-error { color: var(--sp-danger); font-size: var(--sp-text-sm); }
  .pending-change__link { display: inline-flex; align-items: center; min-height: var(--sp-hit-dense); }
  @media (pointer: coarse) { .pending-change__link { min-height: var(--sp-hit); } }
  .pending-change__summary { font-weight: var(--sp-weight-medium); }
  .pending-change__facts { display: grid; gap: var(--sp-space-2); padding: var(--sp-space-4) var(--sp-space-5); border-radius: var(--sp-radius-xs); background: var(--sp-surface-sunken); }
  .pending-change__facts dl { display: grid; gap: var(--sp-space-2); margin: 0; }
  .pending-change__facts dl > div { display: grid; gap: 0 var(--sp-space-5); }
  .pending-change__facts dt { color: var(--sp-text-muted); font-size: var(--sp-text-sm); }
  .pending-change__facts dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
  @media (min-width: 640px) { .pending-change__facts dl > div { grid-template-columns: minmax(8rem, 2fr) minmax(0, 5fr); } }
  .pending-change__group { display: grid; gap: var(--sp-space-2); }
  .pending-change__group + .pending-change__group { margin-top: var(--sp-space-4); }
  .pending-change__group-title { font-weight: var(--sp-weight-medium); font-size: var(--sp-text-sm); }
  .pending-change__tag { color: var(--sp-text-muted); font-size: var(--sp-text-sm); }
  .pending-change__changes { display: grid; gap: 0; margin: 0; }
  .pending-change__change {
    display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-space-1);
    padding: var(--sp-space-3) 0; border-top: 1px solid var(--sp-border);
  }
  .pending-change__change:first-child { border-top: 0; }
  .pending-change__change dt { color: var(--sp-text-muted); font-size: var(--sp-text-sm); }
  .pending-change__change dd { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-space-1) var(--sp-space-3); overflow-wrap: anywhere; }
  .pending-change__before { color: var(--sp-text-muted); text-decoration: line-through; }
  .pending-change__now { color: var(--sp-on-warning-soft); background: var(--sp-warning-soft); padding: 0 var(--sp-space-3); border-radius: var(--sp-radius-xs); font-weight: var(--sp-weight-medium); }
  .pending-change__was { flex-basis: 100%; color: var(--sp-text-muted); font-size: var(--sp-text-xs); }
  .pending-change__missing { display: flex; align-items: center; gap: var(--sp-space-4); font-weight: var(--sp-weight-medium); }
  .pending-change__missing .icon { color: var(--sp-warning); }
  .pending-change__actions { display: grid; gap: var(--sp-space-5); }
  .pending-change__actions form > .btn, .pending-change__confirm .btn { width: 100%; min-height: var(--sp-hit); }
  @media (min-width: 640px) {
    .pending-change__change { grid-template-columns: minmax(8rem, 2fr) minmax(0, 5fr); gap: var(--sp-space-5); }
    .pending-change__actions { grid-template-columns: auto minmax(0, 1fr); align-items: start; }
    .pending-change__actions form > .btn, .pending-change__confirm .btn { width: auto; }
  }
  .nav__count { display: contents; }
  .nav__badge {
    display: inline-flex; align-items: center; justify-content: center; min-width: 1.25rem; height: 1.25rem;
    padding: 0 var(--sp-space-2); border-radius: var(--sp-radius-pill);
    background: var(--sp-accent); color: var(--sp-on-accent); font-size: var(--sp-text-2xs); font-weight: var(--sp-weight-bold);
  }
  .nav__badge--unknown { background: var(--sp-nav-active-bg); color: var(--sp-nav-fg); }
  @media (max-width: 899px) { .nav__link { position: relative; } .nav__badge { position: absolute; top: var(--sp-space-2); left: calc(50% + 0.5rem); } }
  @media (forced-colors: active) { .nav__badge { border: 1px solid CanvasText; } .pending-change { border-left-color: CanvasText; } }
  /* ── Planning: one entry per visit, installation day or inspection ── */
  .stack-tight { display: grid; gap: var(--sp-space-4); align-content: start; min-width: 0; }
  .planning__next { color: var(--sp-text-muted); font-size: var(--sp-text-sm); font-weight: var(--sp-weight-medium); }
  .visits { display: grid; gap: var(--sp-space-3); margin: 0; padding: 0; list-style: none; }
  .visit {
    display: grid; gap: var(--sp-space-3); min-width: 0;
    padding: var(--sp-space-5) var(--sp-space-6); background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: var(--sp-radius-m);
  }
  .visit__title { margin: 0; display: flex; flex-wrap: wrap; gap: var(--sp-space-1) var(--sp-space-4); }
  .visit__meta { margin: 0; color: var(--sp-text-muted); font-size: var(--sp-text-sm); overflow-wrap: anywhere; }
  .visit__report { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-space-1) var(--sp-space-4); overflow-wrap: anywhere; }
  .visit__report a { display: inline-flex; align-items: center; min-height: var(--sp-hit); }
  .visit__report-name { overflow-wrap: anywhere; font-weight: var(--sp-weight-regular); }
}

/* ── Quote flow: packages, compositions, quotes (feat/quote-from-project) ── */
@layer components {
  .package-row { display: grid; gap: var(--sp-space-3) var(--sp-space-5); grid-template-columns: minmax(0, 1fr) auto; align-items: end; padding-block: var(--sp-space-4); border-top: 1px solid var(--sp-border); }
  .package-row:first-child { border-top: 0; padding-top: 0; }
  .package-row__members { grid-column: 1 / -1; font-size: var(--sp-text-sm); }

  /* Composition form: one dense row per requirement. The legend floats, so it is an ordinary grid
     item: name and status left, product and quantity in the middle, "N.v.t." right. */
  .reqs { display: grid; }
  .req {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "head na" "body body";
    gap: var(--sp-space-2) var(--sp-space-5); align-items: center;
    margin: 0; padding: var(--sp-space-4) 0; border: 0; border-top: 1px solid var(--sp-border); min-width: 0;
  }
  .reqs > .req:first-child { border-top: 0; padding-top: 0; }
  .req__head { float: left; grid-area: head; display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-space-2) var(--sp-space-4); padding: 0; font-size: var(--sp-text-sm); font-weight: var(--sp-weight-semibold); }
  .req__body { grid-area: body; display: grid; gap: var(--sp-space-3); min-width: 0; }
  .req__na { grid-area: na; font-size: var(--sp-text-xs); }
  .req--wide { grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "body"; padding-top: var(--sp-space-5); }
  .req__note { margin: 0; font-size: var(--sp-text-xs); color: var(--sp-text-muted); }
  .req__lines { display: grid; gap: var(--sp-space-3); }
  .req__lines > .form__actions { margin: 0; }
  .req__line { display: grid; grid-template-columns: minmax(0, 1fr) 6.5rem; gap: var(--sp-space-2) var(--sp-space-4); align-items: start; }
  .req__line > .req__package, .req__line > .findings { grid-column: 1 / -1; }
  .req__package { margin: 0; font-size: var(--sp-text-xs); color: var(--sp-text-muted); }
  .findings { display: grid; gap: var(--sp-space-2); margin: 0; padding: 0; list-style: none; font-size: var(--sp-text-xs); }
  .findings li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-space-3); }
  .manual-row { display: grid; grid-template-columns: minmax(0, 1fr) 6.5rem; gap: var(--sp-space-3) var(--sp-space-4); align-items: start; }
  .manual-row__description { grid-column: 1 / -1; }
  .composition-list { gap: 0; }
  .composition-list__item { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-space-3) var(--sp-space-5); padding-block: var(--sp-space-4); border-top: 1px solid var(--sp-border); }
  .composition-list__item:first-child { border-top: 0; padding-top: 0; }
  .composition-list__name { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-space-3) var(--sp-space-4); min-width: 0; }
  .composition-list__name a { font-weight: var(--sp-weight-semibold); }
  @media (min-width: 64rem) {
    .req { grid-template-columns: 12rem minmax(0, 1fr) auto; grid-template-areas: "head body na"; align-items: start; }
    .req__head { min-height: var(--sp-control-h); }
    .req--wide { grid-template-columns: 12rem minmax(0, 1fr); grid-template-areas: "head body"; }
    .manual-row { grid-template-columns: minmax(0, 1fr) 6.5rem 9rem 9rem 10rem; }
    .manual-row__description { grid-column: auto; }
  }
}

/* ── Mail templates: the preview of a filled-in mail (communication, G.2) ── */
@layer components {
  /* Looks like a mail, set apart from the page: the real HTML part has its own inline styles. */
  .mail-preview { display: grid; gap: var(--sp-space-5); min-width: 0; }
  .mail-preview__subject { margin: 0; padding-bottom: var(--sp-space-4); border-bottom: 1px solid var(--sp-border); overflow-wrap: anywhere; }
  .mail-preview__body {
    max-width: 40rem; padding: var(--sp-space-6); border: 1px solid var(--sp-border-strong); border-radius: var(--sp-radius-s);
    background: var(--sp-surface); overflow-wrap: anywhere;
  }
  .mail-preview__body p { margin: 0 0 var(--sp-space-5); white-space: pre-line; }
  .mail-preview__body h3 { margin: var(--sp-space-7) 0 var(--sp-space-3); font-size: var(--sp-text-md); }
  .mail-preview__body > :first-child h3:first-child { margin-top: 0; }
  .mail-preview__body ul { margin: 0 0 var(--sp-space-5); padding-left: var(--sp-space-7); }
  .mail-preview__callout { margin: 0 0 var(--sp-space-6); padding: var(--sp-space-5) var(--sp-space-6); border-left: 4px solid var(--sp-accent); background: var(--sp-surface-sunken); }
  .mail-preview__callout h3 { margin-top: 0; }
  .mail-preview__callout p:last-child { margin-bottom: 0; }
  .mail-preview__action { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-space-3) var(--sp-space-5); }
  /* Not a link in the app: the preview never opens what a customer would click. */
  .mail-preview__button { display: inline-block; padding: var(--sp-space-4) var(--sp-space-7); border-radius: var(--sp-radius-s); background: var(--sp-accent); color: var(--sp-on-accent); font-weight: var(--sp-weight-semibold); }
  .mail-preview__link { font-size: var(--sp-text-sm); color: var(--sp-text-muted); overflow-wrap: anywhere; }
  .mail-preview__signature { margin-top: var(--sp-space-7); color: var(--sp-text-muted); }
  .mail-preview__text { margin: 0; padding: var(--sp-space-5); border-radius: var(--sp-radius-s); background: var(--sp-surface-sunken); font-family: var(--sp-font-mono); font-size: var(--sp-text-sm); white-space: pre-wrap; overflow-wrap: anywhere; }
  /* A variable without a value: marked with a dashed outline and its braces, not by colour alone. */
  .mail-var { padding: 0 var(--sp-space-1); border-radius: var(--sp-radius-xs); background: var(--sp-warning-soft); color: var(--sp-on-warning-soft); outline: 1px dashed var(--sp-warning); font-family: var(--sp-font-mono); font-size: 0.9em; }
  .mail-code { font-family: var(--sp-font-mono); font-size: var(--sp-text-sm); overflow-wrap: anywhere; }
  /* A fieldset as a card, its legend a section title: the float takes the legend out of the border
     (a browser draws a plain legend across it), onto the first row. */
  :is(.proposal-block, fieldset.card.stack) { min-width: 0; margin: 0; }
  :is(.proposal-block, fieldset.card.stack) > legend { float: left; width: 100%; padding: 0; }
  :is(.proposal-block, fieldset.card.stack) > legend + * { clear: both; }
  .photo-pick { display: grid; gap: var(--sp-space-2); cursor: pointer; font-size: var(--sp-text-xs); color: var(--sp-text-muted); }
  .photo-pick img {
    width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--sp-radius-s);
    background: var(--sp-surface-sunken); outline: 1px solid rgb(0 0 0 / 0.08); outline-offset: -1px;
  }
  .photo-pick .check { align-items: flex-start; overflow-wrap: anywhere; }
  /* A choice with a second line (format, caption): text under each other, the box at the first line. */
  .check:has(.subline) { align-items: flex-start; padding-block: var(--sp-space-3); }
  .check:has(.subline) input { margin-top: 0.1em; flex: none; }
  .check .subline { display: block; color: var(--sp-text-subtle); font-size: var(--sp-text-xs); }
  .plain-list.dossier-links { gap: var(--sp-space-4); }
  .dossier-links li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-space-2) var(--sp-space-4); }
  .dossier-links a { font-weight: var(--sp-weight-semibold); }
  /* A chosen photo: the ticked box, and a frame that does not rely on colour alone (thicker). */
  .photo-pick:has(input:checked) img { outline: 3px solid var(--sp-accent); outline-offset: 2px; }
  .proposal-list { display: grid; gap: var(--sp-space-6); }
  .proposal-list__item { display: grid; gap: var(--sp-space-3); padding-bottom: var(--sp-space-6); border-bottom: 1px solid var(--sp-border); }
  .proposal-list__item:last-child { padding-bottom: 0; border-bottom: 0; }
  .proposal-list__head { display: flex; flex-wrap: wrap; gap: var(--sp-space-2) var(--sp-space-4); align-items: baseline; }
  .proposal-list__options { display: grid; gap: var(--sp-space-1); font-size: var(--sp-text-sm); }
  /* A fieldset as a card: the float takes the legend out of the border, onto the first row. */
  .mail-block { min-width: 0; margin: 0; }
  .mail-block > legend { float: left; width: 100%; padding: 0; font-weight: var(--sp-weight-semibold); }
}

@layer components {
  /* ── Energy chart (ADR-33): an SVG drawn on the server, colours only through these classes ── */
  .chart__months { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-space-4); }
  .chart__month { flex: 1 1 auto; text-align: center; font-size: var(--sp-text-lg); }
  .chart__step { min-height: var(--sp-hit); }
  .chart__step--none { display: inline-flex; align-items: center; padding: 0 var(--sp-space-7); color: var(--sp-text-subtle); }
  .chart__figure { margin: 0; }
  /* A kept image (retention job) carries the light theme's colours: on a white sheet in both themes. */
  .chart__img { background: var(--sp-chart-sheet); border-radius: var(--sp-radius-s); }
  /* Below about 640 px the chart keeps a readable size and scrolls sideways instead of shrinking. */
  .chart__scroll { overflow-x: auto; border-radius: var(--sp-radius-s); }
  .chart__svg { display: block; width: 100%; min-width: 40rem; height: auto; font-family: var(--sp-font); }
  .chart__label { fill: var(--sp-text-muted); }
  .chart__label--strong { fill: var(--sp-text); font-weight: var(--sp-weight-semibold); }
  .chart__grid { stroke: var(--sp-viz-grid); stroke-width: 1; }
  .chart__axis { stroke: var(--sp-viz-axis); stroke-width: 1.5; }
  .chart__bar { stroke: var(--sp-surface); stroke-width: 1.5; }
  .chart__fill--afname-dag { fill: var(--sp-viz-afname-dag); }
  .chart__fill--afname-nacht { fill: var(--sp-viz-afname-nacht); }
  .chart__fill--afname { fill: var(--sp-viz-afname); }
  .chart__fill--injectie-dag { fill: var(--sp-viz-injectie-dag); }
  .chart__fill--injectie-nacht { fill: var(--sp-viz-injectie-nacht); }
  .chart__fill--injectie { fill: var(--sp-viz-injectie); }
  .chart__avg { fill: none; }
  .chart__avg-halo { stroke: var(--sp-surface); }
  .chart__stroke--avg-afname { stroke: var(--sp-viz-avg-afname); }
  .chart__stroke--avg-injectie { stroke: var(--sp-viz-avg-injectie); }
  .chart__gap { fill: none; stroke: var(--sp-viz-gap); stroke-width: 1.5; }
  /* Night is hatched as well as darker: day and night differ by more than lightness (WCAG 1.4.1). */
  .chart__hatch { stroke: var(--sp-surface); }
  .chart__hatch-area { pointer-events: none; }
  @media (forced-colors: active) {
    .chart__bar, .chart__swatch { fill: CanvasText; stroke: Canvas; }
    .chart__hatch { stroke: Canvas; }
    .chart__avg, .chart__gap, .chart__axis { stroke: CanvasText; }
    .chart__label { fill: CanvasText; }
  }
}

@layer utilities {
  .muted { color: var(--sp-text-muted); }
  .plain-list { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--sp-space-2); }
  .text-danger { color: var(--sp-danger); font-weight: var(--sp-weight-medium); }
  /* No dimming: that would drop text contrast below 4.5:1 while a request runs. */
  .htmx-request { cursor: progress; }
  .visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  [hidden] { display: none !important; }
}

/* ── Print: only the content, tables as tables ───────────────────── */
@media print {
  .nav, .topbar, .skip-link, .toasts, .no-print { display: none !important; }
  body, .main { background: #fff; color: #000; padding: 0; margin: 0; }
  .shell { display: block; }
  .print-table { container-type: normal; border: 0; overflow: visible; }
  .print-table .table { font-size: 9pt; }
  .print-table .table tr { break-inside: avoid; }
  .print-table .cell-label { display: none; }
}

/* Product photos (catalogue): a manufacturer's picture is often on white or transparent, so it is
   shown whole (contain) on a light surface, not cropped like a photo of a site. */
@layer components {
  .product-thumb {
    float: left; width: 48px; height: 48px; margin-right: var(--sp-space-3); object-fit: contain;
    border-radius: var(--sp-radius-s); background: var(--sp-surface); outline: 1px solid rgb(0 0 0 / 0.08); outline-offset: -1px;
  }
  .photo-tile img.product-photo-tile { object-fit: contain; background: var(--sp-surface); }
}

@layer components {
  /* ── Mailbox (ADR-11 Wijziging 5): folders beside the list from 900 px, above it below ── */
  .mailbox { display: grid; gap: var(--sp-space-6); }
  @media (min-width: 900px) { .mailbox { grid-template-columns: minmax(10rem, 14rem) 1fr; align-items: start; } }
  .mailbox__folder-list { display: flex; flex-wrap: wrap; gap: var(--sp-space-2); margin: 0; padding: 0; list-style: none; }
  @media (min-width: 900px) { .mailbox__folder-list { flex-direction: column; } }
  .mailbox__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-space-4); }
  .mailbox__folder {
    display: flex; align-items: center; min-height: var(--sp-hit); padding: 0 var(--sp-space-5);
    border-radius: var(--sp-radius-s); color: inherit; text-decoration: none; overflow-wrap: anywhere;
  }
  .mailbox__folder:hover { background: var(--sp-surface-hover); }
  /* The current folder: bold and a bar, not colour alone. */
  .mailbox__folder[aria-current="page"] { background: var(--sp-surface-selected); font-weight: var(--sp-weight-semibold); box-shadow: inset 3px 0 0 var(--sp-accent); }
  .mail-list { display: grid; margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--sp-border); }
  .mail-list__item { border-bottom: 1px solid var(--sp-border); }
  .mail-list__link {
    display: grid; gap: var(--sp-space-1); min-height: var(--sp-hit); padding: var(--sp-space-4) var(--sp-space-3);
    color: inherit; text-decoration: none; min-width: 0;
  }
  .mail-list__link:hover { background: var(--sp-surface-hover); }
  .mail-list__from, .mail-list__subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mail-list__meta { color: var(--sp-text-muted); font-size: var(--sp-text-xs); }
  /* Unread: bold and a dot before the sender (the dot is not the only sign: the text says it too). */
  .mail-list__item--unread .mail-list__from, .mail-list__item--unread .mail-list__subject { font-weight: var(--sp-weight-semibold); }
  .mail-list__item--unread .mail-list__from::before { content: "● "; color: var(--sp-accent); }
  .mail-frame { width: 100%; min-height: 32rem; height: 70vh; border: 1px solid var(--sp-border-strong); border-radius: var(--sp-radius-s); }
  /* A photo with its annotation, and the editor (annotate.js). The stage gets the photo's aspect
     ratio from the script. While drawing, touch-action keeps a finger drawing instead of scrolling;
     "Verplaatsen" (.is-moving) gives scrolling and zooming back. The toolbar stays in view right
     above the photo, so tools and "ongedaan maken" are at hand on a phone. */
  .annotate-figure { margin: 0; display: grid; gap: var(--sp-space-4); justify-items: start; }
  .annotate-figure img { display: block; max-width: 100%; max-height: 70vh; max-height: 70dvh; width: auto; height: auto; border-radius: var(--sp-radius-s); }
  .pre-line { white-space: pre-line; }
  .link-target { display: inline-flex; align-items: center; min-height: var(--sp-hit); }
  .annotate-toolbar {
    position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; gap: var(--sp-space-4) var(--sp-space-6); align-items: end;
    padding: var(--sp-space-4) 0; background: var(--sp-surface); border-bottom: 1px solid var(--sp-border);
  }
  .annotate-toolbar .choices legend { margin-bottom: var(--sp-space-2); font-size: var(--sp-text-xs); }
  .annotate-toolbar .segmented label { min-height: var(--sp-hit); gap: var(--sp-space-3); padding: 0 var(--sp-space-5); }
  .annotate-toolbar__actions { display: flex; flex-wrap: wrap; gap: var(--sp-space-4); }
  .annotate-swatch { width: 1rem; height: 1rem; border-radius: 50%; border: 1px solid var(--sp-border-ink); background: var(--swatch); }
  .annotate-swatch[data-color="rood"] { --swatch: var(--sp-annot-rood); }
  .annotate-swatch[data-color="geel"] { --swatch: var(--sp-annot-geel); }
  .annotate-swatch[data-color="blauw"] { --swatch: var(--sp-annot-blauw); }
  .annotate-swatch[data-color="wit"] { --swatch: var(--sp-annot-wit); }
  .annotate-swatch[data-color="zwart"] { --swatch: var(--sp-annot-zwart); }
  .annotate-stage { position: relative; width: 100%; max-width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; background: var(--sp-surface-sunken); border-radius: var(--sp-radius-s); overflow: hidden; }
  .annotate-stage.is-moving { touch-action: pan-x pan-y pinch-zoom; }
  .annotate-stage.is-moving .annotate-layer { cursor: grab; }
  .annotate-stage img { display: block; width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
  .annotate-layer { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
  .annotate-status { min-height: 1.5em; margin: 0; }
  @media (forced-colors: active) { .annotate-swatch, .annotate-layer { forced-color-adjust: none; } }
}
