/* ============================================================
   Kitchen PWA — стили
   Тёплый редакционный минимализм. Светлая и тёмная темы.
   ============================================================ */

/* ---- Шрифты (локальные системные стеки с характером) ---- */
/* Заголовки — гротеск с характером; тело — гуманистический шрифт.
   Без внешних зависимостей: PWA должна работать офлайн. */

:root {
  /* типографика */
  --font-display: "Trebuchet MS", "Segoe UI", "Helvetica Neue", sans-serif;
  --font-body: "Segoe UI", "Helvetica Neue", system-ui, sans-serif;

  /* радиусы / тени / отступы */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 24px;
  --pad: 16px;
  --maxw: 720px;

  /* акценты — общие для обеих тем */
  --accent: #e07a41;
  --accent-deep: #c75f2b;
  --accent-soft: rgba(224, 122, 65, 0.12);
  --freeze: #4a90c2;
  --freeze-soft: rgba(74, 144, 194, 0.14);
}

/* ---- Светлая тема (по умолчанию) ---- */
:root,
:root[data-theme="light"] {
  --bg: #f3ede1;
  --bg-grain: rgba(120, 90, 50, 0.025);
  --surface: #fbf7ef;
  --surface-2: #f6efe1;
  --ink: #2c2620;
  --ink-soft: #6b6155;
  --ink-faint: #9a8f80;
  --line: #e4d9c5;
  --line-strong: #d4c5a8;
  --shadow: 0 2px 6px rgba(80, 60, 30, 0.06), 0 8px 24px rgba(80, 60, 30, 0.07);
  --shadow-sm: 0 1px 3px rgba(80, 60, 30, 0.08);
}

/* ---- Тёмная тема ---- */
:root[data-theme="dark"] {
  --bg: #211e1a;
  --bg-grain: rgba(255, 255, 255, 0.015);
  --surface: #2b2722;
  --surface-2: #322d27;
  --ink: #f0e9dc;
  --ink-soft: #b3a896;
  --ink-faint: #7d7466;
  --line: #3d382f;
  --line-strong: #4a443a;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --accent-soft: rgba(224, 122, 65, 0.18);
  --freeze-soft: rgba(74, 144, 194, 0.22);
}

/* следуем системной теме, если пользователь не выбрал вручную */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #211e1a;
    --bg-grain: rgba(255, 255, 255, 0.015);
    --surface: #2b2722;
    --surface-2: #322d27;
    --ink: #f0e9dc;
    --ink-soft: #b3a896;
    --ink-faint: #7d7466;
    --line: #3d382f;
    --line-strong: #4a443a;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --accent-soft: rgba(224, 122, 65, 0.18);
    --freeze-soft: rgba(74, 144, 194, 0.22);
  }
}

/* ---- Сброс ---- */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  background-image: radial-gradient(var(--bg-grain) 1px, transparent 1px);
  background-size: 4px 4px;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

/* безопасные зоны для standalone на iOS */
.app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100%;
  padding:
    calc(env(safe-area-inset-top) + 0px)
    env(safe-area-inset-right)
    calc(env(safe-area-inset-bottom) + 84px)
    env(safe-area-inset-left);
}

/* ============================================================
   Шапка
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) var(--pad) 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar__logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.topbar__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  flex: 1;
}
.topbar__title small {
  display: block;
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 0.7rem;
  color: var(--ink-faint);
  letter-spacing: 0;
}

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.1rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}
.icon-btn:active { transform: scale(0.92); }

/* ============================================================
   Офлайн-плашка / статус данных
   ============================================================ */
.datastatus {
  margin: 10px var(--pad) 0;
  font-size: 0.74rem;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 6px;
}
.datastatus.is-offline { color: var(--accent-deep); }
.datastatus__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #5bbd7a;
}
.datastatus.is-offline .datastatus__dot { background: var(--accent); }

/* ============================================================
   Контент
   ============================================================ */
.view { padding: 8px var(--pad) 0; }
.view[hidden] { display: none; }

.section-label {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-deep);
  margin: 22px 2px 10px;
}

/* ---- Выбор дня (ShowMenu) ---- */
.daybar {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-top: 14px;
}
.daybar select {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  padding: 13px 14px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position:
    calc(100% - 19px) calc(50% - 2px),
    calc(100% - 13px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
.daybar .nav-btn {
  width: 48px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--r-md);
  font-size: 1.3rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}
.daybar .nav-btn:active { transform: scale(0.9); }
.daybar .nav-btn:disabled { opacity: 0.32; cursor: default; }

/* ---- Карточка приёма пищи ---- */
.meal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}
.meal__head {
  padding: 15px 17px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.meal__titles { flex: 1; min-width: 0; }
.meal__type {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  font-weight: 700;
}
.meal__name {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin-top: 2px;
}
.tag-freeze {
  flex-shrink: 0;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--freeze);
  background: var(--freeze-soft);
  border-radius: 999px;
  padding: 5px 10px;
  white-space: nowrap;
}

.meal__body { padding: 13px 17px 16px; }

/* блок ингредиентов */
.ing-list { list-style: none; }
.ing-list li {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.92rem;
}
.ing-list li:last-child { border-bottom: 0; }
.ing-list .q {
  font-weight: 700;
  color: var(--accent-deep);
  white-space: nowrap;
}

/* техника */
.devices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}
.chip {
  font-size: 0.74rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 5px 11px;
  font-weight: 500;
}

/* рецепт */
.recipe-toggle {
  margin-top: 13px;
  width: 100%;
  text-align: left;
  background: var(--accent-soft);
  border: 0;
  color: var(--accent-deep);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.86rem;
  padding: 11px 14px;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.recipe-toggle .arr { transition: transform 0.2s ease; }
.recipe-toggle[aria-expanded="true"] .arr { transform: rotate(90deg); }

.recipe-text {
  white-space: pre-wrap;
  font-size: 0.92rem;
  color: var(--ink-soft);
  line-height: 1.62;
  padding: 12px 2px 2px;
}
.recipe-text[hidden] { display: none; }

/* подзаголовок внутри тела карточки */
.meal__sub {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 700;
  color: var(--ink-faint);
  margin: 4px 0 2px;
}
.meal__note {
  font-size: 0.92rem;
  color: var(--ink-soft);
  white-space: pre-wrap;
  line-height: 1.6;
}

/* ============================================================
   Слайдер порций
   ============================================================ */
.portions {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 13px 16px;
  margin-top: 14px;
  box-shadow: var(--shadow-sm);
}
.portions__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.portions__label {
  font-weight: 600;
  font-size: 0.9rem;
}
.portions__val {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--accent-deep);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 3px 11px;
  min-width: 54px;
  text-align: center;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--line-strong);
  margin-top: 13px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  cursor: pointer;
}

/* ============================================================
   MealPrep — мультивыбор дней, фильтры
   ============================================================ */
.field {
  margin-top: 14px;
}
.field__label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 7px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.linklike {
  background: none; border: 0;
  color: var(--accent-deep);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-body);
}

/* чипы дней (мультивыбор) */
.day-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.day-chip {
  font-family: var(--font-body);
  font-size: 0.84rem;
  font-weight: 600;
  text-align: left;
  padding: 11px 12px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.14s ease;
}
.day-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-deep);
}
.day-chip[disabled] {
  opacity: 0.4;
  cursor: default;
}
.day-chip:active:not([disabled]) { transform: scale(0.97); }

/* сегментированный фильтр заморозки */
.segment {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 3px;
  gap: 3px;
}
.segment button {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 9px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.14s ease;
}
.segment button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* числовой ввод порций */
.stepper {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  overflow: hidden;
  width: fit-content;
}
.stepper button {
  width: 44px; height: 44px;
  border: 0;
  background: var(--surface);
  color: var(--accent-deep);
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
}
.stepper button:active { background: var(--accent-soft); }
.stepper input {
  width: 64px; height: 44px;
  border: 0;
  border-left: 1.5px solid var(--line);
  border-right: 1.5px solid var(--line);
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface);
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

/* список закупок */
.shop-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  margin-top: 16px;
  overflow: hidden;
}
.shop-card__head {
  padding: 14px 17px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.shop-card__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
}
.shop-card__count {
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-weight: 600;
}
.shop-list { list-style: none; padding: 6px 17px 10px; }
.shop-list li {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.95rem;
}
.shop-list li:last-child { border-bottom: 0; }
.shop-list .q {
  font-weight: 700;
  color: var(--accent-deep);
  white-space: nowrap;
}
.shop-list li.is-taste .q {
  color: var(--ink-faint);
  font-weight: 600;
  font-style: italic;
}

.btn-primary {
  width: 100%;
  margin-top: 14px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: var(--r-md);
  padding: 15px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, background 0.15s ease;
}
.btn-primary:active { transform: scale(0.98); background: var(--accent-deep); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

/* ============================================================
   Пустые состояния
   ============================================================ */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-faint);
}
.empty__icon { font-size: 2.4rem; margin-bottom: 10px; }
.empty__text { font-size: 0.92rem; }

/* ============================================================
   Нижняя навигация
   ============================================================ */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
  display: flex;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  max-width: var(--maxw);
  margin: 0 auto;
}
.tab {
  flex: 1;
  background: none;
  border: 0;
  padding: 8px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--ink-faint);
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 12px;
  transition: color 0.15s ease;
}
.tab__icon {
  width: 26px; height: 26px;
  display: grid; place-items: center;
}
.tab__icon svg { width: 24px; height: 24px; }
.tab[aria-selected="true"] { color: var(--accent); }

/* ============================================================
   Тосты
   ============================================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bg);
  font-size: 0.86rem;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  max-width: 86vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   Анимации появления
   ============================================================ */
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.rise { animation: rise 0.34s ease both; }
.rise:nth-child(2) { animation-delay: 0.04s; }
.rise:nth-child(3) { animation-delay: 0.08s; }
.rise:nth-child(4) { animation-delay: 0.12s; }
.rise:nth-child(5) { animation-delay: 0.16s; }
.rise:nth-child(6) { animation-delay: 0.20s; }

@media (prefers-reduced-motion: reduce) {
  .rise { animation: none; }
  * { transition: none !important; }
}
