:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f5f6f2);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1d231c);
  --muted: var(--tg-theme-subtitle-text-color, #6e756c);
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --green: #3f7838;
  --green-soft: #e9f2e6;
  --amber: #8b6418;
  --amber-soft: #f7efd9;
  --red-soft: #f8e9e6;
  --radius: 17px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font: 15px/1.42 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: wait; opacity: 0.52; }
svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[hidden] { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.shell {
  width: min(100%, 660px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

.topbar,
.picker-header,
.section-heading,
.delivery-title,
.household,
.picker-summary {
  display: flex;
  align-items: center;
}

.topbar { justify-content: space-between; margin-bottom: 28px; }
.picker-header { gap: 10px; margin-bottom: 18px; }
.section-heading { justify-content: space-between; padding: 0 2px 10px; }
.picker-summary { justify-content: space-between; padding: 17px 2px 10px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 29px; line-height: 1.1; letter-spacing: -0.035em; }
h2 { font-size: 18px; letter-spacing: -0.01em; }
h3 { font-size: 16px; }
.subtle { margin-top: 4px; color: var(--muted); font-size: 13px; }

.icon-button {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}
.back-button { margin-left: -5px; background: transparent; }

.service-error {
  margin: -10px 0 22px;
  padding: 12px 14px;
  border-radius: 13px;
  color: #7d3024;
  background: var(--red-soft);
  font-size: 14px;
}

.delivery-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.blacklist-section { margin-top: 26px; }
.blacklist-section .section-heading { align-items: flex-end; }
.blacklist-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.blacklist-row {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px 9px 14px;
  border-bottom: 1px solid var(--line);
}
.blacklist-row:last-child { border-bottom: 0; }
.blacklist-row strong { min-width: 0; line-height: 1.25; }
.allow-button,
.never-button {
  min-height: 44px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.delivery-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 88px;
  padding: 14px 10px 14px 16px;
  border-bottom: 1px solid var(--line);
}
.delivery-row:last-child { border-bottom: 0; }
.delivery-row.paused { color: color-mix(in srgb, var(--text) 70%, var(--bg)); }
.delivery-row.past { opacity: 0.68; }
.delivery-title { gap: 8px; }
.delivery-main p { margin-top: 5px; color: var(--muted); font-size: 13px; }
.status {
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 11px;
  font-weight: 700;
}
.status.paused { color: var(--amber); background: var(--amber-soft); }
.status.inactive { color: var(--muted); background: var(--bg); }
.week-actions { display: flex; align-items: center; gap: 2px; }
.week-action {
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 12px;
  color: var(--tg-theme-link-color, var(--green));
  background: transparent;
  font-weight: 650;
  cursor: pointer;
}
.week-action.choose { padding-inline: 13px; color: #fff; background: var(--green); }
.empty { padding: 25px 16px; color: var(--muted); text-align: center; }

.household {
  justify-content: space-between;
  min-height: 64px;
  margin-top: 16px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 14px;
}

#picker-view { padding-bottom: 82px; }
.search-box {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--muted);
  background: var(--surface);
}
.search-box svg { width: 19px; height: 19px; flex: 0 0 auto; }
.search-box input {
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}
.search-box input::placeholder { color: var(--muted); }

.meal-list { display: grid; gap: 9px; }
.meal-card {
  width: 100%;
  min-height: 116px;
  position: relative;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--text);
  background: var(--surface);
  content-visibility: auto;
  contain-intrinsic-size: 116px;
  transition: border-color 140ms ease, background 140ms ease;
}
.meal-card.selected { border-color: var(--green); background: var(--green-soft); }
.meal-card.blacklisted { border-color: color-mix(in srgb, #a84c40 45%, var(--line)); background: var(--red-soft); }
.meal-detail {
  width: 100%;
  min-height: 116px;
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.meal-image-wrap { position: relative; min-height: 116px; background: var(--line); }
.meal-image-wrap img { width: 100%; height: 100%; position: absolute; inset: 0; object-fit: cover; }
.meal-toggle {
  width: 44px;
  height: 44px;
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
}
.meal-toggle:disabled { cursor: default; opacity: 0.62; }
.check {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  color: transparent;
  background: rgba(24, 30, 23, 0.28);
  backdrop-filter: blur(4px);
}
.selected .check { color: white; border-color: var(--green); background: var(--green); }
.blacklisted .check { color: white; border-color: #963f35; background: #963f35; }
.check svg { width: 18px; height: 18px; stroke-width: 2.4; }
.meal-copy { min-width: 0; display: flex; flex-direction: column; padding: 13px 13px 54px; }
.meal-copy strong { font-size: 15px; line-height: 1.25; }
.headline {
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.meal-meta { margin-top: auto; padding-top: 7px; color: var(--muted); font-size: 12px; }
.surcharge { margin-top: 3px; color: var(--amber); font-size: 12px; font-weight: 650; }
.never-button { position: absolute; right: 9px; bottom: 8px; z-index: 2; }
.meal-card:not(.blacklisted) .never-button { color: #8a3a31; }

body.dialog-open { overflow: hidden; }
.ingredient-dialog {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  align-items: end;
}
.ingredient-backdrop {
  position: absolute;
  inset: 0;
  padding: 0;
  border: 0;
  background: rgba(10, 14, 10, 0.44);
  backdrop-filter: blur(3px);
}
.ingredient-sheet {
  width: min(100%, 660px);
  max-height: min(86vh, 760px);
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  box-shadow: 0 -18px 48px rgba(0, 0, 0, 0.18);
}
.ingredient-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 16px 14px 20px;
  border-bottom: 1px solid var(--line);
}
.ingredient-header h2 { margin-top: 2px; font-size: 22px; }
.ingredient-kicker {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.ingredient-content { padding: 2px 20px 22px; overflow-y: auto; }
.ingredient-group { padding-top: 18px; }
.ingredient-group h3 { margin-bottom: 7px; color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.ingredient-row {
  min-height: 46px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--line);
}
.ingredient-row:last-child { border-bottom: 0; }
.ingredient-amount { color: var(--muted); text-align: right; white-space: nowrap; }
.ingredient-actions {
  padding: 12px 16px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.loader { min-height: 210px; display: flex; align-items: center; justify-content: center; gap: 7px; }
.loader span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 900ms ease-in-out infinite;
}
.loader span:nth-child(2) { animation-delay: 120ms; }
.loader span:nth-child(3) { animation-delay: 240ms; }
@keyframes pulse { 0%, 70%, 100% { opacity: 0.25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-4px); } }

.save-dock {
  position: fixed;
  z-index: 4;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 14px max(16px, calc((100vw - 628px) / 2)) max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 18%);
}
.save-button {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 15px;
  color: #fff;
  background: var(--green);
  font-weight: 720;
  cursor: pointer;
}

:focus-visible { outline: 3px solid var(--tg-theme-link-color, var(--green)); outline-offset: 2px; }

@media (max-width: 380px) {
  .delivery-row { grid-template-columns: 1fr; }
  .week-actions { justify-content: flex-end; margin-top: -4px; }
  .meal-detail { grid-template-columns: 104px minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #151815);
    --surface: var(--tg-theme-secondary-bg-color, #202420);
    --text: var(--tg-theme-text-color, #eef1ed);
    --muted: var(--tg-theme-subtitle-text-color, #a1a89f);
    --green: #5f9655;
    --green-soft: #21351f;
    --amber: #dfbd72;
    --amber-soft: #3a301b;
    --red-soft: #3a2420;
  }
  .service-error { color: #f0b4aa; }
}
