:root {
  --img-h: clamp(40px, calc((100vh - 140px) / 5 - 80px), 190px);
  --bg: #f6f5f2;
  --surface: #fff;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --line: #e3e1db;
  --accent: #2f7d4f;
  --accent-soft: #e3f1e8;
  --warn: #9a5b00;
  --past: #d08a00;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #222220;
    --text: #ecebe7;
    --muted: #a3a19b;
    --line: #363531;
    --accent: #5cc285;
    --accent-soft: #1f3a2a;
    --warn: #e0a447;
    --past: #f0b13a;
  }
}

* { box-sizing: border-box; }
body { margin: 0; }

header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}
h1 { font-size: 18px; margin: 0; white-space: nowrap; }
.badge {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  background: var(--accent-soft); color: var(--accent);
  padding: 2px 6px; border-radius: 4px; vertical-align: middle;
}

#days { display: flex; gap: 6px; overflow-x: auto; }
#days button {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; text-align: center;
  font: inherit; font-size: 13px; line-height: 1.2; white-space: nowrap; flex: none;
}
#days button .count { display: block; font-size: 11px; color: var(--muted); }
#days button.done .count { color: var(--accent); }
#days button.locked { opacity: .55; }
#days button.urgent .count { color: var(--warn); font-weight: 600; }
#days button.new { position: relative; }
/* Menu published since you last looked at that day. */
#days button.new::after {
  content: ""; position: absolute; top: 4px; right: 4px;
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
}
#days button.current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

main { padding: 10px 20px 24px; }
#day-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
#day-head h2 { margin: 0; font-size: 20px; }
#day-head button {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 18px;
}
#day-head button:disabled { opacity: .3; cursor: default; }
#day-head button.action { width: auto; height: auto; border-radius: 8px; font-size: 13px; color: var(--accent); }
#day-status { color: var(--muted); font-size: 14px; flex: 1; }
#day-status.locked { color: var(--warn); }
.deadline.urgent { color: var(--warn); font-weight: 600; }

.meal {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
}
.meal-label { padding-top: 4px; }
.meal-label strong { display: block; font-size: 14px; }
.meal-label span { font-size: 12px; color: var(--muted); }
.meal.picked .meal-label strong::after { content: " ✓"; color: var(--accent); }

.tiles {
  display: grid;
  grid-template-columns: repeat(var(--cols, 7), minmax(0, 1fr));
  gap: 10px;
}
.tile {
  position: relative;
  display: flex; flex-direction: column;
  border: 2px solid transparent;
  border-radius: 10px;
  background: var(--surface);
  padding: 0; overflow: hidden; cursor: pointer;
  text-align: left; color: inherit; font: inherit;
  box-shadow: 0 1px 2px rgb(0 0 0 / .08);
}
.tile:hover:not([aria-disabled="true"]) { border-color: var(--line); }
.tile[aria-disabled="true"] { cursor: default; }
.tile img {
  /* Size images from the viewport height so all five meal rows fit on one screen. */
  width: 100%; height: var(--img-h);
  object-fit: cover; background: var(--line); display: block;
}
.tile .name {
  font-size: 12.5px; line-height: 1.3; padding: 6px 8px 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tile .facts {
  font-size: 11px; color: var(--muted); padding: 2px 8px 6px; margin-top: auto;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile.selected { border-color: var(--accent); background: var(--accent-soft); }
.tile.selected::after {
  content: "✓"; position: absolute; top: 6px; right: 6px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 13px;
  display: grid; place-items: center;
}
/* Dish the caterer assigned by default: shown, but not yet chosen by the user. */
.tile.selected.default { border-style: dashed; background: var(--surface); }
.tile.selected.default::after { background: var(--muted); }
.tile.saving { opacity: .6; }

#message { color: var(--muted); }
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 14px;
}
#toast.error { background: #b3261e; color: #fff; }

@media (max-width: 900px) {
  :root { --img-h: 100px; }
  .meal { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(var(--cols, 7), 140px); overflow-x: auto; }
  header { flex-direction: column; align-items: stretch; gap: 8px; }
}

/* Pages nav and actions */
nav.pages { display: flex; gap: 4px; }
nav.pages a {
  color: var(--muted); text-decoration: none; font-size: 14px; padding: 4px 10px; border-radius: 6px;
}
nav.pages a[aria-current="page"] { color: var(--text); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.action {
  border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent);
  border-radius: 8px; padding: 5px 12px; font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.action:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; margin-left: auto; }
#day-kcal { font-size: 14px; font-weight: 600; }
.keys { font-size: 12px; color: var(--muted); white-space: nowrap; }
kbd {
  font: 11px ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 4px; background: var(--surface); color: var(--muted);
}

/* Planner extras */
.meal.active { box-shadow: inset 3px 0 0 var(--accent); }
.meal.active .meal-label { padding-left: 8px; }
.tile kbd { position: absolute; top: 6px; left: 6px; opacity: .85; }
.tile .badges {
  position: absolute; left: 6px; right: 34px; display: flex; gap: 4px; flex-wrap: wrap;
  top: calc(var(--img-h) - 24px);
}
.badges span {
  font-size: 10.5px; font-weight: 600; padding: 1px 5px; border-radius: 4px;
  background: rgb(0 0 0 / .62); color: #fff; white-space: nowrap;
}
.badges .eaten { background: var(--past); color: #1d1d1b; }
/* Dish you already had: a frame outside the tile, so it combines with the chosen/default border. */
.tile.eaten-before, #zoom.eaten-before { outline: 2px solid var(--past); outline-offset: 2px; }
.legend-past { display: inline-block; width: 10px; height: 10px; border-radius: 3px; outline: 2px solid var(--past); outline-offset: 1px; margin: 0 4px 0 2px; vertical-align: -1px; }

#zoom {
  position: fixed; z-index: 5; top: 0; left: 0;
  max-height: calc(100vh - 16px); overflow: hidden auto;
  background: var(--surface); border: 2px solid transparent; border-radius: 14px;
  box-shadow: 0 18px 50px rgb(0 0 0 / .3);
  transform-origin: 0 0; will-change: transform, clip-path;
  transition: transform 260ms cubic-bezier(.2, .8, .2, 1), clip-path 260ms cubic-bezier(.2, .8, .2, 1),
    opacity 200ms ease;
}
#zoom.selected { border-color: var(--accent); }
#zoom.selected.default { border-style: dashed; }
.tile .info {
  position: absolute; right: 6px; top: calc(var(--img-h) - 28px);
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: rgb(255 255 255 / .92); color: #1d1d1b; box-shadow: 0 1px 3px rgb(0 0 0 / .3);
  font: italic 700 13px Georgia, serif; cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}
.tile .info:hover, .tile .info:focus-visible { transform: scale(1.15); background: #fff; outline: 2px solid var(--accent); }
.zoom-close {
  position: absolute; z-index: 1; top: 8px; right: 8px; width: 28px; height: 28px; border: 0; border-radius: 50%;
  background: rgb(0 0 0 / .55); color: #fff; font-size: 18px; line-height: 1; cursor: pointer;
}
.zoom-close:hover { background: rgb(0 0 0 / .75); }
.zoom-foot { padding: 4px 14px 14px; }
.zoom-foot .zoom-action { padding: 0; }
.zoom-choose { width: 100%; padding: 8px 12px; font-size: 14px; }
.zoom-media { position: relative; overflow: hidden; }
.zoom-media img {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--line);
  /* Slow Ken Burns pan while the card is open. */
  animation: zoom-pan 9s ease-in-out infinite alternate;
}
@keyframes zoom-pan {
  from { transform: scale(1.02) translate(0, 0); }
  to { transform: scale(1.14) translate(-3%, -2%); }
}
.zoom-media .badges { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 6px; }
.zoom-media .badges span { font-size: 12px; padding: 2px 7px; }
.zoom-head { padding: 10px 14px 0; }
.zoom-head h3 { font-size: 16px; line-height: 1.3; margin: 0 0 4px; }
.zoom-head .facts { margin: 0; font-size: 12.5px; color: var(--muted); }
#zoom .hint, .hist-meal .hint { margin: 4px 0; font-size: 12px; color: var(--accent); }
.hist-meal .hint { margin: 4px 14px; }
.zoom-action { margin: 0; font-size: 13px; font-weight: 600; color: var(--accent); }
@media (prefers-reduced-motion: reduce) {
  #zoom { transition: opacity 150ms ease; }
  .zoom-media img { animation: none; }
}
.details { padding: 0 14px; font-size: 12.5px; }
.details dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 8px 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.details .composition { line-height: 1.4; margin: 8px 0 4px; }
.details .may-contain { color: var(--muted); font-size: 11.5px; margin: 4px 0; }

/* History page */
.history-page main { max-width: 1200px; margin: 0 auto; }
.note { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 12px 0 20px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.card .label { display: block; font-size: 12px; color: var(--muted); }
.card strong { display: block; font-size: 20px; margin: 2px 0; }
.card .sub { font-size: 12px; color: var(--muted); }
.history-page h2 { font-size: 16px; margin: 20px 0 8px; }
.favorites { margin: 0; padding-left: 20px; columns: 2; font-size: 14px; line-height: 1.6; }
.hist-day { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; overflow: hidden; }
.hist-day > header {
  position: static; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: transparent;
}
.hist-day h3 { margin: 0; font-size: 15px; }
.hist-day .totals { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.hist-meal { border-top: 1px solid var(--line); }
.hist-meal:first-of-type { border-top: 0; }
.hist-meal summary {
  display: grid; grid-template-columns: 64px 110px 1fr 70px 150px 40px 70px; gap: 12px; align-items: center;
  padding: 6px 14px; cursor: pointer; list-style: none; font-size: 13.5px;
}
.hist-meal summary::-webkit-details-marker { display: none; }
.hist-meal summary img { width: 64px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--line); }
.hist-meal .meal-name { color: var(--muted); font-size: 12.5px; }
.hist-meal .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hist-meal[open] { background: var(--bg); padding-bottom: 8px; }
.hist-meal .details { max-width: 800px; padding-left: 90px; }
table.orders { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); border-radius: 10px; overflow: hidden; }
table.orders th, table.orders td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.orders th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.orders .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Account and login */
.account { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; font-size: 13px; color: var(--muted); }
.history-page .account { margin-left: 0; }
.login-page { min-height: 100vh; display: grid; place-items: center; }
.login-card {
  width: min(360px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px;
  box-shadow: 0 8px 30px rgb(0 0 0 / .08);
}
.login-card h1 { font-size: 20px; }
.login-card p { margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input {
  font: inherit; font-size: 15px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login-card .action { padding: 9px; font-size: 15px; }
.login-card .error { color: #b3261e; font-size: 14px; }
