/* =========================================================
   Klar — sheet dialog
   ----------------------------------------------------------
   Dialogs stay in the mobile context: a readable title, a close
   button, focus led in and returned, Escape and Cancel changing
   nothing (UIUX.md).

   The reference positions its dialog against the phone frame with
   inline styles. In production there is no frame, so the sheet is
   simply centred in the viewport and capped at the content width —
   which is also what keeps it inside a 320 px screen.
   ========================================================= */

dialog.sheet {
  padding: 6px 0 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 25px;
  width: min(var(--container-max), calc(100vw - 24px));
  max-height: min(680px, calc(100dvh - 40px));
  overflow: auto;
  box-shadow: var(--shadow-lg);
  margin: auto;
  overscroll-behavior: contain;
}

dialog.sheet::backdrop {
  background: rgba(22, 39, 31, 0.4);
  backdrop-filter: blur(3px);
}

.sheet__head {
  padding: 20px 20px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.sheet__head h2 {
  font-size: var(--text-xl);
  overflow-wrap: anywhere;
  min-width: 0;
}

.sheet__content {
  padding: 8px 20px;
  display: grid;
  gap: 18px;
  min-width: 0;
}

.sheet__content > * {
  min-width: 0;
}

/* F3: "Duplizieren" (``variantActionsSheet``) is a write, so it is a
 * ``<form>`` rather than a link -- but the other entries in that sheet's
 * content are plain buttons/links, and a ``<form>`` sitting among them as its
 * own grid item would still stretch to the same width, only through an extra
 * box. ``display: contents`` dissolves that box so the form's one button
 * becomes a direct grid item, indistinguishable from a sibling
 * ``<a class="btn--block">``. Scoped to this one sheet: other sheets nest a
 * ``<form>`` with real layout of its own (labels, hidden fields) inside
 * ``.sheet__content``, and dissolving those forms' boxes is not this rule's
 * job. */
#variantActionsSheet .sheet__content > form {
  display: contents;
}

/* Gestapelt, nicht nebeneinander -- aus zwei Gruenden, die beide zaehlen.
 *
 * Die Konzeptform: ``dialog-delete-recipe`` stellt ``secondary.full`` ueber
 * ``primary.full``, zwei Knoepfe in voller Breite untereinander. Unsere
 * Markup-Reihenfolge stimmt damit bereits ueberein.
 *
 * Und die Sicherheit: nebeneinander teilen sich „Abbrechen" und „Endgueltig
 * loeschen" eine Kante, und die zerstoerende Aktion liegt rechts, wo der
 * Daumen ohnehin ruht. Gestapelt liegen rund 60 px dazwischen. Das wiegt
 * schwerer, seit die Bestaetigung nicht mehr rot gefuellt ist, sondern
 * ``primary`` wie im Kit -- wir haben die Warnfarbe abgegeben, also nehmen wir
 * uns den Abstand.
 *
 * ``.sheet__actions > .btn`` ist entfallen: im Raster ist jedes Kind schon
 * voll breit, die Flex-Zeile brauchte die Regel nur, um es zu erzwingen.
 *
 * Benannte Abweichung: das Konzept hat gar keinen Aktionsblock, seine Knoepfe
 * stehen im ``sheet-content`` mit dessen 18 px Abstand. Unserer ist ein
 * eigener gepolsterter Bereich; 18 px zwischen zwei Knoepfen darin saehen
 * verloren aus, deshalb bleiben es 9. */
.sheet__actions {
  display: grid;
  gap: 9px;
}

/* Der Mahlzeitenbogen ist der einzige mit einer langen, scrollenden Liste.
 * Seine Hauptaktion bleibt deshalb unten stehen, so wie ``.sheet__head`` oben
 * stehen bleibt: sonst wandert „Auswahl übernehmen" bei vielen Mahlzeiten aus
 * dem Bild, und die einzige Art, die Auswahl durchzusetzen, wäre erst zu
 * scrollen. Das eigene Polster, weil ``.sheet__actions`` keines mitbringt --
 * jede Verwendung setzt ihres selbst (siehe ``.sheet--household``). */
.sheet__actions--anchored {
  position: sticky;
  bottom: 0;
  z-index: 1;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

/* Household forms retain separate Django POST actions while sharing the
   reference's inset, vertically spaced dialog layout. */
.sheet--household {
  --household-inset: 20px;
}

.sheet--household .household-permissions {
  border: 0;
  padding: 0;
  margin: 0;
  min-inline-size: 0;
  display: grid;
  gap: 18px;
}

.sheet--household .sheet__actions {
  padding: 0 var(--household-inset) 22px;
}

.sheet--household .sheet__content .hint {
  margin: 0;
}

.sheet--household form + form {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.sheet--household .permission-row > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.sheet--household .permission-row input {
  flex-shrink: 0;
}

/* A choice row inside a sheet: label left, meaning right. */
.sheet__choice {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  padding: 13px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 52px;
  font-size: var(--text-base);
  color: inherit;
  text-decoration: none;
  align-items: center;
}

.sheet__choice small {
  color: var(--muted);
  display: block;
  font-size: var(--text-xs);
  margin-top: 5px;
}

/* An action list: one destination per row, 60 px tall. */
.sheet__list {
  display: grid;
  gap: 5px;
}

.sheet__list > a,
.sheet__list > button {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 10px;
  border: 0;
  background: var(--surface);
  text-align: left;
  border-radius: 12px;
  font-size: var(--text-base);
  font-weight: 700;
  color: inherit;
  text-decoration: none;
  width: 100%;
}

.sheet__list > a:hover,
.sheet__list > button:hover {
  background: var(--bg);
}

.sheet__list .sheet__caret {
  margin-left: auto;
  color: var(--muted);
  flex-shrink: 0;
}

/* A radio list of fixed types (new meal, copy target). */
.sheet__radio-list {
  display: grid;
  gap: 8px;
}

.sheet__radio-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  font-size: var(--text-base);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-weight: 600;
}

.sheet__radio-list input {
  width: 17px;
  height: 17px;
  min-width: 17px;
  accent-color: var(--accent);
}

.sheet__radio-list svg {
  color: var(--accent);
  width: 19px;
  height: 19px;
}

/* F2's multi-select picker (several checked options at once): the label
   grows with its content -- a nutrient line plus a subline -- so it starts
   at the top rather than centering, and the checkbox itself keeps the plain
   list styling above. */
.sheet__radio-list--multi label {
  align-items: flex-start;
}

.sheet__radio-list label.is-disabled {
  opacity: 0.45;
}

.sheet__option-body {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.sheet__option-body small {
  color: var(--muted);
  font-size: var(--text-xs);
}

/* ---------------------------------------------------------- Bottom-Sheet (F2)
   Unten verankert statt zentriert: Inhaltsbreite bis ``--container-max``,
   Rundung nur oben, Kante unten, Abstand für die Geste. Die Höchsthöhe ist
   die aller Sheets (``dialog.sheet``); darüber scrollt der Inhalt bei
   feststehendem Kopf und Hauptknopf (``.sheet__actions--anchored``).
   ``max-width: none`` hebt die Grenze des Browsers für modale Dialoge auf
   (``calc(100% - 6px - 2em)``), damit das Sheet randbündig steht. */
dialog.sheet.sheet--bottom {
  width: min(var(--container-max), 100%);
  max-width: none;
  margin: auto auto 0;
  border-radius: 25px 25px 0 0;
  border-bottom-width: 0;
}

dialog.sheet.sheet--bottom .sheet__actions--anchored {
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

/* Auswahlliste mit Kästchen (Durchschnitt, F2; Eintragskorrektur): Radio und
   Checkbox zeichnen dasselbe Kästchen -- ein runder Ring (22 px, 2 px
   ``--muted``), gewählt eine Akzentfläche mit weißem Haken, gesperrt ein
   blasser Ring. Die Eingaben bleiben echte Radios und Checkboxen (Tastatur,
   Skript, Vorleser); nur ihr Aussehen ist gleich. Die gewählte Zeile trägt
   Tönung und einen 1,5-px-Akzentrahmen (1 px Rahmen plus 0,5 px Innenlinie),
   im Durchschnitt auch mehrere zugleich. Der Fokusring sitzt 2 px außerhalb
   und ist 3 px dick, so bleibt er vom Rahmen der Wahl unterscheidbar.
   Gesperrte Zeilen (``.is-disabled``) behalten die Optik der App. */
.sheet__radio-list--choice label:not(.is-disabled) {
  cursor: pointer;
}

.sheet__radio-list--choice label:not(.is-disabled):has(input:checked) {
  border-color: var(--accent);
  background: var(--tint);
  box-shadow: inset 0 0 0 0.5px var(--accent);
}

.sheet__radio-list--choice label:has(input:focus-visible) {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Der Ring an der Zeile ist der einzige Fokusanzeiger; der eigene Ring der Eingabe entfällt. */
.sheet__radio-list--choice input:focus-visible {
  outline: none;
}

.sheet__radio-list--choice input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 22px;
  height: 22px;
  min-width: 22px;
  margin: -1px 0 0;
  border: 2px solid var(--muted);
  border-radius: 50%;
  background: var(--surface) center / 14px no-repeat;
}

.sheet__radio-list--choice input:checked {
  border-color: var(--accent);
  background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}

.sheet__radio-list--choice input:disabled {
  border-color: var(--muted);
  background-color: var(--bg);
}

@media (forced-colors: active) {
  .sheet__radio-list--choice input:checked {
    background-color: Highlight;
    border-color: Highlight;
    forced-color-adjust: none;
  }
}

/* ------------------------------------------- tool row and "select all" (UX2)
   A row above the list of a sheet: its tools on the right, an optional hint
   on the left taking the rest.

   The switch "Alle auswählen / abwählen" (``components/average_select_all.html``)
   is the shared small outline button -- 44 px tall, the build of the variant
   picker's sort button -- and only adds what keeps it on one line.

   While its question is open (F14) the switch is hidden and the block takes
   the whole row; ``recipe-average-picker.js`` sets ``is-asking`` for that. The
   question is set apart quietly, tinted like the explanation cards of the
   smart sheet (``.smart-card``): the two answers side by side, one below the
   other on narrow phones, each with its short word and the number of variants
   as a second line. */
.sheet__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.sheet__tools > .hint {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
}

.select-all {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 0;
}

.select-all.is-asking {
  flex: 1 0 100%;
  align-items: stretch;
}

.select-all__toggle {
  flex: none;
  gap: 5px;
  white-space: nowrap;
}

.select-all__toggle svg {
  width: 15px;
  height: 15px;
}

/* On touch a hover sticks to the button that was tapped. The switch stays in
   its place after the tap, so the accent of ``.btn--outline:hover`` would
   remain on it and read as a state. */
@media (hover: none) {
  .select-all__toggle:hover {
    border-color: var(--line);
    color: var(--ink);
  }
}

.select-all__ask {
  display: grid;
  gap: 8px;
  padding: 12px 12px 6px;
  border-radius: var(--radius-md);
  background: var(--bg);
}

.select-all__question {
  color: var(--ink);
  font-size: var(--text-base);
  font-weight: 750;
  line-height: 1.4;
  overflow-wrap: break-word;
}

.select-all__choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

/* Narrow side padding: at 360 px the second line ("je Portion · 12 Varianten")
   then still fits beside the other answer without wrapping. */
.select-all__choice {
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 9px 6px;
}

.select-all__choice strong,
.select-all__choice small {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.select-all__choice small {
  font-size: var(--text-xs);
  font-weight: 600;
}

@media (max-width: 350px) {
  .select-all__choices {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 350px) {
  .sheet--household {
    --household-inset: 15px;
  }
  dialog.sheet {
    border-radius: 20px;
    width: calc(100vw - 16px);
  }
  dialog.sheet.sheet--bottom {
    width: 100%;
    border-radius: 20px 20px 0 0;
  }
  .sheet__head,
  .sheet__content {
    padding-left: 15px;
    padding-right: 15px;
  }
}
