/* Matlei – warm, calm, mobile first */
:root {
  --bg: #f6f2ea;
  --surface: #ffffff;
  --surface-2: #fbf8f3;
  --ink: #1d2a21;
  --muted: #6d7268;
  --line: #e8e1d4;
  --primary: #2f6b46;
  --primary-ink: #ffffff;
  --primary-soft: #e4efe6;
  --accent: #d9703f;
  --accent-soft: #fbe8dd;
  --warn: #9a5b00;
  --warn-soft: #fdf1d8;
  --danger: #b3412e;
  --shadow: 0 1px 2px rgba(29, 42, 33, .06), 0 6px 18px rgba(29, 42, 33, .06);
  --radius: 16px;
  --radius-sm: 10px;
  --tone-sage: #dbe8dc;
  --tone-clay: #f3dccd;
  --tone-butter: #f6ebc4;
  --tone-sky: #d8e6ee;
  --tone-plum: #eadbe7;
  --tone-moss: #e2e6cf;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a16;
    --surface: #1c241e;
    --surface-2: #19201b;
    --ink: #ebefe8;
    --muted: #a3aba0;
    --line: #2d382f;
    --primary: #6fbf8c;
    --primary-ink: #0f1a13;
    --primary-soft: #23382a;
    --accent: #ec9367;
    --accent-soft: #3a271d;
    --warn: #f0c46b;
    --warn-soft: #362c17;
    --danger: #f08a77;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
    --tone-sage: #26372b;
    --tone-clay: #3b2b22;
    --tone-butter: #39331c;
    --tone-sky: #213039;
    --tone-plum: #342634;
    --tone-moss: #2f3322;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; line-height: 1.2; margin: 0; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar / nav ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; padding: .7rem 16px; }
.logo { display: flex; align-items: center; gap: .5rem; text-decoration: none; color: var(--ink); }
.logo-mark { width: 32px; height: 32px; }
.logo-word { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; }
.logo-word span { color: var(--accent); }
.nav-top { display: none; margin-left: auto; gap: .25rem; }
.nav-top a {
  text-decoration: none; color: var(--muted); padding: .45rem .8rem; border-radius: 999px; font-weight: 500;
}
.nav-top a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.nav-top a:hover { color: var(--ink); }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: .55rem 0 .5rem; text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 500;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--primary); }

@media (min-width: 860px) {
  body { padding-bottom: 2rem; }
  .tabbar { display: none; }
  .nav-top { display: flex; }
}

.page { max-width: 1180px; margin: 0 auto; padding: 1.25rem 16px 2rem; }

/* ---------- buttons, chips, inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; font-size: .92rem;
  border: 1px solid transparent; border-radius: 999px; padding: .55rem 1rem;
  background: var(--primary); color: var(--primary-ink); cursor: pointer; text-decoration: none;
  transition: transform .08s ease, background .15s ease; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 18px; height: 18px; }
.badge svg, .dish-warn svg { width: 13px; height: 13px; flex: none; }
.day-empty svg { width: 18px; height: 18px; flex: none; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface); }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; padding: 0;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { border-color: var(--muted); }

.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; font: inherit; font-size: .85rem; font-weight: 500;
  padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.chip[aria-pressed="true"], .chip.active { background: var(--ink); border-color: var(--ink); color: var(--bg); }
label.chip { display: inline-flex; align-items: center; gap: .35rem; }
label.chip input { accent-color: var(--primary); margin: 0; }
label.chip:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  font-size: .74rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.badge-green { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

.field { display: grid; gap: .35rem; margin-bottom: 1rem; }
.field label, .field .label { font-weight: 600; font-size: .9rem; }
.input, select.input, textarea.input {
  font: inherit; width: 100%; padding: .65rem .8rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.input:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
.hint { font-size: .82rem; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 1.25rem; }
.alert { border-radius: var(--radius-sm); padding: .75rem 1rem; margin-bottom: 1rem; font-size: .92rem; }
.alert-error { background: #fbe3df; color: #8a2a1b; }
.alert-ok { background: var(--primary-soft); color: var(--primary); }
@media (prefers-color-scheme: dark) { .alert-error { background: #3d211c; color: #f4b0a3; } }

/* ---------- page head / week nav ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.weeknav { display: flex; align-items: center; gap: .5rem; }
.weeknav h1 { font-size: 1.45rem; }
.weeknav .sub { color: var(--muted); font-size: .9rem; }
.today-link { font-size: .82rem; font-weight: 600; }

/* ---------- layout: plan + suggestions ---------- */
.layout { display: grid; gap: 1.5rem; }
@media (min-width: 980px) {
  .layout { grid-template-columns: 360px 1fr; align-items: start; }
  .plan-col { position: sticky; top: 76px; }
}
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }

/* plan */
.plan { display: grid; gap: .5rem; }
.day {
  display: grid; grid-template-columns: 62px 1fr; gap: .6rem; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: .5rem .6rem;
  min-height: 64px; transition: border-color .15s, background .15s;
}
.day.is-today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.day.is-past { opacity: .62; }
.day.drop-target { background: var(--primary-soft); border-color: var(--primary); border-style: dashed; }
.day-name { line-height: 1.15; }
.day-name strong { display: block; font-size: .9rem; }
.day-name span { font-size: .75rem; color: var(--muted); }
.day-empty {
  display: flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .88rem;
  border: 1.5px dashed var(--line); border-radius: 10px; padding: .55rem .7rem; background: transparent;
  font-family: inherit; cursor: pointer; text-align: left; width: 100%;
}
.day-empty:hover { border-color: var(--primary); color: var(--primary); }
.day-dish { display: grid; grid-template-columns: 40px 1fr auto; gap: .55rem; align-items: center; min-width: 0; }
.day-dish[draggable="true"] { cursor: grab; }
.day-dish .thumb { width: 40px; height: 40px; border-radius: 10px; font-size: 1.3rem; }
.day-dish a { color: var(--ink); text-decoration: none; font-weight: 600; font-size: .92rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-dish a:hover { color: var(--primary); }
.day-tools { display: flex; align-items: center; gap: .25rem; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.stepper button { border: 0; background: transparent; color: var(--ink); width: 26px; height: 26px; cursor: pointer; font-size: 1rem; line-height: 1; }
.stepper button:hover, .stepper a:hover { background: var(--primary-soft); }
.stepper a { width: 26px; height: 26px; display: grid; place-items: center; text-decoration: none; color: var(--ink); }
.stepper span { min-width: 2.6em; text-align: center; font-size: .78rem; font-weight: 600; }
.plan-foot { margin-top: .9rem; display: flex; gap: .5rem; }
.plan-foot .btn { flex: 1; }

/* suggestions */
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.dish {
  display: flex; flex-direction: column; overflow: hidden; position: relative;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease;
}
.dish:hover { transform: translateY(-2px); }
.dish[draggable="true"] { cursor: grab; }
.dish.is-dragging { opacity: .5; }
.dish.does-not-fit { opacity: .72; }
.thumb { display: grid; place-items: center; background: var(--tone-sage); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.tone-sage { background: var(--tone-sage); }
.tone-clay { background: var(--tone-clay); }
.tone-butter { background: var(--tone-butter); }
.tone-sky { background: var(--tone-sky); }
.tone-plum { background: var(--tone-plum); }
.tone-moss { background: var(--tone-moss); }
.dish .thumb { height: 128px; font-size: 3rem; position: relative; }
.dish .fav-btn { position: absolute; top: .55rem; right: .55rem; }
.dish .planned-badge { position: absolute; left: .55rem; top: .55rem; }
.dish-body { padding: .85rem .95rem .4rem; display: grid; gap: .4rem; flex: 1; align-content: start; }
.dish-title { font-family: var(--font-display); font-size: 1.08rem; font-weight: 600; color: var(--ink); text-decoration: none; line-height: 1.25; }
.dish-title:hover { color: var(--primary); }
.dish-desc { color: var(--muted); font-size: .86rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 0; }
.dish-meta { display: flex; flex-wrap: wrap; gap: .3rem; }
.dish-warn { font-size: .8rem; color: var(--warn); display: flex; gap: .3rem; align-items: center; }
.dish-actions { display: flex; gap: .4rem; padding: .6rem .95rem .9rem; }
.dish-actions .btn:first-child { flex: 1; }
.dish-pending { display: grid; place-items: center; text-align: center; gap: .5rem; padding: 1.5rem 1rem; min-height: 260px; border-style: dashed; box-shadow: none; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--primary-soft); border-top-color: var(--primary); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.fav-btn {
  width: 34px; height: 34px; border-radius: 999px; border: 0; cursor: pointer; display: grid; place-items: center;
  background: color-mix(in srgb, var(--surface) 90%, transparent); color: var(--muted); box-shadow: var(--shadow);
}
.fav-btn svg { width: 18px; height: 18px; }
.fav-btn[aria-pressed="true"] { color: #e0445c; }
.fav-btn[aria-pressed="true"] svg { fill: currentColor; }

.empty {
  text-align: center; padding: 2.5rem 1.25rem; border: 1.5px dashed var(--line); border-radius: var(--radius); color: var(--muted);
}
.empty .big { font-size: 2.5rem; margin-bottom: .5rem; }
.menu-note { background: var(--accent-soft); color: var(--ink); border-radius: var(--radius-sm); padding: .7rem .9rem; font-size: .92rem; margin-bottom: 1rem; }

/* ---------- dialogs ---------- */
dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(20, 26, 22, .45); backdrop-filter: blur(2px); }
.dialog-head { padding: 1.1rem 1.25rem .4rem; display: flex; justify-content: space-between; align-items: start; gap: 1rem; }
.dialog-body { padding: .4rem 1.25rem 1.25rem; }
.day-pick { display: grid; gap: .4rem; }
.day-pick button {
  display: flex; justify-content: space-between; gap: .75rem; align-items: center; text-align: left;
  font: inherit; padding: .65rem .85rem; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); cursor: pointer;
}
.day-pick button:hover { border-color: var(--primary); background: var(--primary-soft); }
.day-pick button .taken { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }
.day-pick button:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- recipe page ---------- */
.recipe-hero { display: grid; gap: 1.25rem; margin-bottom: 1.5rem; }
.recipe-hero .thumb { height: 220px; border-radius: var(--radius); font-size: 5rem; overflow: hidden; }
@media (min-width: 860px) { .recipe-hero { grid-template-columns: 1.1fr 1fr; align-items: center; } .recipe-hero .thumb { height: 300px; } }
.recipe-hero h1 { font-size: 2.1rem; margin-bottom: .5rem; }
.meta-row { display: flex; flex-wrap: wrap; gap: .4rem; margin: .75rem 0; }
.stars { display: inline-flex; gap: 2px; }
.stars button { border: 0; background: none; padding: 2px; cursor: pointer; color: var(--line); }
.stars button svg { width: 24px; height: 24px; fill: currentColor; }
.stars button.on { color: #e9a93b; }
.recipe-cols { display: grid; gap: 1.25rem; }
@media (min-width: 860px) { .recipe-cols { grid-template-columns: 340px 1fr; align-items: start; } }
.ingredients { list-style: none; padding: 0; margin: 0; }
.ingredients li { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.ingredients li:last-child { border-bottom: 0; }
.ingredients .amt { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.steps { padding-left: 0; margin: 0; list-style: none; counter-reset: step; }
.steps li { counter-increment: step; position: relative; padding: 0 0 1.1rem 2.6rem; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: -.1rem; width: 1.9rem; height: 1.9rem; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; display: grid; place-items: center; font-size: .88rem;
}
.sources { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.sources a { display: flex; gap: .6rem; align-items: center; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--ink); background: var(--surface-2); }
.sources a:hover { border-color: var(--primary); }
.sources .host { color: var(--muted); font-size: .8rem; display: block; }
.sources svg { width: 18px; height: 18px; flex: none; color: var(--primary); }

/* ---------- shopping ---------- */
.shop-wrap { max-width: 720px; margin: 0 auto; }
.progress { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin: .4rem 0 1rem; }
.progress span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .3s ease; }
.shop-group { margin-bottom: 1.25rem; }
.shop-group h3 { font-family: var(--font); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 .4rem .2rem; }
.shop-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.shop-item { display: flex; align-items: center; gap: .8rem; padding: .7rem .9rem; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; }
.shop-item:last-child { border-bottom: 0; }
.shop-item input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; cursor: pointer; }
.shop-item .name { flex: 1; min-width: 0; }
.shop-item .from { display: block; font-size: .76rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shop-item .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; font-size: .9rem; }
.shop-item.checked .name, .shop-item.checked .amt { text-decoration: line-through; color: var(--muted); }
.shop-item .del { opacity: .5; }
.add-row { display: flex; gap: .5rem; margin-bottom: 1rem; }
.planned-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1.25rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 16px; }
.auth .card { width: min(420px, 100%); padding: 2rem 1.5rem; }
.btn-google { gap: .6rem; }
.btn-google svg { width: 18px; height: 18px; flex: none; }
.divider { display: flex; align-items: center; gap: .75rem; margin: 1.1rem 0; color: var(--muted); font-size: .82rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.auth .logo { justify-content: center; margin-bottom: 1rem; }
.auth h1 { text-align: center; font-size: 1.5rem; margin-bottom: .35rem; }
.auth .lead { text-align: center; color: var(--muted); margin-bottom: 1.5rem; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; margin-bottom: 1rem; }
.tabs button { font: inherit; font-weight: 600; font-size: .88rem; border: 0; border-radius: 999px; padding: .45rem; background: transparent; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- settings ---------- */
.settings { display: grid; gap: 1.25rem; max-width: 760px; margin: 0 auto; }
.members { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: .5rem; }
.members li { display: flex; align-items: center; gap: .7rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; }
.invite { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.15rem; letter-spacing: .12em; background: var(--surface-2); border: 1px dashed var(--line); border-radius: 10px; padding: .4rem .8rem; }
.chip-grid { display: flex; flex-wrap: wrap; gap: .4rem; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 999px; font-size: .9rem; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 860px) { .toast { bottom: 2rem; } }

@media print {
  .topbar, .tabbar, .toolbar, .add-row, .no-print { display: none !important; }
  body { background: #fff; padding: 0; }
  .shop-list { border: 0; }
}
