:root {
  --c-protein: #2f9e6e; --c-carbs: #3b82c4; --c-fat: #d9962b; --c-alcohol: #9a6bc9;
  --bg: #f6f7f5; --card: #ffffff; --text: #1d2420; --muted: #66706a; --line: #dfe3df;
  --accent: #2f7d5b; --accent-ink: #ffffff; --bad: #c2462e; --good: #2f7d5b; --track: #e8ece8;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #131715; --card: #1c211e; --text: #e7ece8; --muted: #9aa49e; --line: #2d3430;
    --accent: #5cbf8f; --accent-ink: #0d1a13; --bad: #ef7b62; --good: #5cbf8f; --track: #2a312d; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line); padding: calc(8px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 0 calc(16px + env(safe-area-inset-left)); }
.topbar h1 { font-size: 18px; margin: 0 0 6px; color: var(--accent); }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-bottom: 3px solid transparent; border-radius: 0; color: var(--muted); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
main { max-width: 760px; margin: 0 auto; padding: 12px calc(16px + env(safe-area-inset-right)) calc(80px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
.tab { display: none; } .tab.active { display: block; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
h2 { font-size: 18px; margin: 0 0 10px; } h3 { font-size: 15px; margin: 0 0 8px; }
button, .button-like { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; display: inline-block; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; }
button.small { padding: 4px 10px; font-size: 13px; }
button.icon { border: 0; background: none; color: var(--muted); padding: 4px 8px; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); max-width: 100%; }
input[type=search], textarea, label > input[type=text], label > input[type=password] { width: 100%; }
label { display: block; margin: 6px 0; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin-right: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.row.end { justify-content: flex-end; }
.row > input[type=search] { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 12px; }
.grid2 input { width: 100%; }
.hint { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.datebar { display: flex; gap: 6px; align-items: center; }
.datebar input { flex: 1; min-width: 0; }
.sum-head { display: flex; justify-content: space-around; text-align: center; margin-bottom: 6px; }
.big { font-size: 22px; font-weight: 700; } .over { color: var(--bad); }
.pbar { margin: 6px 0; }
.pbar-label { display: flex; justify-content: space-between; font-size: 13px; }
.pbar-track { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.pbar-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.pbar-fill.bad { background: var(--bad); }
.meal-head { display: flex; align-items: center; gap: 8px; } .meal-head h3 { margin: 0; flex: 1; }
.entry { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.entry-main { flex: 1; min-width: 0; cursor: pointer; overflow-wrap: anywhere; }
.entry-kcal { font-weight: 600; }
.empty { padding: 6px 0; }
.results { max-height: 50vh; overflow-y: auto; }
.result { display: flex; flex-direction: column; align-items: flex-start; width: 100%; text-align: left; margin: 4px 0; gap: 2px; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--track); color: var(--muted); margin-left: 4px; white-space: nowrap; }
.tag-recipe, .tag-custom { background: var(--accent); color: var(--accent-ink); }
.food-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }
.ntable { width: 100%; border-collapse: collapse; font-size: 14px; }
.ntable th, .ntable td { text-align: left; padding: 5px 4px; border-bottom: 1px solid var(--line); }
.ntable tr.click { cursor: pointer; } .ntable tr.click:hover { background: var(--track); }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); width: min(560px, calc(100vw - 24px)); padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-body { padding: 16px; max-height: 85vh; overflow-y: auto; }
.chart svg { width: 100%; height: auto; }
.chart .bar { fill: var(--accent); } .chart .bar.over { fill: var(--bad); }
.chart .goal { stroke: var(--muted); stroke-dasharray: 4 4; }
.chart .baseline { stroke: var(--line); }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; } .chart .dot { fill: var(--accent); }
.banner { background: var(--accent); color: var(--accent-ink); padding: 10px 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.banner span { flex: 1; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: calc(100vw - 32px); }
#scan-video { width: 100%; border-radius: 8px; }
details summary { cursor: pointer; font-weight: 600; }
code { font-size: 12px; }

/* iPhone: 16px inputs stop Safari zooming in on focus; bigger tap targets */
html { -webkit-text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
input, select, textarea { font-size: 16px; }
@media (pointer: coarse) {
  button { min-height: 40px; }
  button.small { min-height: 34px; }
  button.icon { min-width: 40px; }
}
[hidden] { display: none !important; }
.sync-badge { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.sync-badge.err { color: var(--bad); }
/* barcode scanner */
.scan-view { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; }
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-guide { position: absolute; left: 10%; right: 10%; top: 30%; bottom: 30%; border: 3px solid rgba(255,255,255,.9); border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); }
#scan-status { min-height: 2.6em; }
/* search filters */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 8px; }
.chip { border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tag-restaurant { background: #c77d2e; color: #fff; }
.attribution { font-size: 11px; }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.quick-actions button { padding: 12px; font-size: 15px; font-weight: 600; }

/* food screen (full-height sheet) */
dialog.sheet { width: 100vw; max-width: 640px; height: 100dvh; max-height: 100dvh; margin: 0 auto; border-radius: 0; border: 0; padding: 0; }
@media (min-width: 700px) { dialog.sheet { height: 92vh; max-height: 92vh; margin-top: 4vh; border-radius: var(--radius); border: 1px solid var(--line); } }
.sheet-form { display: flex; flex-direction: column; height: 100%; }
.sheet-head { position: relative; display: flex; align-items: center; gap: 6px; padding: calc(10px + env(safe-area-inset-top)) 10px 10px; border-bottom: 1px solid var(--line); background: var(--card); }
.sheet-head h2 { flex: 1; margin: 0; text-align: center; font-size: 17px; overflow-wrap: anywhere; }
.sheet-body { flex: 1; overflow-y: auto; padding: 8px 14px 16px; background: var(--bg); -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--card); }
.sheet-foot { display: flex; gap: 8px; }
.sheet-foot button { flex: 1; }
button.wide { width: 100%; padding: 12px; font-size: 16px; font-weight: 600; }
.star { border: 0; background: none; font-size: 22px; padding: 0 4px; color: var(--muted); vertical-align: -2px; }
.star.on { color: #e3a21a; }
.menu { position: absolute; right: 10px; top: calc(100% - 4px); z-index: 10; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); min-width: 230px; overflow: hidden; }
.menu button { display: flex; justify-content: space-between; width: 100%; border: 0; border-radius: 0; border-bottom: 1px solid var(--line); padding: 12px 14px; text-align: left; }
.menu button:last-child { border-bottom: 0; }
.form-rows { padding: 0 14px; }
.frow { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0; padding: 10px 0; border-bottom: 1px solid var(--line); }
.frow:last-child { border-bottom: 0; }
.frow > span { font-weight: 600; }
.frow input, .frow select { width: 55%; text-align: right; }
.meta { margin: 6px 0 4px; }
.meta .hint { margin: 2px 0; }
#amount-preview { font-weight: 600; margin-top: 4px; }
.flag { margin: 6px auto; padding: 6px 10px; border-radius: 8px; background: rgba(217,150,43,.15); color: var(--text); font-size: 13px; max-width: 480px; }

/* report sections */
.rsec { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin: 10px 0; }
.rsec > summary { list-style: none; display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; font-weight: 700; font-size: 16px; cursor: pointer; }
.rsec > summary::-webkit-details-marker { display: none; }
.chev { width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; margin-right: 4px; }
.rsec[open] > summary .chev { transform: rotate(-135deg); }
.rsec-body { padding: 0 14px 12px; }
.rgroup { margin: 14px 0 4px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.nrow { display: block; width: 100%; text-align: left; border: 0; border-radius: 6px; background: none; padding: 6px 2px; margin: 0; min-height: 0; }
.nrow:hover { background: var(--track); }
.nrow-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.nname { font-weight: 600; }
.namt { font-weight: 400; color: var(--muted); font-size: 13px; }
.nlimit { font-size: 10px; padding: 0 5px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-weight: 400; }
.npct { font-size: 13px; color: var(--muted); }
.npct.bad { color: var(--bad); font-weight: 600; }
.ntrack { display: block; height: 8px; margin-top: 4px; background: var(--track); border-radius: 4px; overflow: hidden; }
.nfill { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.nfill.bad { background: var(--bad) !important; }
.nrow.plain .nrow-top { border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.nrow.plain .namt { color: var(--text); }
.ind1 { padding-left: 16px; } .ind2 { padding-left: 32px; } .ind3 { padding-left: 48px; }
.hgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; }
.nrow.compact .nname { font-size: 14px; }
.energy { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: center; }
.ring { width: 140px; height: 140px; }
.ring-num { font-size: 22px; font-weight: 700; fill: var(--text); }
.ring-unit { font-size: 12px; fill: var(--muted); }
.legend { flex: 1; min-width: 170px; }
.legend-row { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; padding: 5px 2px; min-height: 0; text-align: left; }
.legend-row > span:nth-child(2) { flex: 1; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.score { margin: 8px 0; }
.score .hint { font-size: 11px; }
.showmissing { margin-top: 12px; }
.info-body h3 { margin: 14px 0 4px; }
.info-body p { margin: 4px 0; }
.srcs { padding-left: 18px; margin: 4px 0; }
.srcs a { color: var(--accent); }
.disclaimer { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 8px; font-size: 12px; }
.fav-mark { color: #e3a21a; }
.goal-group summary { font-weight: 600; margin: 8px 0; }
details.group { border-top: 1px solid var(--line); }
details.group > summary.entry { border-top: 0; cursor: pointer; list-style: none; }
details.group > summary::-webkit-details-marker { display: none; }
.group-parts { margin-left: 12px; padding-left: 10px; border-left: 3px solid var(--line); }
.entry.part { border-top: 1px dashed var(--line); }
.frow.check { display: flex; align-items: center; gap: 10px; }
.frow.check input { width: auto; }
.photo-add { cursor: pointer; margin-left: auto; }
.photo-strip { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.photo-strip .ph { position: relative; }
.photo-strip img { width: 76px; height: 76px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.ph-x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; border-radius: 50%; line-height: 1; }
.entry-photos { display: flex; gap: 4px; margin-top: 6px; align-items: center; }
.entry-photos img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.photo-view img { width: 100%; border-radius: 8px; margin-bottom: 8px; }
.photo-view { max-height: 70vh; overflow-y: auto; }
.meal-row { margin-bottom: 6px; align-items: center; }
.meal-row input { flex: 1; min-width: 0; }
