/* ─────────────────────────────────────────────
   Fridge App — style.css v0.2.0
   ───────────────────────────────────────────── */

/* ── Токены ── */
:root {
  --nav-bg:       #1A1A2E;
  --nav-height:   64px;

  /* Холодильник */
  --cold-accent:  #4A9EBF;
  --cold-bg:      #E8F4FD;
  --cold-card:    #ffffff;

  /* Склад — мягкий жёлтый */
  --warm-accent:  #c8a800;
  --warm-bg:      #fff9c4;
  --warm-card:    #ffffff;

  /* Аптечка — мягкий розовый */
  --pharma-accent: #d47fa0;
  --pharma-bg:     #f8bbd0;
  --pharma-card:   #ffffff;

  /* Покупки */
  --shopping-accent: #BF7A4A;
  --shopping-bg:     #FDF3E8;

  /* Нейтральный (справочник) */
  --neutral-accent: #6B7A8D;
  --neutral-bg:   #F5F5F5;

  /* Текущий акцент — переключается JS-ом */
  --accent:       var(--cold-accent);
  --page-bg:      var(--cold-bg);

  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 2px 8px rgba(0,0,0,0.08);
  --transition:   0.25s ease;
}

/* ── Сброс и база ── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  background: #f0f0f0;
  -webkit-font-smoothing: antialiased;
  /*padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);*/
}

/* ── Лейаут ── */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--page-bg);
  transition: background var(--transition);
  padding-top: env(safe-area-inset-top, 0px);
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 16px;
}

/* ── Экраны ── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Нижняя навигация ── */
nav.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  /*left: 0;*/
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-height);
  background: var(--nav-bg);
  display: flex;
  align-items: stretch;
  z-index: 100;
  border-top: 1px solid rgba(255,255,255,0.06);
  /* Добавляем поддержку безопасной зоны свайпа iOS */
  padding-bottom: env(safe-area-inset-bottom, 0px);

  /* Если у панели фиксированная высота (например, 64px), её нужно увеличить на размер зоны свайпа */
  height: calc(64px + env(safe-area-inset-bottom, 0px)); 

  /* Чтобы контент внутри (иконки/текст) не сползал в самый низ, выравнивай через flex flex-start или добавляй padding */
  box-sizing: border-box;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.45);
  font-size: 11px;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: color var(--transition);
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn .nav-icon { font-size: 22px; line-height: 1; }
.nav-btn.active { color: var(--accent); }

/* ── Заголовок экрана ── */
.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.screen-title {
  font-size: 22px;
  font-weight: 700;
  color: #1a1a1a;
  margin: 0;
}

/* Кнопка ➕ */
.btn-add {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: transform 0.15s, box-shadow 0.15s, background var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn-add:active { transform: scale(0.92); box-shadow: none; }

/* ── Табы хранилища (3 штуки) ── */
.storage-tabs {
  display: flex;
  background: rgba(0,0,0,0.05);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 20px;
  gap: 2px;
}

.storage-tab-btn {
  flex: 1;
  padding: 9px 4px;
  border: none;
  background: none;
  border-radius: calc(var(--radius-sm) - 2px);
  font-size: 12px;
  font-weight: 500;
  color: #888;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.storage-tab-btn.active {
  background: #fff;
  color: #1a1a1a;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* ── Группы категорий ── */
.category-group { margin-bottom: 24px; }

.category-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent);
  margin: 0 0 10px 4px;
}

/* ── Карточки продуктов ── */
.item-card {
  background: var(--cold-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.item-card:active { transform: scale(0.98); box-shadow: none; }

.item-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--cold-bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background var(--transition);
}

.item-info { flex: 1; min-width: 0; }

.item-name {
  font-size: 15px;
  font-weight: 500;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-qty {
  font-size: 13px;
  color: #888;
  margin-top: 2px;
}

/* Свайп для удаления (Покупки) */
.swipe-row {
  position: relative;
  margin-bottom: 8px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #e74c3c;
}
.swipe-row .item-card {
  margin-bottom: 0;
  position: relative;
  z-index: 1;
  transition: transform 0.22s ease;
  touch-action: pan-y;
  will-change: transform;
}
.swipe-action-delete {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 84px;
  border: none;
  background: #e74c3c;
  color: #fff;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  z-index: 0;
}
.swipe-action-delete:active { background: #c0392b; }

/* Кнопка "отметить купленным" — зелёная галочка */
.btn-check {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #eaf7ea;
  border: 1.5px solid #4caf50;
  color: #2e7d32;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
  line-height: 1;
}
.btn-check:active { background: #4caf50; color: #fff; transform: scale(0.92); }

/* Иконка удаления */
.btn-delete {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  color: #ccc;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.btn-delete:active { color: #e55; }

/* ── Подсветка срока годности ── */
.item-card.item-expiring {
  border-left: 4px solid #f39c12;
  background: #fff8e6;
}
.item-card.item-expiring .item-qty {
  color: #b06b00;
  font-weight: 500;
}
.item-card.item-expired {
  border-left: 4px solid #c0392b;
  background: #fdecea;
}
.item-card.item-expired .item-qty {
  color: #c0392b;
  font-weight: 600;
}

/* ── Покупки — купленные ── */
.item-card.bought > * {
  opacity: 0.5;
}
.item-card.bought .item-name {
  text-decoration: line-through;
  color: #999;
}

.bought-section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #bbb;
  margin: 16px 0 10px 4px;
}

/* ── Пустое состояние ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #bbb;
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; margin: 0; }

/* ── Вкладки справочника ── */
.tabs {
  display: flex;
  background: rgba(0,0,0,0.05);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  padding: 8px 4px;
  border: none;
  background: none;
  border-radius: calc(var(--radius-sm) - 2px);
  font-size: 13px;
  font-weight: 500;
  color: #888;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab-btn.active {
  background: #fff;
  color: #1a1a1a;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Фильтр продуктов в справочнике ── */
.catalog-filter-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.catalog-filter-btn {
  padding: 5px 12px;
  border: 1.5px solid #e0e0e0;
  background: #fff;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  color: #888;
  cursor: pointer;
  transition: all 0.15s;
}
.catalog-filter-btn.active {
  background: var(--neutral-accent);
  border-color: var(--neutral-accent);
  color: #fff;
}

/* ── Простой список (категории, юниты) ── */
.simple-list { list-style: none; padding: 0; margin: 0; }
.simple-list li {
  padding: 12px 14px;
  background: #fff;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 14px;
  color: #333;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.simple-list .unit-short {
  font-size: 12px;
  color: #999;
  background: #f0f0f0;
  padding: 2px 8px;
  border-radius: 20px;
}
.simple-list .cat-storage-badge {
  font-size: 11px;
  color: #999;
  background: #f0f0f0;
  padding: 2px 8px;
  border-radius: 20px;
}

/* Строка продукта в справочнике */
.catalog-product-item {
  padding: 12px 14px;
  background: #fff;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.catalog-product-item .prod-info { min-width: 0; }
.catalog-product-item .prod-name { font-size: 14px; font-weight: 500; color: #1a1a1a; }
.catalog-product-item .prod-meta { font-size: 12px; color: #999; margin-top: 2px; }

/* ── Кнопка добавить продукт в справочнике ── */
.btn-primary {
  display: block;
  width: 100%;
  padding: 13px;
  background: var(--neutral-accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 16px;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.8; }

/* ── Модальные окна ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: #fff;
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 16px 32px;
  transform: translateY(100%);
  transition: transform var(--transition);
  max-height: 90dvh;
  overflow-y: auto;
}
.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}
.btn-close {
  background: none;
  border: none;
  font-size: 22px;
  color: #aaa;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

/* ── Поля форм в модалках ── */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #555;
  margin-bottom: 6px;
}
.field input,
.field select {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid #e0e0e0;
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: #1a1a1a;
  background: #fafafa;
  outline: none;
  transition: border-color 0.15s;
  appearance: none;
}
.field input:focus,
.field select:focus {
  border-color: var(--accent);
  background: #fff;
}

/* Список выбора продукта */
.product-pick-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1.5px solid #e0e0e0;
  border-radius: var(--radius-sm);
  background: #fafafa;
}
.product-pick-item {
  padding: 11px 13px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.1s;
}
.product-pick-item:last-child { border-bottom: none; }
.product-pick-item:active { background: #f0f0f0; }
.product-pick-item.selected {
  background: #eaf5fb;
  font-weight: 500;
  color: var(--cold-accent);
}
.product-pick-item .pick-meta {
  font-size: 12px;
  color: #aaa;
  margin-top: 2px;
}

/* Кнопка подтверждения */
.btn-confirm {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: opacity 0.15s, background var(--transition);
}
.btn-confirm:active { opacity: 0.8; }
.btn-confirm:disabled { opacity: 0.4; cursor: default; }

/* ── Сообщение об ошибке ── */
.error-banner {
  background: #fff0f0;
  border: 1px solid #ffcccc;
  color: #c0392b;
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}
.error-banner.visible { display: block; }

/* ── Toast-уведомление ── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30,30,30,0.9);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Скелетон загрузки ── */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-sm);
  height: 60px;
  margin-bottom: 8px;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Акценты по экрану + типу хранилища ── */

/* Экран Хранилище, тип Холодильник (default) */
body.screen-storage.storage-type-1 {
  --accent: var(--cold-accent);
  --page-bg: var(--cold-bg);
}
body.screen-storage.storage-type-1 .item-icon { background: var(--cold-bg); }

/* Экран Хранилище, тип Склад */
body.screen-storage.storage-type-2 {
  --accent: var(--warm-accent);
  --page-bg: var(--warm-bg);
}
body.screen-storage.storage-type-2 .item-icon { background: var(--warm-bg); }

/* Экран Хранилище, тип Аптечка */
body.screen-storage.storage-type-3 {
  --accent: var(--pharma-accent);
  --page-bg: var(--pharma-bg);
}
body.screen-storage.storage-type-3 .item-icon { background: var(--pharma-bg); }

/* Экран Покупки */
body.screen-shopping {
  --accent: var(--shopping-accent);
  --page-bg: var(--shopping-bg);
}
body.screen-shopping .item-icon { background: var(--shopping-bg); }

/* Экран Справочник */
body.screen-catalog {
  --accent: var(--neutral-accent);
  --page-bg: var(--neutral-bg);
}

/* ── Футер ── */
.app-footer {
  flex-shrink: 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted, #6b7280);
  padding: 8px 0 12px;
  margin-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  letter-spacing: 0.3px;
  background: transparent;
}
.app-footer .btn-text-secondary {
  font-size: inherit;
  color: inherit;
}

/* ── Responsive ── */
@media (prefers-reduced-motion: reduce) {
  *, .modal, .modal-overlay, .nav-btn { transition: none !important; animation: none !important; }
}

/* ── Экран логина ── */
#login-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--nav-bg);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
#login-screen.visible {
  display: flex;
}
#login-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  margin: 16px;
}
#login-box h1 {
  text-align: center;
  font-size: 22px;
  margin: 0 0 24px;
}
/* Pico CSS override для логин-формы */
#login-box input {
  all: unset;
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 11px 13px;
  border: 1.5px solid #e0e0e0;
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: #1a1a1a;
  background: #fafafa;
  margin-bottom: 4px;
}
#login-box input:focus {
  outline: 2px solid var(--cold-accent);
  border-color: var(--cold-accent);
  background: #fff;
}

/* ── Рецепты ── */
body.screen-recipes {
  --accent: #6B9E58;
  --page-bg: #DCEFD9;
}

.verified-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  background: #fff;
  color: #555;
  text-decoration: none;
  box-sizing: border-box;
  transition: background var(--transition), color var(--transition);
}
.verified-chip.verified   { background: #e8f5e9; color: #2e7d32; border-color: #c8e6c9; }
.verified-chip.unverified { background: #fff3e0; color: #c08000; border-color: #ffe0b2; }
.verified-chip:active     { opacity: 0.8; }

.verified-chip.link-chip  { background: #e3f2fd; color: #1565c0; border-color: #bbdefb; }
.verified-chip.link-chip:hover { text-decoration: underline; }

.recipe-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform var(--transition);
}
.recipe-card:active { transform: scale(0.98); box-shadow: none; }

.ingredient-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  font-size: 14px;
}
.ingredient-row:last-child { border-bottom: none; }
.ingredient-row .btn-delete { margin-left: 8px; }

.availability-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 14px;
  border-left: 4px solid transparent;
}
.availability-row > span:nth-child(2) { grid-column: 1 / -1; }
.availability-row .availability-status { grid-column: 2; grid-row: 1; font-weight: 600; }
.availability-row.ok   { background: #e8f5e9; border-left-color: #4caf50; }
.availability-row.warn { background: #fff9c4; border-left-color: #c8a800; }
.availability-row.miss { background: #ffebee; border-left-color: #e74c3c; }

.btn-text-secondary {
  background: none;
  border: none;
  color: var(--neutral-accent);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  text-decoration: underline;
}
.btn-text-secondary:active { opacity: 0.6; }

textarea {
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1.5px solid #e0e0e0;
  border-radius: var(--radius-sm);
  background: #fafafa;
  resize: vertical;
}
textarea:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
  background: #fff;
}

/* ── Кнопка «Связанные рецепты» на карточке продукта ── */
.btn-linked-recipes {
  padding: 5px 12px;
  border: 1.5px solid var(--neutral-accent);
  background: #fff;
  color: var(--neutral-accent);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn-linked-recipes:hover {
  background: var(--neutral-accent);
  color: #fff;
}

/* ── Чип активного фильтра рецептов по продукту ── */
.recipe-product-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 14px;
  margin-bottom: 14px;
  background: var(--neutral-accent);
  color: #fff;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
}
.recipe-product-chip button {
  border: none;
  background: rgba(255,255,255,0.25);
  color: #fff;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.recipe-product-chip button:hover {
  background: rgba(255,255,255,0.4);
}

/* ── Кружок лимита ИИ-генераций ── */
.usage-ring {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.usage-ring-label {
  font-size: 12px;
  color: #888;
}
