:root {
  --bg: #121212; --card: #202020; --card2: #2c2c2c; --line: #333; --text: #f2f2f2; --dim: #9a9a9a;
  --kcal: #5b9bff; --p: #ff8a65; --f: #ffd24d; --c: #5cc08a; --w: #b08cff; --x: #ff8a65;
  --radius: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-top: env(safe-area-inset-top); }
#view { padding: 14px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
h1 { font-size: 30px; letter-spacing: .02em; text-transform: uppercase; margin: 8px 0 14px; font-weight: 800; }
h2 { font-size: 22px; margin: 22px 0 10px; font-weight: 700; }
h3 { font-size: 18px; margin: 0 0 6px; font-weight: 600; }
.dim { color: var(--dim); }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.topbar h1 { margin: 0; font-size: 22px; flex: 1; text-align: center; text-transform: none; font-weight: 600; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--card2); border: 0; color: var(--text); display: grid; place-items: center; cursor: pointer; font-size: 18px; }
.icon-btn svg, #nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#nav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; align-items: center; background: #161616; border-top: 1px solid var(--line); padding: 8px 4px calc(8px + env(safe-area-inset-bottom)); z-index: 5; }
#nav a { color: var(--dim); text-decoration: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; min-width: 64px; }
#nav a.on { color: var(--text); }
#nav a.on svg { fill: currentColor; }
#addBtn { width: 58px; height: 58px; border-radius: 50%; background: #fff; border: 0; color: #111; display: grid; place-items: center; margin-top: -16px; cursor: pointer; }
#addBtn svg { width: 28px; height: 28px; fill: none; stroke: #111; stroke-width: 2.5; stroke-linecap: round; }

/* gauge and bars */
.gauge { position: relative; height: 230px; }
.gauge svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.gauge .mid { position: absolute; left: 0; right: 0; top: 70px; text-align: center; }
.gauge .mid b { font-size: 56px; font-weight: 700; display: block; line-height: 1; }
.gauge .side { position: absolute; top: 80px; text-align: center; }
.gauge .side b { font-size: 28px; display: block; }
.gauge .l { left: 4px; } .gauge .r { right: 4px; }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; text-align: center; }
.bar { height: 10px; background: #333; border-radius: 6px; overflow: hidden; margin: 6px 0; }
.bar i { display: block; height: 100%; border-radius: 6px; }
.seg { display: inline-flex; background: var(--card2); border-radius: 22px; padding: 4px; }
.seg button { border: 0; background: none; color: var(--text); padding: 10px 22px; border-radius: 18px; font: inherit; cursor: pointer; }
.seg button.on { background: #fff; color: #111; }
.center { display: flex; justify-content: center; margin: 14px 0; }

/* week strip */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 8px; }
.day { border: 2px solid #3a3a3a; border-radius: 22px; padding: 10px 0; text-align: center; background: none; color: var(--text); font: inherit; cursor: pointer; position: relative; }
.day small { display: block; color: var(--dim); font-size: 13px; }
.day.on { border-color: var(--kcal); }
.day.today small::after { content: ""; display: block; width: 5px; height: 5px; border-radius: 50%; background: #fff; margin: 3px auto 0; }
.sumrow { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; gap: 8px; font-size: 14px; margin-bottom: 4px; }
.sumrow .bar { height: 4px; }

/* log entries */
.hour { display: flex; align-items: center; gap: 10px; margin: 18px 0 8px; }
.pill { background: var(--card2); border-radius: 20px; padding: 8px 14px; font-size: 14px; }
.hour .tot { margin-left: auto; font-size: 14px; color: var(--dim); display: flex; gap: 14px; }
.entry { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 12px; }
.entry .nm { font-weight: 600; }
.entry .mc { color: var(--dim); font-size: 14px; }
.empty { color: var(--dim); text-align: center; padding: 40px 0; }

/* lists and forms */
.list .item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list .item:last-child { border: 0; }
.list .item .nm { font-weight: 600; }
.list .item .mc { color: var(--dim); font-size: 14px; }
label.f { display: block; margin: 10px 0; font-size: 14px; color: var(--dim); }
input, select { width: 100%; background: var(--card2); border: 1px solid #3c3c3c; color: var(--text); border-radius: 12px; padding: 12px; font: inherit; margin-top: 4px; }
input:focus, select:focus { outline: 2px solid var(--kcal); }
.btn { background: #fff; color: #111; border: 0; border-radius: 24px; padding: 13px 22px; font: inherit; font-weight: 600; cursor: pointer; }
.btn.sec { background: var(--card2); color: var(--text); }
.btn.danger { background: #5a2323; color: #ffb4b4; }
.btn:disabled { opacity: .4; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.stat { display: flex; gap: 14px; align-items: flex-start; margin: 14px 0; }
.stat .big { width: 110px; min-height: 90px; background: #2c2c2c; display: grid; place-content: center; text-align: center; border-radius: 6px; padding: 8px; flex: none; }
.stat .big b { font-size: 34px; line-height: 1; }
.stat .big span { color: var(--dim); font-size: 14px; }
.stat p { margin: 0; color: var(--dim); font-size: 15px; }
.stat h3 { color: var(--text); }

/* change table */
.chg { display: grid; grid-template-columns: 54px 70px 1fr 1fr; align-items: center; gap: 8px; padding: 9px 0; color: var(--dim); }
.chg b { color: var(--text); font-weight: 500; }
.chg svg { width: 70px; height: 28px; }

/* ring */
.ringwrap { position: relative; width: 280px; height: 280px; margin: 10px auto; }
.ringwrap svg { width: 100%; height: 100%; }
.ringwrap .mid { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ringwrap .mid b { font-size: 42px; letter-spacing: .02em; }

/* chart */
.chart { width: 100%; height: auto; display: block; }
.ranges { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.ranges .seg { flex: 1; justify-content: space-between; }
.ranges .seg button { padding: 10px 12px; flex: 1; }
.legend { display: flex; justify-content: space-around; font-size: 14px; flex-wrap: wrap; gap: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.kpis { display: flex; gap: 26px; }
.kpis small { color: var(--dim); font-size: 15px; display: block; }
.kpis b { font-size: 38px; font-weight: 500; }
.kpis b span { font-size: 16px; color: var(--dim); font-weight: 400; }

/* sheet */
#sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; }
#sheet[hidden], #toast[hidden] { display: none; }
.panel { background: #1b1b1b; width: 100%; max-width: 640px; margin: 0 auto; border-radius: 26px 26px 0 0; max-height: 92vh; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
.panel .grab { width: 54px; height: 5px; background: #3a3a3a; border-radius: 3px; margin: 10px auto 4px; }
.panel .head { display: flex; align-items: center; gap: 10px; padding: 6px 14px 10px; }
.panel .tabs { display: flex; border-bottom: 2px solid #333; }
.panel .tabs button { flex: 1; background: none; border: 0; color: var(--dim); padding: 12px 4px; font: inherit; border-bottom: 3px solid transparent; margin-bottom: -2px; cursor: pointer; }
.panel .tabs button.on { color: #fff; border-color: #fff; }
.panel .body { overflow: auto; padding: 12px 16px 24px; }
.add { width: 40px; height: 40px; border-radius: 50%; background: var(--card2); border: 0; color: var(--text); font-size: 22px; cursor: pointer; flex: none; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 110px; background: #fff; color: #111; padding: 10px 18px; border-radius: 20px; z-index: 30; font-weight: 600; }
.pre { background: var(--card2); border-radius: 12px; padding: 10px; font-size: 14px; color: var(--dim); margin: 8px 0; }
.warn { color: #ffb86b; font-size: 14px; }
.note { color: var(--dim); font-size: 14px; margin: 6px 0; }
