:root {
  --bg: #f7f5ef;
  --surface: #ffffff;
  --ink: #1d2a22;
  --muted: #5f6b63;
  --line: #e4e0d4;
  --accent: #2f7d4f;
  --accent-ink: #ffffff;
  --warn: #b4531a;
  --warn-bg: #fdf0e4;
  --err: #a6322b;
  --protein: #c4572f;
  --carbs: #c99a1c;
  --fat: #4a7fb0;
  --radius: 14px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131a15; --surface: #1b251e; --ink: #eaf1ec; --muted: #9aa8a0; --line: #2b382f;
    --accent: #5fbf86; --accent-ink: #0d1a12; --warn: #f0a874; --warn-bg: #2d2217; --err: #f08a82;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); }
#app { max-width: 560px; margin: 0 auto; padding: 16px 16px 96px; padding-top: max(16px, env(safe-area-inset-top)); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
p { margin: 0; }
.muted { color: var(--muted); font-size: .9rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 14px; }
.stack > * + * { margin-top: 12px; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); min-height: 44px;
}
textarea { resize: vertical; min-height: 88px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px;
}
button { cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 14px; min-height: 44px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.danger { color: var(--err); }
button:disabled { opacity: .55; cursor: not-allowed; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bar h1 { text-align: center; flex: 1; font-size: 1.1rem; }
.icon { width: 44px; padding: 0; font-size: 1.15rem; }
.msg { padding: 10px 12px; border-radius: 10px; margin-top: 12px; font-size: .92rem; }
.msg.err { background: color-mix(in srgb, var(--err) 12%, transparent); color: var(--err); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }

.summary { display: grid; grid-template-columns: 132px 1fr; gap: 16px; align-items: center; }
.ring { position: relative; width: 132px; height: 132px; }
.ring svg { transform: rotate(-90deg); }
.ring .num { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .num b { font-size: 1.6rem; line-height: 1; }
.macro + .macro { margin-top: 8px; }
.macro .top { display: flex; justify-content: space-between; font-size: .82rem; }
.macro .track { height: 7px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 3px; }
.macro .fill { height: 100%; border-radius: 99px; }

.meal .head { display: flex; justify-content: space-between; align-items: center; }
.entry { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left;
  border: 0; border-top: 1px solid var(--line); border-radius: 0; background: transparent; padding: 10px 0; }
.entry:first-of-type { margin-top: 8px; }
.entry .name { overflow-wrap: anywhere; }
.entry .kc { white-space: nowrap; font-variant-numeric: tabular-nums; }

dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 20px)); max-height: 92vh;
  background: var(--surface); color: var(--ink); box-shadow: 0 18px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10, 18, 13, .55); }
.dlg-body { padding: 18px; max-height: 92vh; overflow: auto; }
.tabs { display: flex; gap: 6px; margin: 12px 0; }
.tabs button { flex: 1; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.row { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-top: 10px; }
.row.needs { border-color: var(--warn); }
.row .line { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.row .line input { max-width: 110px; }
.row .kcal { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.thumb { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; margin-top: 10px; }
.spin { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: s .7s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes s { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2s; } }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.unsure { color: var(--warn); font-weight: 600; font-size: .85rem; }

/* ───────────── week / month progress ───────────── */
.viewtabs { margin: 14px 0 0; }
.weightrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 14px; }
.tiles .tile { margin-top: 0; display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; }
.tile b { font-size: 1.45rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile b small { font-size: .9rem; color: var(--muted); font-weight: 600; }
.nowrap { white-space: nowrap; }
.chart { margin-top: 10px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .baseline { stroke: var(--line); stroke-width: 1; }
.chart .goal { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 5 5; opacity: .55; }
.chart .ax { fill: var(--muted); font-size: 11px; }
.chart .v { fill: var(--ink); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart .na { fill: var(--muted); font-size: 16px; }
.chart .b-on { fill: var(--accent); }
.chart .b-over { fill: var(--warn); }
.chart .b-under { fill: color-mix(in srgb, var(--accent) 45%, var(--surface)); }
.chart .wline { fill: none; stroke: var(--fat); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .wdot { fill: var(--fat); stroke: var(--surface); stroke-width: 2; }
.legend { margin-top: 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: .82rem; }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-left: 6px; vertical-align: -1px; }
.key:first-child { margin-left: 0; }
.key.on { background: var(--accent); }
.key.over { background: var(--warn) repeating-linear-gradient(45deg, transparent 0 3px, var(--surface) 3px 5px); }
.key.under { background: color-mix(in srgb, var(--accent) 45%, var(--surface)); }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-top: 10px; }
.cal .ch { font-size: .75rem; color: var(--muted); text-align: center; padding-bottom: 2px; }
.cal .cd { min-height: 54px; padding: 4px 2px; border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 2px; font-size: .78rem; border: 1px solid var(--line); background: var(--bg); }
.cal .cd .dn { font-weight: 700; }
.cal .cd .kc { font-variant-numeric: tabular-nums; font-size: .7rem; white-space: nowrap; letter-spacing: -.02em; }
.cal .cd .sym { font-size: .65rem; font-weight: 400; }
.cal .cd.on { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.cal .cd.over { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.cal .cd.under { background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.cal .cd.today { outline: 2px solid var(--ink); outline-offset: -2px; }
.cal .cd:disabled { opacity: .45; }
@media (max-width: 380px) { .cal .cd .kc { font-size: .6rem; } }
.key.goalkey { height: 0; border-radius: 0; border-top: 2px dashed var(--ink); opacity: .6; width: 16px; vertical-align: 3px; }
.greet { margin: 10px 2px 0; font-size: 1.05rem; }

/* ───────────── settings groups + printable summary ───────────── */
.group { border-top: 1px solid var(--line); padding-top: 12px; }
.group h3 { font-size: .95rem; margin-bottom: 2px; }
.report h1 { font-size: 1.4rem; }
.report table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.report th, .report td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; }
.report th:first-child, .report td:first-child { text-align: left; }
.report th { font-size: .78rem; color: var(--muted); font-weight: 600; }
.report .kv { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; }
.report .kv div { display: flex; flex-direction: column; }
.report .kv b { font-size: 1.15rem; }
.report .scroll-x { overflow-x: auto; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff; color: #000; }
  #app { max-width: none; padding: 0; }
  .no-print, dialog { display: none !important; }
  .report .card { border: 0; padding: 0; margin-top: 16px; break-inside: avoid; }
  .report .muted { color: #444; }
  .report th, .report td { border-color: #bbb; }
}
.group button { width: 100%; }
.report td { white-space: nowrap; }
.welcome h1 { font-size: 1.45rem; color: var(--accent); }
.welcome p { margin-top: 6px; }
.report .actions { display: flex; gap: 8px; }
.when { margin-top: 10px; }
.when input { max-width: 200px; }
.when .muted { margin-top: 6px; }
.msg.ok { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
#syncline { font-size: .82rem; margin-top: -4px; }
