:root {
  --bg: #f6f7f5; --card: #fff; --text: #1d2420; --muted: #6b746e; --border: #dfe3df;
  --primary: #2f7d4f; --primary-text: #fff; --danger: #b3261e; --selected: #e7f3ec;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141816; --card: #1e2421; --text: #e8ece9; --muted: #9aa39d; --border: #333b36;
    --primary: #4caf73; --primary-text: #0d1310; --danger: #f2827a; --selected: #1f3328; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text);
  padding-bottom: env(safe-area-inset-bottom); }
main { max-width: 640px; margin: 0 auto; padding: 12px 12px 120px; }
h1, h2, h3 { margin: 12px 0; } h2 { font-size: 1.4rem; } h3 { font-size: 1.05rem; color: var(--muted); }

header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border-bottom: 1px solid var(--border); padding: 0 12px; padding-top: env(safe-area-inset-top); }
header nav { display: flex; }
header nav a { padding: 14px 14px; color: var(--muted); text-decoration: none; font-weight: 600; border-bottom: 3px solid transparent; }
header nav a.active { color: var(--primary); border-bottom-color: var(--primary); }

input, select, textarea, button, .button { font: inherit; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); padding: 10px 12px; min-height: 44px; }
textarea { width: 100%; margin-top: 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
button, .button { cursor: pointer; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; }
button.primary, .button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--muted); font-weight: 400; }

.row { display: flex; gap: 8px; align-items: center; }
.row > input:not(.qty) { flex: 1; min-width: 0; }
.row.space { justify-content: space-between; }
.qty { width: 7.5em; flex: 0 0 auto; }
.add { margin: 8px 0 16px; }
.footer { margin-top: 20px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.cards { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.link-card { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: inherit; text-decoration: none; }
.link-card.done strong { text-decoration: line-through; color: var(--muted); }
.muted { color: var(--muted); font-size: .9em; }
.hint { margin: 8px 0; }
.empty { color: var(--muted); text-align: center; padding: 32px 12px; }
.back { display: inline-block; margin-top: 8px; color: var(--muted); text-decoration: none; }
.editable { cursor: pointer; }
.error { color: var(--danger); margin: 0; }

.login { max-width: 360px; margin: 15vh auto 0; display: grid; gap: 12px; }
.login h1 { text-align: center; font-size: 1.5rem; }

/* shopping list items */
.items { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.items:empty { display: none; }
.item { display: flex; align-items: center; border-bottom: 1px solid var(--border); min-height: 52px; }
.item:last-child { border-bottom: 0; }
.item.editing { padding: 8px; }
.item.editing form { width: 100%; }
.item.editing button { padding: 10px; min-width: 44px; }
.check { padding: 12px; display: flex; cursor: pointer; }
.check input { width: 24px; height: 24px; min-height: 0; margin: 0; accent-color: var(--primary); cursor: pointer; }
.item-text { flex: 1; padding: 10px 12px 10px 0; cursor: pointer; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.item-text .name { font-weight: 500; }
.qty-label { color: var(--primary); font-weight: 600; }
.source { flex-basis: 100%; }
.item.checked .name, .item.checked .qty-label { text-decoration: line-through; color: var(--muted); }

/* dishes */
.dish { display: flex; align-items: center; padding: 4px 14px 4px 2px; }
.dish.selected { background: var(--selected); border-color: var(--primary); }
.dish-text { flex: 1; display: grid; color: inherit; text-decoration: none; padding: 8px 0; min-width: 0; }
.dish-text .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ingredients { list-style: none; padding: 0; margin: 0 0 8px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.ingredients .qty { width: 6.5em; }
.card > input { width: 100%; }

.action-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--card); border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center;
  box-shadow: 0 -4px 16px rgb(0 0 0 / .08); }
.action-bar select { flex: 1; min-width: 140px; max-width: 280px; }
.group { margin-top: 18px; }
.group-head { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.group-head .check { padding: 8px 10px 8px 2px; }
.group-head h3 { flex: 1; margin: 0; color: var(--text); }
.group-head .count { font-weight: 400; }
.button.small, button.icon { min-height: 36px; min-width: 40px; padding: 4px 10px; }
.group-row { padding-left: 14px; gap: 4px; padding-right: 8px; }
.group-row .item-text { padding-left: 0; }
button:disabled { opacity: .35; cursor: default; }
select.full { width: 100%; }
[hidden] { display: none !important; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; z-index: 10; }
