/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

/* ── Tokens ── */
:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --border: #e5e5e0;
  --text: #1a1a1a;
  --muted: #666;
  --accent: #1a1a1a;
  --accent-fg: #fff;

  /* Progress ring */
  --ring-under: #4ade80;   /* calm green — under goal */
  --ring-over: #f97316;    /* warm orange — over goal, not alarming */
  --ring-track: #e5e5e0;
  --ring-gap: rgba(250,250,248,0.9);

  /* Chart */
  --chart-under: #86efac;
  --chart-over: #fdba74;
  --chart-goal: #a1a1aa;

  /* Meals */
  --meal-morning: #fef3c7;
  --meal-lunch: #dcfce7;
  --meal-snack: #e0f2fe;
  --meal-dinner: #ede9fe;
  --meal-night: #f3f4f6;
}

/* ── Base ── */
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

/* ── Layout ── */
.app { max-width: 420px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

/* ── Typography ── */
h1 { font-size: 1.25rem; font-weight: 700; }
h2 { font-size: 0.875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.5rem; }
.big-number { font-size: 1.75rem; font-weight: 700; line-height: 1.1; }
.sub { font-size: 0.8125rem; color: var(--muted); margin-top: 0.25rem; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

/* ── Inputs ── */
input, select, button {
  font-size: 1rem;
  font-family: inherit;
  border-radius: 8px;
  outline: none;
}
input[type=text], input[type=email], input[type=number], select {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26,26,26,0.08); }
label { font-size: 0.875rem; font-weight: 500; display: block; margin-bottom: 0.375rem; }
.field { margin-bottom: 1rem; }

button {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.75rem 1.25rem;
  border: none; cursor: pointer;
  font-weight: 500; transition: opacity 0.15s;
}
button:hover { opacity: 0.85; }
.btn-primary { background: var(--accent); color: var(--accent-fg); width: 100%; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8125rem; }

/* ── Spiral ring ── */
.ring-wrap { display: flex; justify-content: center; align-items: center; margin: 0.5rem 0 1rem; }
.ring-label { position: absolute; text-align: center; pointer-events: none; }

/* ── Trend graph ── */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap svg { width: 100%; display: block; overflow: visible; }

/* ── Meal breakdown (collapsible) ── */
.meal { border-bottom: 1px solid var(--border); }
.meal:last-child { border-bottom: none; }
.meal > summary {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 0; cursor: pointer; list-style: none; user-select: none;
}
.meal > summary::-webkit-details-marker { display: none; }
.meal > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.meal-head { display: inline-flex; align-items: center; gap: 0.4rem; }
.meal-caret { color: var(--muted); font-size: 0.7rem; transition: transform 0.15s; }
.meal[open] .meal-caret { transform: rotate(90deg); }
.meal-name { font-size: 0.875rem; font-weight: 500; text-transform: capitalize; }
.meal-time { font-size: 0.75rem; color: var(--muted); }
.meal-kcal { font-size: 0.875rem; color: var(--muted); }
.meal-items { padding: 0 0 0.5rem 1.1rem; }
.meal-item { display: flex; justify-content: space-between; gap: 1rem; padding: 0.3rem 0; font-size: 0.8125rem; }
.meal-item-name { color: var(--text); }
.meal-item-right { display: inline-flex; align-items: center; gap: 0.5rem; }
.meal-item-kcal { color: var(--muted); white-space: nowrap; }
.meal-item-del {
  background: none; border: none; width: auto; padding: 0 0.2rem;
  color: var(--muted); font-size: 1.05rem; line-height: 1; cursor: pointer;
  border-radius: 4px; opacity: 0.55; transition: color 0.15s, opacity 0.15s;
}
.meal-item-del:hover { color: var(--chart-over); opacity: 1; }
.meal-item-del:disabled { opacity: 0.3; cursor: default; }
.lens-badge {
  display: inline-block; margin-left: 0.4rem; padding: 0.05rem 0.4rem;
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 0.7rem; font-weight: 600; color: var(--muted); white-space: nowrap;
}

/* ── Suggestion chips (profile meal-lens) ── */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 0.75rem; }
.chip {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: auto; padding: 0.3rem 0.6rem; border-radius: 999px;
  font-size: 0.8125rem; line-height: 1; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip-off { color: var(--muted); }

/* ── Macro row ── */
.macro-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 0.5rem; }
.macro { font-size: 0.8125rem; }
.macro strong { font-weight: 600; }
.macro span { color: var(--muted); }

/* ── Macro balance (calorie split + protein) ── */
.macro-balance { margin-top: 0.875rem; }
.mbar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--border); }
.mbar-seg { height: 100%; }
.mbar-p, .dot-p { background: #4ade80; }
.mbar-c, .dot-c { background: #fbbf24; }
.mbar-f, .dot-f { background: #a78bfa; }
.mbar-legend { display: flex; gap: 1rem; margin-top: 0.5rem; font-size: 0.75rem; color: var(--muted); }
.mbar-legend i.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.35rem; vertical-align: middle; }
.protein-note { font-size: 0.75rem; color: var(--muted); margin-top: 0.5rem; }
.protein-note .ok { color: #16a34a; font-weight: 600; }

/* ── Onboarding ── */
.step-indicator { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
.step-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.step-dot.active { background: var(--accent); }

.radio-group { display: flex; flex-direction: column; gap: 0.5rem; }
.radio-opt { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.radio-opt input[type=radio] { accent-color: var(--accent); }
.radio-opt:has(input:checked) { border-color: var(--accent); background: rgba(26,26,26,0.03); }

/* ── MCP setup ── */
.code-block {
  background: #1a1a1a; color: #e5e5e0;
  border-radius: 8px; padding: 0.875rem 3.75rem 0.875rem 1rem;
  font-family: monospace; font-size: 0.8125rem;
  overflow-x: auto; white-space: pre;
  margin: 0;
}
.code-copy { position: relative; margin: 0.5rem 0; }
.copy-btn {
  position: absolute; top: 50%; right: 0.5rem; transform: translateY(-50%);
  background: rgba(255,255,255,0.12); color: #e5e5e0;
  border: 1px solid rgba(255,255,255,0.2); border-radius: 6px;
  padding: 0.25rem 0.625rem; font-size: 0.75rem; font-weight: 500;
  cursor: pointer; width: auto; transition: background 0.15s;
}
.copy-btn:hover { background: rgba(255,255,255,0.22); opacity: 1; }
.agent-link {
  font-size: 0.7rem; color: var(--muted); text-decoration: none;
  font-weight: 400; text-transform: none; letter-spacing: 0;
  margin-left: 0.5rem; vertical-align: middle;
}
.agent-link:hover { color: var(--text); }

/* ── Dashboard top ── */
.dash-top { display: flex; align-items: center; justify-content: space-between; padding: 0.25rem 0 0.75rem; }
.dash-name { font-size: 0.9375rem; font-weight: 600; }
.dash-settings-btn { background: none; border: none; color: var(--muted); font-size: 0.8125rem; padding: 0; width: auto; cursor: pointer; }
.dash-settings-btn:hover { color: var(--text); opacity: 1; }

/* ── Brand mark ── */
.brand-mark { height: 1.25rem; width: 1.25rem; flex-shrink: 0; }
.brand-top { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9375rem; font-weight: 600; margin-bottom: 1.25rem; }
.brand-word { font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.brand-badge { display: inline-block; background: #3d9e5c; color: #fff; font-weight: 800; padding: 0.02em 0.2em; margin: 0 0.05em; border-radius: 2px; }

/* Static hero: shown to non-JS crawlers/AI engines; hidden once the SPA boots. */
.js .static-hero { display: none; }
.static-hero { max-width: 640px; margin: 3rem auto; padding: 0 1.25rem; }
.static-hero-brand { display: flex; align-items: center; gap: 0.5rem; font-size: 1.75rem; margin-bottom: 0.5rem; }
.static-hero-brand .brand-mark { height: 1.75rem; width: 1.75rem; }
.static-hero-tagline { font-size: 1.0625rem; color: var(--muted); margin-bottom: 1.5rem; }
.static-hero p { margin-bottom: 1rem; line-height: 1.6; }

/* ── Profile page ── */
.profile-top { margin-bottom: 0.75rem; display: flex; align-items: center; justify-content: space-between; }
.btn-ghost { background: none; border: none; color: var(--muted); font-size: 0.875rem; padding: 0; width: auto; cursor: pointer; }
.btn-ghost:hover { color: var(--text); opacity: 1; }
.save-status { font-size: 0.8125rem; color: #16a34a; margin-top: 0.375rem; min-height: 1.1rem; }
.history-row { display: flex; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.history-row:last-child { border-bottom: none; }

/* ── Weight log ── */
.weight-top { display: flex; align-items: center; gap: 1rem; }
.weight-latest { flex-shrink: 0; }
.weight-chart { flex: 1; min-width: 0; }
.weight-chart svg { width: 100%; display: block; overflow: visible; }
.weight-form { display: flex; gap: 0.5rem; margin-top: 1rem; }
.weight-form input { flex: 1; }
.weight-form button { white-space: nowrap; }

/* ── Push button ── */
.push-status { font-size: 0.8125rem; color: var(--muted); margin-top: 0.5rem; }

/* ── Language switcher ── */
.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.lang-opt {
  background: none; border: none; width: auto;
  padding: 0.2rem 0.5rem; font-size: 0.7rem; font-weight: 600;
  letter-spacing: 0.03em; color: var(--muted); cursor: pointer;
}
.lang-opt:hover { color: var(--text); opacity: 1; }
.lang-opt.active { background: var(--accent); color: var(--accent-fg); }
.lang-opt.active:hover { color: var(--accent-fg); }
.dash-actions { display: flex; align-items: center; gap: 0.75rem; }

/* ── Footer ── */
.app-footer {
  display: flex; justify-content: center; gap: 0.5rem;
  margin-top: 1.5rem; font-size: 0.8125rem; color: var(--muted);
}
.app-footer a { color: var(--muted); text-decoration: none; }
.app-footer a:hover { color: var(--text); text-decoration: underline; }

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

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ── Mobile ── */
@media (max-width: 480px) {
  .app { padding: 1rem 0.75rem 2.5rem; }
}
