:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --field: #ffffff;
  --accent: #2a78d6;
  --btn: #256abf;
  --wash: rgba(42, 120, 214, 0.10);
  --danger: #d03b3b;
  --good: #006300;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink2: #c3c2b7;
    --muted: #898781;
    --line: #2c2c2a;
    --axis: #383835;
    --field: #111110;
    --accent: #3987e5;
    --btn: #256abf;
    --wash: rgba(57, 135, 229, 0.16);
    --danger: #e66767;
    --good: #0ca30c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#app { max-width: 720px; margin: 0 auto; padding: 12px 16px calc(84px + env(safe-area-inset-bottom)); }
.boot { color: var(--muted); text-align: center; padding: 48px 0; }
h1 { font-size: 20px; margin: 4px 0 12px; }
h2 { font-size: 16px; margin: 0; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--ink2); font-weight: 600; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack > * + * { margin-top: 12px; }

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.card > header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card > header .sum { color: var(--ink2); font-size: 14px; text-align: right; }

/* ---- form controls ---- */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  min-width: 0;
  background: var(--field);
  border: 1px solid var(--axis);
  border-radius: 8px;
  padding: 9px 10px;
}
textarea { resize: vertical; min-height: 72px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
label.f { display: block; font-size: 12px; color: var(--ink2); }
label.f > span { display: block; margin-bottom: 3px; }
.row { display: grid; gap: 8px; align-items: end; }
.row + .row { margin-top: 8px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.cols-meal { grid-template-columns: minmax(110px, 0.6fr) 1.4fr; }
.cols-weight { grid-template-columns: 1fr auto; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.actions .spacer { flex: 1; }

button, a.btn { cursor: pointer; border-radius: 8px; border: 1px solid var(--axis); background: var(--surface); padding: 9px 14px; }
a.btn { display: inline-block; color: inherit; text-decoration: none; }
button.primary { background: var(--btn); border-color: var(--btn); color: #fff; font-weight: 600; }
button.ghost { border-color: transparent; background: transparent; color: var(--accent); padding: 9px 8px; }
button.danger { color: var(--danger); }
button.icon { border: 0; background: transparent; padding: 6px 8px; color: var(--muted); line-height: 1; font-size: 18px; border-radius: 6px; }
button.icon:hover { background: var(--wash); color: var(--ink); }
button:disabled { opacity: 0.5; cursor: default; }
button.add { width: 100%; border-style: dashed; color: var(--accent); background: transparent; }

/* ---- date bar ---- */
.datebar { display: grid; grid-template-columns: 44px 1fr 44px; gap: 8px; align-items: center; position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 6px 0; }
.datebar button { height: 52px; }
.datebar .nav { font-size: 20px; padding: 0; }
.datebar .day { position: relative; text-align: center; font-weight: 600; padding: 4px 8px; line-height: 1.25; }
.datebar .day small { display: block; font-weight: 400; color: var(--ink2); font-size: 12px; }
.datebar .day input { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
.jump { text-align: center; margin-top: 4px; }

/* ---- entry lists ---- */
.list { list-style: none; margin: 0 0 10px; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .main { flex: 1; min-width: 0; }
.list .main b { font-weight: 600; }
.list .sub { color: var(--ink2); font-size: 13px; overflow-wrap: anywhere; }
.list .val { color: var(--ink2); font-size: 13px; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.group-h { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 10px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 5px 10px; font-size: 13px; color: var(--ink2); }
button.chip:hover, button.chip.on { border-color: var(--accent); color: var(--ink); background: var(--wash); }
.hint { font-size: 13px; color: var(--ink2); margin: 8px 0; }
.meter { height: 8px; border-radius: 999px; background: var(--wash); overflow: hidden; margin-bottom: 10px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.setrow { display: grid; grid-template-columns: 28px 1fr 1fr 36px; gap: 8px; align-items: center; margin-top: 6px; }
.setrow .n { color: var(--muted); font-size: 13px; text-align: center; }
.form { border-top: 1px solid var(--line); padding-top: 10px; }
.list:empty + .form, .form.first { border-top: 0; padding-top: 0; }

/* ---- bottom nav ---- */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs > div { max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); }
nav.tabs button { border: 0; background: transparent; border-radius: 0; padding: 8px 2px 9px; font-size: 11px; color: var(--muted); display: grid; justify-items: center; gap: 2px; }
nav.tabs button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav.tabs button[aria-current="page"] { color: var(--accent); font-weight: 600; }

/* ---- progress ---- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 620px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.tile .k { font-size: 12px; color: var(--ink2); }
.tile .v { font-size: 24px; font-weight: 600; margin-top: 2px; }
.tile .v small { font-size: 13px; font-weight: 400; color: var(--ink2); }
.tile .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chart { position: relative; touch-action: pan-y; }
.chart svg { display: block; width: 100%; }
.chart text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart text.endlabel { fill: var(--ink); font-weight: 600; font-size: 12px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: 0.1; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .bar { fill: var(--accent); }
.chart .bar.dim { opacity: 0.45; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.tip {
  position: absolute; pointer-events: none; z-index: 2;
  background: var(--ink); color: var(--bg);
  border-radius: 8px; padding: 6px 9px; font-size: 12px; white-space: nowrap;
}
.tip .tip-h { opacity: 0.75; }
details.data { margin-top: 8px; font-size: 13px; }
details.data summary { color: var(--ink2); cursor: pointer; }
details.data .scroll { max-height: 220px; overflow: auto; margin-top: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 5px 8px 5px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
th { color: var(--ink2); font-weight: 600; border-top: 0; }
td.num, th.num { text-align: right; padding-right: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--wash); }

/* ---- history ---- */
.hist { list-style: none; padding: 0; margin: 0; }
.hist button { width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: transparent; padding: 10px 2px; }
.hist li:first-child button { border-top: 0; }
.hist button:hover { background: var(--wash); }
.hist .d { font-weight: 600; }
.hist .chips { margin-top: 4px; }

/* ---- reports ---- */
.files { list-style: none; padding: 0; margin: 8px 0 0; }
.files li { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 3px 0; }
.files a { overflow-wrap: anywhere; }
.kv { grid-template-columns: 1.4fr 1fr 0.8fr 36px; }
.report-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.report-head .t { font-weight: 600; }

/* ---- auth ---- */
.auth { max-width: 360px; margin: 12vh auto 0; }
.auth .logo { width: 56px; height: 56px; border-radius: 14px; display: block; margin: 0 auto 12px; }
.auth h1 { text-align: center; }
.auth p { text-align: center; color: var(--ink2); font-size: 14px; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 8px; }

/* ---- toast ---- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--ink); color: var(--bg);
  padding: 9px 14px; border-radius: 10px; font-size: 14px;
  display: flex; gap: 12px; align-items: center; max-width: calc(100vw - 32px);
}
#toast button { border: 0; background: transparent; color: inherit; font-weight: 700; padding: 0 2px; text-decoration: underline; }

/* ---- workout icons and pickers ---- */
.gl { width: 24px; height: 24px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.list li > .gl { color: var(--accent); }
.acts { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; margin-top: 6px; }
button.act { display: grid; justify-items: center; align-content: start; gap: 5px; padding: 10px 4px 8px; font-size: 12px; line-height: 1.2; text-align: center; background: var(--bg); border-color: var(--line); color: var(--ink); }
button.act .gl { width: 30px; height: 30px; color: var(--accent); }
button.act:hover { border-color: var(--accent); background: var(--wash); }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
@media (min-width: 620px) { .chips.scroll { flex-wrap: wrap; overflow: visible; } }
.chips.scroll .chip { white-space: nowrap; flex: none; }
.picklist { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
.picklist:empty { display: none; }
.picklist button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: transparent; padding: 9px 10px; }
.picklist button:first-child { border-top: 0; }
.picklist button:hover { background: var(--wash); }
.picklist .gl { color: var(--accent); }
.picklist small { color: var(--muted); margin-left: auto; font-size: 12px; white-space: nowrap; }
.sel { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.sel .gl { width: 30px; height: 30px; color: var(--accent); }
.sel .name { font-weight: 600; }
.sel .sub { font-size: 12px; color: var(--ink2); }
.sel .spacer { flex: 1; }
input[type="search"] { -webkit-appearance: none; appearance: none; }
