/* Calories: a phone-first food log. One column, a bottom tab bar with a big Add button,
   sheets that slide up for adding food. Light and dark follow the phone. */
:root {
  --bg: #F4F6F1; --surface: #FFFFFF; --sunk: #E8ECE4; --line: #D7DDD2;
  --fg: #1B2620; --muted: #5E6B63;
  --accent: #2F7A4F; --accent-ink: #FFFFFF; --accent-soft: #DDEFE3;
  --protein: #3D63B8; --carbs: #C27A12; --fat: #B0436A;
  --over: #B3361F; --over-soft: #F8E1DB;
  --radius: 16px;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111612; --surface: #1A211C; --sunk: #232C25; --line: #2F3A32;
    --fg: #E8EEE9; --muted: #9AA89F;
    --accent: #5DBB82; --accent-ink: #0D1A12; --accent-soft: #1E3628;
    --protein: #7E9EEA; --carbs: #E0A548; --fat: #E07BA0;
    --over: #F07A63; --over-soft: #3A201B;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.4 var(--body); -webkit-text-size-adjust: 100%; }
body { padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }

/* Top bar */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.day-btn { border: 0; background: none; font-weight: 700; font-size: 18px; padding: 6px 12px; border-radius: 10px; min-width: 150px; }
.icon-btn { border: 0; background: var(--sunk); width: 40px; height: 40px; border-radius: 50%; font-size: 22px; line-height: 1; display: grid; place-items: center; flex: none; }
.icon-btn:active { transform: scale(.95); }

main { max-width: 560px; margin: 0 auto; padding: 4px 16px 24px; }
body.no-top main { padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }

.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: 0 1px 0 var(--line); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }

/* Calorie ring */
.summary { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: center; }
.ring { position: relative; width: 150px; height: 150px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--sunk); }
.ring .fill { stroke: var(--accent); transition: stroke-dashoffset .4s; }
.ring.over .fill { stroke: var(--over); }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-label b { font-size: 30px; line-height: 1; }
.ring-label span { font-size: 13px; color: var(--muted); }
.ring.over .ring-label b { color: var(--over); }
.stat-row { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; }
.stat-row b { font-weight: 600; }

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.macro .bar { height: 8px; border-radius: 4px; background: var(--sunk); overflow: hidden; margin: 6px 0 4px; }
.macro .bar i { display: block; height: 100%; border-radius: 4px; }
.macro.protein i { background: var(--protein); }
.macro.carbs i { background: var(--carbs); }
.macro.fat i { background: var(--fat); }
.macro .name { font-size: 13px; color: var(--muted); }
.macro .val { font-size: 14px; font-weight: 600; }

/* Meal sections */
.meal-head { display: flex; align-items: baseline; justify-content: space-between; }
.meal-head h3 { text-transform: capitalize; }
.entry { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.entry + .entry { border-top: 1px solid var(--line); }
.entry .what { flex: 1; min-width: 0; }
.entry .what div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .kcal { font-weight: 600; white-space: nowrap; }
.x { border: 0; background: none; color: var(--muted); font-size: 18px; width: 32px; height: 32px; border-radius: 50%; flex: none; }
.x:active { background: var(--sunk); }
.meal-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* Buttons */
.btn { border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 600; background: var(--sunk); min-height: 44px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 7px 12px; min-height: 36px; font-size: 14px; }
.btn.ghost { background: none; color: var(--accent); padding-left: 4px; padding-right: 4px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row .btn { flex: 1; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.quick button { border: 0; background: var(--surface); border-radius: 14px; padding: 12px 4px; font-size: 13px; font-weight: 600; display: grid; gap: 4px; justify-items: center; box-shadow: 0 1px 0 var(--line); }
.quick button span { font-size: 22px; }

/* Forms */
label.field { display: block; margin: 10px 0; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=search], input[type=date], select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 12px; font-size: 16px; min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grid4 label.field > span { font-size: 12px; }
.seg { display: flex; background: var(--sunk); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px 4px; font-size: 14px; font-weight: 600; text-transform: capitalize; }
.seg button.on { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.err { color: var(--over); font-size: 14px; margin: 8px 0 0; }

/* Food lists */
.list { margin: 0; padding: 0; list-style: none; }
.food { display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.list > .food:first-child { border-top: 0; }
.food .what { flex: 1; min-width: 0; }
.food .what div:first-child { font-weight: 500; }
.food .kcal { font-weight: 600; white-space: nowrap; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 6px; background: var(--sunk); color: var(--muted); margin-left: 4px; vertical-align: 1px; }
.tag.mine { background: var(--accent-soft); color: var(--accent); }
.section-label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 4px; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; font-size: 15px; }

/* Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
}
.tabs button { border: 0; background: none; display: grid; justify-items: center; gap: 1px; font-size: 11px; color: var(--muted); padding: 4px 0; font-weight: 600; }
.tabs .ti { font-size: 20px; line-height: 26px; }
.tabs button.on { color: var(--accent); }
.tabs .add-tab .ti { background: var(--accent); color: var(--accent-ink); width: 46px; height: 46px; line-height: 46px; border-radius: 50%; font-size: 26px; margin-top: -18px; box-shadow: 0 3px 10px rgba(0,0,0,.2); text-align: center; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  border-radius: 20px 20px 0 0; padding: 14px 16px calc(20px + env(safe-area-inset-bottom, 0px)); animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .6; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; position: sticky; top: -14px; background: var(--bg); padding: 4px 0; z-index: 1; }

.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; z-index: 30; max-width: calc(100% - 32px); }

/* Charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); }
.chart .goal { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1.5; }
.chart .bar { fill: var(--accent); }
.chart .bar.over { fill: var(--over); }
.chart .target { stroke: var(--fg); stroke-width: 1.5; stroke-dasharray: 3 3; opacity: .6; }
.big-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; margin-top: 10px; }
.big-stats b { display: block; font-size: 20px; }
.big-stats span { font-size: 12px; color: var(--muted); }

.photo-preview { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; display: block; margin-bottom: 8px; }
.check-item { display: grid; grid-template-columns: 28px 1fr 80px; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.check-item input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.check-item input[type=number] { padding: 8px; min-height: 38px; }
.note { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 8px 0; }
@media (max-width: 370px) { .summary { grid-template-columns: 120px 1fr; } .ring { width: 120px; height: 120px; } .ring-label b { font-size: 24px; } }
