/* ============ FitTrack styles ============ */
:root{
  --bg:#f4f5f9; --surface:#ffffff; --surface-2:#f0f1f6; --text:#1a1d29; --muted:#6b7280;
  --border:#e5e7eb; --primary:#4f46e5; --primary-d:#4338ca; --primary-soft:#eef2ff;
  --success:#16a34a; --warning:#d97706; --danger:#dc2626; --info:#2563eb;
  --water:#0ea5e9; --protein:#ef4444; --carbs:#f59e0b; --fat:#8b5cf6;
  --radius:16px; --shadow:0 1px 3px rgba(0,0,0,.06),0 1px 2px rgba(0,0,0,.04);
}
[data-theme="dark"]{
  --bg:#0f1117; --surface:#1a1d27; --surface-2:#232733; --text:#e8eaf0; --muted:#9aa1b1;
  --border:#2c3040; --primary:#6366f1; --primary-d:#4f46e5; --primary-soft:#1e2130;
  --shadow:0 1px 3px rgba(0,0,0,.3);
}
*{box-sizing:border-box}
html,body{margin:0}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  background:var(--bg); color:var(--text); line-height:1.5;
  -webkit-font-smoothing:antialiased; padding-bottom:80px;
}
a{color:var(--primary); text-decoration:none}
h1{font-size:1.6rem; margin:.2rem 0} h3{margin:0}
.muted{color:var(--muted)} .small{font-size:.82rem} .center{text-align:center} .pad{padding:1rem 0}

/* Top bar */
.topbar{position:sticky; top:0; z-index:20; display:flex; align-items:center; justify-content:space-between;
  padding:.7rem 1rem; background:var(--surface); border-bottom:1px solid var(--border);
  padding-top:calc(.7rem + env(safe-area-inset-top));}
.brand{font-weight:700; font-size:1.1rem; color:var(--text)}
.topbar-actions{display:flex; align-items:center; gap:.6rem}
.avatar{width:34px; height:34px; border-radius:50%; background:var(--primary); color:#fff;
  display:grid; place-items:center; font-weight:700}
.icon-btn{background:none; border:none; cursor:pointer; font-size:1.1rem; color:var(--text); padding:.3rem; border-radius:8px}
.icon-btn.danger{color:var(--danger); font-size:.9rem}

.container{max-width:760px; margin:0 auto; padding:1rem}
.page-head{display:flex; align-items:center; justify-content:space-between; margin:.3rem 0 1rem}

/* Cards */
.card{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  padding:1.1rem; margin-bottom:1rem; box-shadow:var(--shadow)}
.card-title{font-size:1rem; margin-bottom:.8rem}
.grid{display:grid; gap:.9rem}
.grid-2{grid-template-columns:repeat(2,1fr)}
.grid-3{grid-template-columns:repeat(3,1fr)}
.grid-4{grid-template-columns:repeat(4,1fr)}
@media(max-width:520px){ .grid-4{grid-template-columns:repeat(2,1fr)} }

/* Stats */
.stat .stat-top{display:flex; justify-content:space-between; align-items:center; font-weight:600; font-size:.9rem}
.stat-big{font-size:2rem; font-weight:700; margin:.2rem 0; line-height:1}
.stat-big.xxl{font-size:3.4rem}
.stat-big .unit{font-size:.9rem; font-weight:500; color:var(--muted); margin-left:.25rem}
.mini-link{font-size:.8rem}

/* Progress bars */
.progress{height:8px; background:var(--surface-2); border-radius:99px; overflow:hidden; margin:.5rem 0}
.progress span{display:block; height:100%; background:var(--primary); border-radius:99px; transition:width .4s}
.progress.water span{background:var(--water)} .progress.lg{height:12px}

/* Pills / badges */
.pill{display:inline-block; padding:.15rem .55rem; border-radius:99px; font-size:.75rem; font-weight:600}
.pill-success{background:rgba(22,163,74,.15); color:var(--success)}
.pill-warning{background:rgba(217,119,6,.15); color:var(--warning)}
.pill-danger{background:rgba(220,38,38,.15); color:var(--danger)}
.pill-info{background:rgba(37,99,235,.15); color:var(--info)}
.pill-muted{background:var(--surface-2); color:var(--muted)}
.badge{background:var(--primary-soft); color:var(--primary); font-weight:700; padding:.25rem .55rem; border-radius:10px; font-size:.85rem}

/* Macro rings */
.macro-row{display:flex; justify-content:space-around; text-align:center}
.macro-ring{width:72px; height:72px; border-radius:50%; display:grid; place-items:center; margin:0 auto .4rem;
  background:conic-gradient(var(--ring) calc(var(--pct)*1%), var(--surface-2) 0)}
.macro-ring b{background:var(--surface); width:54px; height:54px; border-radius:50%; display:grid; place-items:center; font-size:.85rem}
.macro-protein{--ring:var(--protein)} .macro-carbs{--ring:var(--carbs)} .macro-fat{--ring:var(--fat)}

/* Forms */
label{display:block; font-size:.85rem; font-weight:600; color:var(--text)}
.stack{display:flex; flex-direction:column; gap:.8rem}
input,select,textarea{width:100%; padding:.65rem .75rem; margin-top:.3rem; border:1px solid var(--border);
  border-radius:10px; background:var(--surface); color:var(--text); font-size:1rem; font-family:inherit}
input:focus,select:focus{outline:none; border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-soft)}
input:disabled{opacity:.6}
.check{display:flex; align-items:center; gap:.5rem; font-weight:500}
.check input{width:auto; margin:0}
.sub{margin:.4rem 0 0; font-size:.95rem}

/* Buttons */
.btn{display:inline-flex; align-items:center; justify-content:center; gap:.4rem; padding:.7rem 1.1rem;
  border:none; border-radius:10px; font-size:.95rem; font-weight:600; cursor:pointer; font-family:inherit}
.btn-primary{background:var(--primary); color:#fff} .btn-primary:hover{background:var(--primary-d)}
.btn-ghost{background:var(--surface-2); color:var(--text); margin-bottom:.5rem; width:100%}
.btn-danger-ghost{background:transparent; color:var(--danger); border:1px solid var(--border); width:100%}
.btn-block{width:100%}
.chip{background:var(--surface-2); border:1px solid var(--border); color:var(--text); padding:.5rem .9rem;
  border-radius:99px; font-weight:600; cursor:pointer; font-size:.9rem}
.chip:hover{border-color:var(--primary); color:var(--primary)}

/* Lists */
.list{list-style:none; margin:0; padding:0}
.list-item{display:flex; align-items:center; justify-content:space-between; gap:.6rem;
  padding:.7rem 0; border-bottom:1px solid var(--border)}
.list-item:last-child{border-bottom:none}
.li-main{display:flex; align-items:center; gap:.6rem; min-width:0}
.li-main>div{min-width:0} .li-main b{display:block}
.li-side{display:flex; align-items:center; gap:.5rem; flex-shrink:0}
.thumb{width:42px; height:42px; border-radius:10px; object-fit:cover}

/* Flash & banner */
.flash{padding:.7rem .9rem; border-radius:10px; margin-bottom:.8rem; font-size:.9rem; font-weight:500}
.flash-success{background:rgba(22,163,74,.12); color:var(--success)}
.flash-danger{background:rgba(220,38,38,.12); color:var(--danger)}
.flash-info{background:rgba(37,99,235,.12); color:var(--info)}
.banner{display:block; background:var(--primary-soft); color:var(--primary); padding:.8rem 1rem;
  border-radius:12px; margin-bottom:1rem; font-weight:600; font-size:.9rem}

/* Quick actions */
.quick-actions{display:grid; grid-template-columns:repeat(4,1fr); gap:.7rem; margin-top:.3rem}
.qa{display:flex; flex-direction:column; align-items:center; gap:.3rem; background:var(--surface);
  border:1px solid var(--border); border-radius:14px; padding:.9rem .3rem; font-size:1.4rem; box-shadow:var(--shadow)}
.qa span{font-size:.72rem; color:var(--muted); font-weight:600}

/* Water */
.water-big{font-size:3rem; font-weight:700} .water-big .unit{font-size:1rem; color:var(--muted)}
.chips{display:flex; flex-wrap:wrap; gap:.5rem; justify-content:center; margin:1rem 0}
.inline{display:inline} .inline-form{display:flex; gap:.5rem; margin-top:.5rem}
.inline-form input{margin:0}

/* Food */
.day-summary{display:flex; align-items:center; gap:1rem; flex-wrap:wrap}
.day-summary>div:first-child b{font-size:1.6rem}
.macro-mini{font-size:.85rem; color:var(--muted); display:flex; align-items:center; gap:.3rem}
.dot{width:10px; height:10px; border-radius:50%; display:inline-block}
.dot.protein{background:var(--protein)} .dot.carbs{background:var(--carbs)} .dot.fat{background:var(--fat)}
.meal-head{display:flex; justify-content:space-between; align-items:center; margin-bottom:.5rem}

/* Tabs */
.tabs{display:flex; gap:.4rem; margin-bottom:1rem; background:var(--surface-2); padding:.3rem; border-radius:12px}
.tab-btn{flex:1; padding:.55rem; border:none; background:none; border-radius:9px; font-weight:600;
  color:var(--muted); cursor:pointer; font-size:.9rem; font-family:inherit}
.tab-btn.is-active{background:var(--surface); color:var(--primary); box-shadow:var(--shadow)}
.tab-panel{display:none} .tab-panel.is-active{display:block}

/* Search results */
.results{margin-top:.7rem; display:flex; flex-direction:column; gap:.4rem}
.result{display:flex; justify-content:space-between; align-items:center; padding:.6rem .8rem;
  border:1px solid var(--border); border-radius:10px; cursor:pointer; background:var(--surface)}
.result:hover{border-color:var(--primary); background:var(--primary-soft)}
.result small{color:var(--muted)}

/* Camera */
.file-drop{display:grid; place-items:center; min-height:150px; border:2px dashed var(--border);
  border-radius:14px; cursor:pointer; text-align:center; padding:1rem; color:var(--muted); margin-bottom:.8rem}
.file-drop img{max-width:100%; max-height:260px; border-radius:12px}
.ai-status{padding:.7rem; text-align:center; color:var(--muted); font-size:.9rem}
.empty-ai{text-align:center; padding:1.5rem 1rem}
.empty-ai code{background:var(--surface-2); padding:.1rem .35rem; border-radius:6px; font-size:.85rem}
.spinner{width:22px; height:22px; border:3px solid var(--border); border-top-color:var(--primary);
  border-radius:50%; animation:spin .8s linear infinite; display:inline-block; vertical-align:middle}
@keyframes spin{to{transform:rotate(360deg)}}

/* BMI scale */
.bmi-scale{margin:1.2rem 0}
.bmi-bar{position:relative; height:14px; border-radius:99px;
  background:linear-gradient(90deg,var(--info) 0%,var(--info) 14%,var(--success) 14%,var(--success) 40%,var(--warning) 40%,var(--warning) 60%,var(--danger) 60%)}
.bmi-bar .marker{position:absolute; top:-5px; width:6px; height:24px; background:var(--text); border-radius:99px; transform:translateX(-50%); border:2px solid var(--surface)}
.bmi-legend{display:flex; justify-content:space-between; font-size:.72rem; color:var(--muted); margin-top:.3rem}
.legend-list{list-style:none; padding:0; margin:0 0 .8rem; display:flex; flex-direction:column; gap:.5rem}
.legend-list li{display:flex; align-items:center; gap:.6rem}

/* Auth */
.auth-body{background:linear-gradient(160deg,var(--primary),#7c3aed); min-height:100vh}
.auth-wrap{display:grid; place-items:center; min-height:100vh; padding:1.2rem}
.auth-card{background:var(--surface); border-radius:20px; padding:2rem 1.6rem; width:100%; max-width:400px; box-shadow:0 20px 50px rgba(0,0,0,.25)}
.auth-card h1{text-align:center; margin-bottom:.2rem}
.auth-card>.muted{text-align:center; margin-top:0}

/* Hero / weight journey */
.hero{background:linear-gradient(135deg,var(--primary),#7c3aed); color:#fff; border-radius:var(--radius);
  padding:1.2rem; margin-bottom:1rem; box-shadow:0 8px 24px rgba(79,70,229,.28)}
.hero-top{display:flex; justify-content:space-between; align-items:flex-start}
.hero-lbl{font-size:.78rem; opacity:.85; font-weight:600; text-transform:uppercase; letter-spacing:.03em}
.hero-big{font-size:2.4rem; font-weight:800; line-height:1.1}
.hero-big .unit{font-size:1rem; font-weight:500; opacity:.85; margin-left:.25rem}
.hero-pct{text-align:right; font-size:1.6rem; font-weight:800; line-height:1}
.hero-pct span{display:block; font-size:.7rem; font-weight:600; opacity:.85; text-transform:uppercase}
.journey-bar{height:10px; background:rgba(255,255,255,.25); border-radius:99px; overflow:hidden; margin:.9rem 0 .5rem}
.journey-bar span{display:block; height:100%; background:#fff; border-radius:99px; transition:width .5s}
.journey-ends{display:flex; justify-content:space-between; font-size:.78rem; opacity:.95}
.journey-ends b{font-weight:700} .journey-mid{opacity:1; font-weight:700; text-align:center}

/* Streak badge */
.streak-badge{background:linear-gradient(135deg,#f59e0b,#ef4444); color:#fff; padding:.5rem .8rem;
  border-radius:14px; font-weight:800; font-size:1.1rem; display:flex; align-items:baseline; gap:.3rem; box-shadow:var(--shadow)}
.streak-badge span{font-size:.65rem; font-weight:600; opacity:.9}

.banner-soft{background:var(--surface); border:1px dashed var(--border); color:var(--text); font-weight:500}
.banner-soft b{color:var(--primary)}

/* Weekly / stat tiles */
.week-grid{display:grid; grid-template-columns:repeat(4,1fr); gap:.6rem}
@media(max-width:520px){ .week-grid{grid-template-columns:repeat(2,1fr)} }
.week-tile{background:var(--surface-2); border-radius:12px; padding:.7rem; text-align:center}
.week-tile b{display:block; font-size:1.4rem; font-weight:800; line-height:1.1}
.week-tile span{font-size:.72rem; color:var(--muted); font-weight:600}
.week-tile small{display:block; font-size:.65rem; margin-top:.1rem}

/* Achievements */
.ach-grid{display:grid; grid-template-columns:repeat(3,1fr); gap:.7rem}
.ach{background:var(--surface-2); border-radius:14px; padding:.9rem .5rem; text-align:center}
.ach-ico{font-size:1.8rem; display:block}
.ach-lbl{font-size:.72rem; font-weight:600; color:var(--muted); display:block; margin-top:.25rem}
.ach-off{opacity:.4; filter:grayscale(1)}
.ach-on{background:var(--primary-soft)} .ach-on .ach-lbl{color:var(--primary)}

/* Wizard */
.wizard{background:var(--surface); border-radius:20px; padding:1.8rem 1.4rem; width:100%; max-width:440px;
  box-shadow:0 20px 50px rgba(0,0,0,.25)}
.wiz-brand{font-weight:800; color:var(--primary); font-size:1.05rem; margin-bottom:.6rem}
.wizard h1{font-size:1.5rem; margin:0 0 .2rem}
.wizard>p.muted{margin-top:0}
.wiz-progress{height:6px; background:var(--surface-2); border-radius:99px; overflow:hidden; margin:1rem 0 1.4rem}
.wiz-progress span{display:block; height:100%; width:33%; background:var(--primary); border-radius:99px; transition:width .3s}
.wiz-step{display:none; flex-direction:column; gap:.9rem}
.wiz-step.is-active{display:flex}
.wiz-step h3{font-size:1rem; color:var(--muted)}
.wiz-actions{display:flex; gap:.6rem; margin-top:.3rem}
.wiz-actions .btn{flex:1}
.choice-grid{display:flex; flex-direction:column; gap:.5rem}
.choice{display:block; cursor:pointer}
.choice input{position:absolute; opacity:0}
.choice span{display:block; padding:.75rem 1rem; border:2px solid var(--border); border-radius:12px; font-weight:600; font-size:.95rem}
.choice input:checked+span{border-color:var(--primary); background:var(--primary-soft); color:var(--primary)}

/* Bottom tab bar */
.tabbar{position:fixed; bottom:0; left:0; right:0; z-index:20; display:flex;
  background:var(--surface); border-top:1px solid var(--border);
  padding-bottom:env(safe-area-inset-bottom)}
.tab{flex:1; display:flex; flex-direction:column; align-items:center; gap:.15rem; padding:.55rem 0;
  color:var(--muted); font-size:.68rem; font-weight:600}
.tab-ico{font-size:1.35rem}
.tab.is-active{color:var(--primary)}
