:root {
  --paper: #FAFBF9;
  --surface: #FFFFFF;
  --ink: #1E2B27;
  --muted: #56665F;
  --line: #D6DED9;
  --kale: #2F6B4F;
  --kale-soft: #E4EEE8;
  --pumpkin: #B85A0C;
  --pumpkin-soft: #FBEADB;
  --danger: #A12B2B;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #121816;
    --surface: #19211E;
    --ink: #E6ECE9;
    --muted: #9CAAA4;
    --line: #2D3834;
    --kale: #86C7A3;
    --kale-soft: #1F2E27;
    --pumpkin: #F2A45E;
    --pumpkin-soft: #33251A;
    --danger: #F08A8A;
  }
}

* { box-sizing: border-box; }
/* The hidden attribute must win over display: grid/flex below (the stock form's Cancel relied on it). */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
}
.wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px 64px;
  display: grid;
  gap: 32px;
}
h1, h2, h3 { line-height: 1.15; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(1.8rem, 6vw, 2.6rem); font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.35rem; font-weight: 800; margin-bottom: 10px; }
h3 { font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.eyebrow {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--kale);
}
header { display: grid; gap: 8px; }
.title-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.sub { color: var(--muted); max-width: 64ch; }
select, input, textarea, button { font: inherit; color: inherit; }
select, input, textarea {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}
:focus-visible { outline: 2px solid var(--kale); outline-offset: 2px; }

/* Ask */
.ask {
  background: var(--kale-soft);
  border-radius: 10px;
  padding: 16px;
}
.ask h2 { font-size: 1.1rem; }
#ask-form { display: grid; gap: 10px; }
#ask-form textarea { width: 100%; resize: vertical; }
.ask-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.who { display: flex; gap: 8px; align-items: center; color: var(--muted); }
.who input { width: 10em; }
button {
  background: var(--kale);
  color: var(--paper);
  border: 0;
  border-radius: 6px;
  padding: 8px 18px;
  font-weight: 700;
  cursor: pointer;
}
button:disabled { opacity: 0.55; cursor: progress; }
button.quiet {
  background: transparent;
  color: var(--kale);
  border: 1px solid var(--kale);
  padding: 2px 10px;
  font-size: 0.85rem;
}
.ask-status { margin-top: 10px; }
.ask-status.question { color: var(--pumpkin); font-weight: 600; }
.ask-status.bad { color: var(--danger); }

/* Dinners */
.dinners { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.dinner {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.dinner.today { border: 2px solid var(--kale); }
.dinner.out, .dinner.skipped { background: transparent; }
.dinner.past { opacity: 0.7; }
.dinner summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 4.2em 1fr;
  gap: 4px 12px;
}
.dinner summary::-webkit-details-marker { display: none; }
.dinner .day { font-weight: 800; line-height: 1.2; }
.dinner .day small { display: block; font-weight: 400; font-size: 0.8rem; color: var(--muted); }
.dinner .dish { font-weight: 700; }
.dinner.out .dish, .dinner.skipped .dish { font-weight: 400; color: var(--muted); }
.dinner .line { grid-column: 2; font-size: 0.88rem; color: var(--muted); }
.dinner .line.prep { color: var(--kale); }
.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 3px;
  padding: 0 5px;
  margin-left: 6px;
  vertical-align: 2px;
  border: 1px solid currentColor;
  color: var(--kale);
}
.badge.today { background: var(--kale); color: var(--paper); border-color: var(--kale); }
.badge.warm { color: var(--pumpkin); }
.dinner-body { padding: 0 14px 16px; display: grid; gap: 14px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: 0.88rem; }
.sec-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.dinner-body ul, .dinner-body ol { margin: 6px 0 0; padding-left: 1.3em; display: grid; gap: 5px; }
.src { font-size: 0.75rem; color: var(--kale); margin-left: 4px; }
.tomorrow { border-left: 3px solid var(--kale); background: var(--kale-soft); border-radius: 0 6px 6px 0; padding: 8px 12px; }
.tomorrow strong { color: var(--kale); }
.more dt { font-weight: 700; font-size: 0.85rem; color: var(--muted); }
.more dd { margin: 0 0 6px; }

/* Notes */
.notes { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.note { background: var(--kale-soft); border-radius: 8px; padding: 14px 16px; display: grid; gap: 6px; align-content: start; }
.note.note-safety { background: var(--pumpkin-soft); }
.note ul { margin: 0; padding-left: 1.1em; display: grid; gap: 4px; }

/* Shopping */
.shop { display: grid; gap: 12px; }
.shop-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.shop-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px 36px; }
.shop-cols h3 { margin-bottom: 4px; }
.items { list-style: none; margin: 0; padding: 0; }
.items li { border-bottom: 1px solid var(--line); }
.items label {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 9px 0;
  cursor: pointer;
}
.items input { accent-color: var(--kale); width: 1.15rem; height: 1.15rem; transform: translateY(3px); }
.items input:checked + span { text-decoration: line-through; color: var(--muted); }
.items .for { font-size: 0.8rem; color: var(--muted); }
.items .price { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.total {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px;
  padding-top: 10px; border-top: 2px solid var(--ink); font-variant-numeric: tabular-nums;
}
.total:empty { display: none; }

/* Not logged in: only the title and how to log in */
.logged-out .wrap > :not(header):not(#logged-out) { display: none !important; }
.logged-out-note { background: var(--kale-soft); border-radius: 10px; padding: 16px; display: grid; gap: 6px; }

/* Stock */
.stock { display: grid; gap: 10px; }
.stock-view { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; display: grid; gap: 8px; }
.stock-view h3 { margin-top: 6px; }
.stock-view ul { margin: 0; padding-left: 1.2em; display: grid; gap: 3px; }
#stock-form { display: grid; gap: 10px; }
#stock-form textarea { width: 100%; font-family: ui-monospace, monospace; font-size: 0.9rem; }

/* Extra, history */
.extra { display: grid; gap: 8px; color: var(--muted); }
.extra:empty { display: none; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: start; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.history .when { font-size: 0.8rem; color: var(--muted); }
/* A new plan's summary can be long: show three lines, the full text is in the tooltip. */
.history .change { display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.error { color: var(--danger); font-weight: 600; }

/* ---- Paper ----
   First: title, the week at a glance, the shopping list and the notes. Then the recipes, straight
   after (no forced page break, so no half-empty page), each kept together, ingredients beside the
   method. Everything interactive is left out. */
.print-only { display: none; }

@media print {
  @page { size: A4; margin: 12mm 12mm 14mm; }
  :root {
    color-scheme: light;
    --paper: #fff; --surface: #fff; --ink: #111; --muted: #444; --line: #bbb;
    --kale: #1f5a3e; --kale-soft: #eef4f0; --pumpkin: #9a4a08; --pumpkin-soft: #fdf1e6;
  }
  body { background: #fff; font-size: 10pt; line-height: 1.4; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  /* Flex, not grid: Chrome splits grids across pages badly (overlapping rows). */
  .wrap { max-width: none; padding: 0; gap: 14px; display: flex; flex-direction: column; }
  h1 { font-size: 20pt; }
  h2, h3 { break-after: avoid; }
  h2 { font-size: 13pt; margin-bottom: 6px; }

  .print-only { display: block; }
  .screen-only, .ask, .stock, .history-section, #week, #error, #shop-count, button { display: none !important; }

  /* Order on paper; the screen order stays as it is. */
  header { order: 1; }
  .overview { order: 2; }
  .shop { order: 3; }
  .notes { order: 4; }
  .extra { order: 5; }
  .week-section { order: 6; }

  .sub { max-width: none; }

  /* The week at a glance */
  .overview table { width: 100%; border-collapse: collapse; }
  .overview th, .overview td { text-align: left; vertical-align: top; padding: 4px 6px; border-bottom: 1px solid var(--line); }
  .overview th { font-size: 8pt; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border-bottom: 1.5px solid var(--ink); }
  .overview .day { white-space: nowrap; font-weight: 700; }
  .overview .day small { font-weight: 400; color: var(--muted); }
  .overview .time { white-space: nowrap; color: var(--muted); }
  .overview .prep { font-size: 8.5pt; color: var(--kale); }
  .overview tr.out td, .overview tr.skipped td { color: var(--muted); }
  .overview tr.out strong { font-weight: 400; }

  /* Shopping list: two columns, empty boxes to tick with a pen */
  .shop { gap: 6px; }
  /* Sections one below the other, items in two columns as inline blocks: plain lines of text,
     which break across pages cleanly (CSS columns and grids don't, in Chrome). */
  .shop-cols { display: block; }
  .shop-cols > div { margin-bottom: 8px; }
  #shop-intro { font-size: 8.5pt; }
  .items li { display: inline-block; width: calc(50% - 12px); margin-right: 12px; vertical-align: top; }
  .items label { padding: 2px 0; gap: 6px; }
  .items input { width: 0.85rem; height: 0.85rem; }
  .items input:checked + span { text-decoration: none; color: inherit; }
  .total { padding-top: 4px; }
  .notes { display: block; }
  .note { display: block; padding: 6px 10px; margin-bottom: 6px; font-size: 8.5pt; }
  .note ul { display: block; }
  .extra { font-size: 8.5pt; }

  /* Recipes */
  .dinners { gap: 10px; font-size: 9.5pt; }
  .dinner, .dinner.out, .dinner.skipped { border: 0; border-top: 1.5px solid var(--ink); border-radius: 0; background: none; break-inside: avoid; }
  .dinner.today { border-width: 1.5px 0 0; }
  .dinner.past { opacity: 1; }
  .badge.today { display: none; }
  .dinner summary { padding: 8px 0 6px; }
  /* Evenings away are on the overview; no card for them among the recipes. */
  .dinners > li:has(> .dinner.out), .dinners > li:has(> .dinner.skipped) { display: none; }
  .dinner-body { padding: 0 0 8px; grid-template-columns: 1fr 2fr; gap: 6px 20px; }
  .dinner-body > :not(.ingr):not(.method) { grid-column: 1 / -1; }
  .dinner-body .ingr { grid-column: 1; }
  .dinner-body .method { grid-column: 2; }
  .dinner-body ul, .dinner-body ol { gap: 2px; }
  /* Recipes open for paper even where the beforeprint script can't run. */
  details.dinner::details-content { content-visibility: visible; display: contents; }
}
