/* Oberfläche der Vorratsverwaltung.
 *
 * Das Farbsystem hat zwei Ebenen, die sich nicht ins Gehege kommen dürfen:
 * der Akzent (Indigo) markiert alles Bedienbare, die fünf Ampelfarben sagen
 * ausschließlich etwas über Haltbarkeit. Deshalb ist der Akzent bewusst kein
 * Grün, Gelb oder Rot — sonst läse man eine Schaltfläche als Warnung.
 */

:root {
  --grund:      #F7F6F2;
  --flaeche:    #FFFFFF;
  --flaeche-2:  #EFEEE8;
  --tinte:      #23241F;
  --leise:      #6B6D63;
  --linie:      #E3E1D8;
  --linie-fein: #EDEBE4;
  --akzent:     #33477A;
  --akzent-hell:#E8ECF6;
  --akzent-tief:#26355C;

  /* Ampel: abgelaufen → frisch. Zusätzlich zur Farbe trägt jeder Zustand ein
     Wort — Farbe allein schließt Menschen mit Rotsehschwäche aus. */
  --abgelaufen: #B23B32;  --abgelaufen-grund: #F8E7E5;
  --bald:       #B76A15;  --bald-grund:       #FAEEDD;
  --woche:      #8A7A15;  --woche-grund:      #F5F1D9;
  --frisch:     #3E7A45;  --frisch-grund:     #E6F0E5;
  --ohne:       #7C7F74;  --ohne-grund:       #EEEEE9;

  --rundung: 10px;
  --schatten: 0 1px 2px rgba(35,36,31,.05), 0 10px 26px -18px rgba(35,36,31,.45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --grund:      #141511;
    --flaeche:    #1C1E19;
    --flaeche-2:  #24271F;
    --tinte:      #E8E9E2;
    --leise:      #989B90;
    --linie:      #2C2F27;
    --linie-fein: #23261F;
    --akzent:     #93A9E0;
    --akzent-hell:#1E2536;
    --akzent-tief:#B9C7EE;

    --abgelaufen: #E88A81;  --abgelaufen-grund: #2E1A18;
    --bald:       #DDA45E;  --bald-grund:       #2C2213;
    --woche:      #CBBB5C;  --woche-grund:      #292611;
    --frisch:     #82BE8A;  --frisch-grund:     #16251A;
    --ohne:       #8E9188;  --ohne-grund:       #23261F;

    --schatten: 0 1px 2px rgba(0,0,0,.5), 0 12px 30px -20px rgba(0,0,0,.9);
  }
}

* { box-sizing: border-box; }

/* Ohne diese Zeile ist `hidden` wirkungslos, sobald ein Element irgendwo ein
   `display` bekommt — die Browservorgabe `[hidden] { display: none }` verliert
   dann gegen jede eigene Regel. Das betrifft hier die Reiter, den
   Ampelstreifen und die Fußzeile der Einkaufsliste, also genau das, was
   abwechselnd sichtbar sein soll. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--grund);
  color: var(--tinte);
  font-family: "Karla", ui-sans-serif, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 {
  font-family: "Bitter", ui-serif, Georgia, serif;
  font-weight: 600;
  line-height: 1.25;
  margin: 0;
  text-wrap: balance;
}
h1 { font-size: 1.7rem; }
h2 { font-size: 1.12rem; margin-top: 26px; }
h3 { font-size: .98rem; }
p { margin: 0; }
a { color: var(--akzent); text-underline-offset: 3px; }

.leise { color: var(--leise); }
.hinweis { color: var(--leise); font-size: .82rem; margin-top: 5px; }
.dehnen { flex: 1; }
.zahl, .mono { font-family: "Roboto Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }

:focus-visible { outline: 2px solid var(--akzent); outline-offset: 2px; border-radius: 4px; }

/* ── Bedienelemente ──────────────────────────────────────────────────── */
.knopf, .knopf-still {
  font: inherit;
  font-weight: 700;
  font-size: .88rem;
  padding: 9px 15px;
  border-radius: 8px;
  border: 1px solid var(--akzent);
  background: var(--akzent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  transition: filter .15s ease, background-color .15s ease;
}
:root:not([data-theme="light"]) .knopf { color: #14161C; }
@media (prefers-color-scheme: light) { .knopf { color: #fff; } }
.knopf:hover { filter: brightness(1.08); }
.knopf-still {
  background: transparent;
  border-color: var(--linie);
  color: var(--tinte);
  font-weight: 500;
}
.knopf-still:hover { background: var(--flaeche-2); }
.knopf-voll { width: 100%; padding: 12px; font-size: .95rem; }

.alslink {
  font: inherit; font-size: .87rem; font-weight: 500;
  background: none; border: 0; padding: 4px 0;
  color: var(--akzent); cursor: pointer; text-decoration: underline;
  text-underline-offset: 3px;
}
.alslink.still { color: var(--leise); }
.alslink.gefahr { color: var(--abgelaufen); }

input, select {
  font: inherit;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--linie);
  border-radius: 8px;
  background: var(--flaeche);
  color: var(--tinte);
}
input[type="checkbox"] { width: auto; accent-color: var(--akzent); }
select { cursor: pointer; }

.feld { display: flex; flex-direction: column; gap: 5px; }
.feld > label {
  font-size: .72rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--leise);
}
.feld-reihe { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mit-knopf { display: flex; gap: 8px; }
.mit-knopf input { flex: 1; }

.meldung {
  background: var(--abgelaufen-grund);
  color: var(--abgelaufen);
  border-radius: 8px;
  padding: 10px 13px;
  font-size: .89rem;
}
.meldung.gut { background: var(--frisch-grund); color: var(--frisch); }

/* ── Anmeldeseite ────────────────────────────────────────────────────── */
body.tor {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
}
.tor-blatt {
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 22px;
}
.tor-kopf { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.tor-zeichen { display: block; }
.tor-form {
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: var(--rundung);
  padding: 22px;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: var(--schatten);
}
.tor-wechsel { text-align: center; font-size: .9rem; color: var(--leise); }

/* ── Kopf und Reiter ─────────────────────────────────────────────────── */
.kopf {
  position: sticky; top: 0; z-index: 20;
  background: var(--grund);
  border-bottom: 1px solid var(--linie);
  padding-top: env(safe-area-inset-top);
}
.kopf-innen, .reiter, .blatt { max-width: 780px; margin: 0 auto; padding-inline: 18px; }
.kopf-innen {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding-block: 12px;
}
.marke {
  display: flex; align-items: center; gap: 9px;
  font-family: "Bitter", serif; font-weight: 600; font-size: 1.12rem;
  color: var(--tinte); text-decoration: none;
}
.kopf-rechts { display: flex; align-items: center; gap: 10px; }

.abgleich { font-size: .74rem; color: var(--leise); font-family: "Roboto Mono", monospace; }
.abgleich[data-stand="laeuft"]::before { content: "⟳ "; }
.abgleich[data-stand="offen"]  { color: var(--bald); }
.abgleich[data-stand="fehler"] { color: var(--abgelaufen); }

.reiter { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.reiter::-webkit-scrollbar { display: none; }
.reiter-knopf {
  font: inherit; font-weight: 500; font-size: .92rem;
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 9px 12px; color: var(--leise); cursor: pointer; white-space: nowrap;
}
.reiter-knopf.ist-an { color: var(--tinte); border-bottom-color: var(--akzent); font-weight: 700; }
.zaehler {
  font-family: "Roboto Mono", monospace; font-size: .74rem;
  background: var(--flaeche-2); border-radius: 20px; padding: 1px 7px; margin-left: 3px;
}

.blatt { padding-block: 20px 60px; }
.tafel { display: flex; flex-direction: column; gap: 14px; }

/* ── Werkzeugleiste ──────────────────────────────────────────────────── */
.werkzeuge { display: flex; flex-wrap: wrap; gap: 8px; }
.werkzeuge .suche { flex: 1 1 180px; }
.werkzeuge select { width: auto; flex: 0 1 auto; font-size: .88rem; }

/* ── Ampelstreifen ───────────────────────────────────────────────────── */
.ampel { display: flex; flex-wrap: wrap; gap: 7px; }
.ampel button {
  font: inherit; font-size: .8rem; font-weight: 500;
  border: 1px solid transparent; border-radius: 20px;
  padding: 4px 11px; cursor: pointer;
}
.ampel button[aria-pressed="true"] { outline: 2px solid currentColor; outline-offset: 1px; }
.a-EXPIRED           { background: var(--abgelaufen-grund); color: var(--abgelaufen); }
.a-EXPIRES_SOON      { background: var(--bald-grund);       color: var(--bald); }
.a-EXPIRES_THIS_WEEK { background: var(--woche-grund);      color: var(--woche); }
.a-FRESH             { background: var(--frisch-grund);     color: var(--frisch); }
.a-NO_DATE           { background: var(--ohne-grund);       color: var(--ohne); }

/* ── Listen ──────────────────────────────────────────────────────────── */
.liste { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.posten {
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-left-width: 4px;
  border-radius: var(--rundung);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 4px 13px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
}
.posten:hover { border-color: var(--akzent); }
.posten.s-EXPIRED           { border-left-color: var(--abgelaufen); }
.posten.s-EXPIRES_SOON      { border-left-color: var(--bald); }
.posten.s-EXPIRES_THIS_WEEK { border-left-color: var(--woche); }
.posten.s-FRESH             { border-left-color: var(--frisch); }
.posten.s-NO_DATE           { border-left-color: var(--linie); }

.posten-emoji { font-size: 1.35rem; grid-row: span 2; line-height: 1; }
.posten-name { font-weight: 700; }
.posten-unten {
  grid-column: 2 / 3;
  display: flex; flex-wrap: wrap; gap: 4px 12px;
  font-size: .83rem; color: var(--leise);
}
.posten-rechts { grid-row: span 2; text-align: right; display: flex; flex-direction: column; gap: 3px; align-items: flex-end; }

.fahne {
  font-size: .74rem; font-weight: 700; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 20px; white-space: nowrap;
}
.f-EXPIRED           { background: var(--abgelaufen-grund); color: var(--abgelaufen); }
.f-EXPIRES_SOON      { background: var(--bald-grund);       color: var(--bald); }
.f-EXPIRES_THIS_WEEK { background: var(--woche-grund);      color: var(--woche); }
.f-FRESH             { background: var(--frisch-grund);     color: var(--frisch); }
.f-NO_DATE           { background: var(--ohne-grund);       color: var(--ohne); }
.nicht-gesendet { font-size: .72rem; color: var(--bald); }

/* Einkaufsliste */
.schnell { display: flex; gap: 8px; }
.liste-einkauf .posten { grid-template-columns: auto 1fr auto; cursor: default; }
.liste-einkauf .posten-name { font-weight: 500; }
.abgehakt .posten-name { text-decoration: line-through; color: var(--leise); }
.einkauf-fuss { display: flex; gap: 18px; flex-wrap: wrap; padding-top: 4px; }

.leer { color: var(--leise); text-align: center; padding: 40px 0; }

/* ── Statistik ───────────────────────────────────────────────────────── */
.kacheln { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kachel {
  background: var(--flaeche); border: 1px solid var(--linie);
  border-radius: var(--rundung); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px;
}
.kachel dt { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--leise); }
.kachel dd { margin: 0; font-family: "Roboto Mono", monospace; font-size: 1.5rem; font-weight: 500; }

.verteilung { display: flex; flex-direction: column; gap: 7px; }
.balkenzeile { display: grid; grid-template-columns: 130px 1fr 42px; align-items: center; gap: 10px; font-size: .87rem; }
/* Die Rundung sitzt an der Hülle, nicht an den Rechtecken: das SVG wird
   waagerecht gestreckt (preserveAspectRatio="none"), ein `rx` würde dabei
   mitgestreckt und aus den Enden Linsen machen. */
.balkenzeile .spur {
  width: 100%; height: 12px; display: block;
  border-radius: 20px; overflow: hidden;
}
.balkenzeile .spur-grund { fill: var(--flaeche-2); }
.balkenzeile .fuellung { fill: var(--akzent); }
.fuellung.b-EXPIRED           { fill: var(--abgelaufen); }
.fuellung.b-EXPIRES_SOON      { fill: var(--bald); }
.fuellung.b-EXPIRES_THIS_WEEK { fill: var(--woche); }
.fuellung.b-FRESH             { fill: var(--frisch); }
.fuellung.b-NO_DATE           { fill: var(--ohne); }
.fuellung.b-akzent            { fill: var(--akzent); }
.balkenzeile .wert { font-family: "Roboto Mono", monospace; font-size: .84rem; text-align: right; color: var(--leise); }

/* ── Rezepte ─────────────────────────────────────────────────────────── */
.rezepte { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.rezept {
  background: var(--flaeche); border: 1px solid var(--linie);
  border-radius: var(--rundung); overflow: hidden;
  display: flex; flex-direction: column;
}
.rezept img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--flaeche-2); }
.rezept-text { padding: 11px 13px; display: flex; flex-direction: column; gap: 5px; }
.rezept-titel { font-weight: 700; font-size: .95rem; }
.rezept-fehlt { font-size: .8rem; color: var(--leise); }

/* ── Dialoge ─────────────────────────────────────────────────────────── */
.dialog {
  border: 1px solid var(--linie);
  border-radius: 14px;
  padding: 0;
  background: var(--flaeche);
  color: var(--tinte);
  width: min(520px, calc(100vw - 28px));
  box-shadow: var(--schatten);
}
.dialog::backdrop { background: rgba(20, 21, 17, .45); }
.dialog-form { padding: 20px; display: flex; flex-direction: column; gap: 15px; }
.dialog-kopf { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-fuss { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-top: 4px; }
.dialog-scan video { width: 100%; border-radius: 8px; background: #000; aspect-ratio: 4 / 3; object-fit: cover; }

.geraete { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.geraete li {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--linie); border-radius: 8px; padding: 9px 12px; font-size: .89rem;
}
.geraete .dieses { color: var(--frisch); font-size: .76rem; font-weight: 700; }

/* ── Kurzmeldung ─────────────────────────────────────────────────────── */
.brot {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(140%);
  background: var(--tinte); color: var(--grund);
  padding: 10px 18px; border-radius: 22px; font-size: .88rem; font-weight: 500;
  box-shadow: var(--schatten); z-index: 60; max-width: calc(100vw - 32px);
  transition: transform .22s ease;
}
.brot.zeigt { transform: translateX(-50%) translateY(0); }

@media (max-width: 560px) {
  .feld-reihe { grid-template-columns: 1fr; }
  .balkenzeile { grid-template-columns: 96px 1fr 38px; }
  h1 { font-size: 1.45rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ── Haushalt ────────────────────────────────────────────────────────── */
.einladung { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.code {
  font-family: "Roboto Mono", ui-monospace, monospace;
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: .16em;
  background: var(--akzent-hell);
  color: var(--akzent);
  padding: 10px 16px;
  border-radius: 8px;
  user-select: all;          /* ein Tippen wählt den ganzen Code aus */
}
.geraete .rolle { font-size: .72rem; color: var(--leise); }

.klein { font-size: .78rem; }
.grossbuchstaben { text-transform: uppercase; }
