:root {
  --bg: #f3f5f9; --card: #fff; --ink: #1b2230; --muted: #667085; --line: #dde2ea;
  --accent: #2563c9; --accent-ink: #fff; --accent-soft: #e3ecfb; --warn: #a15c00; --bad: #a3312b;
  --lock: #c8362e; --lock-soft: #fbdcd9; --love: #e0457b;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11141a; --card: #1a1f29; --ink: #e8ebf1; --muted: #98a2b3; --line: #2b3340; --accent: #5b9bf0; --accent-ink: #0b1220; --accent-soft: #1a2a45; --warn: #e0a044; --bad: #e37a73;
    --lock: #ea5f57; --lock-soft: #4d1f1d; --love: #f06a98; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 16px/1.45 system-ui, sans-serif; background: var(--bg); color: var(--ink); padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
.top { position: sticky; top: 0; z-index: 2; background: var(--bg); border-bottom: 1px solid var(--line); }
header { padding: 10px 16px; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 4px; }
h3 { font-size: 15px; margin: 0; }
main { max-width: 1400px; margin: 0 auto; padding: 12px 16px; }
#status { margin-top: 6px; font-size: 14px; color: var(--muted); }
#status.error { color: var(--bad); }
.hint, small { color: var(--muted); font-size: 13px; font-weight: normal; }
.center { text-align: center; }
.banner { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

button, select, textarea, input { font: inherit; color: inherit; }
button, select { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-height: 40px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: .5; }
textarea { width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-top: 4px; }
label { display: block; margin-top: 16px; font-weight: 600; }
label.radio { font-weight: normal; margin: 6px 0; }
.toolbar, .row { display: flex; gap: 8px; align-items: center; }
.toolbar { flex-wrap: wrap; }
.toolbar select { flex: 1 1 150px; min-width: 0; }
.row { justify-content: flex-end; margin-top: 12px; }
.row.left { justify-content: flex-start; margin: 0 0 8px; }

/* buffet tray */
#buffet { max-width: 1400px; margin: 0 auto; padding: 0 16px 8px; }
.buffet-head { display: flex; align-items: baseline; gap: 8px; }
.buffet-head button { margin-left: auto; min-height: 32px; padding: 4px 10px; font-size: 13px; }
.tray { display: flex; gap: 8px; overflow-x: auto; padding: 6px 0 4px; }
.chip { flex: none; width: 150px; display: flex; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px 6px 2px; cursor: pointer; }
.chip.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.chip b, .meal:not([open]) summary b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chip b, .meal summary b { font-size: 14px; line-height: 1.25; }
.preview { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-top: 4px; max-height: 32vh; overflow-y: auto; font-size: 14px; }
.preview .row { justify-content: space-between; margin: 0; }
.preview ol { margin: 6px 0; padding-left: 20px; }

.grip { flex: none; display: grid; place-items: center; width: 32px; align-self: stretch; color: var(--muted); font-size: 20px; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.slot { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.macros { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ghost { position: fixed; left: 0; top: 0; z-index: 10; pointer-events: none; max-width: 220px; background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: 10px; font-weight: 600; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); }
body.dragging { user-select: none; -webkit-user-select: none; }
body.dragging .meal[data-drop], body.placing .meal[data-drop] { border-style: dashed; border-color: var(--accent); }
.meal.drop { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent); }

/* days and meals: each day is a row of small tiles */
.day { margin-top: 16px; }
.day-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding-bottom: 6px; border-bottom: 2px solid var(--line); }
.day-head h2 { margin: 0; }
.day-head .totals { font-size: 14px; font-variant-numeric: tabular-nums; }
.structure { display: flex; gap: 6px; margin-left: auto; }
.structure select { min-height: 32px; padding: 2px 6px; font-size: 13px; }
.badge { font-size: 12px; padding: 1px 8px; border-radius: 99px; border: 1px solid currentColor; }
.badge.ok { color: var(--accent); } .badge.warn { color: var(--warn); }
.audit { font-size: 13px; color: var(--warn); margin: 6px 0 0; padding-left: 18px; }
.meals { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); grid-auto-flow: dense; gap: 8px; margin-top: 8px; }
@media (min-width: 900px) {
  .day { display: grid; grid-template-columns: 170px 1fr; gap: 0 16px; padding-top: 12px; border-top: 2px solid var(--line); }
  .day-head { flex-direction: column; align-items: flex-start; align-content: flex-start; border: 0; padding: 8px 0 0; }
  .structure { margin-left: 0; }
  .meals { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
}

.meal { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 14px; min-width: 0; }
.meal[open] { grid-column: 1 / -1; padding: 10px 14px; }
.meal.eaten { opacity: .65; }
.meal.locked { background: var(--lock-soft); border-color: var(--lock); }
.meal { position: relative; }
.meal .slot { min-height: 22px; padding-right: 54px; }
.icons { position: absolute; top: 3px; right: 3px; display: flex; }
.icon { display: grid; place-items: center; width: 28px; height: 28px; min-height: 0; padding: 0; border: 0; background: none; color: var(--muted); cursor: pointer; }
.icon svg { width: 17px; height: 17px; fill: currentColor; }
.icon.heart svg { fill: none; stroke: currentColor; stroke-width: 2; }
.icon.heart.on { color: var(--love); }
.icon.heart.on svg { fill: currentColor; }
.icon.lock.on { color: var(--lock); }

.guide, .add { display: flex; gap: 6px; margin-top: 8px; }
.guide input, .add input { flex: 1; min-width: 0; min-height: 38px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 14px; }
.guide button { min-height: 38px; font-size: 14px; }
.wide { grid-column: 1 / -1; }
#prefs h3 { margin-top: 12px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.tag { display: inline-flex; align-items: center; gap: 2px; background: var(--accent-soft); border-radius: 99px; padding: 2px 4px 2px 12px; font-size: 14px; }
.tag.dislikes { background: var(--lock-soft); }
.tag button { min-height: 28px; padding: 0 8px; border: 0; background: none; color: var(--muted); }
a { color: var(--accent); }
.send { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 8px; }
.send button, .send a { flex: 1; text-align: center; white-space: nowrap; }
.send a { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; background: var(--card); color: inherit; text-decoration: none; }
#dlg-text { font-size: 15px; line-height: 1.5; }
.day-head .share { min-height: 32px; padding: 2px 10px; font-size: 13px; }
.meal summary { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px; cursor: pointer; list-style: none; }
.meal summary::-webkit-details-marker { display: none; }
.meal .grip { width: 26px; margin-left: -8px; }
.meal .macros { font-size: 12px; }
.meal > .macros { margin: 6px 0 0; font-size: 13px; }
.meal:not([open]) .put { width: 100%; }
.put { display: none; flex: none; min-height: 34px; padding: 4px 10px; font-size: 13px; }
body.placing .put { display: block; }
.meal[open] > :not(summary) { max-width: 70ch; }
.meal ol { margin: 8px 0; padding-left: 20px; }
.meal li { margin: 3px 0; }
.why, .changes { font-size: 13px; color: var(--muted); margin: 6px 0 4px; }
.changes { color: var(--accent); }
.photos { display: flex; gap: 6px; overflow-x: auto; margin: 8px 0; }
.photos img { height: 96px; border-radius: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.actions button { font-size: 14px; padding: 6px 10px; }
.empty { text-align: center; color: var(--muted); padding: 40px 8px 12px; }

/* cost dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 12px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 8px 24px; }
.panels h3 { margin: 16px 0 8px; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; border-bottom: 1px solid var(--line); }
.bars div { flex: 1; min-height: 1px; background: var(--accent); border-radius: 3px 3px 0 0; }
.bar-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 6px 0 6px 10px; border-bottom: 1px solid var(--line); }
th { font-weight: 600; color: var(--muted); font-size: 12px; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }

/* shopping list */
.list-title { margin-top: 16px; }
.sections { columns: 280px; column-gap: 32px; }
.group { break-inside: avoid; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 20px; }
.section { margin-top: 16px; padding-bottom: 2px; border-bottom: 1px solid var(--line); }
.checklist { list-style: none; margin: 4px 0; padding: 0; }
.checklist label { display: flex; gap: 10px; align-items: flex-start; margin: 0; padding: 7px 0; font-weight: normal; }
.checklist input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; }
.checklist input:checked + span { color: var(--muted); text-decoration: line-through; }

nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 2; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav button { flex: 1; border: 0; border-radius: 0; background: none; min-height: 56px; padding: 4px 2px; font-size: 13px; color: var(--muted); }
nav button.active { color: var(--accent); font-weight: 600; }

dialog { width: min(92vw, 520px); border: 1px solid var(--line); border-radius: 14px; background: var(--bg); color: var(--ink); padding: 16px; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.file { font-weight: normal; font-size: 14px; }
.file input { display: block; margin-top: 4px; max-width: 100%; }

@media print {
  .top, nav, .noprint { display: none !important; }
  body { background: #fff; color: #000; padding: 0; font-size: 12pt; }
  main { max-width: none; padding: 0; }
  .sections { columns: 2; }
  .checklist li { break-inside: avoid; }
  .checklist label { padding: 3px 0; }
  .checklist input:checked + span { color: #000; text-decoration: none; }
  .section { border-color: #000; break-after: avoid; }
}

/* ---------- sign-in ---------- */
.login { display: grid; place-items: center; min-height: 80vh; padding: 16px; }
.login form { width: min(340px, 100%); display: grid; gap: 14px; }
.login input { width: 100%; margin-top: 6px; }
.login .error { color: var(--lock); margin: 0; }
