:root {
  --bg: #fbf8f4;
  --surface: #ffffff;
  --border: #e6ded3;
  --text: #23201d;
  --muted: #6f6862;
  --accent: #8c4a2f;
  --accent-soft: #f3e6de;
  --danger: #a32b1e;
  --radius: 10px;
  --gap: 1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f;
    --surface: #201d18;
    --border: #332e26;
    --text: #ece6dd;
    --muted: #a09890;
    --accent: #e0855f;
    --accent-soft: #2e241d;
    --danger: #e07a6b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 62rem;
  margin: 0 auto;
  padding: var(--gap) var(--gap) 4rem;
}

a { color: var(--accent); }

/* ------------------------------------------------------------------ Topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  padding: 0.7rem var(--gap);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--text);
}

.topbar nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar nav a { text-decoration: none; }
.inline { display: inline; margin: 0; }

/* ------------------------------------------------------------ Formularteile */

input[type="text"], input[type="search"], input[type="password"],
input[type="number"], textarea, select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

textarea { resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.92rem; }

label { display: block; margin-bottom: 1rem; font-weight: 600; }
label input, label textarea, label select { margin-top: 0.3rem; font-weight: 400; }

.hint { display: block; font-weight: 400; font-size: 0.85rem; color: var(--muted); margin-top: 0.15rem; }

button, .button {
  display: inline-block;
  padding: 0.6rem 1.1rem;
  font: inherit;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); border-color: var(--border); }
button.linklike { border: 0; background: none; padding: 0; color: var(--accent); }

.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; margin: 1rem 0; }
.row { display: flex; gap: var(--gap); flex-wrap: wrap; }
.row label { flex: 1 1 8rem; }

.centered-card {
  max-width: 22rem;
  margin: 12vh auto;
  padding: 1.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.error {
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--danger);
}

/* ---------------------------------------------------------------- Übersicht */

.searchbar { margin-bottom: var(--gap); }

.tagbar { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: var(--gap); }

.tag {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  font-size: 0.85rem;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.tag.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tag .count { color: var(--muted); font-size: 0.75rem; }
.tag.active .count { color: #f0d9cd; }

.recipe-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: var(--gap);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card a { display: block; text-decoration: none; color: inherit; padding-bottom: 0.8rem; }
.card img, .thumb-placeholder {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: var(--accent-soft);
}
.thumb-placeholder {
  display: grid;
  place-items: center;
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent);
}
.card h2 { font-size: 1.05rem; margin: 0.7rem 0.8rem 0.2rem; }
.card p { margin: 0 0.8rem; font-size: 0.88rem; }

.muted { color: var(--muted); }
.meta { font-size: 0.85rem; color: var(--muted); }
.footer-stats { margin-top: 2rem; text-align: center; font-size: 0.85rem; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.pager { display: flex; gap: var(--gap); justify-content: center; margin-top: 1.5rem; }

/* ------------------------------------------------------------- Rezeptseite */

.recipe-head h1 { margin-bottom: 0.2rem; }
.lead { font-size: 1.05rem; color: var(--muted); margin-top: 0; }
.hero { width: 100%; border-radius: var(--radius); margin-bottom: 1.5rem; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); flex-wrap: wrap; }

.portions { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.portions button { padding: 0.2rem 0.65rem; line-height: 1.2; font-size: 1.1rem; }
#portions { font-weight: 700; }

.ingredient-list, .step-list { padding-left: 0; }
.ingredient-list { list-style: none; }
.ingredient-list li { padding: 0.15rem 0; }
.ingredient-section {
  font-weight: 700;
  margin-top: 1rem;
  padding-bottom: 0.2rem;
  border-bottom: 1px solid var(--border);
}
.ingredient-list label, .step-list label { font-weight: 400; display: flex; gap: 0.55rem; margin: 0; align-items: baseline; }
.ingredient-list .amount { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 2.6rem; text-align: right; }
.ingredient-list .unit { min-width: 3rem; color: var(--muted); }

.step-list { padding-left: 1.4rem; }
.step-list li { margin-bottom: 0.9rem; }

/* Abgehakte Zeilen treten zurueck, verschwinden aber nicht. */
input[type="checkbox"]:checked ~ span { opacity: 0.45; text-decoration: line-through; }

.recipe-foot { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* Kochmodus: grosse Schrift, Ablenkung weg, Daumen-tauglich. */
body.cookmode { font-size: 19px; }
body.cookmode .topbar,
body.cookmode .recipe-foot,
body.cookmode .tagbar,
body.cookmode .hero { display: none; }
body.cookmode .step-list li { margin-bottom: 1.5rem; }
body.cookmode input[type="checkbox"] { width: 1.4rem; height: 1.4rem; }

/* ---------------------------------------------------------- Einstellungen */

.token-reveal {
  padding: 1rem;
  margin: 1rem 0;
  background: var(--accent-soft);
  border-radius: var(--radius);
}
code.token { display: block; word-break: break-all; font-size: 1rem; padding: 0.5rem 0; }

.inline-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 1rem 0; }
.inline-form input { flex: 1 1 12rem; }

table.tokens { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.tokens th, table.tokens td { text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--border); }
tr.revoked { opacity: 0.5; }

/* ------------------------------------------------------------------ Import */

.import-box {
  padding: 1rem;
  margin-bottom: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.import-box h2 { margin-top: 0; font-size: 1.1rem; }
.import-box textarea { margin-bottom: 0.6rem; font-family: inherit; font-size: 1rem; }
.import-box input[type="file"] { margin-bottom: 0.6rem; display: block; }

.job-history { list-style: none; padding: 0; }
.job-history li { padding: 0.4rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.job-history a { text-decoration: none; display: inline-flex; gap: 0.5rem; align-items: center; }
.job-history .ref { color: var(--text); word-break: break-all; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  white-space: nowrap;
  background: var(--accent-soft);
  color: var(--accent);
}
.badge-failed { background: #f6dcd8; color: var(--danger); }
.badge-imported { background: #dcecdc; color: #2f6b34; }
@media (prefers-color-scheme: dark) {
  .badge-failed { background: #3a201c; }
  .badge-imported { background: #1e3220; color: #8fca94; }
}

.waiting { text-align: center; padding: 3rem 1rem; }
.waiting h1::after {
  content: "";
  display: inline-block;
  width: 0.7em; /* haelt die Breite konstant, sonst zappelt die Ueberschrift */
  text-align: left;
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.warnings {
  padding: 0.8rem 1rem;
  margin-bottom: 1rem;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
}
.warnings h2 { margin: 0 0 0.4rem; font-size: 1rem; }
.warnings ul { margin: 0; padding-left: 1.2rem; }

.confidence { font-size: 0.9rem; margin-top: 0; }
.confidence-high { color: var(--muted); }
.confidence-mid { color: var(--accent); }
.confidence-low { color: var(--danger); font-weight: 600; }

.trace { margin: 1rem 0; font-size: 0.85rem; color: var(--muted); }
.trace summary { cursor: pointer; }
.discard { margin-top: 2rem; text-align: center; }

.howto li { margin-bottom: 0.4rem; }
code { background: var(--accent-soft); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.9em; }

@media (max-width: 34rem) {
  .topbar nav { gap: 0.7rem; font-size: 0.9rem; }
  main { padding: 0.8rem 0.8rem 4rem; }

  /* Auf dem Handy ist die Liste zum Wiederfinden da, nicht zum Blaettern.
     Kacheln mit 4:3-Bild zeigen ein Rezept pro Bildschirm — als Zeile
     passen sechs drauf. */
  .recipe-grid { grid-template-columns: 1fr; gap: 0.5rem; }
  .card a {
    display: grid;
    grid-template-columns: 4.5rem 1fr;
    grid-template-areas: "thumb title" "thumb desc" "thumb meta";
    align-items: center;
    column-gap: 0.8rem;
    padding: 0.5rem;
  }
  .card img, .thumb-placeholder {
    grid-area: thumb;
    aspect-ratio: 1;
    border-radius: 8px;
    font-size: 1.6rem;
  }
  .card h2 { grid-area: title; margin: 0; font-size: 1rem; }
  .card p.muted { grid-area: desc; margin: 0; font-size: 0.82rem; }
  .card p.meta { grid-area: meta; margin: 0; }

  /* Zutatenzeile umbricht sonst mitten im Namen. */
  .ingredient-list .unit { min-width: 2.4rem; }
}
