/* Mini App «Питание». Тема — переменные, которые app.js перекрывает
   значениями Telegram.WebApp.themeParams; вне Telegram работают фолбэки
   ниже (системная тема через prefers-color-scheme). Телефон: тач-таргеты
   от 44px, системные шрифты, никакой анимационной мишуры. */

:root {
  --bg: #ffffff;
  --text: #1c1c1e;
  --hint: #8e8e93;
  --link: #2481cc;
  --button: #2481cc;
  --button-text: #ffffff;
  --card: #f2f2f7;
  --border: rgba(0, 0, 0, 0.08);
  --ok: #2e9e4f;
  --warn: #d97706;
  --bad: #d93025;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --text: #f2f2f7;
    --hint: #98989e;
    --link: #6ab2f2;
    --button: #3390ec;
    --button-text: #ffffff;
    --card: #2c2c2e;
    --border: rgba(255, 255, 255, 0.1);
    --ok: #4cc36c;
    --warn: #f0a34e;
    --bad: #f28b82;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
}

/* ── Каркас ─────────────────────────────────────────────────────────────── */

.screen {
  padding: 12px 12px calc(72px + env(safe-area-inset-bottom, 0px));
  max-width: 640px;
  margin: 0 auto;
}

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 10;
}

.tab {
  flex: 1;
  min-height: 56px;
  border: 0;
  background: none;
  color: var(--hint);
  font: inherit;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tab.active { color: var(--link); font-weight: 600; }
.tab-icon { font-size: 22px; line-height: 1; }

/* ── Общие блоки ────────────────────────────────────────────────────────── */

h1 {
  font-size: 20px;
  margin: 4px 0 12px;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 20px 0 8px;
}

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
}

.muted { color: var(--hint); }
.small { font-size: 13px; }
.error-note { color: var(--bad); padding: 12px 0; }

.btn {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--button);
  color: var(--button-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled { opacity: 0.45; }

.btn.secondary {
  background: transparent;
  color: var(--link);
  border: 1px solid var(--border);
  background-color: var(--bg);
}

.btn.danger { background: transparent; border: 1px solid var(--border); color: var(--bad); }

.btn-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

input[type='number'] {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  width: 100%;
}

/* ── Сегодня ────────────────────────────────────────────────────────────── */

.meal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.meal-slot { font-weight: 600; }
.meal-time { color: var(--hint); font-variant-numeric: tabular-nums; }
.meal-title { margin: 2px 0 6px; font-size: 17px; }
.portions { margin: 0; padding: 0; list-style: none; }
.portions li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 0;
  font-size: 14px;
}
.portions .grams { color: var(--hint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals { margin-top: 6px; font-size: 13px; color: var(--hint); }
.eaten-mark { color: var(--ok); font-weight: 600; margin-top: 8px; }

.progress {
  height: 10px;
  border-radius: 5px;
  background: var(--border);
  overflow: hidden;
  margin: 8px 0 4px;
}
.progress-fill { height: 100%; background: var(--link); border-radius: 5px; }
.progress-fill.done { background: var(--ok); }

.inline-form { display: flex; gap: 8px; margin-top: 8px; }
.inline-form input { flex: 1; }
.inline-form .btn { flex: none; }

/* ── Неделя ─────────────────────────────────────────────────────────────── */

details.day { margin-bottom: 8px; }
details.day summary {
  list-style: none;
  cursor: pointer;
  background: var(--card);
  border-radius: 14px;
  padding: 12px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
details.day summary::-webkit-details-marker { display: none; }
details.day[open] summary { border-radius: 14px 14px 0 0; }
.day-title { font-weight: 600; }
.day-compact { color: var(--hint); font-size: 13px; margin-top: 2px; }
.day-body {
  background: var(--card);
  border-radius: 0 0 14px 14px;
  padding: 0 12px 10px;
}
.day-meal {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
  align-items: baseline;
}
.day-meal .meal-time { flex: none; width: 3.2em; }
.today-marker { color: var(--link); }

/* ── Графики ────────────────────────────────────────────────────────────── */

canvas.chart { width: 100%; height: 240px; display: block; }

.chips { display: flex; gap: 8px; margin: 8px 0 12px; }
.chip {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chip.active { background: var(--button); color: var(--button-text); border-color: var(--button); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-card { background: var(--card); border-radius: 14px; padding: 10px 12px; }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value.good { color: var(--ok); }
.stat-value.poor { color: var(--warn); }
.stat-label { font-size: 12px; color: var(--hint); margin-top: 2px; }

/* ── Кухня ──────────────────────────────────────────────────────────────── */

.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.item-row:last-child { border-bottom: 0; }
.item-name { flex: 1; }
.item-name .note { display: block; font-size: 12px; color: var(--hint); }
.item-grams { color: var(--hint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.item-expired { color: var(--bad); }

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  background: none;
  font-size: 20px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bought .item-name { text-decoration: line-through; color: var(--hint); }

.fridge-editor { padding: 8px 0 12px; border-bottom: 1px solid var(--border); }

/* ── Тост ───────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  background: var(--text);
  color: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  z-index: 20;
  white-space: pre-line;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
.toast.error { background: var(--bad); color: #fff; }
