/* Wuckel Supplies - Layout fuer Handys ab 360 dp Breite (S25, OnePlus 8 Pro). */

:root {
  --accent: #E2690C;
  --accent-ink: #FFFFFF;
  --accent-weak: #E2690C22;

  --bg: #F4F4F2;
  --surface: #FFFFFF;
  --surface-2: #EDEDEA;
  --ink: #1B1D1F;
  --muted: #6A6F75;
  --faint: #9AA0A6;
  --line: #DFDFDB;

  --ok: #4C8C2B;
  --warn: #D99100;
  --bad: #CC3B30;

  --radius: 12px;
  --row-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131416;
    --surface: #1D1F22;
    --surface-2: #26292D;
    --ink: #ECEDEE;
    --muted: #9BA1A8;
    --faint: #6C7278;
    --line: #2F3337;

    --ok: #6FBF3F;
    --warn: #E8A72A;
    --bad: #E8564A;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
  font-size: 16px;
  overscroll-behavior-y: contain;
  padding-bottom: calc(64px + var(--safe-b));
}

button, input, select { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
.hidden { display: none !important; }

/* ------------------------------------------------------------------ Kopfzeile */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--accent);
  padding: 10px 12px calc(10px + env(safe-area-inset-top, 0px));
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  display: flex; flex-direction: column; gap: 10px;
}
.topbar-row { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.topbar h1 { font-size: 19px; font-weight: 600; color: var(--accent-ink); flex: 1; }
.topbar .sub { font-size: 12px; color: #FFFFFFCC; font-weight: 400; }

.icon-btn {
  width: 38px; height: 38px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px; color: var(--accent-ink); font-size: 20px;
}
.icon-btn:active { background: #00000022; }

.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: #FFFFFF; flex: none; }
.sync-dot.live { background: #8BE07A; }
.sync-dot.offline { background: #FFD166; }
.sync-dot.error { background: #FF7A6E; }

.addbar { display: flex; gap: 8px; position: relative; }
.addbar input {
  flex: 1; min-width: 0;
  background: var(--surface); border: none; border-radius: 10px;
  padding: 11px 12px; font-size: 16px;
}
.addbar input:focus { outline: 2px solid #00000033; }

/* Vorschlaege waehrend des Tippens */
.ac {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 8px 24px #00000033;
  max-height: 52vh; overflow-y: auto;
}
.ac-row { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); }
.ac-row:last-child { border-bottom: none; }
.ac-row:active { background: var(--surface-2); }
.ac-row .ac-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-row .ac-note { font-size: 12px; color: var(--muted); flex: none; }
.ac-row.new .ac-name { color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------------- Modi */

.modebar { display: flex; gap: 6px; padding: 10px 12px 0; }
.modebar button {
  flex: 1; padding: 7px 4px; border-radius: 999px;
  font-size: 13px; color: var(--muted);
  background: var(--surface-2);
}
.modebar button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

main { padding: 10px 12px 24px; }

.group-head {
  display: flex; align-items: center; gap: 8px;
  padding: 16px 2px 6px; font-size: 12px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.group-head .gh-count { margin-left: auto; text-transform: none; letter-spacing: 0; color: var(--faint); }

.empty {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 32px 18px; text-align: center; color: var(--muted); font-size: 14px;
}

/* -------------------------------------------------------------------- Zeilen */

.card { background: var(--surface); border-radius: var(--radius); overflow: hidden; }

.row {
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px; min-height: var(--row-h);
  border-bottom: 1px solid var(--line);
  position: relative;
}
.card .row:last-child { border-bottom: none; }
.row:active { background: var(--surface-2); }

.cat-dot {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; line-height: 1;
}

/* Gezeichnete Symbole (Lagerorte). Nehmen Groesse und Farbe vom Elternteil. */
.gi {
  width: 1.15em; height: 1.15em; flex: none;
  fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -0.2em;
}
.cat-dot .gi { width: 19px; height: 19px; }
/* In der Ueberschrift steht das Symbol neben Grossbuchstaben und traegt die
   Bedeutung (schmal/breit, Faecher/Schubladen) -- deshalb bewusst groesser
   als die Schrift, sonst verschwimmen die Innenlinien. */
.group-head .gi { width: 18px; height: 18px; vertical-align: -0.35em; margin-right: 2px; }
.row-sub .gi { width: 14px; height: 14px; vertical-align: -0.25em; margin-right: 1px; }

.row-main { flex: 1; min-width: 0; padding: 8px 0; }
.row-name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 11.5px; color: var(--faint); margin-top: 2px; }

/* Fuellstandsbalken: Ist/Soll auf einen Blick */
.bar { height: 3px; border-radius: 2px; background: var(--surface-2); margin-top: 5px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 2px; }
.bar.lvl-0 > i { background: var(--bad); }
.bar.lvl-1 > i { background: var(--warn); }
.bar.lvl-2 > i { background: var(--ok); }

.row-qty { flex: none; text-align: right; min-width: 62px; }
.row-qty .q { font-size: 14px; font-variant-numeric: tabular-nums; }
.row-qty .q.lvl-0 { color: var(--bad); font-weight: 600; }
.row-qty .q.lvl-1 { color: var(--warn); font-weight: 600; }
.row-qty .q.lvl-2 { color: var(--muted); }
.row-qty .age { font-size: 11px; color: var(--faint); margin-top: 1px; }
.row-qty .age.due { color: var(--warn); }
.row-qty .age.never { color: var(--bad); }

.tick {
  width: 26px; height: 26px; flex: none; border-radius: 7px;
  border: 2px solid var(--faint);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: transparent;
}
.tick.on { background: var(--ok); border-color: var(--ok); color: #fff; }

.row.done .row-name { text-decoration: line-through; }
.row.done { opacity: .45; }

.pill {
  flex: none; font-size: 10.5px; padding: 2px 7px; border-radius: 999px;
  background: var(--accent-weak); color: var(--accent); font-weight: 600;
}
@media (prefers-color-scheme: dark) { .pill { color: #FFB273; } }

/* ------------------------------------------------------------ Aufgeklappte Zeile */

.detail { padding: 4px 12px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.detail-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.detail-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); width: 100%; }

.step { display: flex; align-items: center; gap: 2px; background: var(--surface); border-radius: 10px; overflow: hidden; }
.step button { width: 42px; height: 40px; font-size: 20px; color: var(--ink); }
.step button:active { background: var(--surface-2); }
.step .val {
  min-width: 56px; text-align: center; font-size: 16px;
  font-variant-numeric: tabular-nums; padding: 0 4px;
}

.btn {
  padding: 9px 14px; border-radius: 10px; font-size: 14px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
}
.btn:active { background: var(--surface-2); }
.btn.primary { background: var(--ok); color: #fff; border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.wide { flex: 1; text-align: center; }

.detail input[type="text"], .detail input[type="number"], .detail select {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 10px; font-size: 15px; min-width: 0;
}
.detail input[type="text"] { flex: 1; }
.detail input[type="number"] { width: 78px; }

/* Kaufhaeufigkeit */
.freq { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); width: 100%; }
.freq .fbar { flex: 1; height: 4px; border-radius: 2px; background: var(--surface); overflow: hidden; max-width: 130px; }
.freq .fbar > i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

/* --------------------------------------------------------------- Vorschlaege */

.sugg { margin-top: 22px; }
.sugg-head { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 11px; border-radius: 999px;
  border: 1px dashed var(--line); color: var(--muted);
  font-size: 13px; background: transparent;
}
.chip:active { background: var(--surface-2); }
.chip .chip-emoji { font-size: 13px; }
.chip .fbar { width: 22px; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.chip .fbar > i { display: block; height: 100%; background: var(--faint); }

/* ------------------------------------------------------------------ Fusszeile */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar button {
  flex: 1; padding: 8px 2px 9px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10.5px; color: var(--muted);
}
.tabbar button .tb-icon { font-size: 20px; line-height: 1.1; }
.tabbar button.on { color: var(--accent); font-weight: 600; }
.tabbar .badge {
  position: absolute; transform: translate(14px, -4px);
  background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 17px; height: 17px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* ------------------------------------------------------------------- Overlays */

.sheet-bg {
  position: fixed; inset: 0; z-index: 40;
  background: #00000077; display: flex; align-items: flex-end;
}
.sheet {
  background: var(--bg); width: 100%; max-height: 88vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 16px 14px calc(20px + var(--safe-b));
}
.sheet h2 { font-size: 17px; font-weight: 600; }
.sheet .sheet-note { font-size: 13px; color: var(--muted); margin-bottom: 14px; }

/* Haftet oben am Blatt, mit deckendem Grund -- sonst scheint der Inhalt
   darunter durch, waehrend man scrollt. */
.sheet-head {
  position: sticky; top: 0; z-index: 6;
  display: flex; align-items: center; gap: 10px;
  background: var(--bg);
  padding: 4px 0 10px; margin-bottom: 4px;
  box-shadow: 0 6px 10px -8px #00000055;
}
.sheet-head h2 { flex: 1; min-width: 0; }
.sheet-close {
  width: 38px; height: 38px; flex: none; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 21px; color: var(--muted);
}
.sheet-close:active { background: var(--surface-2); }

.catrow { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.catrow:last-child { border-bottom: none; }
.catrow .cat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.catrow .move { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 17px; border-radius: 8px; }
.catrow .move:active { background: var(--surface-2); }
.catrow .move[disabled] { opacity: .25; }

/* --------------------------------------------------------------- Rezepte */

.rgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.rcard {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 10px;
  min-height: 116px; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.rcard:active { background: var(--surface-2); }
.rcard-emoji { font-size: 30px; line-height: 1; }
.rcard-name {
  font-size: 14px; font-weight: 500; line-height: 1.25;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.rcard-img {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover;
  border-radius: 8px; display: block;
}
.rcard:has(.rcard-img) { padding: 8px; gap: 7px; }
.rcard-foot { font-size: 11px; color: var(--faint); }
.rcard-foot.ok { color: var(--ok); }
.rcard-foot.miss { color: var(--warn); }
.rcard-foot.unknown { color: var(--muted); }
.rcard.dim .rcard-emoji, .rcard.dim .rcard-name, .rcard.dim .rcard-img { opacity: .45; }

.rsheet-img {
  width: 100%; max-height: 190px; object-fit: cover;
  border-radius: 12px; display: block; margin-bottom: 12px;
}
.rcard.geplant { border-color: var(--accent); border-width: 2px; }
.rcard.add { color: var(--faint); font-size: 30px; border-style: dashed; }

.ingrow {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-bottom: 1px solid var(--line);
}
.ingrow:last-child { border-bottom: none; }
.ingrow .row-sub.ok { color: var(--ok); }
.ingrow .row-sub.miss { color: var(--bad); }
.ingrow .row-sub.unknown { color: var(--warn); }
.ingrow input[type="number"] {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 8px; font-size: 14px; flex: none;
}
#ingHits { margin-top: 8px; }

/* ---------------------------------------------------------------- Zettel */

.sheet textarea {
  width: 100%; font: inherit; font-size: 16px; font-family: inherit;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; resize: vertical; min-height: 76px;
}
.sheet textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.notecard { border-bottom: 1px solid var(--line); padding: 4px 0 10px; }
.notecard:last-child { border-bottom: none; }
.note-body { flex: 1; min-width: 0; }
.note-text { font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; display: block; }
.note-text.clamp {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.notecard.done { opacity: .55; }
.notecard.done .note-text { text-decoration: line-through; }
.note-act { width: 32px; height: 32px; font-size: 15px; color: var(--faint); flex: none; margin-left: auto; }
.notecard.editing { padding: 10px 12px; }
.notecard.editing .detail-row { margin-top: 8px; }

/* Ganze Zeile ist der Aufklapp-Knopf. */
.note-open {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  width: 100%; text-align: left; padding: 8px 12px;
}
.note-open:active { background: var(--surface-2); }
.notecard .detail-row, .notecard .thread { padding: 0 12px; }

.stpill {
  font-size: 10.5px; font-weight: 600; letter-spacing: .03em;
  padding: 2px 8px; border-radius: 999px;
}
.st-pruefen { background: var(--accent-weak); color: var(--accent); }
.st-offen   { background: var(--surface-2); color: var(--muted); }
.st-fertig  { background: var(--surface-2); color: var(--faint); }
@media (prefers-color-scheme: dark) { .st-pruefen { color: #FFB273; } }

.pill.accent { background: var(--accent); color: #fff; }

/* Kommentarfaden: eingerueckt, eigener Grund, eigene Ueberschrift. Damit ist
   beim Scrollen erkennbar, dass man noch im selben Zettel steckt. */
.thread {
  margin: 8px 0 4px 12px;
  border-left: 3px solid var(--accent-weak);
  background: var(--surface-2);
  border-radius: 0 10px 10px 0;
  padding: 8px 10px 10px;
}
@media (prefers-color-scheme: dark) { .thread { border-left-color: #E2690C66; } }
.thread-kopf {
  font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--faint); margin-bottom: 6px;
}
.cmt {
  position: relative;
  padding: 6px 30px 7px 24px;
  border-top: 1px solid var(--line);
}
.cmt:first-of-type { border-top: none; }
.cmt-head { font-size: 11px; color: var(--faint); margin-top: 3px; }
.cmt-text { font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Beide Knoepfe in den oberen Ecken statt in einer eigenen Zeile. */
.cmt-act {
  position: absolute; top: 4px;
  width: 24px; height: 24px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--faint);
}
.cmt-act.links  { left: -2px; }
.cmt-act.rechts { right: 0; }
.cmt-act:active { background: var(--surface); }
.notecard .detail-row input[type="text"],
.notecard .detail-row textarea {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font-size: 15px; min-width: 0;
}
/* Umbricht statt einzeilig wegzuscrollen -- lange Kommentare bleiben lesbar. */
.notecard .detail-row textarea {
  flex: 1; font: inherit; font-size: 15px; font-family: inherit;
  resize: vertical; min-height: 58px; line-height: 1.4;
}

.toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(74px + var(--safe-b)); z-index: 50;
  background: var(--ink); color: var(--bg);
  border-radius: 10px; padding: 11px 14px; font-size: 14px;
  display: flex; align-items: center; gap: 10px;
}
.toast button { color: var(--bg); font-weight: 600; margin-left: auto; text-decoration: underline; }

/* Zutat im Rezeptblatt: Name und Symbol klappen den Artikel-Editor auf. */
.ing-open {
  display: flex; align-items: center; gap: 10px;
  flex: 1; min-width: 0; text-align: left; padding: 2px 0;
}
.ing-open:active { opacity: .6; }
.ing-open .row-main { display: block; flex: 1; min-width: 0; }
.ing-open .row-name, .ing-open .row-sub { display: block; }
.ingrow + .detail { margin-top: -2px; }

/* Zutat-Suche im Rezeptblatt: Treffer schweben darueber, damit der Inhalt
   beim Tippen nicht auf und ab springt. */
.ingsearch { position: relative; flex: 1; min-width: 0; }
.ingsearch input {
  width: 100%; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 10px; font-size: 15px;
}
.ingsearch .ac { top: calc(100% + 4px); }

/* Im Einkauf hakt nur noch die Box ab. Damit sie trotzdem bequem zu treffen
   ist, bekommt sie eine unsichtbar vergroesserte Trefferflaeche. */
.row .tick { position: relative; }
.row .tick::after { content: ""; position: absolute; inset: -11px -8px; }

/* Unterteilung der erledigten Zettel nach Bereich. */
.group-head.sub {
  padding-top: 10px; padding-left: 12px;
  font-size: 11px; color: var(--faint); text-transform: none; letter-spacing: 0;
}
/* Zweite Zahl auf der Rezeptkarte ("1 fehlt · 8 unklar"). */
.rcard-foot .u2 { color: var(--muted); }

/* Wartende PDFs im Posteingang, einer pro Zeile. */
.pdfliste { margin-top: 8px; border-left: 2px solid var(--line); }
.pdfzeile { padding: 5px 0 5px 10px; display: flex; gap: 10px; align-items: baseline; }
.pdfname { flex: 1; min-width: 0; font-size: 13px; overflow-wrap: anywhere; }
.pdfmeta { font-size: 11px; color: var(--faint); flex: none; }

/* Abgeblendete Rezeptkarte: nur das Bild abdunkeln, der Name muss lesbar
   bleiben -- bei 45 % war er kaum noch zu entziffern. */
.rcard.dim .rcard-name { opacity: 1; color: var(--muted); }
.rcard.dim .rcard-emoji, .rcard.dim .rcard-img { opacity: .55; }


/* Einklappbare Abschnitte im Zettel-Blatt. Deutlich groesser und kontrastreicher
   als die alten Ueberschriften -- in der langen Liste waren sie kaum zu lesen. */
.klapp {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 11px 12px; margin-top: 12px;
  border-radius: 10px; background: var(--surface-2);
  color: var(--ink); text-align: left;
}
.klapp:active { filter: brightness(.94); }
.klapp.haupt { font-size: 15px; font-weight: 600; }
.klapp.sub {
  font-size: 13.5px; font-weight: 500; margin-top: 8px; margin-left: 10px;
  background: transparent; border: 1px solid var(--line);
}
.klapp-text { flex: 1; min-width: 0; }
.klapp-zahl {
  flex: none; font-size: 12px; font-weight: 600;
  color: var(--muted); background: var(--surface);
  border-radius: 999px; padding: 1px 9px;
}
.klapp-pfeil { flex: none; font-size: 12px; color: var(--muted); transition: transform .12s; }
.klapp.zu .klapp-pfeil { transform: rotate(-90deg); }

/* Eingabefelder in den Blaettern. Ohne das nimmt der Browser seine Vorgabe --
   weisser Grund mitten im dunklen Blatt. */
.sheet input[type="text"], .sheet input[type="number"], .sheet select {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 10px; font-size: 15px; min-width: 0;
}
.sheet .catrow input[type="text"] { border: none; }
