:root {
  --bg: #edf1f0;
  --panel: #f9fbfa;
  --ink: #1d2a30;
  --muted: #586a72;
  --line: #d3dcda;
  --accent: #2f5f7e;
  --accent-ink: #ffffff;
  --accent-soft: #d9e7f0;
  --note: #e4e9ec;
  --note-ink: #46585f;
  --done: #8497a0;
  --fresh: #dfece3;
  --fresh-ink: #2d5a3d;
  --scrim: rgba(20, 30, 36, 0.55);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141b1f;
    --panel: #1b242a;
    --ink: #e4ecef;
    --muted: #9baeb6;
    --line: #2c3a41;
    --accent: #8dbbd6;
    --accent-ink: #10222c;
    --accent-soft: #223845;
    --note: #26333a;
    --note-ink: #b6c6cd;
    --done: #6f838c;
    --fresh: #223a2c;
    --fresh-ink: #a9d3b8;
    --scrim: rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }
html { font-size: clamp(16px, 1.55vw, 22px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.4;
  min-height: 100vh;
}
h1, h2 { margin: 0; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---- layout ---- */
.screen { display: flex; flex-direction: column; height: 100vh; }
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.when { display: flex; align-items: baseline; gap: 0.9rem; min-width: 0; }
.when h1 { font-size: 1.6rem; }
.clock { color: var(--muted); font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }

main {
  flex: 1; min-height: 0; display: grid; grid-template-columns: 38% 1fr; gap: 1rem;
  padding: 1rem 1.25rem;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 1rem 1.1rem; min-height: 0; display: flex; flex-direction: column;
}
.panel > h2 { font-size: 1.15rem; margin-bottom: 0.6rem; }
.scroll { overflow-y: auto; min-height: 0; flex: 1; }

/* ---- buttons ---- */
.btn {
  min-height: 2.9rem; padding: 0.4rem 1rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); font-weight: 500;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { min-height: 2.2rem; padding: 0.2rem 0.7rem; font-size: 0.9rem; }

/* ---- tasks ---- */
.tasks { list-style: none; margin: 0; padding: 0; }
.task { display: flex; gap: 0.8rem; align-items: flex-start; padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.tick {
  flex: none; width: 2.1rem; height: 2.1rem; border-radius: 8px; border: 2px solid var(--muted);
  background: transparent; display: grid; place-items: center; padding: 0; font-size: 1.2rem; line-height: 1;
}
.tick[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 1.15rem; word-break: break-word; }
.task.done .task-title { color: var(--done); text-decoration: line-through; text-decoration-thickness: 1px; }
.tags { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.25rem; }
.tag { font-size: 0.85rem; background: var(--note); color: var(--note-ink); border-radius: 6px; padding: 0.05rem 0.5rem; }
.subs { list-style: none; margin: 0.5rem 0 0; padding: 0; display: grid; gap: 0.35rem; }
.sub { display: flex; align-items: center; gap: 0.6rem; }
.sub .tick { width: 1.6rem; height: 1.6rem; font-size: 1rem; border-width: 1.5px; }
.sub.done span { color: var(--done); text-decoration: line-through; text-decoration-thickness: 1px; }
.task-tools { display: flex; gap: 0.2rem; }
.queued { color: var(--muted); font-size: 0.9rem; margin: 0.6rem 0 0; }

/* ---- events ---- */
.events { list-style: none; margin: 0; padding: 0; }
.event { border-bottom: 1px solid var(--line); }
.event:last-child { border-bottom: 0; }
.event.today { background: var(--accent-soft); border-radius: 10px; border-bottom-color: transparent; }
.event button {
  all: unset; box-sizing: border-box; cursor: pointer; width: 100%; display: grid;
  grid-template-columns: 7.5rem 3.6rem 1fr; gap: 0.5rem; align-items: baseline; padding: 0.75rem 0.7rem;
}
.event .d { font-weight: 600; }
.event .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.event .more { grid-column: 3; color: var(--muted); font-size: 0.95rem; white-space: pre-wrap; }
.event .more:empty { display: none; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 0.6rem 0; }

/* ---- popup and sheets ---- */
.overlay {
  position: fixed; inset: 0; background: var(--scrim); display: grid; place-items: center;
  padding: 1rem; z-index: 10;
}
.sheet {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  width: min(34rem, 100%); max-height: 92vh; overflow-y: auto; padding: 1.4rem;
}
.sheet.wide { width: min(46rem, 100%); }
.sheet h2 { font-size: 1.3rem; margin-bottom: 0.9rem; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.9rem; }
.sheet-head h2 { margin: 0; }
.popup-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.9rem; }
.popup-text { font-size: 1.4rem; font-weight: 600; margin: 1rem 0 1.4rem; line-height: 1.35; }
.popup-actions { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); }
.popup-actions .btn { min-height: 4rem; font-size: 1.05rem; }

/* ---- forms ---- */
label.field { display: grid; gap: 0.3rem; margin-bottom: 0.9rem; font-weight: 500; }
input[type="text"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
  width: 100%; min-height: 2.8rem; padding: 0.45rem 0.7rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
}
textarea { min-height: 5.5rem; resize: vertical; }
.chips, .choices { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.9rem; }
.chip, .choice {
  min-height: 2.6rem; padding: 0.3rem 0.9rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg);
}
.choice { border-radius: 10px; }
.choice[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.check { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 0.9rem; }
.check input { width: 1.4rem; height: 1.4rem; }
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row > input[type="text"] { flex: 1; min-width: 8rem; }
.tabs { display: flex; gap: 0.4rem; margin-bottom: 1rem; flex-wrap: wrap; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 0.9rem; margin-bottom: 0.8rem; }
.card h3 { margin: 0 0 0.6rem; font-size: 1rem; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0.2rem 0 0.8rem; }
.error { color: var(--ink); background: var(--note); border-radius: 8px; padding: 0.5rem 0.7rem; margin-bottom: 0.8rem; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }

/* ---- login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .sheet { width: min(24rem, 100%); }

/* ---- phones and narrow windows ---- */
@media (max-width: 760px) {
  html { font-size: 17px; }
  .screen { height: auto; min-height: 100vh; }
  .bar { flex-direction: column; align-items: stretch; }
  .actions { justify-content: flex-start; }
  main { grid-template-columns: 1fr; }
  .event button { grid-template-columns: 6.5rem 3.4rem 1fr; }
  .task { flex-wrap: wrap; }
  .task-body { flex-basis: calc(100% - 3.2rem); }
  .task-tools { flex-basis: 100%; padding-left: 2.9rem; margin-top: -0.2rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---- messages ---- */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 0.7rem 1.2rem; border-radius: 10px;
  max-width: 90vw; font-weight: 500;
}
.card h3:not(:first-child) { margin-top: 1.2rem; }

/* slimmer top bar */
.bar { padding: 0.25rem 1.25rem; }
.when h1 { font-size: 1.2rem; }
.clock { font-size: 0.95rem; }
.bar .btn { min-height: 2.2rem; padding: 0.1rem 0.8rem; font-size: 0.95rem; }

@media (max-width: 760px) {
  .bar { padding: 0.3rem 1rem; gap: 0.3rem; }
  .actions { flex-wrap: nowrap; gap: 0.4rem; }
  .bar .btn { padding: 0.1rem 0.6rem; font-size: 0.9rem; }
}

/* ---- evening meals ---- */
.meals { margin: 0 1.25rem 1rem; flex: none; padding: 0.7rem 1rem 0.9rem; }
.meals-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.meals-head h2 { font-size: 1.15rem; margin: 0; }
.meal-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.5rem; }
.meal {
  text-align: left; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  padding: 0.5rem 0.6rem; min-height: 4.8rem; display: flex; flex-direction: column; gap: 0.25rem;
}
.meal:hover { border-color: var(--muted); }
.meal.today { border-color: var(--accent); background: var(--accent-soft); }
.mday { font-weight: 600; font-size: 0.9rem; color: var(--muted); }
.meal.today .mday { color: var(--accent); }
.mentry { display: flex; flex-direction: column; gap: 0.2rem; align-items: flex-start; }
.mname { font-weight: 500; line-height: 1.2; word-break: break-word; }
.mtag { font-size: 0.8rem; border-radius: 6px; padding: 0 0.45rem; border: 1px solid transparent; }
.mtag.freezer { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.mtag.fresh { background: var(--fresh); color: var(--fresh-ink); border-color: var(--fresh-ink); }
.mempty { color: var(--muted); font-size: 0.9rem; }
.btn.step { min-width: 3rem; font-size: 1.4rem; line-height: 1; padding: 0; }
.sheet h3 { font-size: 1rem; margin: 0.4rem 0 0.4rem; }

@media (max-width: 760px) {
  .meals { margin: 0 1rem 1rem; }
  .meal-row { grid-template-columns: 1fr; }
  .meal { flex-direction: row; align-items: center; gap: 0.8rem; min-height: 3rem; }
  .mday { width: 4.5rem; flex: none; }
  .mentry { flex-direction: row; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
}
.row > select { flex: 1; width: auto; min-width: 8rem; }

/* ---- stock, shopping and restock ---- */
.levels { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.choice.small { min-height: 2.2rem; padding: 0.1rem 0.7rem; font-size: 0.9rem; }
@media (max-width: 760px) {
  .actions { flex-wrap: wrap; }
}

/* slightly smaller task list */
#tasks .task { padding: 0.55rem 0; gap: 0.7rem; }
#tasks .task-title { font-size: 1.02rem; }
#tasks .sub { font-size: 0.92rem; }
#tasks .tick { width: 1.9rem; height: 1.9rem; }
#tasks .sub .tick { width: 1.45rem; height: 1.45rem; }