/* ---------- Tokens ---------- */
:root {
  /* Athletic dark — clay accent on near-black */
  --bg: #0b0a09;
  --bg-soft: #141210;
  --bg-card: #1a1815;
  --bg-elev: #221f1b;
  --bg-input: #18161300;
  --line: #2a2622;
  --line-soft: #1f1c19;
  --text: #f5f1ea;
  --text-soft: #b8b0a4;
  --text-dim: #847a6e;
  --accent: #D97757;
  --accent-2: #f0a07c;
  --accent-soft: rgba(217, 119, 87, 0.12);
  --accent-glow: rgba(217, 119, 87, 0.35);
  --good: #84cc8c;
  --warn: #e8c468;
  --bad:  #ef6f5e;
  --water: #6cb7e8;
  --carbs: #e8c468;
  --protein: #ef6f5e;
  --fat:    #b58bd9;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;
  --shadow-lg: 0 24px 60px -20px rgba(0,0,0,0.7), 0 2px 0 0 rgba(255,255,255,0.02) inset;
  --shadow: 0 8px 24px -10px rgba(0,0,0,0.5);

  --serif: 'Fraunces', 'Cormorant Garamond', Georgia, serif;
  --sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:  'JetBrains Mono', 'SF Mono', Menlo, monospace;
}

:root[data-theme="light"] {
  --bg: #f5f1ea;
  --bg-soft: #ece6db;
  --bg-card: #ffffff;
  --bg-elev: #fdfaf5;
  --line: #d9cfbf;
  --line-soft: #e5dccd;
  --text: #1a1612;
  --text-soft: #5b5147;
  --text-dim: #8a8074;
  --accent: #C25A36;
  --accent-2: #D97757;
  --accent-soft: rgba(194, 90, 54, 0.10);
  --accent-glow: rgba(194, 90, 54, 0.25);
  --shadow-lg: 0 24px 60px -28px rgba(60, 40, 20, 0.25), 0 1px 0 0 rgba(0,0,0,0.02) inset;
  --shadow: 0 8px 24px -14px rgba(60, 40, 20, 0.18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Accent radial in dark for depth */
body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  background: radial-gradient(1200px 600px at 80% -10%, var(--accent-soft) 0%, transparent 60%),
              radial-gradient(900px 500px at -10% 110%, var(--accent-soft) 0%, transparent 55%);
  z-index: 0;
}

#root { position: relative; z-index: 1; }

/* ---------- Typography ---------- */
.display { font-family: var(--serif); font-weight: 500; letter-spacing: -0.02em; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; letter-spacing: -0.02em; margin: 0; }
h1 { font-size: clamp(28px, 4vw, 44px); line-height: 1.05; }
h2 { font-size: clamp(22px, 2.6vw, 30px); line-height: 1.1; }
h3 { font-size: 18px; line-height: 1.2; }
.eyebrow {
  font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--text-dim); font-weight: 600;
}

/* ---------- Layout ---------- */
.app {
  min-height: 100vh;
  display: flex; flex-direction: column;
  padding-bottom: 96px; /* room for bottom nav */
}
.app-header {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border-bottom: 1px solid var(--line-soft);
}
.app-header-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--serif); font-size: 19px; font-weight: 500;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent);
  display: grid; place-items: center;
  color: #fff; font-family: var(--serif); font-weight: 600; font-size: 16px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06) inset, 0 6px 16px -4px var(--accent-glow);
}
.brand small { display: block; font-size: 10px; color: var(--text-dim); letter-spacing: 0.16em; text-transform: uppercase; font-family: var(--sans); line-height: 1; margin-top: 3px; }

.header-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-elev); color: var(--text); border-color: var(--line); }

main.app-main {
  flex: 1;
  max-width: 1200px; width: 100%;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 16px;
  z-index: 40;
  display: flex;
  gap: 4px;
  padding: 6px;
  background: color-mix(in srgb, var(--bg-card) 92%, transparent);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 24px);
  overflow-x: auto;
  scrollbar-width: none;
}
.bottom-nav::-webkit-scrollbar { display: none; }
.nav-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: transparent; border: 0; border-radius: 999px;
  color: var(--text-soft); font-weight: 500; font-size: 13px;
  cursor: pointer; white-space: nowrap;
  transition: color 0.15s, background 0.15s, transform 0.15s;
  font-family: var(--sans);
}
.nav-btn:hover { color: var(--text); }
.nav-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 22px -8px var(--accent-glow);
}
.nav-btn svg { width: 16px; height: 16px; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.card-tight { padding: 18px; border-radius: var(--radius); }
.card h3 + p, .card h2 + p { color: var(--text-soft); margin: 8px 0 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-weight: 500; font-size: 14px; font-family: var(--sans);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--bg-soft); border-color: var(--text-dim); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
  box-shadow: 0 10px 24px -10px var(--accent-glow);
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--bg-elev); color: var(--text); border-color: var(--line); }
.btn-sm { padding: 7px 12px; font-size: 12px; border-radius: 9px; }
.btn-lg { padding: 14px 22px; font-size: 15px; border-radius: 14px; }

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field label, .label {
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-dim); font-weight: 600;
}
.input, .textarea, .select {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { min-height: 120px; resize: vertical; font-family: var(--sans); line-height: 1.5; }
.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M3 4.5l3 3 3-3' fill='none' stroke='%23847a6e' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 34px; }

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  gap: 2px;
}
.segmented button {
  background: transparent; border: 0; padding: 8px 14px;
  border-radius: 9px;
  color: var(--text-soft); font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--accent); color: #fff; }

/* ---------- Stat tiles ---------- */
.stat {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px;
  position: relative; overflow: hidden;
  min-height: 130px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 14px;
}
.stat-label { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-dim); font-weight: 600; }
.stat-val { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 36px; font-weight: 500; line-height: 1; letter-spacing: -0.02em; }
.stat-val small { font-size: 13px; color: var(--text-dim); margin-left: 6px; font-weight: 400; }
.stat-sub { font-size: 12px; color: var(--text-soft); }

/* Progress */
.progress {
  height: 6px; background: var(--bg-elev); border-radius: 99px; overflow: hidden;
  position: relative;
}
.progress > span {
  display: block; height: 100%;
  background: var(--accent);
  border-radius: inherit;
  transition: width 0.5s cubic-bezier(.2,.7,.2,1);
}
.progress.thick { height: 10px; }
.progress-row {
  display: flex; flex-direction: column; gap: 6px;
}
.progress-row .pr-head {
  display: flex; justify-content: space-between; font-size: 13px;
}
.progress-row .pr-head .pr-name { color: var(--text); font-weight: 500; }
.progress-row .pr-head .pr-val  { color: var(--text-soft); font-family: var(--mono); }

/* ---------- Day card / log row ---------- */
.daycard {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
}
.daycard-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.daycard .meal-section { border-top: 1px dashed var(--line-soft); padding-top: 12px; }
.daycard .meal-section:first-of-type { border-top: 0; padding-top: 0; }
.meal-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  color: var(--text-soft);
  letter-spacing: 0.04em;
}
.meal-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.meal-pill[data-meal="Breakfast"] .dot { background: #f0a07c; }
.meal-pill[data-meal="Lunch"] .dot { background: #e8c468; }
.meal-pill[data-meal="Dinner"] .dot { background: #b58bd9; }
.meal-pill[data-meal="Snack"] .dot { background: #84cc8c; }
.meal-pill[data-meal="Water"] .dot { background: var(--water); }

.log-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 14px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line-soft);
}
.log-row:last-child { border-bottom: 0; }
.log-row .lr-name { font-size: 14px; }
.log-row .lr-name small { display: block; color: var(--text-dim); font-size: 11px; margin-top: 2px; }
.log-row .lr-cal { font-family: var(--mono); font-size: 14px; color: var(--text-soft); }
.log-row .lr-edit {
  width: 28px; height: 28px; border-radius: 8px; border: 0; background: transparent;
  color: var(--text-dim); cursor: pointer;
  display: grid; place-items: center;
}
.log-row .lr-edit:hover { background: var(--bg-elev); color: var(--accent); }

.log-row .lr-del {
  width: 28px; height: 28px; border-radius: 8px; border: 0; background: transparent;
  color: var(--text-dim); cursor: pointer;
  display: grid; place-items: center;
}
.log-row .lr-del:hover { background: var(--bg-elev); color: var(--bad); }

/* ---------- Grid helpers ---------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-cols-mobile-1 { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.row { display: flex; gap: 12px; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.flex-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; } .mt-32 { margin-top: 32px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; } .mb-32 { margin-bottom: 32px; }
.muted { color: var(--text-soft); }
.dim { color: var(--text-dim); }

/* ---------- Chips & badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-soft);
}
.chip-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-good { background: rgba(132, 204, 140, 0.15); color: var(--good); border: 0; }
.badge-warn { background: rgba(232, 196, 104, 0.15); color: var(--warn); border: 0; }
.badge-bad { background: rgba(239, 111, 94, 0.15); color: var(--bad); border: 0; }

/* ---------- Tables ---------- */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl th, .tbl td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
}
.tbl th {
  font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-dim); font-weight: 600;
  position: sticky; top: 0; background: var(--bg-card); z-index: 1;
}
.tbl .num-col { text-align: right; font-family: var(--mono); }
.tbl tr:hover td { background: var(--bg-soft); }
.tbl-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-card); }

/* ---------- Preview card (lookup result) ---------- */
.preview {
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: 0 24px 60px -28px var(--accent-glow);
  position: relative;
}
.preview::before {
  content: 'PREVIEW · NOT YET LOGGED';
  position: absolute; top: 14px; right: 18px;
  font-size: 10px; letter-spacing: 0.18em; color: var(--accent); font-weight: 600;
}
.preview h3 { font-family: var(--serif); font-size: 24px; }
.macros-strip {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  margin: 16px 0;
}
.macro {
  background: var(--bg-elev);
  border-radius: 12px; padding: 12px;
  text-align: center;
}
.macro .v { font-family: var(--mono); font-size: 20px; font-weight: 500; }
.macro .l { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-dim); margin-top: 4px; font-weight: 600; }
.macro[data-k="calories"] .v { color: var(--accent); }
.macro[data-k="protein"] .v { color: var(--protein); }
.macro[data-k="carbs"] .v { color: var(--carbs); }
.macro[data-k="fat"] .v { color: var(--fat); }

.micro-strip {
  display: flex; gap: 6px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-soft);
}
.micro-strip .chip { background: transparent; }

/* ---------- Insight card ---------- */
.insight {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-elev) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 22px;
  position: relative; overflow: hidden;
}
.insight::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(400px 200px at 100% 0%, var(--accent-soft) 0%, transparent 70%);
  pointer-events: none;
}
.insight > * { position: relative; }
.insight .ai-tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--accent); font-weight: 600;
}
.insight .ai-tag svg { width: 12px; height: 12px; }

/* ---------- Day picker ---------- */
.day-picker {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 4px;
}
.day-picker button {
  width: 36px; height: 36px;
  background: transparent; border: 0; color: var(--text-soft);
  display: grid; place-items: center;
  cursor: pointer; border-radius: 10px;
}
.day-picker button:hover { background: var(--bg-elev); color: var(--text); }
.day-picker .day-label {
  padding: 0 14px; font-family: var(--serif); font-size: 18px;
  display: flex; flex-direction: column; align-items: center; line-height: 1.05;
}
.day-picker .day-label small { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-dim); font-family: var(--sans); font-weight: 600; }

/* ---------- Toasts ---------- */
.toast-host { position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  pointer-events: auto;
  background: var(--bg-card); border: 1px solid var(--line);
  padding: 12px 16px; border-radius: 12px;
  font-size: 13px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  animation: tin 0.2s ease;
}
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.toast.error .dot { background: var(--bad); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Misc ---------- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-soft); }
.empty-state .em-icon { width: 48px; height: 48px; border-radius: 14px; background: var(--bg-elev); display: grid; place-items: center; margin: 0 auto 14px; color: var(--text-dim); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.divider { height: 1px; background: var(--line-soft); margin: 16px 0; border: 0; }

/* Pull tweaks panel above bottom nav on mobile */
@media (max-width: 720px) {
  .tweaks-panel { bottom: 96px !important; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
::-webkit-scrollbar-track { background: transparent; }
