/* Warm kitchen palette. Light by default, dark follows the system unless the toggle picks one. */
:root {
  --bg: #faf6ef;
  --bg-glow: #f6e4d2;
  --surface: #fffdf9;
  --surface-2: #f5eee4;
  --text: #2b2420;
  --muted: #7a6d62;
  --line: #ebe1d3;
  --accent: #c2562d;
  --accent-hover: #a9461f;
  --on-accent: #fff8ef;
  --accent-soft: #f9e5d9;
  --herb: #4d7a4f;
  --herb-soft: #e3eedf;
  --warn: #9a5f0c;
  --warn-soft: #fbeed3;
  --danger: #b23a2b;
  --shadow: 0 1px 2px rgb(60 40 20 / .06), 0 4px 14px rgb(60 40 20 / .06);
  --shadow-hover: 0 2px 4px rgb(60 40 20 / .08), 0 10px 24px rgb(60 40 20 / .10);
  --radius: 14px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", var(--font);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18140f;
    --bg-glow: #2a1d14;
    --surface: #221c17;
    --surface-2: #2b241e;
    --text: #f3ebe1;
    --muted: #ab9d90;
    --line: #382f28;
    --accent: #f08a5d;
    --accent-hover: #f59d76;
    --on-accent: #2a1309;
    --accent-soft: #3b261b;
    --herb: #9cc79a;
    --herb-soft: #24321f;
    --warn: #f0b860;
    --warn-soft: #362a17;
    --danger: #f08a7b;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 14px rgb(0 0 0 / .25);
    --shadow-hover: 0 2px 4px rgb(0 0 0 / .35), 0 10px 24px rgb(0 0 0 / .35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #18140f;
  --bg-glow: #2a1d14;
  --surface: #221c17;
  --surface-2: #2b241e;
  --text: #f3ebe1;
  --muted: #ab9d90;
  --line: #382f28;
  --accent: #f08a5d;
  --accent-hover: #f59d76;
  --on-accent: #2a1309;
  --accent-soft: #3b261b;
  --herb: #9cc79a;
  --herb-soft: #24321f;
  --warn: #f0b860;
  --warn-soft: #362a17;
  --danger: #f08a7b;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 14px rgb(0 0 0 / .25);
  --shadow-hover: 0 2px 4px rgb(0 0 0 / .35), 0 10px 24px rgb(0 0 0 / .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 500px at 85% -10%, var(--bg-glow), transparent 70%), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
main { max-width: 1120px; margin: 0 auto; padding: 20px 16px 48px; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
h1, h2 { font-family: var(--font-display); letter-spacing: -.01em; }
h1 { font-size: 1.7rem; line-height: 1.2; margin: .25rem 0 1rem; font-weight: 750; }
h2 { font-size: 1.2rem; margin: 2rem 0 .6rem; font-weight: 700; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1rem; margin: .25rem 0 1.25rem; }
.page-head h1 { margin: 0; }
.page-head .actions { margin: 0; }
code { background: var(--surface-2); border-radius: 5px; padding: .05rem .3rem; font-size: .9em; }
.muted, .hint { color: var(--muted); }
.hint { font-size: .88rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Top bar */
.topbar {
  display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between;
  padding: .55rem 16px; position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: .55rem; font-family: var(--font-display); font-weight: 750; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--text); }
.logo { width: 30px; height: 30px; flex: none; }
.brand { margin-right: auto; }
.topbar nav, .topbar-end { display: flex; flex-wrap: wrap; gap: .15rem; align-items: center; }
.topbar nav a, .topbar-end .link, .topbar-end .back { padding: .4rem .75rem; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 550; font-size: .95rem; }
.topbar nav a:hover, .topbar-end .link:hover, .topbar-end .back:hover { color: var(--text); background: var(--surface-2); }
.topbar nav a.on { background: var(--accent-soft); color: var(--accent); }
.topbar form { display: inline; margin: 0; }

.theme-toggle {
  display: inline-flex; align-items: center; gap: .35rem; margin-left: .25rem;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: .3rem .65rem; font-size: .85rem; font-weight: 600; box-shadow: none;
}
.theme-toggle:hover { color: var(--text); background: var(--surface-2); border-color: var(--muted); }
.theme-toggle svg { width: 16px; height: 16px; display: none; }
.theme-toggle[data-mode="auto"] .i-auto, .theme-toggle[data-mode="light"] .i-light, .theme-toggle[data-mode="dark"] .i-dark { display: block; }
.theme-toggle:not([data-mode]) .i-auto { display: block; }

/* Messages */
.flash { display: flex; gap: .5rem; align-items: center; padding: .7rem 1rem; border-radius: 12px; margin-bottom: 1rem;
  background: var(--herb-soft); color: var(--herb); font-weight: 550; border: 1px solid color-mix(in srgb, var(--herb) 25%, transparent); }
.flash::before { content: "✓"; font-weight: 800; }
.flash.alert { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.flash.alert::before { content: "!"; }
.errors { color: var(--danger); font-weight: 550; }
.flash.nudge { justify-content: space-between; flex-wrap: wrap; }
.flash.nudge::before { content: none; }
.flash.nudge .btn { padding: .4rem .9rem; font-size: .9rem; }
details.help { margin-top: 1.2rem; font-size: .92rem; }
.card h3 { font-family: var(--font-display); font-size: 1rem; margin: 1.2rem 0 .3rem; }
.card h3:first-child { margin-top: 0; }
.divider { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .85rem; margin: 1.2rem 0 .8rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
details.help summary, details.more > summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details.more { margin-top: .8rem; }
details.help ul { padding-left: 1.1rem; margin: .4rem 0 0; }
details.help li { margin-bottom: .5rem; }
details.help code { display: inline-block; margin-top: .25rem; font-size: .8rem; word-break: break-all; }

/* Forms */
input, select, textarea, button { font: inherit; color: inherit; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 2.2rem !important; min-width: 6rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 1.05rem) 52%, calc(100% - .75rem) 52%;
  background-size: .3rem .3rem, .3rem .3rem; background-repeat: no-repeat;
}
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  background-color: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; max-width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
/* One control height everywhere so labels and buttons in a row line up. */
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select { height: 2.75rem; }
/* Text fields fill their form; selects, numbers and dates keep their natural width. */
.card :is(input[type=text], input[type=email], input[type=password], input[type=search]) { width: 100%; }
td :is(input[type=text], input[type=number], select) { width: 100%; min-width: 0; }
td input[type=number] { max-width: 7rem; }
.narrow, input.narrow { max-width: 28rem; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
input[type=number] { width: 5.5em; }
input[type=checkbox] { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; }
textarea { width: 100%; }
label { display: block; margin: .9rem 0 .3rem; font-weight: 650; font-size: .92rem; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; margin: 0 .9rem .35rem 0; font-weight: 450; }
.slot-pick { display: flex; align-items: center; gap: .3rem; }
.slot-pick label.inline { margin: 0; min-width: 5.5rem; }
label.rule-pick { display: flex; align-items: baseline; }
label.rule-pick input { flex: none; transform: translateY(.15rem); }

.btn, button, input[type=submit] {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  background: var(--accent); color: var(--on-accent); border: 1px solid transparent; border-radius: 999px;
  padding: .55rem 1.1rem; font-weight: 650; cursor: pointer; text-decoration: none; line-height: 1.2;
  box-shadow: 0 1px 2px rgb(0 0 0 / .08); transition: background .15s, transform .05s, border-color .15s;
}
.btn:hover, button:hover, input[type=submit]:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn:active, button:active, input[type=submit]:active { transform: translateY(1px); }
.btn.secondary, button.secondary, input[type=submit].secondary { background: var(--surface); color: var(--text); border-color: var(--line); box-shadow: none; }
.btn.secondary:hover, button.secondary:hover, input[type=submit].secondary:hover { background: var(--surface-2); color: var(--text); border-color: var(--muted); }
button.link { background: none; border: 0; box-shadow: none; padding: .35rem .6rem; color: var(--muted); font-weight: 550; }
button.link:hover { background: var(--surface-2); color: var(--text); }
button.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); box-shadow: none; }
button.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.toggle { min-width: 3.6rem; padding: .35rem .8rem; font-size: .88rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: 1.1rem; }
.actions form { margin: 0; }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
details.card > summary { cursor: pointer; font-family: var(--font-display); font-weight: 700; list-style: none; display: flex; align-items: center; gap: .5rem; }
details.card > summary::-webkit-details-marker { display: none; }
/* Plus drawn with two bars so it is exactly centred; rotates into a cross when open. */
details.card > summary::before {
  content: ""; flex: none; width: 1.4rem; height: 1.4rem; border-radius: 50%; transition: transform .15s;
  background:
    linear-gradient(var(--on-accent), var(--on-accent)) center / .7rem 2px no-repeat,
    linear-gradient(var(--on-accent), var(--on-accent)) center / 2px .7rem no-repeat,
    var(--accent);
}
details.card[open] > summary::before { transform: rotate(45deg); }
details.card[open] > summary { margin-bottom: .6rem; }
.row { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: end; }
.row > div { min-width: 0; }

.tag { display: inline-block; font-size: .8rem; font-weight: 600; padding: .12rem .55rem; border-radius: 999px; background: var(--herb-soft); color: var(--herb); margin: 0 .2rem .25rem 0; text-decoration: none; }
.tag.off { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.pill, .tag { white-space: nowrap; }
.pill { font-size: .75rem; font-weight: 600; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: .05rem .5rem; }

/* Plan: days are rows, meal slots are columns; stacks on phones. */
.plan { display: grid; gap: .6rem; }
.slots-head, .day { display: grid; grid-template-columns: 5.5rem repeat(var(--slots), minmax(0, 1fr)); gap: .6rem; }
.slots-head { font-size: .75rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 0 .2rem; }
.day { align-items: stretch; }
.day-head { padding: .35rem 0; }
.date { display: grid; justify-items: start; line-height: 1.1; }
.date .wd { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.date .dd { font-family: var(--font-display); font-size: 1.6rem; font-weight: 750; }
.date .mm { font-size: .75rem; color: var(--muted); }
.day.today .date .wd, .day.today .date .dd { color: var(--accent); }
.day.today .meal:not(.out) { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
/* Floating panel: opens over the grid instead of stretching the row. */
.day-head { position: relative; }
details.popover > summary { font-size: .78rem; color: var(--muted); cursor: pointer; margin-top: .3rem; list-style: none; }
details.popover > summary::-webkit-details-marker { display: none; }
details.popover > summary:hover, details.popover[open] > summary { color: var(--accent); }
.popover-panel {
  position: absolute; z-index: 15; top: calc(100% + 2px); left: 0; width: 17rem; max-width: calc(100vw - 32px);
  display: grid; gap: .6rem; padding: .9rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow-hover);
}
.popover-panel strong { font-family: var(--font-display); }
.popover-panel input[type=text] { width: 100%; }
.popover-panel .actions { margin-top: .5rem; }
.popover-panel button { width: 100%; }

.meal {
  display: flex; flex-direction: column; gap: .15rem; min-height: 4.6rem; padding: .65rem .8rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  color: var(--text); text-decoration: none; transition: box-shadow .15s, transform .15s, border-color .15s;
}
.meal:hover { color: var(--text); box-shadow: var(--shadow-hover); transform: translateY(-1px); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.meal .slot { display: flex; justify-content: space-between; gap: .3rem; font-size: .72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.meal .slot .who { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 600; }
@media (min-width: 721px) { .meal .slot .name { display: none; } }
.meal .dish { font-weight: 650; font-size: 1rem; line-height: 1.3; }
.meal.empty { background: transparent; box-shadow: none; border-style: dashed; }
.meal.empty .dish { font-weight: 450; color: var(--muted); font-style: italic; font-size: .92rem; }
.meal.locked { border-left: 4px solid var(--herb); }
.meal.out { background: var(--warn-soft); border-color: transparent; color: var(--warn); box-shadow: none; }
.meal.out .slot { color: var(--warn); opacity: .85; }
.meal.out .dish::before { content: "↗ "; }
.meal .note { font-size: .85rem; }
@media (max-width: 720px) {
  .day { grid-template-columns: 1fr; gap: .45rem; }
  .meal { min-height: 0; padding: .55rem .8rem; }
  .slots-head { display: none; }
  .day-head { grid-column: 1 / -1; display: flex; align-items: baseline; gap: .8rem; padding-top: .8rem; border-top: 1px solid var(--line); }
  .date { display: flex; gap: .35rem; align-items: baseline; }
  .date .dd { font-size: 1.3rem; }
  details.popover > summary { margin-top: 0; }
}

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.card :is(th, td):first-child { padding-left: 0; }
.card :is(th, td):last-child { padding-right: 0; }
tr:last-child td { border-bottom: 0; }
th { font-size: .75rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
.table-wrap { overflow-x: auto; }
td a { text-decoration: none; font-weight: 650; }
td a:hover { text-decoration: underline; }

/* Toggle pills for filters: the checkbox stays for keyboard and no-JS use. */
.tag-filter { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .7rem; }
.tag-filter label { position: relative; display: inline-flex; align-items: center; gap: .35rem; margin: 0; padding: .25rem .7rem; border: 1px solid var(--line); border-radius: 999px; font-size: .85rem; font-weight: 600; color: var(--muted); cursor: pointer; transition: all .15s; }
.tag-filter label:hover { border-color: var(--herb); color: var(--herb); }
.tag-filter label:has(input:checked) { background: var(--herb-soft); border-color: transparent; color: var(--herb); }
.tag-filter label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.tag-filter input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tag-filter .count { font-size: .72rem; opacity: .7; }

/* Sign-in and setup */
.topbar.bare { background: transparent; border-bottom: 0; backdrop-filter: none; -webkit-backdrop-filter: none; position: static; }
.auth { max-width: 420px; margin: 2.5rem auto; padding: 1.6rem; }
.auth h1 { font-size: 1.5rem; }
.auth input[type=email], .auth input[type=text], .auth input[type=password] { width: 100%; }
.auth .actions > :only-child, .auth > form.button_to button, .auth .actions > form:only-child button { width: 100%; }
.auth > form.button_to { margin-top: 1rem; }
main:has(> .auth) > .flash { max-width: 420px; margin-inline: auto; }

/* Tag picker: searchable checkbox dropdown */
.tag-select { position: relative; }
.tag-control { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .35rem .5rem; cursor: text; transition: border-color .15s, box-shadow .15s; }
.tag-control:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-control input { border: 0; background: transparent; flex: 1; min-width: 8rem; padding: .2rem; outline: none; box-shadow: none; }
.tag-control input:focus { box-shadow: none; }
.tag-control { min-height: 2.75rem; }
.tag-control .caret { align-self: stretch; width: 1.4rem; font-size: 0; cursor: pointer;
  background: linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(50% - .15rem) 52% / .3rem .3rem no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(50% + .15rem) 52% / .3rem .3rem no-repeat; }
.tag-pills { display: contents; }
button.tag { border: 0; cursor: pointer; font-size: .82rem; padding: .18rem .6rem; margin: 0; box-shadow: none; background: var(--herb-soft); color: var(--herb); }
button.tag:hover { background: var(--herb-soft); color: var(--herb); filter: brightness(.96); }
.tag-menu { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0; max-height: 16rem; overflow-y: auto; padding: .3rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-hover); }
.tag-option { display: flex; align-items: center; gap: .55rem; margin: 0; padding: .45rem .6rem; border-radius: 8px; font-weight: 500; cursor: pointer; }
.tag-option:hover, .tag-option.active { background: var(--surface-2); }
.tag-option:has(input:checked) { color: var(--herb); font-weight: 650; }
.tag-create { display: block; width: 100%; text-align: left; background: transparent; color: var(--accent); border: 0; box-shadow: none; border-radius: 8px; padding: .45rem .6rem; font-weight: 650; }
.tag-create:hover, .tag-create.active { background: var(--accent-soft); color: var(--accent); }
.tag-empty { margin: 0; padding: .45rem .6rem; color: var(--muted); font-size: .9rem; }

/* Two-option switch (sign-up method) */
.segmented { display: inline-flex; padding: .2rem; gap: .2rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; }
.segmented label { margin: 0; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented span { display: inline-block; padding: .35rem .95rem; border-radius: 999px; font-weight: 600; color: var(--muted); }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

@media (max-width: 720px) {
  .topbar nav { order: 3; flex-wrap: nowrap; overflow-x: auto; width: calc(100% + 32px); margin: 0 -16px; padding: 0 12px .1rem; scrollbar-width: none; }
  .topbar nav::-webkit-scrollbar { display: none; }
  .topbar nav > * { flex: none; }
  .topbar nav a { padding: .35rem .65rem; }
  h1 { font-size: 1.45rem; }
  .page-head .actions { gap: .35rem; }
  .page-head .btn { padding: .4rem .7rem; font-size: .85rem; }
  .card { padding: 1rem; }
  /* Tables become stacked rows on phones. */
  table.stack tr:has(th) { display: none; }
  table.stack tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .3rem .6rem; align-items: center; padding: .7rem 0; border-bottom: 1px solid var(--line); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { padding: 0; border: 0; }
  table.stack td.wide { grid-column: 1 / -1; order: 2; }
  table.stack td.side { order: 1; }
  table.stack.ingredients tr { grid-template-columns: 4.5rem minmax(0, 1fr) minmax(0, 1.5fr); }
  table.stack.ingredients td:first-child, table.stack.ingredients td:last-child { grid-column: 1 / -1; }
  table.stack.ingredients td:last-child:not(:has(*)) { display: none; }
  table.stack.ingredients td { order: 0; }
}

@media print {
  .topbar, .no-print, .flash { display: none; }
  body { background: #fff; color: #000; }
  .card { border: 0; padding: 0; box-shadow: none; }
}
