/*
 * Zone wizard (sheets/zone-wizard/, components/step-container.js) and its
 * entries on the Zones page. Reads tokens only; animates transform and
 * opacity only (the Pi 4's GPU). Touch targets 48 px on the kiosk, 44 px
 * elsewhere; nothing below 13 px.
 */
@layer pages {
  /* ------------------------------------------------------------------
     The sheet: tall like the zone sheet, so a step change never moves
     its top edge; "Selbst eintragen" in the head
     ------------------------------------------------------------------ */
  .sheet.zone-wizard-sheet {
    width: min(880px, 100%);
    height: calc(100dvh / var(--display-zoom) - var(--header-height) - var(--space-2));
  }

  .zw-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  .zw-toolbar-label {
    color: var(--text-secondary);
  }

  /* ------------------------------------------------------------------
     Step container: progress under the head, steps that slide 48 px
     ------------------------------------------------------------------ */
  .step-container {
    display: flex;
    flex-direction: column;
  }

  .step-progress.progress {
    flex: none;
    height: 4px;
    margin: 0 0 var(--space-4);
    border-radius: 2px;
  }

  .step-stage {
    position: relative;
  }

  /* The step that leaves lies over the new one while it fades. */
  .step-pane.is-leaving {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    pointer-events: none;
  }

  .zone-wizard {
    padding-bottom: var(--space-5);
  }

  .zw-draft {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin: 0 0 var(--space-3);
    padding: var(--space-1) var(--space-1) var(--space-1) var(--space-4);
    border-radius: var(--radius-row);
    background: var(--surface-2);
    color: var(--text-secondary);
  }

  /* ------------------------------------------------------------------
     A step: the question left, the answers right (kiosk); stacked below
     760 px
     ------------------------------------------------------------------ */
  .zw-step,
  .zw-summary {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    align-items: start;
    gap: var(--space-4) var(--space-6);
  }

  .zw-aside,
  .zw-main {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 0;
  }

  /* The info button follows the question's last word, also when it wraps. */
  .zw-heading {
    min-height: 32px;
  }

  .zw-heading > .zw-title {
    display: inline;
  }

  .zw-heading > .info-button {
    margin-left: calc(-6px - var(--info-grow));
  }

  .zw-title {
    font-size: var(--type-title2-size);
    line-height: var(--type-title2-line);
    letter-spacing: var(--type-title2-tracking);
    font-weight: var(--weight-semibold);
    text-wrap: balance;
  }

  .zw-title:focus {
    outline: none;
  }

  .zw-lead {
    color: var(--text-secondary);
    text-wrap: pretty;
  }

  .zw-note,
  .zw-sub {
    font-size: var(--type-caption-size);
    line-height: var(--type-caption-line);
    letter-spacing: var(--type-caption-tracking);
    color: var(--text-secondary);
    text-wrap: pretty;
  }

  .zw-notice {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    color: var(--text-primary);
    text-wrap: pretty;
  }

  .zw-notice > .icon {
    flex: none;
    margin-top: 1px;
    color: var(--warning);
  }

  .zw-notice[data-tone="hint"] {
    color: var(--text-secondary);
  }

  /* A question that warns of nothing (a drip zone's measurement): no sign, the weight of a title. */
  .zw-notice[data-tone="question"] {
    font-weight: var(--weight-semibold);
  }

  .zw-eyebrow {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--success);
    font-weight: var(--weight-semibold);
  }

  /* ------------------------------------------------------------------
     Answers: a grouped list, one row per answer, a radio dot as control
     ------------------------------------------------------------------ */
  .answer-list {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: var(--radius-card);
    background: var(--surface-2);
  }

  .answer-row,
  .answer-switch {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 56px;
    padding: 6px var(--space-4);
    color: var(--text-primary);
    text-align: left;
  }

  .answer-row {
    width: 100%;
    transition: transform 100ms ease-out;
  }

  .answer-row + .answer-row {
    box-shadow: inset 0 1px 0 var(--hairline);
  }

  .answer-row[aria-checked="true"] {
    background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
  }

  /* Feedback on the press (press.js), a slight give. */
  .answer-row.is-pressed {
    background: var(--surface-3);
    transform: scale(0.98);
  }

  .answer-switch {
    border-radius: var(--radius-card);
    background: var(--surface-2);
  }

  .answer-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }

  .answer-title {
    font-size: var(--type-headline-size);
    line-height: var(--type-headline-line);
    letter-spacing: var(--type-headline-tracking);
    font-weight: var(--weight-medium);
  }

  .answer-example {
    font-size: var(--type-caption-size);
    line-height: var(--type-caption-line);
    letter-spacing: var(--type-caption-tracking);
    color: var(--text-secondary);
  }

  .answer-radio {
    position: relative;
    flex: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 2px var(--text-tertiary);
  }

  .answer-row[aria-checked="true"] .answer-radio {
    background: var(--accent);
    box-shadow: none;
  }

  .answer-row[aria-checked="true"] .answer-radio::after {
    content: "";
    position: absolute;
    inset: 8px;
    border-radius: 50%;
    background: var(--on-accent);
  }

  /* ------------------------------------------------------------------
     Area and soil
     ------------------------------------------------------------------ */
  .zw-area {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }

  .zw-area-mode {
    width: 100%;
  }

  .zw-area-fields .form-row {
    padding: 0;
  }

  .zw-area-fields.is-pair {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: end;
    gap: var(--space-2);
  }

  .zw-area-fields.is-pair .form-stepper {
    grid-template-columns: var(--control-height) minmax(0, 1fr) var(--control-height);
  }

  /* A narrow phone (a 390 px phone at the display size's larger step is 355 px): side by side the value between
     − and + had 36 px, under a finger's width (measured 2026-10-11); length and width stack, the × goes (it is a
     picture, aria-hidden), the labels say which is which. */
  @container app (max-width: 379px) {
    .zw-area-fields.is-pair {
      grid-template-columns: minmax(0, 1fr);
    }

    .zw-area-fields.is-pair .zw-times {
      display: none;
    }
  }

  .zw-times {
    padding-bottom: 12px;
    color: var(--text-secondary);
  }

  .zw-area-result {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-card);
    background: var(--surface-2);
  }

  .zw-area-result-label {
    color: var(--text-secondary);
  }

  .zw-area-result-value {
    font-size: var(--type-title2-size);
    line-height: var(--type-title2-line);
    letter-spacing: var(--type-title2-tracking);
    font-variant-numeric: tabular-nums;
  }

  /* Re-setup: the size so far under length × width (beside the area field it is the row's hint). */
  .zw-area-previous {
    margin: 0;
    text-align: center;
  }

  .zw-soil,
  .zw-mulch,
  .zw-cover,
  .zw-planting,
  .zw-planted {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .zw-cover-question,
  .zw-planted-question {
    font-weight: var(--weight-medium);
  }

  /* ------------------------------------------------------------------
     "Selbst eintragen": one column, the suggestion under a typed value
     ------------------------------------------------------------------ */
  .zw-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .zw-suggestion {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0 var(--space-3);
    font-size: var(--type-caption-size);
    line-height: var(--type-caption-line);
    color: var(--text-secondary);
  }

  /* ------------------------------------------------------------------
     Summary: name, output, automatic left; the answers right
     ------------------------------------------------------------------ */
  .zw-summary {
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  }

  /* A new zone: the title above the answers on the kiosk, above everything on a phone (where the focus goes). */
  .zw-summary.is-create {
    grid-template-columns: minmax(0, 0.74fr) minmax(0, 1.26fr);
    grid-template-areas:
      "aside heading"
      "aside main";
    grid-template-rows: auto 1fr;
    row-gap: var(--space-3);
  }

  .zw-summary.is-create > .summary-heading {
    grid-area: heading;
  }

  .zw-summary.is-create > .summary-aside {
    grid-area: aside;
  }

  .zw-summary.is-create > .summary-main {
    grid-area: main;
  }

  /* Kiosk: every row and the preview fit the sheet without scrolling. */
  :root[data-device="kiosk"] .zw-summary.is-create .summary-aside {
    gap: var(--space-2);
  }

  :root[data-device="kiosk"] .zw-summary.is-create .summary-aside .form-row {
    row-gap: var(--space-1);
  }

  :root[data-device="kiosk"] .zw-summary.is-create .zw-outputs {
    margin-top: 0;
  }

  /* The preview and its warnings in the caption size, like the reason beside the switch. */
  :root[data-device="kiosk"] .zw-summary.is-create .summary-preview,
  :root[data-device="kiosk"] .zw-summary.is-create .summary-aside .zw-notice {
    font-size: var(--type-caption-size);
    line-height: var(--type-caption-line);
    letter-spacing: var(--type-caption-tracking);
  }

  :root[data-device="kiosk"] .zw-summary.is-create {
    grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.3fr);
  }

  /* The labels' column holds the longest label: „Pflanzen“ and „Watering“ ran 1.8 and 3.7 px past 64 px (the layout
     probe's `spilled`, 2026-10-11). */
  :root[data-device="kiosk"] .zw-summary.is-create .summary-row {
    grid-template-columns: 70px minmax(0, 1fr) auto;
    min-height: max(48px, var(--touch-min));
    padding-top: var(--space-1);
    padding-bottom: var(--space-1);
  }

  /* Every row in view above the footer: the values keep the phone's caption size (tokens.css). */
  :root[data-device="kiosk"] .zw-summary.is-create .summary-values {
    font-size: var(--type-caption-compact-size);
    line-height: var(--type-caption-compact-line);
  }

  .summary-aside .form-row {
    padding: 0;
  }

  .summary-preview {
    text-wrap: pretty;
  }

  /* "26 m² übernehmen" under the area: its text in line with the field. */
  .zw-area-take {
    margin-inline-start: calc(-1 * var(--space-4));
  }

  /* The preview with its explanation beside it (the info button's hit area adds no height). */
  .summary-preview-row {
    display: flex;
    align-items: flex-start;
    gap: 6px;
  }

  .summary-preview-row > .summary-preview {
    flex: 1 1 auto;
    min-width: 0;
  }

  .summary-list {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: var(--radius-card);
    background: var(--surface-2);
  }

  .summary-item + .summary-item .summary-row {
    box-shadow: inset 0 1px 0 var(--hairline);
  }

  .summary-row {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    min-height: max(52px, var(--touch-min));
    padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
    color: var(--text-primary);
    text-align: left;
  }

  .summary-row.is-pressed {
    background: var(--surface-3);
  }

  .summary-label {
    color: var(--text-secondary);
  }

  .summary-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .summary-answer {
    font-weight: var(--weight-medium);
  }

  .summary-values {
    font-size: var(--type-caption-size);
    line-height: var(--type-caption-line);
    letter-spacing: var(--type-caption-tracking);
    color: var(--text-secondary);
    white-space: pre-line;
  }

  .summary-chevron {
    display: flex;
    color: var(--text-tertiary);
  }

  .zw-summary.is-resetup:not(.is-all) {
    grid-template-columns: minmax(0, 1fr);
  }

  .zw-summary.is-resetup:not(.is-all) .summary-aside {
    max-width: 560px;
  }

  .summary-changes {
    display: flex;
    flex-direction: column;
  }

  .summary-changes > li {
    padding: var(--space-2) 0;
    font-variant-numeric: tabular-nums;
  }

  .summary-changes > li + li {
    border-top: 1px solid var(--hairline);
  }

  .summary-rest {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    color: var(--text-secondary);
  }

  .zw-outputs {
    margin-top: var(--space-1);
  }

  /* "Durchfluss messen" in the zone's settings (zone/settings.js): beside the flow, not across. */
  .flow-block .flow-measure {
    justify-self: start;
  }

  /* ------------------------------------------------------------------
     Measurement
     ------------------------------------------------------------------ */
  .zw-enable {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }

  .measure-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-card);
    background: var(--surface-2);
    text-wrap: pretty;
  }

  .measure-card-title {
    font-size: var(--type-headline-size);
    line-height: var(--type-headline-line);
    letter-spacing: var(--type-headline-tracking);
    font-weight: var(--weight-semibold);
  }

  .measure-facts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-6);
  }

  .measure-fact {
    display: flex;
    flex-direction: column;
  }

  .measure-fact-value {
    font-size: var(--type-title3-size);
    line-height: var(--type-title3-line);
    letter-spacing: var(--type-title3-tracking);
    font-weight: var(--weight-semibold);
    font-variant-numeric: tabular-nums;
  }

  .measure-fact-caption,
  .measure-without {
    font-size: var(--type-caption-size);
    line-height: var(--type-caption-line);
    letter-spacing: var(--type-caption-tracking);
    color: var(--text-secondary);
  }

  .measure-live-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: var(--weight-semibold);
  }

  .measure-live-title > .icon {
    color: var(--accent);
  }

  .measure-progress.progress {
    margin-top: 0;
  }

  .measure-value {
    display: flex;
    align-items: baseline;
    gap: var(--space-1);
  }

  .measure-value-number {
    font-size: var(--type-title1-size);
    line-height: var(--type-title1-line);
    letter-spacing: var(--type-title1-tracking);
    font-weight: var(--weight-semibold);
    font-variant-numeric: tabular-nums;
  }

  .measure-value-unit {
    color: var(--text-secondary);
  }

  .measure-lines {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
  }

  /* ------------------------------------------------------------------
     Zones page: "+", the last tile "Zone hinzufügen", the empty state
     ------------------------------------------------------------------ */
  .zones-add {
    flex: none;
    margin-left: auto;
  }

  .zones-establishment:not([hidden]) ~ .zones-add {
    margin-left: 0;
  }

  /* The tiles and the add tile share one grid (the tile list owns .zones-grid). */
  .zones-grid {
    display: contents;
  }

  .zones-grid-wrap {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    grid-auto-rows: auto;
    align-content: start;
    gap: var(--space-3);
  }

  :root[data-device="kiosk"] .zones-grid-wrap {
    flex: 1 0 auto;
    align-content: stretch;
  }

  .zone-add-tile {
    justify-content: center;
    gap: var(--space-1);
    background: transparent;
    box-shadow: none;
    outline: 1.5px dashed var(--text-tertiary);
    outline-offset: -1.5px;
  }

  .zone-add-tile:disabled {
    background: transparent;
    color: var(--text-secondary);
  }

  .zone-add-head {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  .zone-add-icon {
    display: flex;
    color: var(--accent);
  }

  .zone-add-tile:disabled .zone-add-icon {
    color: var(--text-tertiary);
  }

  .zone-add-line {
    font-size: var(--type-caption-size);
    line-height: var(--type-caption-line);
    letter-spacing: var(--type-caption-tracking);
    color: var(--text-secondary);
    text-wrap: pretty;
  }

  .zones-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-12) var(--space-4);
    color: var(--text-secondary);
    text-align: center;
  }

  .zones-empty-title {
    font-size: var(--type-title3-size);
    line-height: var(--type-title3-line);
    letter-spacing: var(--type-title3-tracking);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
  }

  .zones-first {
    margin-top: var(--space-3);
  }

  /* ------------------------------------------------------------------
     Narrow screens: one column
     ------------------------------------------------------------------ */
  @container app (max-width: 759px) {
    .zw-step,
    .zw-summary,
    .zw-summary.is-create {
      grid-template-columns: minmax(0, 1fr);
    }

    .zw-summary.is-create {
      grid-template-areas:
        "heading"
        "aside"
        "main";
      grid-template-rows: auto;
    }

    .zw-toolbar {
      justify-content: space-between;
      width: 100%;
    }
  }

  @container app (max-width: 699px) {
    /* "+" stays in the title row, top right where a list adds; "Establishment now" takes the
       next row at 390 px (title, info, "+" and the button do not fit one row in either language). */
    .zones-add,
    .zones-establishment:not([hidden]) ~ .zones-add {
      order: 1;
      margin-left: auto;
    }

    .zones-establishment {
      order: 2;
      margin-left: 0;
    }

    .zones-grid-wrap {
      grid-template-columns: minmax(0, 1fr);
      gap: var(--space-2);
    }

    .zone-add-tile {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      min-height: 64px;
      padding: var(--space-3) var(--space-4);
    }

    .summary-row {
      grid-template-columns: 72px minmax(0, 1fr) auto;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .answer-row {
      transition: none;
    }

    .answer-row.is-pressed {
      transform: none;
    }
  }
}
