:root {
  --bg: #f4f7f5;
  --bg-secondary: #ffffff;
  --text: #1c2320;
  --hint: #6b7a72;
  --accent: #34a853;
  --accent-2: #ff9800;
  --danger: #e53935;
  --card-radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181a;
    --bg-secondary: #1f2528;
    --text: #f0f4f2;
    --hint: #93a19b;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid rgba(120,130,125,0.15);
}

.brand { font-size: 18px; font-weight: 700; }
.user-greeting { font-size: 13px; color: var(--hint); }

.content {
  padding: 12px 12px calc(84px + var(--safe-bottom));
  min-height: calc(100vh - 56px);
}

.loader, .empty-state, .error-state {
  text-align: center;
  color: var(--hint);
  padding: 40px 16px;
  font-size: 14px;
}

.error-state { color: var(--danger); }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  overflow-x: auto;
  background: var(--bg-secondary);
  border-top: 1px solid rgba(120,130,125,0.15);
  padding-bottom: var(--safe-bottom);
  z-index: 10;
}

.tab-btn {
  flex: 1 0 auto;
  min-width: 60px;
  background: none;
  border: none;
  padding: 8px 6px 10px;
  font-size: 18px;
  color: var(--hint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn span { font-size: 11px; }
.tab-btn.active { color: var(--accent); }

/* Search / filter bar */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.search-bar input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(120,130,125,0.25);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 14px;
}
.search-bar input:focus { outline: 2px solid var(--accent); }

/* Grid of dish cards */
.dish-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.dish-card {
  background: var(--bg-secondary);
  border-radius: var(--card-radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  transition: transform .1s ease;
}
.dish-card:active { transform: scale(0.97); }

.dish-card .thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: linear-gradient(135deg, #e8f5e9, #fff3e0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
  object-fit: cover;
}

.dish-card .info { padding: 8px 10px 10px; }
.dish-card .name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 32px;
}
.dish-card .meta {
  font-size: 12px;
  color: var(--hint);
  margin-top: 4px;
  display: flex;
  justify-content: space-between;
}
.health-badge {
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
}
.health-good { background: #e0f4e3; color: #1e7d34; }
.health-mid  { background: #fff3d6; color: #9a6a00; }
.health-bad  { background: #fde0df; color: #b3261e; }

/* Cards / generic sections */
.card {
  background: var(--bg-secondary);
  border-radius: var(--card-radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.card h3 { margin: 0 0 8px; font-size: 15px; }
.card .row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; }
.card .row .label { color: var(--hint); }

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--hint);
  margin: 14px 4px 8px;
}

.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-secondary);
  font-size: 12px;
  color: var(--hint);
  border: 1px solid rgba(120,130,125,0.2);
  cursor: pointer;
}
.pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Цветные категории (25.07.2026, по просьбе "добавь цвета") — фиксированный
   порядок пилюль из ARCHIVE_CATEGORIES, поэтому красим по позиции */
.pill-row .pill:nth-child(2) { border-color: #66bb6a; color: #2e7d32; }
.pill-row .pill:nth-child(3) { border-color: #9ccc65; color: #558b2f; }
.pill-row .pill:nth-child(4) { border-color: #ffb74d; color: #e65100; }
.pill-row .pill:nth-child(5) { border-color: #f06292; color: #ad1457; }
.pill-row .pill:nth-child(6) { border-color: #64b5f6; color: #1565c0; }
.pill-row .pill:nth-child(7) { border-color: #4db6ac; color: #00695c; }
.pill-row .pill:nth-child(8) { border-color: #a1887f; color: #4e342e; }
.pill-row .pill:nth-child(9) { border-color: #ba68c8; color: #6a1b9a; }
.pill-row .pill.active { background: var(--accent) !important; color: #fff !important; border-color: var(--accent) !important; }

/* Dish detail modal */
.detail-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 20;
  overflow-y: auto;
  padding: 0 0 40px;
}
.detail-back {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg-secondary);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 1px solid rgba(120,130,125,0.15);
}
.detail-photo {
  width: 100%; aspect-ratio: 4/3; object-fit: cover;
}
.detail-photo-fallback {
  width: 100%; aspect-ratio: 4/3;
  display: flex; align-items: center; justify-content: center;
  font-size: 64px;
  background: linear-gradient(135deg, #e8f5e9, #fff3e0);
}
.detail-body { padding: 14px 16px; }
.detail-body h2 { margin: 0 0 8px; font-size: 20px; }

.macro-row { display: flex; gap: 8px; margin: 12px 0; }
.macro-chip {
  flex: 1;
  text-align: center;
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 8px 4px;
}
.macro-chip .icon { font-size: 16px; line-height: 1; margin-bottom: 2px; }
.macro-chip .val { font-size: 16px; font-weight: 700; }
.macro-chip .lbl { font-size: 11px; color: var(--hint); }
.macro-chip.calories { background: linear-gradient(160deg, #fff3e0, #ffe0b2); }
.macro-chip.protein  { background: linear-gradient(160deg, #e3f2fd, #bbdefb); }
.macro-chip.fat      { background: linear-gradient(160deg, #fffde7, #fff59d); }
.macro-chip.carbs    { background: linear-gradient(160deg, #e8f5e9, #c8e6c9); }
@media (prefers-color-scheme: dark) {
  .macro-chip.calories { background: linear-gradient(160deg, #4a3418, #3a2a12); }
  .macro-chip.protein  { background: linear-gradient(160deg, #16324a, #12283a); }
  .macro-chip.fat      { background: linear-gradient(160deg, #4a4416, #3a3512); }
  .macro-chip.carbs    { background: linear-gradient(160deg, #1c3a1f, #172e19); }
}

.health-bar-wrap {
  background: rgba(120,130,125,0.15);
  border-radius: 999px;
  height: 6px;
  margin: 8px 0 4px;
  overflow: hidden;
}
.health-bar-fill { height: 100%; border-radius: 999px; }
.health-bar-fill.health-good { background: linear-gradient(90deg, #43a047, #a5d6a7); }
.health-bar-fill.health-mid  { background: linear-gradient(90deg, #f9a825, #ffe082); }
.health-bar-fill.health-bad  { background: linear-gradient(90deg, #e53935, #ef9a9a); }

.tag {
  display: inline-block;
  background: var(--bg-secondary);
  border: 1px solid rgba(120,130,125,0.2);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  margin: 2px 4px 2px 0;
}

.balance-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.balance-dot { font-size: 14px; }

/* Tips */
.tip-card img {
  width: 100%; border-radius: var(--card-radius);
  aspect-ratio: 16/10; object-fit: cover; margin-bottom: 12px;
}
.tip-text { font-size: 15px; line-height: 1.5; }
.btn-primary {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 14px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* Votes */
.vote-photo { width: 100%; border-radius: var(--card-radius); aspect-ratio: 4/3; object-fit: cover; margin-bottom: 12px;}
.vote-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vote-btn {
  padding: 14px 6px;
  border-radius: 12px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-secondary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.vote-btn.dislike { color: var(--danger); }

/* Tag badges (admin archive detail) */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-secondary);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

/* Facts list */
.fact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(120,130,125,0.12);
  cursor: pointer;
}
.fact-item:last-child { border-bottom: none; }
.fact-emoji { font-size: 22px; }
.fact-label { font-size: 12px; color: var(--hint); }
.fact-name { font-size: 14px; font-weight: 600; }

/* Stats table */
.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th, .stats-table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid rgba(120,130,125,0.12); }
.stats-table th { color: var(--hint); font-weight: 500; }

/* Profile */
.profile-header { display: flex; align-items: center; gap: 12px; }
.profile-header .avatar { font-size: 40px; }
.profile-header .name { font-size: 17px; font-weight: 700; }
.profile-header .sub { font-size: 12px; color: var(--hint); }
.xp-bar-track {
  height: 8px; border-radius: 999px; background: rgba(120,130,125,0.15);
  overflow: hidden; margin-top: 8px;
}
.xp-bar-fill { height: 100%; background: var(--accent); }

/* Домашняя сетка "Профиль" — по одной плитке на функцию, 2 в ряд */
.profile-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 4px; }
.profile-tile {
  background: var(--bg-secondary); border-radius: var(--card-radius);
  padding: 18px 10px; text-align: center; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.profile-tile:active { transform: scale(0.97); }
.profile-tile-icon { font-size: 28px; }
.profile-tile-label { font-size: 13px; font-weight: 600; margin-top: 6px; }

.ach-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 6px; }
.ach-item {
  text-align: center; font-size: 22px; padding: 8px 2px; border-radius: 12px;
  background: var(--bg); opacity: 0.35;
}
.ach-item.unlocked { opacity: 1; background: #fff3d6; }
.ach-item .ach-name { display: block; font-size: 9px; margin-top: 2px; color: var(--hint); line-height: 1.2; }

.challenge-card { border-radius: var(--card-radius); }
.challenge-card .status { font-size: 12px; margin-top: 6px; }
.challenge-card .status.done { color: var(--accent); font-weight: 600; }

.toggle-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 7px 12px; border-radius: 999px; margin: 3px 4px 3px 0;
  border: 1px solid rgba(120,130,125,0.25); background: var(--bg-secondary);
  font-size: 13px; cursor: pointer;
}
.toggle-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.tz-select, .city-input {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid rgba(120,130,125,0.25); background: var(--bg-secondary);
  color: var(--text); font-size: 14px; margin-top: 6px;
}

.link-btn {
  display: block; width: 100%; text-align: left; padding: 12px 14px;
  margin-bottom: 8px; border-radius: 12px; border: none;
  background: var(--bg-secondary); color: var(--text); font-size: 14px;
  text-decoration: none; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.help-page { font-size: 14px; line-height: 1.6; }
.help-nav { display: flex; justify-content: space-between; margin-top: 12px; }
.help-nav button {
  padding: 8px 14px; border-radius: 10px; border: none;
  background: var(--bg); color: var(--text); font-size: 13px; cursor: pointer;
}

.feedback-tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.feedback-textarea {
  width: 100%; min-height: 80px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid rgba(120,130,125,0.25); background: var(--bg-secondary);
  color: var(--text); font-size: 14px; font-family: inherit; resize: vertical;
}
