:root {
  --green: #2f6f4f;
  --green-dark: #245740;
  --green-light: #e7f2ec;
  --amber: #b7791f;
  --amber-light: #fdf3e0;
  --red: #b23b3b;
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #23291f;
  --muted: #6b7263;
  --line: #e3e1d8;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(30, 40, 30, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --green: #58a37e;
    --green-dark: #6fbb95;
    --green-light: #1d2b23;
    --amber: #d9a04a;
    --amber-light: #2c2416;
    --red: #d97b7b;
    --bg: #141712;
    --card: #1d211b;
    --text: #e8eae3;
    --muted: #9aa192;
    --line: #2c3128;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; font-size: .9rem; }

/* ── Login ─────────────────────────────────────────── */
.login {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 32px 28px; width: 100%; max-width: 340px; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
}
.login-logo { font-size: 3rem; }
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-card p { margin: 0; }

/* ── Layout ────────────────────────────────────────── */
#topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 14px calc(10px);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
#topbar h2 { margin: 0; font-size: 1.05rem; }
.week-nav { display: flex; align-items: center; gap: 4px; }
.week-nav button { font-size: 1.1rem; padding: 4px 10px; }
.quota {
  font-size: .72rem; color: var(--muted); background: var(--bg);
  border: 1px solid var(--line); border-radius: 20px; padding: 3px 9px; white-space: nowrap;
}
.quota.warn { color: var(--amber); border-color: var(--amber); }
.quota.bad { color: var(--red); border-color: var(--red); }

#view { padding: 14px 14px 90px; max-width: 640px; margin: 0 auto; }

#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; padding: 8px 0 10px;
  font-size: .7rem; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: 1.25rem; }
.tab.active { color: var(--green); font-weight: 600; }

/* ── Buttons / inputs ──────────────────────────────── */
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 10px; padding: 9px 14px; font-size: .92rem; cursor: pointer;
}
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.btn.primary:active { background: var(--green-dark); }
.btn.small { padding: 5px 10px; font-size: .8rem; border-radius: 8px; }
.btn.danger { color: var(--red); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

input, select {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--green); outline-offset: -1px; }
input[type=radio], input[type=checkbox] { width: auto; flex: none; accent-color: var(--green); }
label { font-size: .8rem; color: var(--muted); display: block; margin: 10px 0 4px; }

/* ── Cards & common bits ───────────────────────────── */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 12px; margin-bottom: 12px;
}
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 8px; }
.chip {
  display: inline-block; font-size: .72rem; border-radius: 20px; padding: 2px 9px;
  background: var(--green-light); color: var(--green); margin: 2px 3px 2px 0;
}
.chip.amber { background: var(--amber-light); color: var(--amber); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.stat-num { font-size: 1.25rem; font-weight: 700; color: var(--green); }
.stat-label { font-size: .72rem; color: var(--muted); margin-top: 2px; }
input[type=range] { padding: 0; accent-color: var(--green); border: none; background: none; }
.empty .big { font-size: 2.2rem; display: block; margin-bottom: 8px; }

/* ── Week board ────────────────────────────────────── */
.surplus-banner { background: var(--green-light); border: none; }
.surplus-banner .title { font-weight: 600; font-size: .85rem; margin-bottom: 4px; color: var(--green); }
.day-card .day-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.day-card .day-head b { font-size: .95rem; }
.day-card .day-head span { font-size: .75rem; color: var(--muted); }
.meal {
  display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 10px;
  background: var(--bg); margin-bottom: 6px; cursor: pointer;
}
.meal img { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--line); }
.meal .meal-info { flex: 1; min-width: 0; }
.meal .meal-title { font-size: .88rem; font-weight: 600; line-height: 1.25; }
.meal .meal-sub { font-size: .74rem; color: var(--muted); }
.meal .slot-tag { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.icon-btn { background: none; border: none; font-size: 1rem; color: var(--muted); cursor: pointer; padding: 6px; }
.add-slot { display: flex; gap: 6px; }
.add-slot .btn { flex: 1; color: var(--muted); border-style: dashed; }

/* ── Recipe cards (search / suggestions) ───────────── */
.recipe-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.recipe-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer;
}
.recipe-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: var(--line); display: block; }
.recipe-card .rc-body { padding: 8px 10px 10px; }
.recipe-card .rc-title { font-size: .82rem; font-weight: 600; line-height: 1.25; }
.recipe-card .rc-sub { font-size: .72rem; color: var(--muted); margin-top: 3px; }

/* ── Shopping list ─────────────────────────────────── */
.list-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }
.list-item input[type=checkbox] { width: 20px; height: 20px; margin-top: 3px; accent-color: var(--green); flex: none; }
.list-item.done .li-name { text-decoration: line-through; color: var(--muted); }
.li-main { flex: 1; min-width: 0; }
.li-name { font-weight: 600; font-size: .92rem; }
.li-qty { font-size: .8rem; color: var(--muted); }
.li-product { font-size: .78rem; margin-top: 2px; }
.li-product a { color: var(--green); text-decoration: none; }
.cart-bar {
  position: fixed; bottom: calc(58px + env(safe-area-inset-bottom)); left: 0; right: 0; z-index: 15;
  padding: 10px 14px; display: flex; gap: 8px; max-width: 640px; margin: 0 auto;
}
.cart-bar .btn { box-shadow: 0 2px 10px rgba(0,0,0,.18); }

/* ── Pantry ────────────────────────────────────────── */
.pantry-row { display: flex; align-items: center; gap: 8px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.pantry-row:last-child { border-bottom: none; }
.pantry-row .pr-name { flex: 1; font-size: .9rem; font-weight: 600; min-width: 0; }
.pantry-row .pr-name small { display: block; font-weight: 400; color: var(--muted); font-size: .72rem; }
.pantry-amount { font-size: .88rem; min-width: 70px; text-align: right; cursor: pointer; }
.pantry-amount input { width: 64px; padding: 4px 6px; text-align: right; }

/* ── Catalog ───────────────────────────────────────── */
.map-row { display: flex; align-items: center; gap: 8px; padding: 9px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.map-row:last-child { border-bottom: none; }
.map-row .mr-ing { flex: 1; font-size: .9rem; font-weight: 600; }
.map-row .mr-prod { font-size: .78rem; color: var(--muted); text-align: right; }
.map-row .mr-prod.unmapped { color: var(--amber); }

/* ── Brand picker ──────────────────────────────────── */
.brand-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 4px;
  border-bottom: 1px solid var(--line); cursor: pointer; font-size: .85rem;
}
.brand-row:last-child { border-bottom: none; }
.brand-row img { width: 40px; height: 40px; object-fit: contain; border-radius: 6px; background: #fff; flex: none; }
.brand-row.picked { background: var(--green-light); border-radius: 8px; }

/* ── Modal ─────────────────────────────────────────── */
#modal-root:not(:empty) {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 20, 15, .5);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); width: 100%; max-width: 640px; max-height: 92dvh;
  border-radius: 18px 18px 0 0; overflow-y: auto; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  animation: slideup .18s ease-out;
}
@keyframes slideup { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.recipe-hero { width: 100%; border-radius: 12px; aspect-ratio: 16/9; object-fit: cover; background: var(--line); }
.step { display: flex; gap: 10px; margin: 10px 0; font-size: .9rem; line-height: 1.45; }
.step b { color: var(--green); }
.ing-line { font-size: .88rem; padding: 5px 0; border-bottom: 1px dashed var(--line); }

/* ── Toast ─────────────────────────────────────────── */
#toast {
  position: fixed; bottom: calc(70px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  z-index: 60; pointer-events: none;
}
#toast div {
  background: var(--text); color: var(--bg); border-radius: 10px; padding: 10px 16px;
  font-size: .85rem; margin-top: 8px; animation: fadein .2s;
}
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

@media (min-width: 520px) {
  .recipe-grid { grid-template-columns: 1fr 1fr 1fr; }
  #modal-root:not(:empty) { align-items: center; padding: 20px; }
  .modal { border-radius: 18px; }
}
