/* ── Brand font ─────────────────────────────────────────────────────────────── */
@font-face {
  font-family: 'EarthForm';
  src: url('/fonts/EarthForm-Bold.woff2') format('woff2'),
       url('/fonts/EarthForm-Bold.woff')  format('woff');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --primary:   #84cc16;
  --primary-dk:#65a30d;
  --bg:        #111827;
  --bg2:       #1F2937;
  --bg3:       #374151;
  --border:    rgba(255,255,255,0.08);
  --text:      #F9FAFB;
  --text-2:    #9CA3AF;
  --text-3:    #6B7280;
  --error:     #ef4444;
  --warning:   #f59e0b;
  --success:   #84cc16;
  --radius:    12px;
  --radius-sm: 8px;
  --nav-h:     64px;
  --safe-b:    env(safe-area-inset-bottom, 0px);
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overscroll-behavior: none;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font: inherit; }

/* ── Screen system ──────────────────────────────────────────────────────────── */
.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }
.screen-center { align-items: center; justify-content: center; }

/* ── Bottom nav ─────────────────────────────────────────────────────────────── */
.nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-b);
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  color: var(--text-3);
  font-size: 10px; font-weight: 500;
  padding: 8px 4px;
  transition: color 0.15s;
}
.nav-item.active { color: var(--primary); }
.nav-item svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Page layout ────────────────────────────────────────────────────────────── */
.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
}
.page-header {
  position: sticky; top: 0;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px; z-index: 10;
  display: flex; align-items: center; gap: 12px;
}
.page-header-inner {
  width: 100%;
  display: flex; align-items: center; gap: 12px;
}
.page-title { font-size: 18px; font-weight: 700; flex: 1; }
.page-content {
  padding: 16px 20px;
  display: flex; flex-direction: column; gap: 16px;
}

/* ── Login ──────────────────────────────────────────────────────────────────── */
.login-box { width: 100%; max-width: 360px; padding: 32px 24px; }
.login-logo {
  font-family: 'EarthForm', -apple-system, sans-serif;
  font-weight: 700; font-size: 36px;
  color: var(--primary);
  text-align: center; margin-bottom: 8px; letter-spacing: -0.5px;
}
.login-tagline { color: var(--text-2); text-align: center; margin-bottom: 32px; font-size: 14px; }
.login-tabs {
  display: flex;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  margin-bottom: 20px; padding: 3px;
}
.login-tab {
  flex: 1; padding: 8px; text-align: center;
  color: var(--text-2); font-size: 14px; font-weight: 500;
  border-radius: 6px; transition: all 0.15s;
}
.login-tab.active { background: var(--bg2); color: var(--text); font-weight: 700; }
.login-input { background: var(--bg3) !important; }

/* ── Form elements ──────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.input {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg3);
  color: var(--text);
  font-size: 16px;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.input:focus { outline: none; border-color: var(--primary); }
.input::placeholder { color: var(--text-3); }
.select-wrap { position: relative; }
.select-wrap select {
  appearance: none;
  width: 100%; padding: 12px 36px 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg3);
  color: var(--text);
  font-size: 15px;
}
.select-wrap::after {
  content: '';
  position: absolute; right: 14px; top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-top-color: var(--text-2);
  pointer-events: none;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-primary { background: var(--primary); color: #111; width: 100%; font-weight: 700; }
.btn-primary:hover { background: var(--primary-dk); color: #fff; }
.btn-outline { border: 1.5px solid var(--border); color: var(--text); background: var(--bg3); }
.btn-ghost { color: var(--text-2); }
.btn-danger { background: var(--error); color: white; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-icon {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
}
.btn-icon:hover { background: var(--bg3); }
.btn-icon svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.card-header {
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14px; font-weight: 700; }
.card-body { padding: 16px; }

/* ── Stats row ──────────────────────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat-item { text-align: center; }
.stat-value { font-size: 18px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.stat-unit { font-size: 12px; font-weight: 400; color: var(--text-2); }

/* ── Progress bars ──────────────────────────────────────────────────────────── */
.progress-group { display: flex; flex-direction: column; gap: 10px; }
.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-label { font-size: 12px; font-weight: 600; color: var(--text-2); width: 56px; flex-shrink: 0; }
.progress-track { flex: 1; height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.progress-fill {
  height: 100%; border-radius: 4px;
  background: var(--primary);
  transition: width 0.4s ease; max-width: 100%;
}
.progress-fill.over    { background: var(--error); }
.progress-fill.warn    { background: var(--warning); }
.progress-fill.protein { background: #3b82f6; }
.progress-fill.carbs   { background: #f59e0b; }
.progress-fill.fat     { background: #ec4899; }
.progress-val { font-size: 12px; color: var(--text-2); width: 68px; text-align: right; flex-shrink: 0; }

/* ── Meal cards ─────────────────────────────────────────────────────────────── */
.meal-card { background: var(--bg2); border-radius: var(--radius); border: 1px solid var(--border); }
.meal-card-header { padding: 14px 16px; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.meal-status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: var(--bg3); }
.meal-status-dot.eaten   { background: var(--success); }
.meal-status-dot.skipped { background: var(--text-3); }
.meal-status-dot.modified{ background: var(--warning); }
.meal-name { font-size: 15px; font-weight: 600; flex: 1; }
.meal-kcal { font-size: 13px; color: var(--text-2); }
.meal-chevron { color: var(--text-3); transition: transform 0.2s; }
.meal-chevron.open { transform: rotate(90deg); }
.meal-items { border-top: 1px solid var(--border); display: none; }
.meal-items.open { display: block; }
.meal-item-row {
  display: flex; align-items: center;
  padding: 10px 16px; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.meal-item-row:last-child { border-bottom: none; }
.meal-item-name { flex: 1; font-size: 14px; }
.meal-item-qty  { font-size: 13px; color: var(--text-2); }
.meal-item-kcal { font-size: 12px; color: var(--text-3); width: 56px; text-align: right; }
.meal-actions { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }

/* ── Training badge ─────────────────────────────────────────────────────────── */
.training-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
  background: rgba(132,204,22,0.12);
  color: var(--primary);
}
.intensity-dots { display: flex; gap: 3px; }
.intensity-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bg3); }
.intensity-dot.active { background: var(--primary); }

/* ── Tomorrow preview ───────────────────────────────────────────────────────── */
.tomorrow-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; font-size: 14px;
}
.tomorrow-row + .tomorrow-row { border-top: 1px solid var(--border); }
.check-icon { width: 20px; height: 20px; color: var(--success); }
.cross-icon { width: 20px; height: 20px; color: var(--text-3); }

/* ── Weight chart ───────────────────────────────────────────────────────────── */
.weight-chart { height: 80px; position: relative; }
.weight-svg { width: 100%; height: 100%; overflow: visible; }

/* ── Date nav ───────────────────────────────────────────────────────────────── */
.date-nav { display: flex; align-items: center; gap: 8px; }
.date-label { font-size: 15px; font-weight: 600; }
.date-today-btn {
  font-size: 11px; font-weight: 600;
  color: var(--primary);
  background: rgba(132,204,22,0.12);
  padding: 3px 8px; border-radius: 20px;
}

/* ── Food list ──────────────────────────────────────────────────────────────── */
.food-row {
  display: flex; align-items: center;
  padding: 12px 0; gap: 12px;
  border-bottom: 1px solid var(--border);
}
.food-row:last-child { border-bottom: none; }
.food-info { flex: 1; min-width: 0; }
.food-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.food-meta { font-size: 12px; color: var(--text-3); }
.food-kcal { font-size: 13px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.pref-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.pref-dot.favorite  { background: #f59e0b; }
.pref-dot.preferred { background: var(--primary); }
.pref-dot.excluded  { background: var(--error); }
.pref-dot.neutral   { background: var(--bg3); }

/* ── Tabs ───────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--bg3); border-radius: var(--radius-sm); }
.tab {
  flex: 1; padding: 8px; text-align: center;
  font-size: 13px; font-weight: 600;
  color: var(--text-2); border-radius: 6px;
  transition: all 0.15s;
}
.tab.active { background: var(--bg2); color: var(--text); }

/* ── Search ─────────────────────────────────────────────────────────────────── */
.search-wrap { position: relative; }
.search-wrap .input { padding-left: 40px; }
.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.search-icon svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ── Onboarding ─────────────────────────────────────────────────────────────── */
.onboard-step { display: none; }
.onboard-step.active { display: flex; flex-direction: column; gap: 20px; }
.onboard-progress { display: flex; gap: 6px; }
.onboard-dot { height: 4px; flex: 1; border-radius: 2px; background: var(--bg3); }
.onboard-dot.done { background: var(--primary); }
.onboard-title { font-size: 24px; font-weight: 800; }
.onboard-desc  { font-size: 15px; color: var(--text-2); }
.goal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.goal-card {
  background: var(--bg2); border: 2px solid var(--border);
  border-radius: var(--radius); padding: 16px; text-align: center;
  color: var(--text); cursor: pointer; transition: all 0.15s;
}
.goal-card.selected { border-color: var(--primary); background: rgba(132,204,22,0.08); }
.goal-card-icon { font-size: 28px; margin-bottom: 8px; }
.goal-card-name { font-size: 13px; font-weight: 700; }
.intensity-row { display: flex; gap: 8px; }
.intensity-btn {
  flex: 1; padding: 12px 8px; text-align: center;
  background: var(--bg2); border: 2px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-weight: 700; font-size: 16px; cursor: pointer; transition: all 0.15s;
}
.intensity-btn.selected { border-color: var(--primary); background: rgba(132,204,22,0.08); }

/* ── Profile ────────────────────────────────────────────────────────────────── */
.profile-row {
  display: flex; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--border); gap: 12px;
}
.profile-row:last-child { border-bottom: none; }
.profile-key { font-size: 14px; color: var(--text-2); flex: 1; }
.profile-val { font-size: 14px; font-weight: 600; }

/* ── Overlays / sheets ──────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200; display: none; align-items: flex-end;
}
.overlay.open { display: flex; }
.sheet {
  background: var(--bg2);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-height: 90dvh;
  overflow-y: auto;
  padding-bottom: calc(24px + var(--safe-b));
}
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--bg3); border-radius: 2px;
  margin: 12px auto 20px;
}
.sheet-header {
  padding: 0 20px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.sheet-title { font-size: 17px; font-weight: 700; }
.sheet-body { padding: 0 20px; display: flex; flex-direction: column; gap: 16px; }

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  left: 50%; transform: translateX(-50%);
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 20px; border-radius: 20px;
  font-size: 14px; font-weight: 500;
  z-index: 300; opacity: 0;
  transition: opacity 0.2s; pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; }

/* ── Spinner ────────────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,0.1);
  border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: flex; align-items: center; justify-content: center; padding: 40px; }

/* ── Empty states ───────────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 48px 24px; color: var(--text-3); }
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-text { font-size: 15px; margin-bottom: 20px; }

/* ── Misc ───────────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); }
.text-muted { color: var(--text-2); font-size: 13px; }
.text-error { color: var(--error); font-size: 13px; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
  background: var(--bg3); color: var(--text-2);
}
.badge.green  { background: rgba(132,204,22,0.12); color: var(--primary); }
.badge.orange { background: rgba(245,158,11,0.12); color: #f59e0b; }
.badge.blue   { background: rgba(59,130,246,0.12);  color: #60a5fa; }
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 4px; }
.flex-1 { flex: 1; }
.mt-auto { margin-top: auto; }
.mt-2 { margin-top: 8px; }
.gap-2 { gap: 8px; }
.fw-bold { font-weight: 700; }
.fs-sm { font-size: 13px; }
