/* ===== ROOT TOKENS ===== */
:root {
  --bg: #f7f6f3;
  --s1: #ffffff;
  --s2: #f2f1ee;
  --s3: #e8e7e3;
  --border: rgba(0,0,0,0.08);
  --text-1: #1a1918;
  --text-2: #6b6560;
  --text-3: #a09488;

  --carbs: #3d6a90;
  --protein: #467a4c;
  --fat: #7a6448;
  --cal: #b8892a;
  --warn: #b04e2a;

  --font: 'Outfit', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', 'Courier New', monospace;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;

  --nav-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-1);
  line-height: 1.5;
  height: 100dvh;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; -webkit-tap-highlight-color: transparent; }
input, select, textarea { font-family: inherit; color: inherit; background: none; border: none; outline: none; }
ul { list-style: none; }
a { color: inherit; text-decoration: none; }

/* ===== APP SHELL ===== */
#app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

/* ===== HEADER ===== */
#header {
  flex-shrink: 0;
  padding: calc(var(--safe-t) + 10px) 16px 11px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.app-name {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-1);
}
.app-name .amp { color: var(--cal); }

.date-nav { display: flex; align-items: center; gap: 2px; }
.nav-arrow {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; line-height: 1;
  color: var(--text-2);
  border-radius: var(--r-sm);
  transition: color 0.15s, background 0.15s;
}
.nav-arrow:hover { color: var(--text-1); background: var(--s3); }
.nav-arrow:disabled { opacity: 0.28; pointer-events: none; }
.date-btn {
  padding: 5px 10px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-1);
  border-radius: var(--r-sm);
  transition: background 0.15s;
  white-space: nowrap;
}
.date-btn:hover { background: var(--s3); }

.day-type-row { display: flex; gap: 6px; }
.dtype-btn {
  flex: 1;
  padding: 7px 0;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-3);
  background: var(--s2);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  letter-spacing: 0.02em;
  transition: all 0.18s;
}
.dtype-btn:hover { color: var(--text-2); background: var(--s3); }
.dtype-btn.active[data-type="rest"]     { color: #8a9ba8; background: rgba(138,155,168,0.1); border-color: rgba(138,155,168,0.22); }
.dtype-btn.active[data-type="training"] { color: var(--cal); background: rgba(212,168,83,0.1); border-color: rgba(212,168,83,0.22); }
.dtype-btn.active[data-type="hard"]     { color: var(--warn); background: rgba(196,98,58,0.1); border-color: rgba(196,98,58,0.22); }

/* ===== MAIN ===== */
#main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 24px);
}

/* ===== VIEWS ===== */
.view { display: none; }
.view.active { display: block; }

/* ===== SUMMARY SECTION ===== */
.summary-section {
  padding: 18px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Ring */
.ring-col { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.calorie-ring { width: 144px; height: 144px; display: block; }
.ring-track  { fill: none; stroke: var(--s3); stroke-width: 11; }
.ring-fill   {
  fill: none;
  stroke: var(--cal);
  stroke-width: 11;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.55s cubic-bezier(.4,0,.2,1), stroke 0.3s;
}
.ring-fill.over-target { stroke: var(--warn); }
.ring-num {
  fill: var(--text-1);
  font-family: var(--mono);
  font-size: 21px;
  font-weight: 500;
}
.ring-sub {
  fill: var(--text-3);
  font-family: var(--font);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ring-stats {
  display: flex;
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  width: 100%;
  max-width: 290px;
}
.rstat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 9px 4px;
}
.rstat-n {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-1);
  line-height: 1;
}
.rstat-l {
  font-size: 0.65rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 3px;
}
.rstat-div { width: 1px; background: var(--border); }

/* Macro bars */
.macro-col { display: flex; flex-direction: column; gap: 10px; }
.macro-row {
  display: grid;
  grid-template-columns: 50px 1fr 64px;
  align-items: center;
  gap: 10px;
}
.macro-lbl { font-size: 0.8rem; color: var(--text-2); }
.macro-track {
  height: 5px;
  background: var(--s3);
  border-radius: 3px;
  overflow: hidden;
}
.macro-fill {
  height: 100%;
  border-radius: 3px;
  width: 0;
  transition: width 0.45s cubic-bezier(.4,0,.2,1);
}
.macro-fill.carbs   { background: var(--carbs); }
.macro-fill.protein { background: var(--protein); }
.macro-fill.fat     { background: var(--fat); }
.macro-val { font-size: 0.72rem; color: var(--text-2); text-align: right; }

/* ===== METRICS ===== */
.metrics-section {
  display: flex;
  margin: 0 16px 12px;
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.metric-entry {
  flex: 1.5;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 14px;
  border-right: 1px solid var(--border);
}
.metric-display {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 11px 4px;
  border-right: 1px solid var(--border);
}
.metric-display:last-child { border-right: none; }
.metric-lbl {
  font-size: 0.65rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.metric-entry .metric-lbl { margin-bottom: 3px; }
.metric-lbl-bf { margin-top: 8px; }
.metric-input-wrap { display: flex; align-items: baseline; gap: 5px; }
.metric-input {
  width: 68px;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-1);
  padding: 0;
  -moz-appearance: textfield;
}
.metric-input::-webkit-outer-spin-button,
.metric-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.metric-input::placeholder { color: var(--text-3); }
.metric-unit { font-size: 0.76rem; color: var(--text-2); }
.metric-big {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-1);
  line-height: 1;
  margin-bottom: 4px;
}
#creatine-indicator { cursor: default; }
#creatine-dot { color: var(--protein); font-size: 0.95rem; }

/* ===== MEALS ===== */
.meals-section { display: flex; flex-direction: column; gap: 10px; padding: 0 16px; }

.meal-card {
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.meal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 9px;
}
.meal-info { display: flex; align-items: center; gap: 8px; }
.meal-icon { font-size: 0.95rem; color: var(--text-3); line-height: 1; }
.meal-name { font-size: 0.9rem; font-weight: 600; color: var(--text-1); }
.meal-time { font-size: 0.72rem; color: var(--text-3); }
.meal-header-stats { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.meal-kcal { font-size: 0.78rem; color: var(--text-2); }
.meal-macros-sum { font-size: 0.68rem; color: var(--text-3); font-family: var(--mono); }

/* food items tappable */
.food-item { cursor: pointer; }
.food-item:active { background: var(--s2); }

.food-list { padding: 0 14px; }
.food-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  gap: 8px;
}
.food-item-left { flex: 1; min-width: 0; }
.food-item-name {
  font-size: 0.85rem;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.food-item-qty { font-size: 0.72rem; color: var(--text-3); margin-top: 1px; }
.food-item-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.food-item-kcal { font-family: var(--mono); font-size: 0.77rem; color: var(--text-2); }
.food-item-macros { font-size: 0.68rem; color: var(--text-3); display: none; }
@media (min-width: 380px) { .food-item-macros { display: inline; } }
.food-item-del {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--text-3);
  border-radius: 50%;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.food-item-del:hover { color: var(--warn); background: rgba(196,98,58,0.1); }

.meal-actions {
  display: flex;
  border-top: 1px solid var(--border);
}
.add-food-btn {
  flex: 1;
  padding: 10px 14px;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-3);
  letter-spacing: 0.01em;
  transition: color 0.15s, background 0.15s;
}
.add-food-btn:hover { color: var(--cal); background: rgba(180,140,40,0.06); }
.copy-yesterday-btn {
  padding: 10px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-3);
  border-left: 1px solid var(--border);
  letter-spacing: 0.01em;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.copy-yesterday-btn:hover { color: var(--carbs); background: rgba(60,110,145,0.06); }

/* Recent foods in modal */
.recent-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-bottom: 8px;
}
.recent-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.recent-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  background: var(--s3);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-1);
  font-family: var(--font);
  transition: background 0.15s, border-color 0.15s;
  cursor: pointer;
}
.recent-chip:hover { background: var(--s2); border-color: var(--cal); }
.recent-chip span { font-family: var(--mono); font-size: 0.7rem; color: var(--text-3); }

/* ===== SCANNER ===== */
.btn-scan {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 11px 16px; margin-top: 10px;
  border: 1.5px dashed var(--border); border-radius: var(--r-md);
  color: var(--text-2); font-size: 0.9rem; font-weight: 500;
  background: var(--s2); transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-scan:hover { background: var(--s3); color: var(--text-1); border-color: var(--cal); }
.scan-frame {
  position: relative; width: 100%; border-radius: var(--r-md); overflow: hidden;
  background: #000; aspect-ratio: 4/3;
}
#qr-reader { width: 100% !important; border: none !important; }
#qr-reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
#qr-reader img { display: none !important; }
#qr-reader__header_message,
#qr-reader__status_span,
#qr-reader__camera_selection,
#qr-reader__dashboard { display: none !important; }
.scan-guide {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.scan-guide::before, .scan-guide::after {
  content: ''; position: absolute; width: 60%; height: 35%;
  border: 2px solid var(--cal); border-radius: 6px;
}
.scan-line {
  position: absolute; width: 56%; height: 2px;
  background: var(--cal); opacity: 0.7;
  animation: scan-sweep 2s ease-in-out infinite;
}
@keyframes scan-sweep {
  0%   { top: 33%; }
  50%  { top: 66%; }
  100% { top: 33%; }
}
.scan-hint { text-align: center; color: var(--text-3); font-size: 0.85rem; margin: 10px 0 14px; }

/* ===== RECOVERY ===== */
.recovery-section {
  margin: 10px 16px 0;
  background: var(--s1); border-radius: var(--r-lg);
  padding: 12px 14px;
}
.recovery-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.recovery-badge {
  font-size: 0.72rem; font-weight: 700; padding: 3px 10px;
  border-radius: 12px; letter-spacing: 0.04em; text-transform: uppercase;
}
.badge-green { background: rgba(107,143,113,0.15); color: #3a6b41; }
.badge-amber { background: rgba(184,137,42,0.15);  color: #8a6010; }
.badge-red   { background: rgba(176,78,42,0.15);   color: #8a2a0a; }
.recovery-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
}
.rec-metric {
  display: flex; flex-direction: column; align-items: center;
  background: var(--s2); border-radius: var(--r-md); padding: 8px 4px;
}
.rec-val { font-size: 1.1rem; font-weight: 600; color: var(--text-1); line-height: 1.2; }
.rec-lbl { font-size: 0.62rem; color: var(--text-3); text-align: center; margin-top: 2px; }
.rec-unit { font-size: 0.58rem; }
.rec-delta { font-size: 0.6rem; margin-top: 3px; font-family: var(--mono); }
.rec-good  { color: #3a6b41; }
.rec-warn  { color: #8a2a0a; }

/* ===== TRAINING ===== */
.training-section {
  margin: 10px 16px 0;
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.training-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 9px;
}
.section-title { font-size: 0.9rem; font-weight: 600; color: var(--text-1); }
.training-burn { font-size: 0.78rem; color: var(--carbs); }

.training-list { padding: 0 14px; }
.train-item {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  gap: 8px;
}
.train-item-left { flex: 1; min-width: 0; }
.train-item-type { font-size: 0.85rem; color: var(--text-1); font-weight: 500; }
.train-item-detail { font-size: 0.72rem; color: var(--text-3); margin-top: 1px; }
.train-item-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.train-item-kcal { font-family: var(--mono); font-size: 0.77rem; color: var(--carbs); }
.train-item-del {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--text-3);
  border-radius: 50%;
  transition: color 0.15s, background 0.15s;
}
.train-item-del:hover { color: var(--warn); background: rgba(196,98,58,0.1); }

.training-btns {
  display: flex;
  border-top: 1px solid var(--border);
}
.add-train-btn {
  flex: 1;
  padding: 10px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-3);
  letter-spacing: 0.01em;
  transition: color 0.15s, background 0.15s;
}
.add-train-btn:first-child { border-right: 1px solid var(--border); }
.add-train-btn:hover { color: var(--carbs); background: rgba(91,127,166,0.07); }

/* ===== STRAVA ===== */
.strava-btn-wrap { display: flex; gap: 8px; padding: 10px 14px 4px; }
.strava-connect-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 14px; border-radius: var(--r-md);
  background: #FC4C02; color: #fff; font-size: 0.85rem; font-weight: 600;
  width: 100%; justify-content: center;
}
.strava-connect-btn:hover { background: #e04302; }
.strava-connected-btn {
  flex: 1; padding: 9px 14px; border-radius: var(--r-md);
  background: var(--s2); color: var(--text-1); font-size: 0.85rem; font-weight: 500;
  border: 1.5px solid var(--border);
}
.strava-connected-btn:hover { background: var(--s3); }
.strava-connected-btn:disabled { opacity: 0.6; }
.strava-disconnect-btn {
  padding: 9px 12px; border-radius: var(--r-md);
  background: transparent; color: var(--text-3); font-size: 0.8rem;
  border: 1.5px solid var(--border);
}
.strava-disconnect-btn:hover { color: var(--warn); border-color: var(--warn); }
.health-badge {
  display: inline-block; font-size: 0.62rem; font-weight: 600;
  background: #e8445a; color: #fff; padding: 1px 5px; border-radius: 4px;
  vertical-align: middle; text-transform: uppercase; letter-spacing: 0.03em;
}
.strava-badge {
  display: inline-block; font-size: 0.62rem; font-weight: 600;
  background: #FC4C02; color: #fff; padding: 1px 5px; border-radius: 4px;
  vertical-align: middle; text-transform: uppercase; letter-spacing: 0.03em;
}

/* ===== COACH VIEW ===== */
.coach-top { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 10px; }
.coach-refresh-btn {
  padding: 7px 14px; border-radius: 20px; font-size: 0.82rem; font-weight: 600;
  background: var(--cal); color: #fff; letter-spacing: 0.02em;
}
.coach-refresh-btn:hover { opacity: 0.88; }
.coach-loading {
  display: flex; flex-direction: column; align-items: center;
  padding: 40px 16px; gap: 16px; color: var(--text-2); font-size: 0.9rem;
}
.coach-spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--cal); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.coach-empty {
  padding: 32px 24px; color: var(--text-2); font-size: 0.9rem; line-height: 1.6;
  text-align: center;
}
.coach-empty strong { color: var(--text-1); }
.coach-headline {
  font-size: 1.15rem; font-weight: 700; color: var(--text-1);
  padding: 0 16px 8px; line-height: 1.3;
}
.coach-summary {
  font-size: 0.9rem; color: var(--text-2); padding: 0 16px 16px; line-height: 1.6;
}
.coach-section-lbl {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-3); padding: 0 16px 8px;
}
.coach-finding {
  display: flex; align-items: flex-start; gap: 10px;
  margin: 0 16px 8px; padding: 10px 12px;
  background: var(--s1); border-radius: var(--r-md);
  border-left: 3px solid var(--border); font-size: 0.88rem; line-height: 1.5; color: var(--text-1);
}
.coach-finding.positive { border-left-color: var(--protein); }
.coach-finding.warning  { border-left-color: var(--warn); }
.coach-finding.info     { border-left-color: var(--carbs); }
.coach-finding-icon { font-size: 0.9rem; margin-top: 1px; flex-shrink: 0; }
.coach-finding.positive .coach-finding-icon { color: var(--protein); }
.coach-finding.warning  .coach-finding-icon { color: var(--warn); }
.coach-finding.info     .coach-finding-icon { color: var(--carbs); }
.coach-recs { list-style: none; padding: 0 16px 4px; margin-bottom: 8px; }
.coach-rec {
  padding: 9px 12px; margin-bottom: 6px;
  background: var(--s2); border-radius: var(--r-md);
  font-size: 0.88rem; line-height: 1.5; color: var(--text-1);
}
.coach-goals { display: flex; flex-direction: column; gap: 8px; padding: 0 16px 16px; }
.coach-goal-card {
  background: var(--s1); border-radius: var(--r-md); padding: 12px 14px;
  border: 1px solid var(--border);
}
.cgc-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--cal); margin-bottom: 5px; }
.cgc-text { font-size: 0.88rem; color: var(--text-1); line-height: 1.55; }
.coach-generated {
  text-align: center; font-size: 0.72rem; color: var(--text-3);
  padding: 8px 16px 20px;
}

/* ===== HISTORY VIEW ===== */
.view-heading {
  padding: 18px 16px 10px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-1);
}
.view-sub { font-size: 0.76rem; color: var(--text-3); font-weight: 400; margin-left: 6px; }

.history-list { display: flex; flex-direction: column; gap: 8px; padding: 0 16px; }
.history-item {
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.history-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
  gap: 10px;
}
.hist-date { font-size: 0.85rem; font-weight: 600; color: var(--text-1); margin-bottom: 3px; }
.hist-dtype {
  display: inline-block;
  font-size: 0.67rem;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 500;
  text-transform: capitalize;
}
.hist-dtype.rest     { background: rgba(138,155,168,0.1); color: #8a9ba8; }
.hist-dtype.training { background: rgba(212,168,83,0.1);  color: var(--cal); }
.hist-dtype.hard     { background: rgba(196,98,58,0.1);   color: var(--warn); }

.hist-summary { text-align: right; flex-shrink: 0; }
.hist-cal { display: block; font-family: var(--mono); font-size: 0.8rem; color: var(--text-1); }
.hist-wkg { display: block; font-size: 0.72rem; color: var(--text-2); margin-top: 2px; }

.history-item-body {
  display: none;
  padding: 0 14px 12px;
  border-top: 1px solid var(--border);
}
.history-item-body.open { display: block; }
.hist-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
}
.hist-row:last-child { border-bottom: none; }
.hist-row-lbl { color: var(--text-3); }
.hist-row-val { font-family: var(--mono); color: var(--text-2); }

/* ===== TRENDS VIEW ===== */
.chart-card {
  margin: 8px 16px;
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 14px 10px;
}
.chart-title {
  font-size: 0.75rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

/* ===== BOTTOM NAV ===== */
#bottom-nav {
  flex-shrink: 0;
  display: flex;
  background: var(--s1);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
  z-index: 20;
}
.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 9px 4px 7px;
  font-size: 0.66rem;
  color: var(--text-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: color 0.15s;
}
.nav-tab.active { color: var(--cal); }
.nav-tab:hover { color: var(--text-2); }
.tab-icon { width: 19px; height: 19px; }

/* ===== MODALS ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-sheet {
  position: relative;
  z-index: 1;
  background: var(--s2);
  border-top: 1px solid var(--border);
  border-top-left-radius: var(--r-lg);
  border-top-right-radius: var(--r-lg);
  padding: 12px 20px calc(var(--safe-b) + 28px);
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: sheet-up 0.28s cubic-bezier(.32,0,.15,1);
}
@keyframes sheet-up {
  from { transform: translateY(100%); opacity: 0.6; }
  to   { transform: translateY(0);    opacity: 1; }
}
.modal-grip {
  width: 38px; height: 4px;
  background: var(--s3);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.modal-hdr { display: flex; align-items: baseline; gap: 10px; margin-bottom: 16px; }
.modal-title { font-size: 1.1rem; font-weight: 600; color: var(--text-1); }
.modal-meal-lbl { font-size: 0.78rem; color: var(--text-3); text-transform: capitalize; }

.modal-close {
  position: absolute;
  top: 13px; right: 15px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.35rem;
  color: var(--text-3);
  border-radius: 50%;
  transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--text-1); background: var(--s3); }

/* Food modal */
.food-textarea {
  width: 100%;
  background: var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  font-size: 0.9rem;
  color: var(--text-1);
  resize: none;
  line-height: 1.5;
  margin-bottom: 12px;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.food-textarea:focus { border-color: rgba(212,168,83,0.35); }
.food-textarea::placeholder { color: var(--text-3); }

.result-card {
  background: var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px;
  margin-bottom: 16px;
}
.result-name {
  font-size: 0.95rem; font-weight: 600; color: var(--text-1);
  width: 100%; border: none; background: transparent; outline: none;
  border-bottom: 1.5px solid var(--border); padding-bottom: 4px; margin-bottom: 4px;
}
.result-name:focus { border-bottom-color: var(--cal); }
.result-qty {
  font-size: 0.78rem; color: var(--text-2); margin-bottom: 14px;
  width: 100%; border: none; background: transparent; outline: none;
  border-bottom: 1px solid transparent; padding-bottom: 2px;
}
.result-qty:focus { border-bottom-color: var(--border); }
.result-macros { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; }
.rmacro { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.rmacro-input {
  width: 100%;
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 7px 4px;
  text-align: center;
  font-size: 0.95rem;
  color: var(--text-1);
  transition: border-color 0.15s;
  -moz-appearance: textfield;
  -webkit-appearance: none;
}
.rmacro-input::-webkit-outer-spin-button,
.rmacro-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.rmacro-input:focus { border-color: rgba(212,168,83,0.35); }
.rmacro-lbl { font-size: 0.65rem; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; }

/* Training modal */
.form-row {
  display: grid;
  grid-template-columns: 76px 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.form-lbl { font-size: 0.83rem; color: var(--text-2); }
.form-select, .form-input {
  width: 100%;
  background: var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 10px;
  font-size: 0.88rem;
  color: var(--text-1);
  -webkit-appearance: none;
  transition: border-color 0.15s;
}
.form-select:focus, .form-input:focus { border-color: rgba(212,168,83,0.35); }
.form-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%234a4540' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
.form-unit { font-size: 0.78rem; color: var(--text-3); white-space: nowrap; }
.form-hint { font-size: 0.76rem; color: var(--text-3); margin: -6px 0 12px 86px; }

.cal-estimate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 11px 14px;
  margin-bottom: 16px;
}
.cal-est-label { font-size: 0.82rem; color: var(--text-2); }
.cal-est-val { font-size: 0.95rem; font-weight: 500; color: var(--carbs); }

/* ===== BUTTONS ===== */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px;
  background: var(--cal);
  color: #0a0a0a;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--r-md);
  letter-spacing: 0.01em;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-appearance: none;
}
.btn-primary:disabled { opacity: 0.55; }
.btn-primary:not(:disabled):active { transform: scale(0.98); opacity: 0.88; }

.btn-ghost {
  padding: 12px 16px;
  font-size: 0.87rem;
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.btn-ghost:hover { color: var(--text-1); background: var(--s3); }

.modal-actions { display: flex; gap: 10px; align-items: stretch; }
.modal-actions .btn-primary { flex: 1; }

/* ===== SPINNER ===== */
.spin {
  width: 16px; height: 16px;
  border: 2px solid rgba(10,10,10,0.3);
  border-top-color: #0a0a0a;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-b) + 14px);
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--s3);
  border: 1px solid var(--border);
  color: var(--text-1);
  font-size: 0.84rem;
  padding: 9px 18px;
  border-radius: 20px;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.22s, transform 0.22s;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== UTILS ===== */
.hidden { display: none !important; }
.mono { font-family: var(--mono); }

/* ===== EMPTY STATES ===== */
.empty-msg {
  text-align: center;
  color: var(--text-3);
  font-size: 0.82rem;
  padding: 24px 16px;
}
