:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --ink: #292524;
  --muted: #78716c;
  --line: #e7e0d8;
  --accent: #ea580c;
  --accent-soft: #ffedd5;
  --breakfast: #22c55e;
  --breakfast-soft: #dcfce7;
  --lunch: #3b82f6;
  --lunch-soft: #dbeafe;
  --dinner: #8b5cf6;
  --dinner-soft: #ede9fe;
  --danger: #dc2626;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; margin-top: 8px; }

h1 { font-size: 24px; margin: 8px 0 4px; }
h2 { font-size: 20px; }
h3 { font-size: 18px; }
h4 { margin: 14px 0 6px; }

/* --- Кнопки --- */
.btn {
  border: none; border-radius: var(--radius); padding: 12px 16px;
  font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: transform .05s ease, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--accent-soft); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-wide { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: .5; cursor: default; }

/* --- Полноэкранные экраны (PIN, профиль) --- */
.fullscreen {
  position: fixed; inset: 0; background: var(--bg); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.center-card { width: 100%; max-width: 380px; text-align: center; }
.logo { font-size: 56px; }
.center-card input {
  width: 100%; margin-top: 14px; padding: 13px 14px; border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 16px; background: var(--card); font-family: inherit;
}
.profile-list { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.profile-btn {
  padding: 15px; border-radius: var(--radius); border: 2px solid var(--line);
  background: var(--card); font-size: 17px; font-weight: 700; cursor: pointer; font-family: inherit;
  display: flex; align-items: center; gap: 12px; justify-content: center;
}
.profile-btn .dot { width: 14px; height: 14px; border-radius: 50%; }
.profile-new { display: flex; gap: 8px; margin-top: 16px; }
.profile-new input { margin-top: 0; flex: 1; }

/* --- Каркас --- */
#app { max-width: 640px; margin: 0 auto; padding-bottom: 90px; }
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 6px;
}
.header-title { font-weight: 800; font-size: 18px; }
.me-chip {
  border: none; border-radius: 999px; padding: 7px 14px; font-weight: 700;
  color: #fff; cursor: pointer; font-size: 14px; font-family: inherit;
}
.view { padding: 8px 16px; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 0; }
.empty { text-align: center; padding: 40px 20px; }
.empty p:first-child { font-size: 17px; font-weight: 600; margin-bottom: 6px; }

/* --- Таббар и FAB --- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--card);
  border-top: 1px solid var(--line); display: flex; z-index: 20;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar .tab {
  flex: 1; border: none; background: none; padding: 9px 0 7px; cursor: pointer;
  font-size: 21px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: inherit;
}
.tabbar .tab span { font-size: 11px; font-weight: 600; }
.tabbar .tab.active { color: var(--accent); }
.fab {
  position: fixed; right: 18px; bottom: 76px; width: 58px; height: 58px;
  border-radius: 50%; border: none; background: var(--accent); color: #fff;
  font-size: 30px; line-height: 1; cursor: pointer; z-index: 21;
  box-shadow: 0 6px 18px rgba(234, 88, 12, .4);
}

/* --- Рецепты --- */
.recipes-list { display: flex; flex-direction: column; gap: 10px; }
.recipe-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; cursor: pointer;
}
.recipe-card .rc-title { font-weight: 700; font-size: 16px; }
.recipe-card .rc-meta { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.chip {
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line);
}
.chip.b { background: var(--breakfast-soft); color: #15803d; border-color: transparent; }
.chip.l { background: var(--lunch-soft); color: #1d4ed8; border-color: transparent; }
.chip.d { background: var(--dinner-soft); color: #6d28d9; border-color: transparent; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }

/* --- Неделя --- */
.week-head { gap: 8px; }
.week-label { font-weight: 700; text-align: center; flex: 1; }
.week-actions { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.toggle { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }
.week-grid { display: flex; flex-direction: column; gap: 10px; }
.day-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.day-card.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.day-title { font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.day-title .dt-date { color: var(--muted); font-weight: 500; }
.slot {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: 10px; margin-top: 6px; border-left: 4px solid transparent; min-height: 40px;
}
.slot.breakfast { background: var(--breakfast-soft); border-left-color: var(--breakfast); }
.slot.lunch { background: var(--lunch-soft); border-left-color: var(--lunch); }
.slot.dinner { background: var(--dinner-soft); border-left-color: var(--dinner); }
.slot .slot-name { font-size: 11px; font-weight: 700; text-transform: uppercase; width: 58px; flex-shrink: 0; opacity: .7; }
.slot .slot-body { flex: 1; font-size: 14px; font-weight: 600; cursor: pointer; }
.slot .slot-body .leftover { font-size: 11px; font-weight: 600; opacity: .65; margin-left: 6px; }
.slot .slot-empty { color: var(--muted); font-weight: 500; font-size: 14px; }
.slot .slot-x { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 4px; }
.slot .slot-plus {
  border: none; background: rgba(255,255,255,.7); color: var(--muted); cursor: pointer;
  border-radius: 8px; width: 30px; height: 30px; font-size: 18px; line-height: 1; flex-shrink: 0;
}

/* --- Продукты --- */
.shop-item {
  display: flex; align-items: center; gap: 12px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px;
}
.shop-item input[type=checkbox] { width: 21px; height: 21px; accent-color: var(--accent); flex-shrink: 0; }
.shop-item .si-name { flex: 1; font-weight: 600; }
.shop-item.checked .si-name { text-decoration: line-through; color: var(--muted); }
.shop-item .si-qty { color: var(--muted); font-size: 14px; font-weight: 600; white-space: nowrap; }
.shop-item .si-recipes { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.shop-section { margin: 14px 0 8px; font-weight: 700; font-size: 14px; color: var(--muted); }

/* --- Модалки --- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh;
  overflow-y: auto; border-radius: 20px 20px 0 0; padding: 18px 18px 30px;
}
@media (min-width: 700px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 20px; max-height: 86vh; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-card label { display: block; margin-top: 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.modal-card input[type=text], .modal-card input[type=number], .modal-card textarea, .modal-card select {
  width: 100%; margin-top: 5px; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 15px; background: var(--card); font-family: inherit; color: var(--ink);
}
.row2 { display: flex; gap: 10px; }
.row2 > * { flex: 1; }

.mode-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.mode-tab {
  flex: 1; padding: 10px 6px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; font-size: 14px; cursor: pointer; font-family: inherit; color: var(--muted);
}
.mode-tab.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.photo-preview { width: 100%; border-radius: 12px; margin-top: 10px; max-height: 300px; object-fit: contain; background: #000; }
.rec-status { margin-top: 10px; text-align: center; min-height: 20px; }
.rec-on { color: var(--danger) !important; font-weight: 700; }

.ing-head { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; font-size: 13px; font-weight: 600; color: var(--muted); }
.ing-row { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.ing-row input { margin-top: 0 !important; }
.ing-row .ing-name { flex: 3; }
.ing-row .ing-amount { flex: 1.2; min-width: 60px; }
.ing-row .ing-unit { flex: 1.2; min-width: 60px; }
.ing-row .ing-del { border: none; background: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 4px; }

.rd-ings li, .rd-steps li { margin: 6px 0 6px 20px; }
.modal-card .row2 .btn { margin-top: 16px; }

.pick-list { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow-y: auto; }
.pick-item {
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; cursor: pointer; font-family: inherit; font-size: 15px; font-weight: 600; color: var(--ink);
}
.pick-item .muted { font-weight: 400; }

.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 60; max-width: 90vw; text-align: center;
}
