:root { --bg:#f6f7f9; --card:#fff; --ink:#1c2430; --muted:#6b7684; --line:#e5e8ec; --accent:#3b82f6; --over:#e74c3c; --good:#12a150; --p:#3b82f6; --c:#f59e0b; --f:#a855f7; }
[data-theme="dark"] { --bg:#0f1419; --card:#1a212b; --ink:#e6e9ee; --muted:#94a2b3; --line:#2b3441; --accent:#3b82f6; --over:#f0676c; --good:#2ea36b; }
* { box-sizing:border-box; }
[hidden] { display:none !important; }
html { -webkit-text-size-adjust:100%; }
body { margin:0; font:16px/1.45 system-ui,-apple-system,Segoe UI,Roboto,sans-serif; background:var(--bg); color:var(--ink); padding-bottom:env(safe-area-inset-bottom); }
body.noscroll { overflow:hidden; }
.wrap { max-width:720px; margin:0 auto; padding:12px 14px 40px; padding-top:calc(12px + env(safe-area-inset-top)); }
.topbar { display:flex; align-items:center; gap:10px; margin-bottom:12px; }
.topbar h1 { font-size:19px; margin:0; }
.brand { color:inherit; text-decoration:none; }
.nav { display:flex; gap:0; flex:1; overflow-x:auto; -webkit-overflow-scrolling:touch; scrollbar-width:none; }
.nav::-webkit-scrollbar { display:none; }
.nav a { color:var(--muted); text-decoration:none; padding:8px 7px; border-radius:9px; font-size:13.5px; white-space:nowrap; min-height:40px; display:flex; align-items:center; }
.nav a.on { background:var(--card); color:var(--ink); font-weight:600; box-shadow:0 1px 3px rgba(0,0,0,.06); }
.theme-toggle { border:0; background:transparent; cursor:pointer; font-size:17px; min-width:40px; min-height:40px; border-radius:8px; }
.login { max-width:320px; margin:12vh auto; background:var(--card); padding:28px; border-radius:14px; box-shadow:0 1px 3px rgba(0,0,0,.08); }
.login h1 { margin:0 0 16px; font-size:20px; }
.login input { width:100%; padding:12px; border:1px solid var(--line); border-radius:9px; font-size:16px; margin-bottom:12px; background:var(--card); color:var(--ink); }
.login button { width:100%; padding:12px; border:0; border-radius:9px; background:var(--accent); color:#fff; font-size:16px; cursor:pointer; }
.error { color:var(--over); font-size:14px; }
.muted { color:var(--muted); }
.small { font-size:12.5px; }
.card { background:var(--card); border-radius:14px; box-shadow:0 1px 3px rgba(0,0,0,.06); padding:14px 16px; margin-bottom:12px; }
[data-theme="dark"] .card, [data-theme="dark"] .kpi { box-shadow:0 1px 3px rgba(0,0,0,.4); }
.card-title { margin:0 0 10px; font-size:15px; display:flex; align-items:center; gap:8px; }
a { color:var(--accent); }

.daynav { display:flex; align-items:center; justify-content:space-between; margin-bottom:10px; }
.daylbl { font-weight:700; font-size:17px; }
.summary { display:flex; gap:16px; align-items:center; }
.ring-wrap { flex:0 0 auto; }
.ring { --p:0; width:128px; height:128px; border-radius:50%; background:conic-gradient(var(--accent) calc(var(--p)*1%), var(--line) 0); display:grid; place-items:center; transition:background .3s; }
.ring.over { background:conic-gradient(var(--over) calc(var(--p)*1%), var(--line) 0); }
.ring-in { width:104px; height:104px; border-radius:50%; background:var(--card); display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; }
.ring-num { font-size:26px; font-weight:800; line-height:1; }
.ring-sub { font-size:12px; color:var(--muted); margin-top:3px; }
.ring-left { font-size:11.5px; color:var(--muted); margin-top:2px; }
.tap { text-decoration:underline dotted; cursor:pointer; }
.macros { flex:1; min-width:0; display:flex; flex-direction:column; gap:8px; }
.macro-h { display:flex; justify-content:space-between; font-size:13px; }
.bar { height:8px; border-radius:999px; background:var(--line); overflow:hidden; margin-top:3px; }
.bar-fill { height:100%; border-radius:999px; background:var(--accent); transition:width .3s; }
.m-protein { background:var(--p); } .m-carbs { background:var(--c); } .m-fat { background:var(--f); }

.actions { display:grid; grid-template-columns:1.4fr 1fr 1fr; gap:8px; margin-bottom:10px; }
.btn { border:0; border-radius:10px; background:var(--accent); color:#fff; font-size:15px; padding:10px 16px; cursor:pointer; min-height:44px; }
.btn.big { font-size:16px; font-weight:600; min-height:52px; }
.btn.alt { background:var(--card); color:var(--ink); box-shadow:0 1px 3px rgba(0,0,0,.08); }
.btn-sm { border:0; border-radius:8px; padding:8px 12px; font-size:14px; cursor:pointer; background:var(--line); color:var(--ink); min-height:40px; min-width:40px; text-decoration:none; display:inline-flex; align-items:center; justify-content:center; }
.linkbtn { background:none; border:0; color:var(--accent); font-size:inherit; cursor:pointer; padding:0; text-decoration:underline; }
.chips { display:flex; gap:6px; overflow-x:auto; -webkit-overflow-scrolling:touch; padding:2px 0 8px; scrollbar-width:none; }
.chips::-webkit-scrollbar { display:none; }
.chip { flex:0 0 auto; border:1px solid var(--line); background:var(--card); color:var(--ink); border-radius:999px; padding:8px 12px; font-size:13.5px; cursor:pointer; min-height:38px; white-space:nowrap; }

.entries, .meds, .medlist, .findlist { list-style:none; margin:0; padding:0; }
.entries li { display:flex; align-items:center; gap:10px; padding:9px 0; border-bottom:1px solid var(--line); cursor:pointer; }
.entries li:last-child { border-bottom:0; }
.entries li.empty { cursor:default; }
.e-main { flex:1; min-width:0; }
.e-name { font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.e-kcal { font-weight:700; font-variant-numeric:tabular-nums; }
.x { border:0; background:transparent; color:var(--muted); font-size:22px; line-height:1; cursor:pointer; min-width:40px; min-height:40px; border-radius:8px; }
.x:hover { color:var(--over); background:var(--line); }
.med { display:flex; align-items:center; gap:10px; padding:8px 0; border-bottom:1px solid var(--line); cursor:pointer; min-height:44px; }
.meds li:last-child .med { border-bottom:0; }
.med input { width:22px; height:22px; accent-color:var(--good); }
.med.taken .med-name { text-decoration:line-through; color:var(--muted); }
.medlist li { display:flex; justify-content:space-between; align-items:center; padding:8px 0; border-bottom:1px solid var(--line); gap:10px; }
.medlist li.off { opacity:.5; }
.medlist li:last-child { border-bottom:0; }

.overlay { position:fixed; inset:0; background:rgba(0,0,0,.55); z-index:50; display:flex; align-items:flex-end; justify-content:center; }
.sheet { background:var(--card); width:100%; max-width:560px; border-radius:16px 16px 0 0; padding:16px 16px calc(16px + env(safe-area-inset-bottom)); max-height:88vh; overflow-y:auto; display:flex; flex-direction:column; gap:10px; }
.sheet-h { display:flex; flex-direction:column; gap:2px; }
.sheet-h b { font-size:17px; }
.sheet label, .pform label { display:flex; flex-direction:column; gap:3px; font-size:13px; color:var(--muted); }
.sheet input:not([type=checkbox]), .pform input:not([type=checkbox]), .pform select, .searchrow input { width:100%; padding:10px 12px; border:1px solid var(--line); border-radius:9px; font-size:16px; background:var(--bg); color:var(--ink); min-height:44px; }
.grid4 { display:grid; grid-template-columns:repeat(4,1fr); gap:8px; }
@media (max-width:480px) { .grid4 { grid-template-columns:repeat(2,1fr); } }
.grams-row { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.grams-row input { width:110px !important; font-size:22px !important; font-weight:700; }
.quick { display:flex; gap:6px; flex-wrap:wrap; }
.sh-calc { font-size:15px; }
.sheet-btns { display:flex; gap:8px; align-items:center; margin-top:4px; }
.grow { flex:1; }
.findlist { max-height:50vh; overflow-y:auto; }
.findlist li { display:flex; justify-content:space-between; gap:10px; padding:10px 0; border-bottom:1px solid var(--line); cursor:pointer; }
.pform.row { flex-direction:row; display:flex; gap:8px; align-items:end; flex-wrap:wrap; }
.pform.row input { flex:1; min-width:140px; }
.pform { display:flex; flex-direction:column; gap:8px; }
.chk { flex-direction:row !important; align-items:center; font-size:14px !important; color:var(--ink) !important; gap:8px !important; }
.searchrow { display:flex; gap:8px; margin-bottom:10px; }

#scan-ov { align-items:center; background:#000; }
.scan-box { position:relative; width:100%; height:100%; display:flex; align-items:center; justify-content:center; }
#scan-video { width:100%; height:100%; object-fit:cover; }
.scan-frame { position:absolute; width:min(80vw,360px); height:160px; border:3px solid rgba(255,255,255,.85); border-radius:14px; box-shadow:0 0 0 100vmax rgba(0,0,0,.35); pointer-events:none; }
.scan-hint { position:absolute; top:calc(24px + env(safe-area-inset-top)); left:0; right:0; text-align:center; color:#fff; font-weight:600; text-shadow:0 1px 3px #000; }
.scan-manual { position:absolute; bottom:calc(28px + env(safe-area-inset-bottom)); left:16px; right:16px; display:flex; gap:8px; }
.scan-manual input { flex:1; padding:10px 12px; border-radius:9px; border:0; font-size:16px; min-height:44px; }
.scan-box .close { position:absolute; top:calc(16px + env(safe-area-inset-top)); right:16px; background:rgba(255,255,255,.9); color:#000; }

.toast { position:fixed; left:50%; bottom:calc(24px + env(safe-area-inset-bottom)); transform:translateX(-50%); background:var(--ink); color:var(--bg); padding:10px 16px; border-radius:999px; font-size:14px; z-index:60; box-shadow:0 4px 14px rgba(0,0,0,.3); max-width:90vw; }
.toast.bad { background:var(--over); color:#fff; }

.kpi-row { display:grid; grid-template-columns:repeat(4,1fr); gap:.6rem; margin-bottom:12px; }
.kpi { background:var(--card); border-radius:10px; padding:.6rem .8rem; display:flex; flex-direction:column; gap:.15rem; box-shadow:0 1px 3px rgba(0,0,0,.06); min-width:0; }
.kpi-lbl { font-size:.72rem; color:var(--muted); text-transform:uppercase; letter-spacing:.03em; }
.kpi-val { font-size:1.05rem; font-weight:800; overflow-wrap:anywhere; }
@media (max-width:640px) { .kpi-row { grid-template-columns:repeat(2,1fr); } }
.bars { display:flex; gap:4px; align-items:flex-end; height:170px; margin-bottom:6px; }
.barcol { flex:1; display:flex; flex-direction:column; align-items:center; height:100%; text-decoration:none; color:inherit; min-width:0; }
.barv { font-size:9px; color:var(--muted); height:14px; overflow:hidden; }
.barstack { flex:1; width:100%; background:var(--line); border-radius:4px 4px 0 0; display:flex; align-items:flex-end; overflow:hidden; }
.barfill { width:100%; background:var(--accent); border-radius:4px 4px 0 0; }
.barfill.over { background:var(--over); }
.barlbl { font-size:11px; color:var(--muted); margin-top:3px; }
.barlbl.now { color:var(--ink); font-weight:700; }
table { width:100%; border-collapse:collapse; font-size:13.5px; }
th, td { text-align:left; padding:6px 8px; border-bottom:1px solid var(--line); }
th { color:var(--muted); font-weight:500; font-size:12.5px; }
td.num, th.num { text-align:right; font-variant-numeric:tabular-nums; }
.past-row td { opacity:.45; }
.tablewrap { overflow-x:auto; }
code { background:var(--line); padding:2px 5px; border-radius:5px; font-size:12.5px; word-break:break-all; }
