:root {
  --bg: #fff6f8;
  --card: #ffffff;
  --ink: #2a1d22;
  --muted: #7a6870;
  --line: #f0dde3;
  --soft: #fceaf0;
  --accent: #c2406a;
  --accent-ink: #ffffff;
  --accent-soft: #fde3ec;
  --c-carb: #d9822b;
  --c-fat: #7f9c2c;
  --c-prot: #3f72af;
  --c-burn: #c2553a;
  --c-weight: #c2406a;
  --good: #2f7d4f;
  --warn: #b7791f;
  --bad: #c0392b;
  --info: #3f72af;
  --grid: #f5e6eb;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171214;
    --card: #211a1d;
    --ink: #f3e9ec;
    --muted: #b09ca4;
    --line: #3a2b31;
    --soft: #2a2024;
    --accent: #f27c9c;
    --accent-ink: #2a0f1a;
    --accent-soft: #3a2129;
    --c-carb: #e89a4c;
    --c-fat: #a3c04a;
    --c-prot: #6d9ad4;
    --c-burn: #e07a5f;
    --c-weight: #f27c9c;
    --good: #4fae76;
    --warn: #e0a64a;
    --bad: #e5675a;
    --info: #6d9ad4;
    --grid: #2c2226;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #171214; --card: #211a1d; --ink: #f3e9ec; --muted: #b09ca4; --line: #3a2b31; --soft: #2a2024;
  --accent: #f27c9c; --accent-ink: #2a0f1a; --accent-soft: #3a2129; --c-carb: #e89a4c; --c-fat: #a3c04a; --c-prot: #6d9ad4;
  --c-burn: #e07a5f; --c-weight: #f27c9c; --good: #4fae76; --warn: #e0a64a; --bad: #e5675a; --info: #6d9ad4;
  --grid: #2c2226; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
button { cursor: pointer; font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* Header */
header.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 6px) 16px 6px;
  border-bottom: 1px solid var(--line);
}
.top-row, .datebar { display: flex; align-items: center; justify-content: space-between; max-width: 640px; margin: 0 auto; }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.logo { width: 28px; height: 28px; display: block; }
.icon-btn { border: 0; background: transparent; font-size: 24px; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; }
.icon-btn:disabled { opacity: .25; }
.date-label { border: 0; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 16px; font-weight: 600; }

main { padding: 12px 16px; max-width: 640px; margin: 0 auto; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0; }
.card h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.card-h { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; margin-bottom: 10px; gap: 8px; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.unit { font-size: 15px; font-weight: 500; color: var(--muted); }
.pos { color: var(--bad); } .neg { color: var(--good); }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px; font-weight: 600; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns.end { justify-content: flex-end; }

input, select, textarea {
  font: inherit; font-size: 16px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); width: 100%; min-width: 0;
}
textarea { min-height: 70px; }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--ink); }
label.chk { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
label.chk input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 380px) { .grid4 { grid-template-columns: 1fr 1fr; } }
.stack > * + * { margin-top: 10px; }

/* Progress bars */
.pbar + .pbar { margin-top: 10px; }
.pbar-h { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.track { height: 8px; border-radius: 99px; background: var(--soft); overflow: hidden; }
.track i { display: block; height: 100%; border-radius: 99px; }
.carb-hero { display: flex; align-items: center; gap: 14px; }
.carb-hero .donut { flex: none; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 4px; vertical-align: 0; }

/* Stats tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--soft); border-radius: 12px; padding: 8px 10px; min-width: 0; }
.tile b { display: block; font-size: 18px; letter-spacing: -0.01em; }
.tile span { font-size: 11px; color: var(--muted); }
@media (max-width: 360px) { .tiles { grid-template-columns: 1fr 1fr; } }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .tap { all: unset; display: block; flex: 1; min-width: 0; cursor: pointer; }
.x-btn { border: 0; background: transparent; color: var(--muted); font-size: 18px; width: 32px; height: 32px; border-radius: 8px; }
.star { border: 0; background: transparent; font-size: 18px; width: 32px; height: 32px; color: var(--muted); }
.star.on { color: #e0a800; }
.empty { color: var(--muted); text-align: center; padding: 14px 0; font-size: 14px; margin: 0; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--soft); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.chip.fav::before { content: "★ "; color: #e0a800; }

.seg { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; }
.seg button { white-space: nowrap; border: 0; background: transparent; padding: 5px 10px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* Charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 9px; }
.chart .ref { stroke-width: 1.2; stroke-dasharray: 4 3; }
.chart .reflbl { font-size: 9px; font-weight: 600; }

/* Ketone swatches */
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.sw { text-align: center; cursor: pointer; }
.sw input { position: absolute; opacity: 0; pointer-events: none; }
.sw span { display: block; height: 36px; border-radius: 8px; border: 2px solid transparent; outline: 1px solid var(--line); }
.sw input:checked + span { border-color: var(--ink); box-shadow: 0 0 0 2px var(--card) inset; }
.sw small { display: block; font-size: 10px; line-height: 1.2; margin-top: 3px; color: var(--muted); }
.sw input:checked ~ small { color: var(--ink); font-weight: 600; }
fieldset { border: 0; margin: 0; padding: 0; }
legend { font-size: 13px; color: var(--muted); margin-bottom: 6px; padding: 0; }
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 4px; outline: 1px solid var(--line); vertical-align: -2px; flex: none; }
.strip { display: grid; grid-template-columns: repeat(15, 1fr); gap: 3px; }
.strip span { aspect-ratio: 1; border-radius: 4px; background: var(--soft); outline: 1px solid var(--line); }
.strip span.none { outline-style: dashed; background: transparent; }

/* Skener */
.scanbox { position: relative; border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; margin-bottom: 8px; }
.scanbox video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanbox i { position: absolute; left: 12%; right: 12%; top: 50%; height: 2px; background: #e5675a; box-shadow: 0 0 8px #e5675a; }
.tag { color: var(--muted); font-weight: 400; }

/* Insights */
.insights { list-style: none; margin: 0; padding: 0; }
.insights li { padding: 8px 10px 8px 30px; border-radius: 10px; background: var(--soft); margin-top: 6px; position: relative; font-size: 14px; }
.insights li::before { position: absolute; left: 10px; top: 8px; font-weight: 700; }
.insights li.good::before { content: "✓"; color: var(--good); }
.insights li.warn::before { content: "!"; color: var(--warn); }
.insights li.bad::before { content: "!"; color: var(--bad); }
.insights li.info::before { content: "i"; color: var(--info); font-style: italic; font-family: Georgia, serif; }
.insights li { color: var(--ink); }

/* Tables */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; }
table.tbl { border-collapse: collapse; width: 100%; font-size: 12px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 6px 4px; text-align: right; border-top: 1px solid var(--line); white-space: nowrap; }
.tbl th { color: var(--muted); font-weight: 600; border-top: 0; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl tr.sum td { font-weight: 700; }

/* Banner */
.banner { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 14px; padding: 12px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; justify-content: space-between; font-size: 14px; }
.banner.warn { background: color-mix(in srgb, var(--warn) 12%, var(--card)); border-color: var(--warn); }

/* Bottom nav */
nav.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.nav button { flex: 1; border: 0; background: none; padding: 8px 0 7px; font-size: 11px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav.nav button svg { width: 23px; height: 23px; }
nav.nav button.on { color: var(--accent); font-weight: 600; }

/* Dialog as bottom sheet */
dialog {
  border: 0; padding: 0; background: var(--card); color: var(--ink);
  width: 100%; max-width: 560px; max-height: 92vh;
  border-radius: 18px 18px 0 0; margin: auto auto 0;
  box-shadow: 0 -8px 30px rgba(0,0,0,.2);
}
@media (min-width: 600px) { dialog { border-radius: 18px; margin: auto; } }
dialog::backdrop { background: rgba(0,0,0,.4); }
.sheet { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 92vh; }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet .preview { background: var(--soft); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.help ol { padding-left: 20px; margin: 6px 0; }
.help li { margin: 4px 0; font-size: 14px; }
.help code { background: var(--soft); padding: 1px 5px; border-radius: 5px; font-size: 12px; word-break: break-all; }
.help pre { background: var(--soft); padding: 8px; border-radius: 8px; font-size: 12px; white-space: pre-wrap; word-break: break-all; }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 20; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Popis namirnica po sekcijama */
.fhead { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin: 14px 0 6px; }
.fsec { border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; background: var(--card); }
.fsec summary { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px; font-weight: 700; cursor: pointer; list-style: none; min-height: 44px; }
.fsec summary::-webkit-details-marker { display: none; }
.fsec summary::after { content: "›"; font-size: 20px; color: var(--muted); transition: transform .15s; }
.fsec[open] summary::after { transform: rotate(90deg); }
.fsec summary .muted { margin-left: auto; }
.fsec-intro { margin: -4px 12px 4px; }
.fsec .fgrp { margin: 12px 12px 0; font-size: 13px; color: var(--accent); display: flex; align-items: center; gap: 6px; }
.fsec .list { padding: 0 12px; }
.pill { display: inline-block; font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 99px; vertical-align: 1px; text-transform: none; letter-spacing: 0; }
.pill.limit { background: color-mix(in srgb, var(--warn) 18%, var(--card)); color: color-mix(in srgb, var(--warn) 70%, var(--ink)); }
.pill.avoid { background: color-mix(in srgb, var(--bad) 15%, var(--card)); color: var(--bad); }

/* Unos potrošnje unatrag */
.bulk-head, .bulk-row { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1fr); gap: 8px; align-items: center; }
.bulk-head { padding: 0 0 6px; border-bottom: 1px solid var(--line); }
.bulk-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.bulk-row label { color: var(--ink); font-size: 14px; display: flex; flex-direction: column; }
.bulk-row label small { font-size: 11px; }
.bulk-row input { padding: 7px 8px; }

/* Hrana: zadnji obrok i najčešće namirnice */
.tiles.tiles4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 360px) { .tiles.tiles4 { grid-template-columns: 1fr 1fr; } }
.freq { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.freq-item { position: relative; display: flex; flex-direction: column; gap: 2px; text-align: left; border: 1px solid var(--line); background: var(--soft); border-radius: 12px; padding: 10px 34px 10px 12px; min-height: 56px; }
.freq-item .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.freq-item .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.freq-n { position: absolute; top: 8px; right: 10px; font-size: 11px; font-weight: 700; color: var(--accent); }

/* Gornja traka u prozorima: ostaje vidljiva pri pomicanju */
.sheet-head { position: sticky; top: -16px; z-index: 2; display: flex; align-items: center; gap: 8px; margin: -16px -16px 12px; padding: 10px 12px 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); border-radius: 18px 18px 0 0; }
.sheet-head h2 { flex: 1; min-width: 0; margin: 0 !important; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.sheet-head .icon-btn { font-size: 20px; width: 44px; height: 44px; color: var(--muted); }

/* Objašnjenje u analizi */
.explain { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.explain summary { cursor: pointer; font-weight: 600; color: var(--accent); min-height: 32px; }
.explain p { font-size: 14px; margin: 8px 0; }

/* Recepti */
button.card.recipe { display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.rmac { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 13px; }
.rmac b { font-size: 16px; }
.steps { padding-left: 20px; margin: 4px 0; }
.steps li { margin: 6px 0; font-size: 14px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.segopt { flex: 1; text-align: center; cursor: pointer; }
.segopt input { position: absolute; opacity: 0; pointer-events: none; }
.segopt span { display: block; padding: 7px 10px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.segopt input:checked + span { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
nav.nav button { font-size: 10.5px; }

/* Pregled izvještaja */
.report-frame { width: 100%; height: calc(92vh - 150px); min-height: 360px; border: 1px solid var(--line); border-radius: 12px; background: #fff6f8; }

/* Moje namirnice u podnaslovima, naslov popisa s prekidačem */
.fsec.mine summary { font-weight: 600; }
.fhead-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.fhead-row .fhead { margin: 6px 0; }

/* Post: ciklus post (crveno) / prozor za jelo (zeleno) */
:root { --fast: #c8344f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --fast: #ef6a7f; } }
:root[data-theme="dark"] { --fast: #ef6a7f; }
.fast-badge { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px; color: #fff; }
.fast-badge.fast { background: var(--fast); }
.fast-badge.eat { background: var(--good); }
.cyclebar { position: relative; height: 14px; margin-top: 12px; }
.cyclefill { display: flex; height: 100%; border-radius: 99px; overflow: hidden; }
.cyclebar i { display: block; height: 100%; }
.cyclebar .seg-fast { background: color-mix(in srgb, var(--fast) 80%, transparent); }
.cyclebar .seg-eat { background: color-mix(in srgb, var(--good) 75%, transparent); }
.cyclebar b { position: absolute; top: -4px; width: 4px; height: 22px; margin-left: -2px; background: var(--ink); border-radius: 2px; box-shadow: 0 0 0 2px var(--card); transition: left .5s; }
.cyclelbl { display: flex; justify-content: space-between; margin-top: 4px; }
.phasebar { height: 12px; border-radius: 99px; background: var(--soft); overflow: hidden; margin-top: 12px; }
.phasebar i { display: block; height: 100%; border-radius: 99px; transition: width .5s; }
