/* ============================================================
   CaloriTrack — premium dark iOS theme
   ============================================================ */
:root {
  --bg: #000000;
  --bg-elev: #0e0f12;
  --card: rgba(28, 28, 32, 0.72);
  --card-solid: #16171b;
  --stroke: rgba(255, 255, 255, 0.08);
  --stroke-strong: rgba(255, 255, 255, 0.14);
  --text: #f5f6f7;
  --text-dim: #9a9ba1;
  --text-faint: #6b6c72;
  --green: #34d36b;
  --green-dim: rgba(52, 211, 107, 0.16);
  --blue: #3b9dff;
  --orange: #ff9f3b;
  --red: #ff5a5f;
  --radius: 22px;
  --radius-sm: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', system-ui, sans-serif;
  color: var(--text);
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

/* ambient glow */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(120% 60% at 80% -10%, rgba(52, 211, 107, 0.12), transparent 60%),
    radial-gradient(100% 50% at -10% 0%, rgba(59, 157, 255, 0.08), transparent 55%),
    var(--bg);
}

/* ---------------- top bar ---------------- */
#topbar {
  position: sticky; top: 0; z-index: 30;
  padding-top: var(--safe-top);
  background: linear-gradient(180deg, rgba(0,0,0,0.85), rgba(0,0,0,0.4) 70%, transparent);
  backdrop-filter: blur(14px);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px 12px;
}
.greeting { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.subtle { font-size: 13px; color: var(--text-dim); margin: 2px 0 0; }
.chip {
  background: var(--card); border: 1px solid var(--stroke);
  color: var(--text); font-size: 13px; font-weight: 600;
  padding: 8px 12px; border-radius: 12px; backdrop-filter: blur(10px);
}

/* ---------------- layout ---------------- */
#app {
  padding: 8px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
  max-width: 520px; margin: 0 auto;
}
.view { animation: fade 0.35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------- cards ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 18px;
  margin: 14px 0;
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}
.card h2, .card h3 { margin: 0 0 12px; font-weight: 650; letter-spacing: -0.01em; }
.card h3 { font-size: 15px; color: var(--text-dim); font-weight: 600; }
.section-title { font-size: 13px; color: var(--text-faint); text-transform: none;
  font-weight: 600; margin: 22px 4px 2px; }

/* calories big number */
.big-kcal { display: flex; align-items: baseline; gap: 8px; }
.big-kcal .num { font-size: 40px; font-weight: 750; letter-spacing: -0.03em; }
.big-kcal .den { font-size: 16px; color: var(--text-dim); }
.pct-right { float: right; color: var(--text-dim); font-size: 14px; font-weight: 600; }

/* progress bars */
.bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,0.08); overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--green);
  transition: width 0.6s cubic-bezier(.2,.8,.2,1); }
.bar.blue > span { background: var(--blue); }
.bar.orange > span { background: var(--orange); }

/* macro row */
.macros { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; margin-top: 18px; }
.macro .label { font-size: 13px; color: var(--text-dim); }
.macro .val { font-size: 20px; font-weight: 700; margin-top: 2px; }
.macro .sub { font-size: 12px; color: var(--text-faint); }

/* metabolism card */
.metab-flex { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.metab-num { font-size: 34px; font-weight: 750; letter-spacing: -0.03em; }
.metab-num small { font-size: 15px; color: var(--text-dim); font-weight: 500; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--green-dim); color: var(--green);
  border: 1px solid rgba(52,211,107,0.3);
  padding: 8px 12px; border-radius: 14px; font-size: 13px; font-weight: 650;
}
.badge.gray { background: rgba(255,255,255,0.06); color: var(--text-dim); border-color: var(--stroke); }

/* confidence meter */
.confidence { margin-top: 14px; }
.confidence .row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-dim); }

/* state pill card */
.state-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.state-card .icon-circle {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--green); color: #04210f;
  font-size: 20px; font-weight: 800;
}
.state-deficit .icon-circle { background: var(--green); }
.state-surplus .icon-circle { background: var(--orange); color:#2a1602; }
.state-maintain .icon-circle { background: var(--blue); color:#021a33; }
.state-title { font-size: 17px; font-weight: 700; }
.state-deficit .state-title { color: var(--green); }
.state-surplus .state-title { color: var(--orange); }
.state-maintain .state-title { color: var(--blue); }
.state-desc { font-size: 13px; color: var(--text-dim); margin-top: 3px; }

/* charts */
.chart-wrap { position: relative; height: 180px; margin-top: 8px; }

/* lists */
.entry { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--stroke); }
.entry:last-child { border-bottom: none; }
.entry .e-main { flex: 1; min-width: 0; }
.entry .e-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .e-sub { font-size: 12px; color: var(--text-faint); }
.entry .e-kcal { font-weight: 700; font-size: 15px; }
.entry .e-del { color: var(--red); background: none; border: none; font-size: 20px; padding: 4px 8px; }
.thumb { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; background: var(--card-solid); flex:none; }
.icon-food { width:40px;height:40px;border-radius:10px;background:var(--green-dim);display:grid;place-items:center;color:var(--green);font-weight:700;flex:none; }

/* segmented control */
.segmented { display: flex; background: rgba(255,255,255,0.06); border-radius: 12px; padding: 3px; gap: 3px; margin: 4px 0 12px; }
.segmented button { flex: 1; border: none; background: transparent; color: var(--text-dim);
  padding: 8px; border-radius: 9px; font-weight: 600; font-size: 13px; }
.segmented button.active { background: var(--card-solid); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.4); }

/* search + inputs */
.search { width: 100%; background: var(--card-solid); border: 1px solid var(--stroke);
  color: var(--text); padding: 13px 14px; border-radius: var(--radius-sm); font-size: 16px; }
.search::placeholder { color: var(--text-faint); }
input, select { font-family: inherit; }
.field { margin: 12px 0; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; background: var(--card-solid); border: 1px solid var(--stroke);
  color: var(--text); padding: 12px 14px; border-radius: var(--radius-sm); font-size: 16px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* buttons */
.btn { width: 100%; border: none; border-radius: var(--radius-sm); padding: 15px;
  font-size: 16px; font-weight: 700; background: var(--green); color: #04210f; margin-top: 8px; }
.btn:active { transform: scale(0.98); }
.btn.secondary { background: var(--card-solid); color: var(--text); border: 1px solid var(--stroke); }
.btn.ghost { background: transparent; color: var(--green); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { margin-top: 0; }

/* small add btn in lists */
.add-btn { width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--green); color: #04210f; font-size: 22px; font-weight: 700; flex: none; }

/* tab bar */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex; align-items: center; justify-content: space-around;
  background: rgba(12,12,14,0.8); backdrop-filter: blur(24px) saturate(160%);
  border-top: 1px solid var(--stroke);
}
.tab { background: none; border: none; color: var(--text-faint);
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10px; font-weight: 600;
  flex: 1; padding: 6px 0; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--green); }
.tab-add { flex: 0 0 auto; }
.fab { width: 52px; height: 52px; border-radius: 50%; background: var(--green); color: #04210f;
  display: grid; place-items: center; font-size: 30px; font-weight: 400; margin-top: -18px;
  box-shadow: 0 6px 20px rgba(52,211,107,0.45); }

/* bottom sheet */
.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet.hidden { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(4px); }
.sheet-card {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--bg-elev); border-top-left-radius: 26px; border-top-right-radius: 26px;
  border-top: 1px solid var(--stroke-strong);
  padding: 10px 18px calc(24px + var(--safe-bottom));
  max-height: 88vh; overflow-y: auto; animation: sheetUp 0.32s cubic-bezier(.2,.9,.2,1);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 99px; background: var(--stroke-strong);
  margin: 6px auto 14px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 24px); transform: translateX(-50%);
  background: var(--card-solid); border: 1px solid var(--stroke-strong); color: var(--text);
  padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 600; z-index: 80;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5); animation: fade 0.25s ease; }
.toast.hidden { display: none; }
.toast.err { border-color: var(--red); color: #ffb4b6; }

/* misc */
.hidden { display: none !important; }
.muted { color: var(--text-dim); font-size: 13px; }
.center { text-align: center; }
.spacer { height: 8px; }
.rangebar { height: 6px; border-radius: 99px; background: rgba(255,255,255,0.08); position: relative; margin: 10px 0; }
.rangebar .fill { position: absolute; height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--blue), var(--green)); }
.rangebar .dot { position: absolute; top: 50%; width: 12px; height: 12px; border-radius: 50%;
  background: #fff; transform: translate(-50%,-50%); box-shadow: 0 0 0 3px rgba(255,255,255,0.15); }
.kv { display:flex; justify-content:space-between; padding:9px 0; border-bottom:1px solid var(--stroke); font-size:14px; }
.kv:last-child { border-bottom:none; }
.kv .k { color: var(--text-dim); }
.kv .v { font-weight:650; }
.empty { text-align:center; color: var(--text-faint); padding: 30px 10px; font-size: 14px; }
.brand-row { display:flex; align-items:center; gap:10px; }
.logo { font-size: 26px; }
.logo-text b { color: var(--green); }
.off-credit { font-size: 11px; color: var(--text-faint); text-align:center; margin-top: 10px; }
