:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e4e3de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7d7c77;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --ref: #9a9993;
  --protein: #2a78d6;
  --carbs: #eb6834;
  --fat: #1baf7a;
  --good: #1a7f37;
  --warn: #b45309;
  --danger: #c62828;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #2e2e2b;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --accent: #3987e5;
    --series-1: #3987e5;
    --ref: #75746e;
    --protein: #3987e5;
    --carbs: #d95926;
    --fat: #199e70;
    --good: #4ac26b;
    --warn: #e3a008;
    --danger: #ef5350;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #2e2e2b;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e88; --accent: #3987e5; --series-1: #3987e5;
  --ref: #75746e; --protein: #3987e5; --carbs: #d95926; --fat: #199e70;
  --good: #4ac26b; --warn: #e3a008; --danger: #ef5350;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
h2 { font-size: 15px; font-weight: 600; margin: 0; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
p { margin: 4px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code { font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
code.copy { display: inline-block; cursor: pointer; }
code.copy:hover { outline: 1px solid var(--border); }

input, select, button { font: inherit; color: inherit; }
input, select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 11px; min-width: 0; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
button { cursor: pointer; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 9px 14px; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.small { padding: 6px 12px; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button:disabled { opacity: .6; cursor: progress; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  max-width: 1180px; margin: 0 auto;
}
.brand { font-weight: 700; letter-spacing: -.01em; }
.datenav { display: flex; align-items: center; gap: 4px; }
.datenav button { border: 0; background: none; padding: 6px 10px; font-size: 18px; }
.datenav .date-label { font-size: 15px; font-weight: 600; min-width: 110px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 4px 16px 32px; max-width: 1180px; margin: 0 auto; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }

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

.hero-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.big { font-size: 48px; font-weight: 700; letter-spacing: -.03em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.big.over { color: var(--danger); }
.hero-side { text-align: right; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.hero-side b { color: var(--text); font-weight: 600; }

.bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 14px 0; }
.bar.thin { height: 6px; margin: 4px 0 12px; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s ease; }
.bar-fill.over { background: var(--danger); }

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.macro .label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.macro .val { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 14px; }
.macro .bar { height: 5px; margin: 6px 0 0; }
.macro.protein .bar-fill { background: var(--protein); }
.macro.carbs .bar-fill { background: var(--carbs); }
.macro.fat .bar-fill { background: var(--fat); }
.warn { margin-top: 12px; font-size: 13px; color: var(--warn); }

.quick { display: flex; gap: 8px; }
.quick input { font-size: 16px; padding: 12px 14px; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.manual { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; margin-top: 10px; }
.manual input[name=name] { grid-column: span 2; }
@media (max-width: 480px) { .manual { grid-template-columns: 1fr 1fr; } .manual input[name=name] { grid-column: span 2; } }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.chip { font-size: 13px; padding: 5px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid transparent; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.chip:hover { border-color: var(--border); }
.chip span { color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }

.meal-group + .meal-group { margin-top: 14px; }
.meal-head { display: flex; justify-content: space-between; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.entry { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.entry:last-child { border-bottom: 0; }
.entry .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.entry .meta { font-size: 12px; color: var(--muted); }
.entry .kcal { font-variant-numeric: tabular-nums; font-weight: 600; cursor: pointer; }
.entry .del { border: 0; background: none; color: var(--muted); padding: 4px 6px; font-size: 16px; }
.entry .del:hover { color: var(--danger); }
.empty { color: var(--muted); font-size: 14px; padding: 12px 0; text-align: center; }

.inline { display: flex; align-items: center; gap: 6px; }
.inline input { width: 130px; padding: 6px 10px; }
.unit { color: var(--muted); font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; margin-bottom: 8px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 13px; color: var(--muted); font-weight: 500; }
.down { color: var(--good); }
.up { color: var(--warn); }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 2px; margin-bottom: 8px; }
.seg button { border: 0; background: none; padding: 4px 12px; font-size: 13px; border-radius: 8px; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.chart-wrap { position: relative; height: 240px; }
.chart-wrap.short { height: 190px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; }
.sw.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ref); }
.sw.line { width: 16px; height: 2px; background: var(--series-1); }
.sw.dash { width: 16px; border-top: 2px dashed var(--ref); }
.sw.bar1 { width: 10px; height: 10px; border-radius: 3px; background: var(--series-1); }

.profile { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.profile label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.profile .wide { grid-column: span 2; }
.actions { display: flex; align-items: center; gap: 12px; }

.conn + .conn { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.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: 12px; font-size: 14px; z-index: 20;
  display: flex; gap: 14px; align-items: center; max-width: calc(100vw - 32px);
}
.toast button { background: none; border: 0; color: inherit; font-weight: 600; text-decoration: underline; padding: 0; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; width: min(360px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
.datenav { position: relative; }
.sr-date { position: absolute; left: 50%; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.toast[hidden] { display: none; }
.sw.dash.strong { border-top-color: var(--text); }
.qr { background: #fff; padding: 14px; border-radius: 10px; align-self: center; line-height: 0; }
.qr img, .qr canvas { width: 220px; height: 220px; }
.saved-head { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }
.saved-head .eyebrow { font-size: 11px; }
#saved { margin-top: 6px; }
#saved:empty { display: none; }
.chip.saved { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.chip .x { display: none; margin-left: 6px; color: var(--danger); }
#saved.editing .chip .x { display: inline; }
.meal-head .save { border: 0; background: none; padding: 0 0 0 8px; color: var(--muted); font-size: 12px; text-transform: none; letter-spacing: 0; }
.meal-head .save:hover { color: var(--accent); }
