:root {
  --green: #16a34a;
  --green-2: #22c55e;
  --green-dark: #15803d;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f5f7f6;
  --card: #ffffff;
  --p: #6366f1; /* protein */
  --c: #f59e0b; /* carbs */
  --f: #ec4899; /* fat */
  --fib: #10b981; /* fiber */
  --water: #0ea5e9;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(16, 24, 40, .08);
  --shadow-sm: 0 2px 8px rgba(16, 24, 40, .06);
  --maxw: 460px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
a { color: var(--green-dark); }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

.app-shell { max-width: var(--maxw); margin: 0 auto; min-height: 100%; position: relative; }

/* ---------- Auth / centered screens ---------- */
.center-screen {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #e9faf0 0%, var(--bg) 60%);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.brand img { width: 44px; height: 44px; }
.brand h1 { font-size: 26px; letter-spacing: -.5px; }
.brand .premium { font-size: 11px; font-weight: 700; color: #fff; background: linear-gradient(135deg,#f59e0b,#f97316);
  padding: 3px 8px; border-radius: 999px; letter-spacing: .4px; }
.tagline { color: var(--muted); margin-bottom: 26px; text-align: center; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 26px; width: 100%; max-width: 400px;
}
.card h2 { font-size: 20px; margin-bottom: 4px; }
.card .sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }

.seg {
  display: flex; background: #eef2f0; border-radius: 12px; padding: 4px; margin-bottom: 18px;
}
.seg button {
  flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 9px;
  color: var(--muted); font-weight: 600; transition: .15s;
}
.seg button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm); }

label.field { display: block; margin-bottom: 14px; }
label.field .lab { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; padding: 14px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff; transition: .15s; font-size: 16px;
}
.input:focus { outline: none; border-color: var(--green-2); box-shadow: 0 0 0 4px rgba(34,197,94,.12); }

.btn {
  width: 100%; border: 0; border-radius: 12px; padding: 14px; font-weight: 700; font-size: 16px;
  color: #fff; background: linear-gradient(135deg, var(--green-2), var(--green-dark));
  box-shadow: 0 8px 20px rgba(21,128,61,.25); transition: .15s;
}
.btn:disabled { opacity: .55; box-shadow: none; cursor: default; }
.btn.secondary { background: #eef2f0; color: var(--ink); box-shadow: none; }
.btn.ghost { background: transparent; color: var(--green-dark); box-shadow: none; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.otp-inputs { display: flex; gap: 8px; justify-content: space-between; margin: 6px 0 18px; }
.otp-inputs input {
  width: 100%; aspect-ratio: 1/1; text-align: center; font-size: 22px; font-weight: 700;
  border: 1.5px solid var(--line); border-radius: 12px;
}
.otp-inputs input:focus { outline: none; border-color: var(--green-2); box-shadow: 0 0 0 4px rgba(34,197,94,.12); }

.note { font-size: 13px; color: var(--muted); text-align: center; margin-top: 14px; }
.err-note { color: #b91c1c; }
.dev-pill { margin-top: 14px; font-size: 13px; background: #fff7ed; border: 1px dashed #fdba74; color: #9a3412;
  padding: 8px 10px; border-radius: 10px; text-align: center; }
.msg { font-size: 13px; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; display: none; }
.msg.err { display: block; background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.msg.ok { display: block; background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* ---------- Onboarding wizard ---------- */
.wizard { min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }
.progress { height: 5px; background: #e6ebe8; }
.progress > div { height: 100%; background: linear-gradient(90deg,var(--green-2),var(--green-dark)); width: 0; transition: width .35s; }
.wiz-body { flex: 1; padding: 28px 22px; max-width: var(--maxw); margin: 0 auto; width: 100%; }
.step { display: none; animation: fade .3s ease; }
.step.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.step h2 { font-size: 24px; letter-spacing: -.4px; margin-bottom: 6px; }
.step p.help { color: var(--muted); margin-bottom: 22px; }

.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 10px; }
.choice {
  border: 1.5px solid var(--line); border-radius: 14px; padding: 16px; background: #fff; text-align: left;
  display: flex; flex-direction: column; gap: 3px; transition: .15s;
}
.choice .emoji { font-size: 22px; }
.choice .t { font-weight: 700; }
.choice .d { font-size: 12px; color: var(--muted); }
.choice.active { border-color: var(--green-2); background: #f0fdf4; box-shadow: 0 0 0 3px rgba(34,197,94,.12); }
.choice.wide { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 12px; }

.row2 { display: flex; gap: 12px; }
.row2 > * { flex: 1; }
.unit-toggle { display: inline-flex; background: #eef2f0; border-radius: 9px; padding: 3px; margin-left: 8px; }
.unit-toggle button { border: 0; background: transparent; padding: 4px 10px; border-radius: 7px; font-size: 12px; font-weight: 700; color: var(--muted); }
.unit-toggle button.active { background: #fff; color: var(--ink); }

.wiz-foot { padding: 16px 22px; max-width: var(--maxw); margin: 0 auto; width: 100%; display: flex; gap: 10px; }
.wiz-foot .btn { flex: 1; }

/* target review */
.target-hero { text-align: center; padding: 10px 0 4px; }
.target-hero .big { font-size: 44px; font-weight: 800; letter-spacing: -1px; }
.target-hero .big span { font-size: 18px; color: var(--muted); font-weight: 600; }
.macro-row { display: flex; gap: 10px; margin: 18px 0; }
.macro-row .m { flex: 1; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.macro-row .m .v { font-size: 20px; font-weight: 800; }
.macro-row .m .k { font-size: 12px; color: var(--muted); }
.macro-row .m.p .v { color: var(--p); } .macro-row .m.c .v { color: var(--c); } .macro-row .m.f .v { color: var(--f); }

/* ---------- App dashboard ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.9); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); padding: 12px 16px; display: flex; align-items: center; gap: 10px;
}
.topbar .brand { margin: 0; }
.topbar .brand h1 { font-size: 18px; }
.topbar .brand img { width: 28px; height: 28px; }
.topbar .spacer { flex: 1; }
.topbar .premium { font-size: 10px; }
.datebar { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 12px; }
.datebar button { border: 0; background: #fff; width: 34px; height: 34px; border-radius: 50%; box-shadow: var(--shadow-sm); color: var(--ink); font-size: 16px; }
.datebar .d { font-weight: 700; min-width: 150px; text-align: center; }

.content { padding: 8px 16px 110px; }
.view { display: none; }
.view.active { display: block; }

.ring-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; text-align: center; }
.ring-wrap { position: relative; width: 200px; height: 200px; margin: 4px auto 8px; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-center .num { font-size: 40px; font-weight: 800; letter-spacing: -1px; }
.ring-center .lab { font-size: 13px; color: var(--muted); }
.ring-sub { display: flex; justify-content: space-around; margin-top: 6px; }
.ring-sub div { font-size: 13px; color: var(--muted); }
.ring-sub b { display: block; font-size: 16px; color: var(--ink); }

.macros { display: flex; gap: 10px; margin-top: 16px; }
.macros .bar { flex: 1; }
.macros .bar .top { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 5px; color: var(--muted); }
.macros .bar .track { height: 8px; background: #eef2f0; border-radius: 999px; overflow: hidden; }
.macros .bar .fill { height: 100%; border-radius: 999px; width: 0; transition: width .4s; }
.macros .bar.p .fill { background: var(--p); } .macros .bar.c .fill { background: var(--c); } .macros .bar.f .fill { background: var(--f); }
.macros .bar.fib .fill { background: var(--fib); }

/* water tracker */
.water-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 16px; margin-top: 14px; }
.water-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.water-title { font-weight: 700; }
.water-sub { font-size: 12px; color: var(--muted); }
.water-amt { font-size: 22px; font-weight: 800; color: var(--water); }
.water-amt small { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.water-track { height: 10px; background: #e0f2fe; border-radius: 999px; overflow: hidden; }
.water-fill { height: 100%; width: 0; background: linear-gradient(90deg, #38bdf8, #0ea5e9); border-radius: 999px; transition: width .4s; }
.water-btns { display: flex; gap: 8px; margin-top: 12px; }
.water-btns button { flex: 1; border: 0; background: #e0f2fe; color: #0369a1; font-weight: 700; padding: 9px; border-radius: 10px; }
.water-btns button.minus { background: #fee2e2; color: #b91c1c; flex: 0 0 72px; }

/* recent-food chips */
.chips-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.chips-row .empty { padding: 12px; }
.food-chip { flex: 0 0 auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow-sm); text-align: left; min-width: 120px; }
.food-chip .cn { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.food-chip .cc { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* add chooser grid */
.add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.add-opt { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 10px; border: 1.5px solid var(--line); border-radius: 16px; background: #fff; font-weight: 700; color: var(--ink); }
.add-opt .ic { font-size: 26px; }
.add-opt:active { background: #f0fdf4; border-color: var(--green-2); }

/* food-fact card (search result) */
.food-fact { background: #f8fafc; border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.ff-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ff-head strong { font-size: 16px; }
.ff-cal { font-size: 24px; font-weight: 800; margin-top: 4px; }
.ff-cal small { font-size: 12px; font-weight: 500; }
.ff-macros { display: flex; gap: 8px; margin-top: 12px; }
.ff-macros div { flex: 1; text-align: center; background: #fff; border-radius: 10px; padding: 8px 4px; }
.ff-macros b { display: block; font-size: 16px; }
.ff-macros span { font-size: 11px; color: var(--muted); }
.ff-macros div:nth-child(1) b { color: var(--p); } .ff-macros div:nth-child(2) b { color: var(--c); }
.ff-macros div:nth-child(3) b { color: var(--f); } .ff-macros div:nth-child(4) b { color: var(--fib); }
.muted { color: var(--muted); }

/* date picker (today / yesterday / past) used in add flows */
.datepick { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.datepick button { border: 1.5px solid var(--line); background: #fff; color: var(--muted); font-weight: 700; padding: 9px 14px; border-radius: 10px; font-size: 13px; }
.datepick button.active { border-color: var(--green-2); background: #f0fdf4; color: var(--green-dark); }
.datepick .dp-input { flex: 1; min-width: 130px; padding: 9px 10px; border: 1.5px solid var(--line); border-radius: 10px; font-size: 14px; color: var(--ink); background: #fff; }

.section-title { font-size: 14px; font-weight: 700; color: var(--muted); margin: 22px 4px 10px; text-transform: uppercase; letter-spacing: .5px; }

.meal {
  display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 14px;
  padding: 12px; box-shadow: var(--shadow-sm); margin-bottom: 10px;
}
.meal .thumb { width: 46px; height: 46px; border-radius: 10px; background: #eef2f0; object-fit: cover; display: flex; align-items: center; justify-content: center; font-size: 20px; flex: none; }
.meal .info { flex: 1; min-width: 0; }
.meal .info .n { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal .info .s { font-size: 12px; color: var(--muted); }
.meal .cal { font-weight: 800; }
.meal .del { border: 0; background: transparent; color: #cbd5e1; font-size: 18px; padding: 4px; }
.empty { text-align: center; color: var(--muted); padding: 26px; font-size: 14px; }

/* bottom nav + FAB */
.bottomnav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: var(--maxw);
  background: rgba(255,255,255,.95); backdrop-filter: blur(8px); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; align-items: center; padding: 8px 6px calc(8px + env(safe-area-inset-bottom)); z-index: 30;
}
.bottomnav button { border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; flex: 1; padding: 4px; }
.bottomnav button .ic { font-size: 20px; }
.bottomnav button.active { color: var(--green-dark); }
.fab {
  width: 58px; height: 58px; border-radius: 50%; background: linear-gradient(135deg,var(--green-2),var(--green-dark));
  color: #fff; font-size: 28px; box-shadow: 0 10px 22px rgba(21,128,61,.4); margin-top: -26px; border: 4px solid var(--bg);
  display: flex; align-items: center; justify-content: center;
}

/* sheets / modal */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 40; display: none; }
.sheet-backdrop.open { display: block; }
.sheet {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(100%); bottom: 0; width: 100%; max-width: var(--maxw);
  background: #fff; border-radius: 22px 22px 0 0; z-index: 50; padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
  transition: transform .28s ease; max-height: 92dvh; overflow-y: auto;
}
.sheet.open { transform: translateX(-50%) translateY(0); }
.sheet h3 { font-size: 18px; margin-bottom: 14px; }
.sheet .grab { width: 40px; height: 4px; background: #e2e8f0; border-radius: 999px; margin: 0 auto 14px; }

.ai-items .ai-item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.ai-items .ai-item .grow { flex: 1; }
.ai-items .ai-item .n { font-weight: 700; }
.ai-items .ai-item .m { font-size: 12px; color: var(--muted); }
.ai-items .ai-item input { width: 74px; text-align: right; padding: 8px; border: 1.5px solid var(--line); border-radius: 9px; }
.spinner { width: 30px; height: 30px; border: 3px solid #e2e8f0; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; margin: 22px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.preview-img { width: 100%; max-height: 230px; object-fit: cover; border-radius: 14px; margin-bottom: 14px; background: #eef2f0; }

.chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: #f0fdf4; color: var(--green-dark); }
.confidence-low { background: #fef2f2; color: #b91c1c; }
.confidence-medium { background: #fffbeb; color: #b45309; }
.confidence-high { background: #f0fdf4; color: #166534; }

/* weight + profile */
.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px; }
.stat-card h3 { font-size: 15px; margin-bottom: 12px; }
.spark { width: 100%; height: 90px; }
.wlist { margin-top: 12px; }
.wlist .w { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.wlist .w .dte { color: var(--muted); }
.kv { display: flex; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line); }
.kv .k { color: var(--muted); } .kv .v { font-weight: 700; }
.profile-head { text-align: center; padding: 10px 0 16px; }
.profile-head .avatar { width: 64px; height: 64px; border-radius: 50%; background: linear-gradient(135deg,var(--green-2),var(--green-dark)); color: #fff; font-size: 26px; font-weight: 800; display: flex; align-items: center; justify-content: center; margin: 0 auto 8px; }
.toast { position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 60; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.hidden { display: none !important; }
