/* ══════════════════════════════════════════════════════════
   NutriTrack — Style Sheet
   ══════════════════════════════════════════════════════════ */

:root {
  --bg:       #0b0f1a;
  --surface:  #131929;
  --surface2: #1a2236;
  --border:   #242d45;
  --text:     #e8eaf6;
  --muted:    #6b7fa3;
  --green:    #10b981;
  --green-dim:#0d9268;
  --blue:     #6366f1;
  --orange:   #f59e0b;
  --red:      #ef4444;
  --purple:   #a855f7;
  --teal:     #06b6d4;
  --pink:     #ec4899;
  --radius:   14px;
  --sidebar-w:240px;
  --transition: .2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ══ SIDEBAR ════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0;
  z-index: 200;
  transition: transform var(--transition);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--green), var(--teal));
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 1.1rem;
  color: #fff;
}

.logo-text { font-weight: 700; font-size: 1.1rem; letter-spacing: -.3px; }

.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: .92rem;
  transition: background var(--transition), color var(--transition);
}

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: linear-gradient(90deg,#10b98120,#10b98108); color: var(--green); border-left: 3px solid var(--green); }
.nav-item i { width: 18px; text-align: center; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.api-key-wrap label {
  font-size: .78rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.api-key-wrap input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: .82rem;
  margin-bottom: 8px;
  outline: none;
}

.btn-save-key {
  width: 100%;
  padding: 8px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: .82rem;
  cursor: pointer;
  transition: background var(--transition);
}
.btn-save-key:hover { background: var(--green-dim); }

/* ══ MAIN CONTENT ═══════════════════════════════════════════ */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-nav button {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 32px; height: 32px;
  cursor: pointer;
  transition: background var(--transition);
}
.date-nav button:hover { background: var(--border); }

.date-label {
  font-weight: 600;
  font-size: .95rem;
  min-width: 90px;
  text-align: center;
}

.btn-today {
  font-size: .78rem !important;
  width: auto !important;
  padding: 0 12px !important;
  color: var(--green) !important;
  border-color: var(--green) !important;
}

.topbar-right { margin-left: auto; }
.topbar-date { font-size: .82rem; color: var(--muted); }

/* ── Pages ──────────────────────────────────────────────── */
.page {
  display: none;
  padding: 28px;
  flex-direction: column;
  gap: 20px;
  flex: 1;
  overflow-y: auto;
}
.page.active { display: flex; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
}

.card-title {
  font-size: .92rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.card-header-row .card-title { margin-bottom: 0; }

/* ── Summary row ────────────────────────────────────────── */
.summary-row {
  display: grid;
  grid-template-columns: 260px 1fr 220px;
  gap: 20px;
}

/* ── Calorie ring ───────────────────────────────────────── */
.calorie-card { display: flex; flex-direction: column; align-items: center; }

.ring-wrap {
  position: relative;
  width: 180px; height: 180px;
  margin: 0 auto 14px;
}

.ring-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.ring-big { display: block; font-size: 2rem; font-weight: 800; line-height: 1; }
.ring-sub { font-size: .72rem; color: var(--muted); }

.calorie-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.leg-item { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.green { background: var(--green); }
.dot.gray  { background: var(--border); }
.leg-item b { color: var(--text); }

/* ── Macro bars ─────────────────────────────────────────── */
.macro-list { display: flex; flex-direction: column; gap: 14px; }

.macro-item { }
.macro-header {
  display: flex;
  justify-content: space-between;
  font-size: .82rem;
  margin-bottom: 6px;
}
.macro-header .macro-name { font-weight: 600; }
.macro-header .macro-vals { color: var(--muted); }
.macro-header .macro-vals b { color: var(--text); }

.bar-bg {
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .6s ease;
}

/* ── Glance grid ────────────────────────────────────────── */
.glance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.glance-item {
  background: var(--surface2);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
.glance-val { font-size: 1.3rem; font-weight: 700; }
.glance-label { font-size: .72rem; color: var(--muted); margin-top: 2px; }

/* ── Micros ─────────────────────────────────────────────── */
.micro-card {}
.micro-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.micro-item {
  background: var(--surface2);
  border-radius: 10px;
  padding: 14px;
}
.micro-name { font-size: .78rem; color: var(--muted); margin-bottom: 4px; }
.micro-vals { font-size: .85rem; font-weight: 600; margin-bottom: 8px; }
.micro-vals .micro-unit { font-size: .72rem; color: var(--muted); font-weight: 400; }
.micro-bar-bg { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.micro-bar-fill { height: 100%; border-radius: 3px; transition: width .6s ease; }
.micro-pct { font-size: .7rem; color: var(--muted); margin-top: 4px; text-align: right; }

/* ── Meals list ─────────────────────────────────────────── */
.meals-list { display: flex; flex-direction: column; gap: 10px; }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state i { font-size: 2.5rem; margin-bottom: 12px; display: block; }
.empty-state p { font-size: .9rem; line-height: 1.6; }

.meal-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  transition: border-color var(--transition);
  animation: fadeIn .25s ease;
}
.meal-item:hover { border-color: var(--green); }

.meal-photo {
  width: 56px; height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.meal-photo-placeholder {
  width: 56px; height: 56px;
  border-radius: 8px;
  background: var(--border);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 1.3rem;
  flex-shrink: 0;
}

.meal-info { flex: 1; min-width: 0; }
.meal-name { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-time { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.meal-meta { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.meal-macro-pill {
  font-size: .72rem;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.pill-cal  { background: #10b98122; color: var(--green); }
.pill-pro  { background: #6366f122; color: var(--blue); }
.pill-carb { background: #f59e0b22; color: var(--orange); }
.pill-fat  { background: #ef444422; color: var(--red); }

.source-badge {
  font-size: .65rem;
  padding: 2px 7px;
  border-radius: 20px;
  font-weight: 600;
}
.source-ai { background: #a855f722; color: var(--purple); }
.source-manual { background: #06b6d422; color: var(--teal); }

.meal-actions { display: flex; gap: 6px; }
.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 7px;
  width: 32px; height: 32px;
  cursor: pointer;
  transition: all var(--transition);
  display: grid;
  place-items: center;
  font-size: .82rem;
}
.btn-icon:hover { border-color: var(--red); color: var(--red); }

/* ── Add meal button ────────────────────────────────────── */
.btn-add-meal {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}
.btn-add-meal:hover { background: var(--green-dim); transform: translateY(-1px); }

/* ══ HISTORY ════════════════════════════════════════════════ */
.week-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  font-weight: 600;
}
.week-nav button {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 34px; height: 34px;
  cursor: pointer;
}

.chart-wrap { position: relative; height: 260px; }
.chart-wrap.sm { height: 160px; }

.history-cards-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

/* ══ GOALS PAGE ═════════════════════════════════════════════ */
.goals-form { display: flex; flex-direction: column; gap: 24px; }
.goals-section-title { font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
.goals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.goal-field label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: 5px; }
.goal-field input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: .88rem;
  outline: none;
  transition: border-color var(--transition);
}
.goal-field input:focus { border-color: var(--green); }
.btn-save-goals {
  padding: 11px 28px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  align-self: flex-start;
  transition: background var(--transition);
}
.btn-save-goals:hover { background: var(--green-dim); }

/* ══ MODAL ══════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px) scale(.97);
  transition: transform .25s ease;
  padding: 28px;
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 1.2rem; font-weight: 700; }

.modal-close {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  width: 34px; height: 34px;
  cursor: pointer;
  font-size: 1rem;
  transition: all var(--transition);
}
.modal-close:hover { color: var(--red); border-color: var(--red); }

/* Tabs */
.modal-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  background: var(--surface2);
  padding: 5px;
  border-radius: 10px;
}
.tab-btn {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 7px;
  background: none;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.tab-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.3); }

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

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  margin-bottom: 14px;
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--green); background: #10b98108; }
.upload-zone i { font-size: 2.2rem; color: var(--muted); display: block; margin-bottom: 10px; }
.upload-zone p { color: var(--muted); font-size: .88rem; line-height: 1.5; }
.upload-zone .hint { font-size: .75rem; }
.upload-zone .link { color: var(--green); text-decoration: underline; cursor: pointer; }

.photo-preview-wrap {
  position: relative;
  margin-bottom: 14px;
  border-radius: 12px;
  overflow: hidden;
}
.photo-preview { width: 100%; max-height: 260px; object-fit: cover; border-radius: 12px; display: block; }
.btn-clear-photo {
  position: absolute;
  top: 10px; right: 10px;
  background: rgba(0,0,0,.7);
  border: none;
  color: #fff;
  border-radius: 8px;
  width: 34px; height: 34px;
  cursor: pointer;
  font-size: .85rem;
}

.btn-analyze {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity var(--transition);
  margin-bottom: 14px;
}
.btn-analyze:disabled { opacity: .4; cursor: not-allowed; }
.btn-analyze:not(:disabled):hover { opacity: .88; }

.photo-desc-wrap {
  margin-bottom: 12px;
}
.photo-desc-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 6px;
}

/* Describe textarea */
.describe-textarea {
  width: 100%;
  min-height: 120px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: .88rem;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
  margin-bottom: 14px;
}
.describe-textarea:focus { border-color: var(--green); }

/* AI result */
.ai-result {
  background: var(--surface2);
  border: 1px solid var(--green);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  animation: fadeIn .25s ease;
}
.ai-result-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: .9rem;
}
.ai-result-header i { color: var(--green); font-size: 1.1rem; }
.ai-notes { font-size: .8rem; color: var(--muted); margin-bottom: 12px; }
.ai-nutrients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.ai-nutrient-pill {
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .78rem;
}
.ai-nutrient-pill .pill-label { color: var(--muted); }
.ai-nutrient-pill .pill-val { font-weight: 700; color: var(--text); }

.confidence-badge {
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.conf-high   { background: #10b98122; color: var(--green); }
.conf-medium { background: #f59e0b22; color: var(--orange); }
.conf-low    { background: #ef444422; color: var(--red); }

.ai-edit-note { font-size: .75rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }

/* Manual form */
.form-row { display: flex; gap: 14px; margin-bottom: 14px; }
.form-field { flex: 1; }
.form-field.full { flex: 1 0 100%; }
.form-field label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: 5px; }
.form-field input, .form-field textarea, .form-field select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: .88rem;
  outline: none;
  font-family: inherit;
  transition: border-color var(--transition);
}
.form-field input:focus, .form-field textarea:focus { border-color: var(--green); }

.nutrient-section { margin-bottom: 16px; }
.ns-title {
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nutrient-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.nf label { display: block; font-size: .75rem; color: var(--muted); margin-bottom: 4px; }
.nf input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: .85rem;
  outline: none;
  transition: border-color var(--transition);
}
.nf input:focus { border-color: var(--green); }

/* Modal footer */
.modal-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.btn-cancel {
  padding: 10px 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: .88rem;
}
.btn-save-meal {
  padding: 10px 24px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  transition: background var(--transition);
}
.btn-save-meal:hover { background: var(--green-dim); }

/* Spinner */
.spinner {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  color: var(--muted);
}
.spin {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ══ TOAST ══════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: .85rem;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: slideUp .25s ease;
}
.toast.success { border-color: var(--green); }
.toast.error   { border-color: var(--red); }
.toast.success i { color: var(--green); }
.toast.error   i { color: var(--red); }

/* ── Badge ──────────────────────────────────────────────── */
.badge {
  font-size: .68rem;
  font-weight: 600;
  padding: 2px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  letter-spacing: .02em;
}

/* ── Utilities ──────────────────────────────────────────── */
.hidden { display: none !important; }

@keyframes fadeIn  { from { opacity: 0; transform: translateY(6px);  } to { opacity: 1; transform: none; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes spin    { to   { transform: rotate(360deg); } }
@keyframes slideInUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ══ SIDEBAR BACKDROP ═══════════════════════════════════════ */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 199;
  backdrop-filter: blur(2px);
}
.sidebar-backdrop.open { display: block; }

/* ══ TOPBAR LOGO (hidden on desktop) ════════════════════════ */
.topbar-logo { display: none; align-items: center; gap: 8px; }
.logo-icon.sm { width: 30px; height: 30px; font-size: .9rem; }

/* ══ FAB ════════════════════════════════════════════════════ */
.fab {
  display: none;
  position: fixed;
  bottom: calc(64px + 16px + env(safe-area-inset-bottom));
  right: 20px;
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--green), var(--teal));
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 1.4rem;
  box-shadow: 0 4px 20px rgba(16,185,129,.45);
  cursor: pointer;
  z-index: 300;
  transition: transform .15s ease, box-shadow .15s ease;
}
.fab:active { transform: scale(.93); box-shadow: 0 2px 10px rgba(16,185,129,.3); }

/* ══ BOTTOM NAV ═════════════════════════════════════════════ */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(64px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 250;
  flex-direction: row;
  align-items: stretch;
}

.bn-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: .68rem;
  font-weight: 600;
  padding: 8px 4px;
  transition: color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.bn-item i { font-size: 1.15rem; }
.bn-item.active { color: var(--green); }
.bn-fab-spacer { flex: 0 0 72px; } /* space for FAB */

/* ══ RESPONSIVE — Tablet ════════════════════════════════════ */
@media (max-width: 1100px) {
  .summary-row { grid-template-columns: 1fr 1fr; }
  .stats-card { grid-column: span 2; }
}

/* ══ RESPONSIVE — Mobile ════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Body & layout ───────────────────────────────────────── */
  html { font-size: 14px; }
  body { display: block; }

  /* ── Sidebar: drawer on mobile ───────────────────────────── */
  .sidebar {
    width: 280px;
    transform: translateX(-100%);
    z-index: 300;
    box-shadow: 4px 0 24px rgba(0,0,0,.5);
  }
  .sidebar.open { transform: translateX(0); }

  /* ── Main content: no left margin, extra bottom for nav ──── */
  .main-content {
    margin-left: 0;
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }

  /* ── Topbar ──────────────────────────────────────────────── */
  .topbar {
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    gap: 10px;
  }
  .sidebar-toggle { display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; font-size: 1rem; }
  .topbar-logo    { display: flex; }
  .topbar-logo .logo-text { font-size: .95rem; }
  .topbar-right   { display: none; }
  .date-nav { margin: 0 auto; gap: 6px; }
  .date-label { font-size: .88rem; min-width: 70px; }
  .date-nav button { width: 36px; height: 36px; }

  /* ── Pages ───────────────────────────────────────────────── */
  .page { padding: 12px; gap: 12px; }

  /* ── Cards ───────────────────────────────────────────────── */
  .card { padding: 16px; border-radius: 12px; }
  .card-title { font-size: .8rem; margin-bottom: 14px; }

  /* ── Summary row: stack vertically ──────────────────────── */
  .summary-row { grid-template-columns: 1fr; gap: 12px; }
  .stats-card  { grid-column: auto; }

  /* ── Calorie + Macros: side by side in one card ─────────── */
  .calorie-card {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    gap: 0 16px;
    align-items: center;
  }
  .calorie-card .card-title {
    grid-column: 1 / -1;
    margin-bottom: 12px;
  }
  .ring-wrap {
    width: 130px; height: 130px;
    margin: 0;
    grid-row: 2;
  }
  .ring-big  { font-size: 1.5rem; }
  .calorie-legend {
    grid-row: 3;
    grid-column: 1;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    margin-top: 8px;
  }

  /* Macro card: always full width, no height constraint ───── */
  .macro-list { gap: 10px; }
  .bar-bg { height: 7px; }

  /* ── Glance grid: horizontal scroll row ─────────────────── */
  .glance-grid {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
    grid-template-columns: unset;
  }
  .glance-grid::-webkit-scrollbar { display: none; }
  .glance-item {
    min-width: 90px;
    flex-shrink: 0;
    padding: 10px 8px;
  }
  .glance-val { font-size: 1.15rem; }

  /* ── Micro grid: 2 columns ───────────────────────────────── */
  .micro-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .micro-item { padding: 10px 12px; border-radius: 8px; }
  .micro-name { font-size: .72rem; }
  .micro-vals { font-size: .8rem; }

  /* ── Meal items ──────────────────────────────────────────── */
  .meal-item { padding: 10px 12px; gap: 10px; }
  .meal-photo, .meal-photo-placeholder { width: 46px; height: 46px; }
  .meal-name  { font-size: .88rem; }
  .meal-meta  { gap: 6px; }
  .meal-macro-pill { font-size: .68rem; padding: 2px 6px; }
  .btn-icon   { width: 36px; height: 36px; }

  /* ── Add Meal button (hide in header on mobile — use FAB) ── */
  .btn-add-meal { font-size: .82rem; padding: 8px 14px; }

  /* ── History ─────────────────────────────────────────────── */
  .history-cards-row { grid-template-columns: 1fr; gap: 12px; }
  .chart-wrap    { height: 200px; }
  .chart-wrap.sm { height: 140px; }

  /* ── Goals ───────────────────────────────────────────────── */
  .goals-grid { grid-template-columns: 1fr 1fr; }
  .btn-save-goals { width: 100%; text-align: center; }

  /* ── Modal: slide up from bottom, full screen ───────────── */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    max-width: 100%;
    width: 100%;
    max-height: 92dvh;
    padding: 20px 18px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    transform: translateY(100%);
  }
  .modal-overlay.open .modal {
    transform: translateY(0);
    animation: slideInUp .28s cubic-bezier(.32,.72,0,1);
  }
  /* Drag handle */
  .modal::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: -8px auto 16px;
  }
  .modal-header { margin-bottom: 14px; }
  .modal-header h2 { font-size: 1.1rem; }

  /* ── Tabs: icon only on very small screens ───────────────── */
  .tab-btn { font-size: .75rem; padding: 8px 4px; gap: 4px; }

  /* ── Upload zone: bigger tap area on mobile ──────────────── */
  .upload-zone { padding: 28px 16px; }
  .upload-zone i { font-size: 1.8rem; }

  /* ── Prevent iOS font zoom on inputs ─────────────────────── */
  input, textarea, select {
    font-size: 16px !important;
  }
  .nf input    { font-size: 16px !important; }
  .goal-field input { font-size: 16px !important; }

  /* ── Nutrient grid: 2 columns on mobile ─────────────────── */
  .nutrient-grid { grid-template-columns: 1fr 1fr; }
  .ai-nutrients-grid { grid-template-columns: 1fr 1fr; }

  /* ── Modal footer ────────────────────────────────────────── */
  .modal-footer { flex-wrap: wrap; gap: 8px; }
  .btn-cancel    { flex: 1; text-align: center; }
  .btn-save-meal { flex: 2; justify-content: center; }

  /* ── FAB & bottom nav: visible on mobile ─────────────────── */
  .fab        { display: flex; align-items: center; justify-content: center; }
  .bottom-nav { display: flex; }

  /* ── Toast: full width at bottom ─────────────────────────── */
  .toast-container {
    bottom: calc(80px + env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
  }
  .toast { min-width: unset; width: 100%; }

  /* ── Describe textarea: smaller min-height ───────────────── */
  .describe-textarea { min-height: 80px; }
}
