/* ============================================================================
   Komponenten — ein Vokabular für alle Ansichten.
   Ein Button sieht überall gleich aus. Ein Chip sieht überall gleich aus.
   ========================================================================= */

/* Icons in Bedienelementen brauchen eine Größe — ein <svg> ohne width/height
   kollabiert im Flex-Kontext auf 0. Spezifischere Regeln (.icon-btn svg,
   .nav__item svg, .check svg) überschreiben das weiter unten. */
.btn svg, .chip svg, .seg__btn svg, .alert > svg, .today__kind svg {
  width: 17px; height: 17px; flex: none;
}
.alert > svg { width: 20px; height: 20px; margin-top: 1px; color: var(--danger); }

/* ------------------------------------------------------------------ Button */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: 0 var(--s4);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink);
  font-size: var(--t-sm); font-weight: 560; letter-spacing: -0.005em;
  border: 1px solid var(--line);
  transition: background var(--d-fast) var(--ease-out),
              border-color var(--d-fast) var(--ease-out),
              transform var(--d-fast) var(--ease-out);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: var(--line); }
.btn:active { transform: scale(0.97); }
.btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.45; pointer-events: none;
}

.btn--primary {
  background: var(--accent); color: var(--accent-ink);
  border-color: transparent; font-weight: 640;
}
.btn--primary:hover { background: var(--accent-hi); }

.btn--ghost { background: none; border-color: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: var(--surface-2); color: var(--ink); }

.btn--danger { color: var(--danger); border-color: var(--danger-dim); }
.btn--danger:hover { background: var(--danger-dim); color: var(--ink); }

.btn--sm { min-height: 36px; padding: 0 var(--s3); font-size: var(--t-label); }

/* Runder Icon-Button (44px Trefferfläche, auch wenn das Icon klein ist). */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: var(--r-pill);
  color: var(--ink-2);
  transition: background var(--d-fast) var(--ease-out), color var(--d-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }

/* -------------------------------------------------------------------- Chip */
.chip {
  display: inline-flex; align-items: center; gap: var(--s1);
  min-height: 34px; padding: 0 var(--s3);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid transparent;
  color: var(--ink-2);
  font-size: var(--t-label); font-weight: 520; line-height: 1;
  white-space: nowrap; flex: none;
  transition: background var(--d-fast) var(--ease-out), color var(--d-fast) var(--ease-out);
}
.chip:hover { background: var(--surface-3); color: var(--ink); }
.chip[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink); font-weight: 640;
}
.chip__count {
  font-size: var(--t-micro); font-variant-numeric: tabular-nums; opacity: 0.7;
}
.chip[aria-pressed="true"] .chip__count { opacity: 0.75; }

/* Statisches Tag-Etikett (nicht klickbar). */
.tag {
  display: inline-block; padding: 2px var(--s2);
  border-radius: var(--r-pill); background: var(--surface-2);
  color: var(--muted); font-size: var(--t-micro); line-height: 1.5;
}

/* ------------------------------------------------------------------ Felder */
.field {
  width: 100%; min-height: 44px;
  padding: 0 var(--s3);
  /* 16px verhindert den Auto-Zoom von iOS-Safari beim Fokus. */
  font-size: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--ink);
  -webkit-appearance: none;
  transition: border-color var(--d-fast) var(--ease-out);
}
.field::placeholder { color: var(--muted); }
.field:focus-visible { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-glow); }

.search { position: relative; }
.search .field { padding-left: 40px; }
.search svg {
  position: absolute; left: var(--s3); top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--muted); pointer-events: none;
}

/* ----------------------------------------------------- Abschnitts-Kopfzeile */
.sec { margin-top: var(--s7); }
.sec:first-of-type { margin-top: var(--s5); }
.sec__head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--s3); margin-bottom: var(--s3);
}
.sec__title { font-size: var(--t-h2); font-weight: 640; letter-spacing: -0.02em; }
.sec__meta { font-size: var(--t-label); color: var(--muted); font-variant-numeric: tabular-nums; }
.sec__link { font-size: var(--t-label); font-weight: 560; color: var(--accent); }

/* ------------------------------------------------------------------- Karte */
.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  overflow: hidden;
}

/* --------------------------------------------------------- Bild-Kacheln */
/* Der Grundbaustein der App: ein Foto im Hochformat, Text auf einem
   Verlaufsträger darüber. Nie nur text-shadow — der Verlauf ist die
   Lesbarkeitsgarantie, auch über hellen Bildern. */
.tile {
  position: relative; display: block;
  border-radius: var(--r-lg); overflow: hidden;
  background: var(--surface-2);
  isolation: isolate;
  transition: transform var(--d-base) var(--ease-out);
}
.tile:hover { transform: translateY(-2px); }
.tile:active { transform: scale(0.985); }

.tile__img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform var(--d-slow) var(--ease-out), filter var(--d-base) var(--ease-out);
}
.tile:hover .tile__img { transform: scale(1.04); }

.tile__veil {
  position: absolute; inset: 0;
  background: linear-gradient(
    to top,
    oklch(0.12 0.01 260 / 0.92) 0%,
    oklch(0.12 0.01 260 / 0.72) 26%,
    oklch(0.12 0.01 260 / 0.20) 55%,
    oklch(0.12 0.01 260 / 0) 78%
  );
  pointer-events: none;
}
.tile__body {
  position: absolute; inset: auto 0 0 0;
  padding: var(--s3);
  display: flex; flex-direction: column; gap: 2px;
}
.tile__title {
  font-size: var(--t-sm); font-weight: 620; line-height: 1.28;
  letter-spacing: -0.01em; color: oklch(0.99 0 0);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile__sub {
  font-size: var(--t-micro); color: oklch(0.86 0.006 260);
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}

/* Kachel ohne Bild: bewusst typografisch statt grauer Klotz.
   Der Titel steht oben und groß, ein Zierglyph unten rechts gibt der Fläche
   Textur — damit sie wie eine Absicht wirkt und nicht wie ein Ladefehler. */
.tile--noimg {
  background:
    radial-gradient(120% 90% at 8% 4%, oklch(0.28 0.020 62 / 0.5), transparent 60%),
    linear-gradient(155deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line-soft);
}
.tile--noimg .tile__veil { background: none; }
.tile--noimg .tile__body { inset: 0; justify-content: flex-start; padding: var(--s4); gap: var(--s2); }
.tile--noimg .tile__title {
  font-size: var(--t-lead); color: var(--ink); -webkit-line-clamp: 4;
  letter-spacing: -0.02em; line-height: 1.24;
}
.tile--noimg .tile__sub { color: var(--muted); font-size: var(--t-label); -webkit-line-clamp: 2; }
.tile--noimg::after {
  content: ""; position: absolute; right: -14%; bottom: -18%;
  width: 62%; aspect-ratio: 1;
  background: currentColor; color: var(--accent);
  opacity: 0.11; border-radius: 50%;
  pointer-events: none;
}

/* Karte mit gestrecktem Link: der ganze Kachelkörper ist klickbar, ohne
   dass Buttons in einem <a> verschachtelt werden (ungültiges HTML). */
.tile__link { position: absolute; inset: 0; z-index: 1; }
.tile__link:focus-visible { outline-offset: -3px; }
.tile__actions {
  position: absolute; top: var(--s2); left: var(--s2); z-index: 2;
  display: flex; gap: var(--s1);
}
.tile__actions .icon-btn,
.tile__actions .check {
  width: 34px; height: 34px;
  background: oklch(0.12 0.01 260 / 0.62);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  color: oklch(0.96 0 0); border-color: transparent;
}
/* Auf dem Poster muss der Haken auch ungedrückt sichtbar sein — ein leerer
   Kreis über einem Foto sagt niemandem, was er tut. In der Tabelle bleibt es
   beim konventionellen leeren Kästchen. */
.tile__actions .check svg { opacity: 0.7; color: oklch(0.96 0 0); }
.tile__actions .check[aria-pressed="true"] { background: var(--ok); }

/* Marke oben rechts auf einer Kachel (kcal, Jahr, Entfernung). */
.tile__badge {
  position: absolute; top: var(--s2); right: var(--s2);
  padding: 3px var(--s2); border-radius: var(--r-pill);
  background: oklch(0.12 0.01 260 / 0.72);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: oklch(0.97 0 0); font-size: var(--t-micro); font-weight: 600;
  font-variant-numeric: tabular-nums; letter-spacing: 0.01em;
}
.tile__badge--accent { background: var(--accent); color: var(--accent-ink); }

/* Seitenverhältnisse: dem Inhalt angemessen, nicht einheitlich erzwungen. */
.ar-reel   { aspect-ratio: 9 / 16; }
.ar-poster { aspect-ratio: 2 / 3; }
.ar-dish   { aspect-ratio: 3 / 4; }
.ar-wide   { aspect-ratio: 16 / 10; }

/* ------------------------------------------------------------------ Raster */
.grid { display: grid; gap: var(--s3); }
.grid--dish   { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid--poster { grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); }
.grid--areas  { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (min-width: 700px) {
  .grid { gap: var(--s4); }
  .grid--dish   { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .grid--poster { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* --------------------------------------------------------------- Zeilen */
.row {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3);
  border-radius: var(--r-md);
  transition: background var(--d-fast) var(--ease-out);
}
.row + .row { box-shadow: 0 -1px 0 var(--line-soft); }
.row:hover { background: var(--surface-2); }
.row__body { min-width: 0; flex: 1; }
.row__title { font-size: var(--t-body); font-weight: 560; line-height: 1.35; }
.row__sub { font-size: var(--t-label); color: var(--muted); margin-top: 1px; }
.row__thumb { width: 52px; height: 52px; border-radius: var(--r-sm); object-fit: cover; flex: none; background: var(--surface-2); }

/* ------------------------------------------------------- Prioritätspunkt */
/* Farbe ist nie der alleinige Träger: der Punkt steht immer neben Text. */
.prio { display: inline-flex; align-items: center; gap: var(--s1); font-size: var(--t-micro); color: var(--muted); }
.prio::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--dot, var(--p4)); flex: none;
}
.prio--p1 { --dot: var(--p1); color: var(--p1); font-weight: 600; }
.prio--p2 { --dot: var(--p2); }
.prio--p3 { --dot: var(--p3); }

/* ------------------------------------------------------------- Ladezustand */
/* Skelette statt Spinner: die Seite behält ihre Form beim Laden. */
.sk { background: var(--surface-2); border-radius: var(--r-sm); position: relative; overflow: hidden; }
.sk::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, oklch(1 0 0 / 0.05), transparent);
  animation: sk-sweep 1.3s var(--ease-out-soft) infinite;
}
@keyframes sk-sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.sk--line { height: 12px; }
.sk--tile { border-radius: var(--r-lg); }
@media (prefers-reduced-motion: reduce) {
  .sk::after { animation: none; }
}

/* ------------------------------------------------------------- Leerzustand */
/* Sagt, was da ist und was zu tun wäre — nicht "keine Daten". */
.empty {
  padding: var(--s8) var(--s5);
  text-align: center; color: var(--muted); font-size: var(--t-sm);
  display: flex; flex-direction: column; align-items: center; gap: var(--s3);
}
.empty__title { color: var(--ink-2); font-size: var(--t-body); font-weight: 560; }
.empty__hint { max-width: 46ch; line-height: 1.55; }
.empty svg { width: 30px; height: 30px; color: var(--muted); opacity: 0.5; }

/* Namen von Env-Vars und Pfaden in Hinweistexten. */
code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 0.92em;
  padding: 1px 5px; border-radius: 5px;
  background: var(--surface-2); color: var(--ink-2);
  white-space: nowrap;
}

/* Fehler: sagt was passiert ist und was hilft. */
.alert {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--danger-dim); border-radius: var(--r-md);
  background: oklch(0.30 0.070 25 / 0.22);
  color: var(--ink-2); font-size: var(--t-sm); line-height: 1.5;
}
.alert strong { color: var(--ink); font-weight: 600; display: block; }

/* ------------------------------------------------------------------- Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--s4));
  z-index: var(--z-toast);
  background: var(--surface-3); color: var(--ink);
  border: 1px solid var(--line);
  padding: var(--s3) var(--s4); border-radius: var(--r-pill);
  font-size: var(--t-sm); box-shadow: var(--sh-3);
  animation: toast-in var(--d-base) var(--ease-out);
  max-width: min(92vw, 420px);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

/* ------------------------------------------------------------------ Dialog */
/* Nativer <dialog>: kein Stacking-Context-Problem, Escape und Fokusfalle gratis. */
dialog.sheet {
  border: none; padding: 0; margin: 0 auto auto;
  max-width: min(720px, 100vw); width: 100%;
  max-height: 100dvh; height: 100dvh;
  background: var(--bg); color: var(--ink);
  overflow: hidden;
}
dialog.sheet::backdrop { background: oklch(0.08 0.01 260 / 0.7); }
dialog.sheet[open] { display: flex; flex-direction: column; }
