/* Themes: variables are switched by [data-theme] on <html>. */
:root, [data-theme="meadow"] {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #5c6a7a;
  --line: #e2e7ee;
  --accent: #2e7d4f;
  --accent-dark: #256b42;
  --header-ink: #ffffff;
  --protein: #3a7bd5;
  --carbs: #e0a458;
  --fat: #c95d7b;
  --water: #2f9fd8;
  --danger: #b3392e;
  --tag-bg: #eef3f0;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(20, 30, 45, 0.07), 0 1px 3px rgba(20, 30, 45, 0.05);
  --shadow-nav: 0 -6px 24px rgba(20, 30, 45, 0.10);
}
[data-theme="ocean"] {
  --bg: #eef4f9;
  --card: #ffffff;
  --ink: #14232e;
  --muted: #54707f;
  --line: #d3e2ec;
  --accent: #1668a8;
  --accent-dark: #0f4f80;
  --protein: #2e9e6b;
  --carbs: #e0a458;
  --fat: #c95d7b;
  --water: #1668a8;
  --tag-bg: #e7f1f8;
}
[data-theme="sunset"] {
  --bg: #faf3ec;
  --card: #fffdfa;
  --ink: #2e2019;
  --muted: #7d6555;
  --line: #ecdccb;
  --accent: #c65a1e;
  --accent-dark: #9c4414;
  --protein: #3a7bd5;
  --carbs: #8fae4c;
  --fat: #b03a5b;
  --water: #2f9fd8;
  --tag-bg: #f9ecdf;
}
[data-theme="berry"] {
  --bg: #f7f1f8;
  --card: #ffffff;
  --ink: #2a1c2e;
  --muted: #75617c;
  --line: #e6d8ec;
  --accent: #8e44ad;
  --accent-dark: #6d2f88;
  --protein: #3a7bd5;
  --carbs: #e0a458;
  --fat: #d3547e;
  --water: #4aa3c7;
  --tag-bg: #f3e8f8;
}
[data-theme="slate"] {
  --bg: #eceff1;
  --card: #fbfcfd;
  --ink: #20262b;
  --muted: #5f6b73;
  --line: #d2d9de;
  --accent: #455a64;
  --accent-dark: #2f4048;
  --protein: #5b7f95;
  --carbs: #b08d57;
  --fat: #96606f;
  --water: #527a8a;
  --tag-bg: #e6ecef;
}
[data-theme="midnight"] {
  --bg: #12161c;
  --card: #1c232d;
  --ink: #e8edf3;
  --muted: #9fb0c1;
  --line: #2e3947;
  --accent: #4caf7d;
  --accent-dark: #12241b;
  --header-ink: #dcefe3;
  --protein: #6aa6e8;
  --carbs: #e8bb7c;
  --fat: #e08aa5;
  --water: #56b6e8;
  --danger: #e0705f;
  --tag-bg: #26302b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }

.site-header {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 78%);
  color: var(--header-ink);
  padding: 26px 0 22px;
}
.site-header h1 { margin: 0; font-size: 1.8rem; font-weight: 750; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; }
.site-header h1 .icon { flex: 0 0 auto; opacity: 0.95; }
.tagline { margin: 4px 0 0; opacity: 0.9; }
.header-flex { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.theme-picker { display: grid; gap: 4px; font-size: 0.85rem; }
.theme-picker select { background: var(--card); color: var(--ink); }

/* Icons (inline SVG, decorative) */
.icon { width: 19px; height: 19px; flex: 0 0 auto; display: inline-block; vertical-align: middle; }
.icon-lg { width: 28px; height: 28px; }
.btn .icon { width: 17px; height: 17px; }
.btn-small .icon { width: 15px; height: 15px; }

/* Tab navigation */
.tab-nav {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 10px rgba(20, 30, 45, 0.04);
  position: sticky;
  top: 0;
  z-index: 20;
}
.tab-nav-inner { display: flex; gap: 6px; overflow-x: auto; padding-top: 9px; padding-bottom: 9px; scrollbar-width: none; }
.tab-nav-inner::-webkit-scrollbar { display: none; }
.tab-btn {
  font: inherit;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 99px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.tab-btn:hover { color: var(--ink); border-color: var(--line); background: var(--tag-bg); }
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 650; box-shadow: 0 3px 10px rgba(20, 30, 45, 0.16); }
.tab-btn.active:hover { background: var(--accent); color: #fff; }

main { padding: 24px 0 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 1.22rem; font-weight: 700; letter-spacing: -0.01em; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row input[type="search"], .row input[type="text"] { flex: 1 1 220px; }
.space-between { justify-content: space-between; }
.inline-label { display: inline-flex; gap: 8px; align-items: center; font-size: 0.94rem; color: var(--muted); }

input, select, textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
}
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.tab-btn:focus-visible, .btn:focus-visible, .seg-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn {
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { border-color: var(--muted); box-shadow: 0 2px 8px rgba(20, 30, 45, 0.08); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-small { padding: 5px 10px; font-size: 0.9rem; }

.hint { color: var(--muted); font-size: 0.9rem; }
.status { min-height: 1.2em; font-size: 0.92rem; color: var(--muted); margin: 6px 0; }
.status.error { color: var(--danger); }

hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.segmented.wrap-seg { display: flex; flex-wrap: wrap; border: none; gap: 6px; margin-bottom: 14px; }
.seg-btn {
  font: inherit; font-size: 0.9rem;
  padding: 6px 12px;
  border: none; border-right: 1px solid var(--line);
  background: var(--card); color: var(--muted); cursor: pointer;
}
.seg-btn:last-child { border-right: none; }
.wrap-seg .seg-btn { border: 1px solid var(--line); border-radius: 99px; }
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

/* Summary / ring */
.summary-flex { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.ring-box { position: relative; width: 170px; height: 170px; flex: 0 0 auto; }
#ring { transform: rotate(-90deg); display: block; }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 13; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 13; stroke-linecap: round; transition: stroke-dashoffset 0.4s ease; }
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
}
.ring-remaining { font-size: 2rem; font-weight: 700; }
.ring-label { color: var(--muted); font-size: 0.85rem; }
.summary-stats { flex: 1 1 260px; }
.stat { display: inline-flex; flex-direction: column; margin-right: 22px; }
.stat-num { font-size: 1.35rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.82rem; }
.macros { margin-top: 14px; display: grid; gap: 8px; }
.macro { display: grid; grid-template-columns: 62px 1fr 56px; align-items: center; gap: 10px; }
.macro-name { font-size: 0.9rem; color: var(--muted); }
.macro-val { font-size: 0.9rem; text-align: right; }
.bar { background: var(--line); border-radius: 99px; height: 9px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; border-radius: 99px; transition: width 0.3s ease; }
.bar-fill.protein { background: var(--protein); }
.bar-fill.carbs { background: var(--carbs); }
.bar-fill.fat { background: var(--fat); }
.bar-fill.water { background: var(--water); }
.home-quick { margin-top: 16px; }

/* Calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-head h2 { margin: 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-weekdays { color: var(--muted); font-size: 0.8rem; text-align: center; margin-bottom: 4px; }
.cal-cell {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 52px;
  padding: 4px 5px;
  font-size: 0.82rem;
  background: var(--card);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.cal-cell:hover { border-color: var(--accent); }
.cal-cell.empty { border: none; background: transparent; cursor: default; }
.cal-cell.today { border-color: var(--accent); border-width: 2px; }
.cal-cell.selected { background: var(--tag-bg); }
.cal-daynum { font-weight: 650; }
.cal-kcal { color: var(--muted); font-size: 0.74rem; line-height: 1.2; }

/* Log */
.day-nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.day-summary { font-weight: 600; margin: 12px 0 0; }
.results { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.result {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.result-main { flex: 1 1 240px; }
.result-name { font-weight: 600; }
.result-meta { color: var(--muted); font-size: 0.86rem; }
.result-grams { width: 84px; }
.result-qty { width: 68px; }
.result-unit { max-width: 160px; }
.source-tag {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.03em;
  background: var(--tag-bg); color: var(--accent-dark);
  border-radius: 99px; padding: 2px 8px; text-transform: uppercase;
}
[data-theme="midnight"] .source-tag { color: var(--accent); }
.meal-group { margin-bottom: 14px; }
.meal-group h3 { margin: 10px 0 6px; font-size: 1rem; display: flex; justify-content: space-between; }
.meal-group h3 .meal-kcal { color: var(--muted); font-weight: 500; font-size: 0.9rem; }
.log-item {
  display: flex; gap: 10px; align-items: baseline; justify-content: space-between;
  padding: 7px 0; border-bottom: 1px solid var(--line);
}
.log-item:last-child { border-bottom: none; }
.log-name { font-weight: 550; }
.log-meta { color: var(--muted); font-size: 0.86rem; }
.log-kcal { font-weight: 650; white-space: nowrap; }
.log-remove { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1rem; padding: 2px 6px; }
.scan-box { margin-top: 10px; }

/* Quick re-log: favorites & recents */
.quick-title { margin: 16px 0 6px; font-size: 0.98rem; }
.quick-list { display: grid; gap: 8px; }
.quick-row {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.quick-main { flex: 1 1 180px; min-width: 0; }
.fav-btn {
  background: none; border: none; cursor: pointer; padding: 4px 6px;
  font-size: 1.2rem; line-height: 1; color: var(--muted); flex: 0 0 auto;
}
.fav-btn[aria-pressed="true"] { color: var(--carbs); }
.copy-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.copy-label { color: var(--muted); font-size: 0.9rem; }
#voice-btn.listening { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Reminders */
.reminder-banner {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  background: var(--tag-bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; margin: 14px 0 0; box-shadow: var(--shadow);
}
label.check { display: flex; gap: 8px; align-items: center; margin: 8px 0 12px; font-size: 0.95rem; }
label.check input { width: auto; }
.scan-box video { width: 100%; max-height: 320px; border-radius: 10px; background: #000; object-fit: cover; }
#scan-zxing video { width: 100% !important; max-height: 320px; border-radius: 10px; background: #000; }

/* Trends */
.chart-box { width: 100%; min-height: 40px; margin: 8px 0 12px; }
.chart-box svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; font-size: 0.88rem; color: var(--muted); margin-bottom: 4px; }
.legend .swatch { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; }
.swatch.protein { background: var(--protein); }
.swatch.carbs { background: var(--carbs); }
.swatch.fat { background: var(--fat); }
.weight-stats { margin-bottom: 10px; }
.weight-list { list-style: none; margin: 12px 0 0; padding: 0; }
.weight-list li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.weight-list li:last-child { border-bottom: none; }
.micro-list { display: grid; gap: 10px; }
.micro { display: grid; grid-template-columns: 108px 1fr 128px; align-items: center; gap: 10px; }
.micro-name { font-size: 0.92rem; }
.micro-val { font-size: 0.86rem; color: var(--muted); text-align: right; }
.micro .bar-fill { background: var(--accent); }

/* Water */
.water-display { text-align: center; margin: 14px 0 6px; }
.water-amount { font-size: 2.2rem; font-weight: 700; }
.water-sub { color: var(--muted); font-size: 0.92rem; }
.water-bar { height: 16px; margin-top: 10px; }
.water-pct { text-align: center; color: var(--muted); font-size: 0.9rem; margin: 6px 0 14px; }
#water-custom-form { margin-top: 12px; }

/* Workouts */
.wk-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.wk-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.wk-card h3 { margin: 0; font-size: 1rem; }
.wk-meta { color: var(--muted); font-size: 0.82rem; }
.wk-level { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; background: var(--tag-bg); border-radius: 99px; padding: 2px 8px; color: var(--accent-dark); }
[data-theme="midnight"] .wk-level { color: var(--accent); }
.wk-stage { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.wk-stage svg { width: 100%; height: auto; display: block; }
.wk-fig { stroke: var(--ink); stroke-width: 3.4; stroke-linecap: round; fill: none; }
.wk-fig-head { fill: var(--ink); }
.wk-prop { stroke: var(--muted); stroke-width: 3; stroke-linecap: round; }
.wk-ground { stroke: var(--line); stroke-width: 2; }
.wk-caps { font-size: 0.85rem; color: var(--muted); display: grid; gap: 2px; }
.wk-caps .cap-on { color: var(--ink); font-weight: 600; }
.wk-sets { font-size: 0.88rem; }
.wk-controls { margin-top: auto; }

/* Planner */
.plan-split { display: grid; gap: 6px; margin-top: 12px; }
.plan-row { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 6px 0; }
.plan-row:last-child { border-bottom: none; }
.plan-row .plan-kcal { font-weight: 650; }
.plan-recipes { display: grid; gap: 10px; margin-top: 12px; }
.recipe { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.recipe h3 { margin: 0 0 4px; font-size: 1rem; }
.recipe .recipe-meta { color: var(--muted); font-size: 0.86rem; margin-bottom: 4px; }
.recipe .have { color: var(--accent-dark); }
.recipe .missing { color: var(--danger); }
.plan-output { margin-top: 12px; display: grid; gap: 10px; }
.shop-list { columns: 2; column-gap: 28px; margin: 6px 0 0; padding-left: 18px; }

/* Photos */
.photo-frame {
  position: relative;
  width: 100%;
  max-width: 360px;
  aspect-ratio: 3 / 4;
  margin: 12px auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #10151b;
}
.photo-frame img, .photo-frame video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.photo-ghost { opacity: 0.45; z-index: 1; }
#photo-video { z-index: 2; }
#photo-preview { z-index: 3; }
.photo-outline {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  border: 2px dashed rgba(255, 255, 255, 0.0);
  background:
    radial-gradient(ellipse 46% 34% at 50% 26%, transparent 96%, rgba(255,255,255,0.55) 97%, transparent 100%),
    linear-gradient(transparent 97%, rgba(255,255,255,0.0));
}
.photo-outline::before {
  content: "";
  position: absolute;
  left: 50%; top: 6%;
  width: 34%; height: 76%;
  transform: translateX(-50%);
  border: 2px dashed rgba(255, 255, 255, 0.55);
  border-radius: 48% 48% 44% 44% / 22% 22% 40% 40%;
}
.photo-frame-label {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 6px 10px;
  background: rgba(10, 14, 18, 0.72);
  color: #eef3f6; font-size: 0.82rem;
}
.photo-gallery { display: grid; gap: 16px; }
.photo-date-group h3 { margin: 0 0 8px; font-size: 1rem; }
.photo-thumbs { display: flex; gap: 10px; flex-wrap: wrap; }
.photo-thumb { position: relative; width: 104px; }
.photo-thumb img { width: 104px; height: 138px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.photo-thumb .thumb-label { font-size: 0.78rem; color: var(--muted); text-transform: capitalize; display: block; margin-top: 3px; }
.photo-thumb .thumb-del { position: absolute; top: 4px; right: 4px; background: rgba(10,14,18,0.75); color: #fff; border: none; border-radius: 99px; width: 24px; height: 24px; cursor: pointer; line-height: 1; }

/* Settings */
.settings-grid { display: grid; gap: 12px; max-width: 430px; }
.settings-grid label { display: grid; gap: 5px; font-size: 0.94rem; color: var(--muted); }
.settings-grid input, .settings-grid select { color: var(--ink); }
.unit-note { color: var(--muted); font-weight: 400; font-size: 0.85em; }

/* Erase confirmation modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 15, 22, 0.55); display: flex; align-items: center; justify-content: center; padding: 18px; z-index: 100; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--card); color: var(--ink); border-radius: var(--radius); box-shadow: var(--shadow); max-width: 420px; width: 100%; padding: 22px; }
.modal h3 { margin-top: 0; }
.modal input { width: 100%; margin: 4px 0 14px; }
.modal-actions { justify-content: flex-end; }

/* First-run setup wizard + settings actions */
.setup-modal { max-width: 460px; }
.setup-progress { color: var(--muted); font-size: 0.85rem; margin: 0 0 6px; }
.setup-list { margin: 8px 0 4px; padding-left: 20px; display: grid; gap: 7px; }
.setup-field { display: grid; gap: 5px; font-size: 0.94rem; color: var(--muted); margin-top: 12px; }
.setup-field input, .setup-field select { color: var(--ink); }
.setup-nav { justify-content: space-between; margin-top: 18px; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
#clear-data { margin-top: 6px; }

.site-footer { padding: 10px 0 30px; color: var(--muted); font-size: 0.9rem; }

@media (max-width: 560px) {
  .summary-flex { justify-content: center; }
  .summary-stats { flex-basis: 100%; }
  .ring-box { margin: 0 auto; }
  .micro { grid-template-columns: 92px 1fr 104px; }
  .shop-list { columns: 1; }
  .cal-cell { min-height: 46px; }
  .card { padding: 18px; }
}

/* Mobile app-style bottom navigation bar */
@media (max-width: 720px) {
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
  main { padding-bottom: 28px; }
  .site-footer { padding-bottom: 24px; }
  .site-header { padding: 20px 0 16px; }
  .site-header h1 { font-size: 1.5rem; }
  .tab-nav {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 60;
    border-bottom: none;
    border-top: 1px solid var(--line);
    box-shadow: var(--shadow-nav);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .tab-nav-inner {
    display: flex;
    gap: 0;
    overflow-x: visible;
    padding: 6px 4px 4px;
    max-width: none;
  }
  .tab-btn {
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 3px;
    white-space: normal;
    text-align: center;
    padding: 6px 1px 5px;
    border-radius: 12px;
    font-size: 0.6rem;
    line-height: 1.15;
    letter-spacing: -0.01em;
  }
  .tab-btn .icon { width: 21px; height: 21px; }
  .tab-btn .tab-label { display: block; max-width: 100%; }
  .tab-btn.active { box-shadow: none; }
}
