:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #f1ede4;
  --text: #2b2620;
  --muted: #7a7166;
  --border: #e3ddd1;
  --accent: #3f7d4e;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe4;
  --meat: #b5523b;
  --meat-soft: #f6e3dd;
  --fish: #2f6f95;
  --fish-soft: #dfecf4;
  --veg: #4f7f2c;
  --veg-soft: #e7f0dc;
  --warn: #a8660b;
  --warn-soft: #fbefd9;
  --danger: #b33a3a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 4px 14px rgba(40, 30, 20, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a17;
    --surface: #25231f;
    --surface-2: #2e2b26;
    --text: #ece6db;
    --muted: #a39a8c;
    --border: #3a362f;
    --accent: #6fb27f;
    --accent-ink: #10200f;
    --accent-soft: #24372a;
    --meat: #e38f78;
    --meat-soft: #43291f;
    --fish: #7fb6d8;
    --fish-soft: #1f3340;
    --veg: #9cc873;
    --veg-soft: #2a3a1e;
    --warn: #e0a64a;
    --warn-soft: #3d3020;
    --danger: #e27a7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h2 { margin: 0 0 .5rem; font-size: 1.35rem; }
h3 { margin: 0 0 .4rem; font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }

/* Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem;
  padding: .7rem 1.25rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; }
.brand .muted { font-weight: 400; margin-left: .4rem; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; }
.tab {
  border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600;
  padding: .45rem .8rem; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { background: var(--accent); color: var(--accent-ink); }

main { max-width: 1180px; margin: 0 auto; padding: 1.25rem; }

/* Bedienelemente */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 600; padding: .5rem .95rem; border-radius: 10px; cursor: pointer;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: .3rem .6rem; font-size: .85rem; border-radius: 8px; }
.btn.danger { color: var(--danger); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 1.2rem; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.input {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: .5rem .7rem; min-width: 0;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea.input { width: 100%; resize: vertical; }
.grow { flex: 1 1 220px; }
.check { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: .75rem; }
.row.end { justify-content: flex-end; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .8rem; }
.field > span { font-size: .85rem; font-weight: 600; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.sub { margin-top: 1.5rem; }
.hint { background: var(--warn-soft); color: var(--text); padding: .45rem .7rem; border-radius: 8px; font-size: .88rem; }

/* Wochen-Navigation */
.week-nav { display: flex; align-items: center; gap: .6rem; }
.week-title { display: flex; flex-direction: column; line-height: 1.2; min-width: 140px; text-align: center; }
.week-title strong { font-size: 1.15rem; }
.week-title span { color: var(--muted); font-size: .85rem; }

/* Wochenplan */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.slot {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.slot.today { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow); }
.slot-days { padding: .6rem .9rem; font-weight: 700; font-size: .9rem; background: var(--surface-2); }
.slot.today .slot-days { background: var(--accent-soft); }
.slot-img { display: block; border: 0; padding: 0; background: none; cursor: pointer; }
.slot-img .img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.slot-body { padding: .75rem .9rem; flex: 1; }
.slot-body h3 a { color: var(--text); text-decoration: none; }
.slot-body h3 a:hover { color: var(--accent); }
.slot-actions { display: flex; flex-wrap: wrap; gap: .35rem; padding: 0 .9rem .9rem; }
.slot-free { flex: 1; display: grid; place-content: center; text-align: center; font-size: 1.15rem; font-weight: 600; padding: 2.5rem 1rem; }
.plan-meta { color: var(--muted); margin-top: 1rem; font-size: .9rem; }
.noimg { display: grid; place-items: center; background: var(--surface-2); font-size: 2.2rem; width: 100%; aspect-ratio: 4 / 3; }

/* Badges */
.badges { display: flex; flex-wrap: wrap; gap: .3rem; margin: .25rem 0; }
.badge { font-size: .75rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
.diet-fleisch { background: var(--meat-soft); color: var(--meat); }
.diet-fisch { background: var(--fish-soft); color: var(--fish); }
.diet-vegetarisch { background: var(--veg-soft); color: var(--veg); }
.badge.season { background: var(--accent-soft); color: var(--accent); }
.badge.season-soft { background: var(--surface-2); color: var(--muted); }
.badge.off { background: var(--warn-soft); color: var(--warn); }

/* Rezepte */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; box-shadow: var(--shadow); transition: transform .12s; }
.card:hover, .card:focus-visible { transform: translateY(-2px); outline: none; border-color: var(--accent); }
.card-img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.card-body { padding: .7rem .85rem .85rem; }
.card-body h3 { font-size: 1rem; line-height: 1.3; }

/* Import */
.import-log { list-style: none; padding: 0; margin: 1rem 0 0; display: flex; flex-direction: column; gap: .4rem; }
.import-log li { display: flex; gap: .6rem; align-items: flex-start; padding: .5rem .7rem; border-radius: 10px; background: var(--surface-2); min-width: 0; }
.import-log li > div { min-width: 0; flex: 1; }
.log-error .log-msg { color: var(--danger); }

/* Einkaufsliste */
.shop-list { display: flex; flex-direction: column; }
.shop-item { display: grid; grid-template-columns: auto 110px 1fr auto; gap: .7rem; align-items: baseline; padding: .5rem .2rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.shop-cat { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin: 1.4rem 0 .2rem; padding-bottom: .3rem; border-bottom: 2px solid var(--accent-soft); }
.shop-cat:first-of-type { margin-top: .6rem; }
.cat-btn { border: 0; background: none; color: var(--muted); font-size: 1rem; cursor: pointer; padding: .1rem .35rem; border-radius: 6px; align-self: center; }
.cat-btn:hover { background: var(--surface-2); color: var(--text); }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .4rem; margin-top: .75rem; }
.cat-grid .btn { justify-content: flex-start; }
.shop-item input { transform: translateY(2px); }
.shop-item .amt { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.shop-item .nm small { display: block; color: var(--muted); font-size: .78rem; }
.shop-item.done .amt, .shop-item.done .nm { text-decoration: line-through; opacity: .5; }

/* Einstellungen */
.settings { max-width: 760px; }
.settings .check { margin-bottom: .9rem; }
.season-table { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .3rem 1rem; font-size: .88rem; }

/* Modal */
dialog {
  border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--text);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog.wide { width: min(980px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(20, 15, 10, .5); }
#modal-body { position: relative; }
#modal-body > .picker, #modal-body > .edit-form { padding: 1.25rem; }
.modal-close {
  position: absolute; top: .6rem; right: .6rem; z-index: 2;
  width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 1.4rem; line-height: 1;
}
.detail-img { width: 100%; max-height: 360px; object-fit: cover; display: block; }
div.detail-img { aspect-ratio: auto; height: 160px; }
.detail-body { padding: 1.25rem; }
.detail-cols { display: grid; grid-template-columns: minmax(240px, 1fr) 2fr; gap: 1.75rem; margin: 1rem 0; }
.stepper { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.stepper span { min-width: 95px; text-align: center; font-weight: 600; }
.ing-list { list-style: none; padding: 0; margin: 0; }
.ing-list li { display: grid; grid-template-columns: 90px 1fr; gap: .6rem; padding: .3rem 0; border-bottom: 1px solid var(--border); }
.ing-list .amt { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.steps { padding-left: 1.3rem; margin: 0; }
.steps li { margin-bottom: .7rem; }
.notes { background: var(--surface-2); padding: .6rem .8rem; border-radius: 10px; margin: .5rem 0; }
.months { display: grid; grid-template-columns: repeat(6, 1fr); gap: .3rem; margin: -.3rem 0 .9rem; font-size: .88rem; }
.months label { display: flex; gap: .3rem; align-items: center; }

/* Anmeldung */
body.logged-out .tabs, body.logged-out #recipe-count { display: none; }
.login { max-width: 380px; margin: 3rem auto; text-align: center; }
.login form { display: flex; flex-direction: column; gap: .6rem; margin-top: 1rem; }
.login .btn { justify-content: center; }
.login-error { color: var(--danger); margin: .75rem 0 0; }

#confirm-dlg { width: min(420px, calc(100vw - 32px)); }
.confirm-box { padding: 1.25rem; }
.confirm-box p { margin: 0 0 .5rem; font-size: 1.02rem; }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Auswahl */
.picker .input { width: 100%; margin: .5rem 0 .75rem; }
.picker-list { display: flex; flex-direction: column; gap: .35rem; max-height: 60vh; overflow: auto; }
.pick-row {
  display: grid; grid-template-columns: 56px 1fr; gap: .2rem .7rem; align-items: center; text-align: left;
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid transparent;
  border-radius: 10px; padding: .4rem; cursor: pointer;
}
.pick-row:hover { border-color: var(--accent); }
.pick-row .thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; aspect-ratio: auto; font-size: 1.4rem; grid-row: span 2; }
.pick-main { display: flex; flex-direction: column; min-width: 0; }
.pick-warn { font-size: .78rem; color: var(--warn); }
.pick-row.warn { opacity: .8; }

/* Hinweise */
#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .4rem; z-index: 100; width: min(460px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: .6rem .9rem; border-radius: 10px; box-shadow: var(--shadow); font-size: .9rem; }
.toast.ok { background: var(--accent); color: var(--accent-ink); }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 720px) {
  main { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
  .detail-cols, .row2 { grid-template-columns: 1fr; }
  .months { grid-template-columns: repeat(4, 1fr); }
  .shop-item { grid-template-columns: auto 80px 1fr auto; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .week-nav { justify-content: space-between; }
}
