:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --bg-soft: #ffffff;
  --line: #e2e6ec;
  --text: #16191d;
  --muted: #6b7280;
  --accent: #2f7d5b;
  --accent-soft: #e6f2ec;
  --danger: #b3453f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --ease: cubic-bezier(.2, .8, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101317;
    --bg-soft: #181c22;
    --line: #272d36;
    --text: #e8ebef;
    --muted: #949cab;
    --accent: #4caf85;
    --accent-soft: #1d2a25;
    --danger: #e0756e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; }

button, input, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 14px;
  background: transparent;
  transition: background .18s var(--ease), border-color .18s var(--ease), transform .12s var(--ease), color .18s var(--ease);
}
button:active { transform: scale(.97); }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { border-color: var(--line); background: var(--bg-soft); }
button.ghost:hover { border-color: var(--accent); color: var(--accent); }
button.icon { border-color: var(--line); background: var(--bg-soft); padding: 8px 12px; font-size: 18px; line-height: 1; }
button.icon:hover { border-color: var(--accent); color: var(--accent); }
button.danger { color: var(--danger); }

input[type="text"], input[type="date"], textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
input:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; line-height: 1.45; }
::placeholder { color: var(--muted); opacity: .8; }

/* ---------- toolbar ---------- */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 12px 22px;
  background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { font-size: 18px; letter-spacing: -.01em; }
.brand-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .02em;
}

.week-nav { display: flex; gap: 6px; align-items: center; margin-inline: auto; }
.week-nav input[type="date"] { width: auto; }

.tool-actions { display: flex; gap: 8px; align-items: center; }
.more { position: relative; }
.more summary {
  list-style: none;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  cursor: pointer;
  user-select: none;
}
.more summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  padding: 6px;
  display: grid;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  animation: pop .16s var(--ease);
}
.menu-item { text-align: left; border-radius: 8px; padding: 8px 10px; }
.menu-item:hover { background: var(--accent-soft); }

/* ---------- layout ---------- */

main { max-width: 1180px; margin: 0 auto; padding: 22px; }

.panel {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.panel-head { margin-bottom: 14px; }
.panel h2 { font-size: 15px; letter-spacing: -.01em; }
.hint { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 15px;
  background: var(--bg-soft);
  color: var(--muted);
  display: inline-flex;
  gap: 7px;
  align-items: center;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip-icon { font-size: 13px; }

/* ---------- week grid ---------- */

.week {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  margin-bottom: 22px;
}

.day {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 16px 14px;
  box-shadow: var(--shadow);
  animation: rise .28s var(--ease) both;
  transition: border-color .2s var(--ease);
}
.day.today { border-color: var(--accent); }
.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
}
.day-head strong { font-size: 16px; letter-spacing: -.01em; }
.day-head span { font-size: 12.5px; color: var(--muted); }
.day.today .day-head span { color: var(--accent); font-weight: 600; }

.meal { border-top: 1px solid var(--line); padding: 10px 0 4px; }
.meal-head { display: flex; align-items: center; gap: 10px; }
.meal-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--accent);
  display: inline-flex;
  gap: 6px;
  align-items: center;
  cursor: pointer;
}
.meal.off .meal-label { color: var(--muted); }
.meal-icon { font-size: 11px; opacity: .8; }
.count { margin-left: auto; font-size: 11.5px; color: var(--muted); }

.meal-body { display: grid; gap: 7px; padding: 8px 0 4px; animation: fade .2s var(--ease) both; }
.meal-body .dish { font-weight: 600; }
.meal-body .note { font-size: 13px; }
.meal-body textarea { font-size: 14px; }

.switch { position: relative; display: inline-flex; flex: 0 0 auto; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.track {
  width: 34px; height: 20px;
  border-radius: 999px;
  background: var(--line);
  transition: background .2s var(--ease);
  position: relative;
}
.track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform .2s var(--ease);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- grocery ---------- */

.progress { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.progress-bar { flex: 1; height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress-bar span {
  display: block; height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .35s var(--ease);
}
.progress-text { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.grocery-tools { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-bottom: 16px; }
.add-form { display: flex; gap: 8px; flex: 1 1 340px; }
.inline { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }

.groups { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.group h3 {
  font-size: 11.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}
.group ul { list-style: none; margin: 0; padding: 0; }
.group li { display: flex; align-items: flex-start; gap: 4px; padding: 3px 0; }
.group li .item { flex: 1; align-items: flex-start; }
.item-text { display: block; }
.item-text small { display: block; font-size: 11.5px; color: var(--muted); }
.group li.done .item-text { text-decoration: line-through; color: var(--muted); }
.remove { color: var(--muted); padding: 0 6px; line-height: 1; font-size: 18px; opacity: 0; }
.group li:hover .remove, .remove:focus-visible { opacity: 1; }
.remove:hover { color: var(--danger); }

.empty { color: var(--muted); margin: 0; }
.foot { text-align: center; color: var(--muted); font-size: 12.5px; padding-bottom: 28px; }

.sheets { display: none; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (max-width: 720px) {
  .toolbar { padding: 12px 14px; }
  .week-nav { margin-inline: 0; order: 3; width: 100%; }
  main { padding: 16px 14px; }
}
