/* Mobile-first. Dark by default because this gets opened at 6am before a
   weigh-in and at 11pm before bed. Light theme follows the OS. */

:root {
  --bg: #12151b;
  --surface: #1a1f28;
  --surface-2: #222834;
  --line: #2e3644;
  --text: #e8ecf2;
  --text-dim: #98a3b3;
  --text-faint: #6b7686;
  --accent: #5eb0ff;
  --good: #4fc98a;
  --warn: #f0b34a;
  --bad: #f0705f;
  --pink: #e58bb8;
  --radius: 14px;
  --tabbar-h: 60px;
  --topbar-h: 54px;
  --pad: 16px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef1f6;
    --line: #dde2ea;
    --text: #161a20;
    --text-dim: #5b6675;
    --text-faint: #8b95a4;
    --accent: #0a68c9;
    --good: #14875a;
    --warn: #a76b00;
    --bad: #c8402e;
    --pink: #b6407e;
  }
}
:root[data-theme="light"] {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #eef1f6; --line: #dde2ea;
  --text: #161a20; --text-dim: #5b6675; --text-faint: #8b95a4;
  --accent: #0a68c9; --good: #14875a; --warn: #a76b00; --bad: #c8402e; --pink: #b6407e;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}

/* ------------------------------- chrome ------------------------------- */

#topbar {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--pad) 0;
  display: flex; align-items: center; justify-content: space-between;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
#topbar h1 { font-size: 19px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }

.icon-btn {
  background: none; border: 0; color: var(--text-dim);
  font-size: 20px; padding: 8px; cursor: pointer; line-height: 1;
}
.icon-btn:active { color: var(--text); }

#view { padding: var(--pad); max-width: 720px; margin: 0 auto; }

#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  background: none; border: 0; color: var(--text-faint); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 10.5px; font-weight: 550; letter-spacing: 0.01em;
}
.tab .ico { font-size: 17px; line-height: 1; }
.tab[aria-current="page"] { color: var(--accent); }

/* -------------------------------- cards ------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px var(--pad);
  margin-bottom: 12px;
}
.card > h2 {
  font-size: 12px; font-weight: 650; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--text-faint); margin: 0 0 10px;
}
.card.tight { padding: 12px var(--pad); }
.card.flush { padding: 0; overflow: hidden; }

/* hero number — the one thing you should see first */
.hero { text-align: center; padding: 20px var(--pad) 18px; }
.hero .value { font-size: 44px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.hero .unit  { font-size: 17px; font-weight: 500; color: var(--text-dim); margin-left: 4px; }
.hero .sub   { font-size: 13px; color: var(--text-dim); margin-top: 8px; }
.hero .caption { font-size: 11px; color: var(--text-faint); margin-top: 3px; text-transform: uppercase; letter-spacing: 0.06em; }

/* stat rows */
.stats { display: grid; gap: 1px; background: var(--line); border-radius: 10px; overflow: hidden; }
.stat { background: var(--surface); padding: 11px 13px; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.stat .k { color: var(--text-dim); font-size: 13.5px; }
.stat .v { font-weight: 620; font-variant-numeric: tabular-nums; text-align: right; }
.stat .v small { display: block; font-weight: 400; font-size: 11.5px; color: var(--text-faint); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.tile { background: var(--surface-2); border-radius: 11px; padding: 12px; text-align: center; }
.tile .n { font-size: 21px; font-weight: 680; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.tile .l { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 3px; }

/* --------------------------- semantic colour --------------------------- */

.good { color: var(--good); }
.warn { color: var(--warn); }
.bad  { color: var(--bad); }
.dim  { color: var(--text-dim); }
.faint{ color: var(--text-faint); }
.accent { color: var(--accent); }
.pink { color: var(--pink); }
.tabnum { font-variant-numeric: tabular-nums; }

/* ------------------------------ controls ------------------------------ */

label.field { display: block; margin-bottom: 12px; }
label.field > span {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-dim);
  margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.05em;
}
input, select, textarea, button.btn {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
textarea { resize: vertical; min-height: 64px; }

.row { display: flex; gap: 8px; align-items: flex-end; }
.row > * { flex: 1; }
.row > .shrink { flex: 0 0 92px; }

button.btn {
  cursor: pointer; font-weight: 600; text-align: center;
  border: 1px solid var(--line); background: var(--surface-2);
}
button.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.btn.ghost { background: transparent; }
button.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
button.btn:active { transform: scale(0.985); }
button.btn:disabled { opacity: 0.45; cursor: default; }
.btn-sm { padding: 7px 11px; font-size: 13.5px; width: auto; }

/* segmented unit toggle */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button {
  background: none; border: 0; color: var(--text-dim); cursor: pointer;
  padding: 6px 13px; border-radius: 7px; font: inherit; font-size: 13px; font-weight: 600;
}
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* --------------------------------- misc -------------------------------- */

.note {
  font-size: 13px; line-height: 1.5; color: var(--text-dim);
  background: var(--surface-2); border-left: 3px solid var(--line);
  border-radius: 0 8px 8px 0; padding: 10px 12px; margin: 10px 0;
}
.note.warn { border-left-color: var(--warn); }
.note.bad  { border-left-color: var(--bad); }
.note.good { border-left-color: var(--good); }
.note.info { border-left-color: var(--accent); }
.note strong { color: var(--text); }

.pill {
  display: inline-block; font-size: 11px; font-weight: 650; padding: 3px 9px;
  border-radius: 999px; background: var(--surface-2); color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.pill.good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.bad  { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.pill.accent { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }

/* progress bar for macro targets */
.bar { height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .3s; }
.bar > i.over { background: var(--warn); }
.bar > i.protein { background: var(--good); }

/* list rows */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px var(--pad); border-bottom: 1px solid var(--line);
  background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%; text-align: left; color: inherit; font: inherit; cursor: pointer;
}
.list-row:last-child { border-bottom: 0; }
.list-row .main { flex: 1; min-width: 0; }
.list-row .title { font-weight: 550; }
.list-row .meta { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.list-row .right { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list-row .right b { display: block; font-weight: 640; }
.list-row .right small { color: var(--text-faint); font-size: 11.5px; }

.empty { text-align: center; color: var(--text-faint); padding: 28px 16px; font-size: 14px; }

/* sparkline / chart container */
.chart { width: 100%; height: 130px; display: block; }
.chart-wrap { overflow-x: auto; }

/* toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 560;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60;
  max-width: 88vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--bad); color: #fff; }

/* modal sheet */
.sheet-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 720px;
  border-radius: 18px 18px 0 0; padding: var(--pad);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  border-top: 1px solid var(--line);
}
.sheet h2 { margin: 0 0 14px; font-size: 17px; }
.sheet-handle { width: 38px; height: 4px; background: var(--line); border-radius: 99px; margin: -4px auto 14px; }

hr.sep { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.section-title {
  font-size: 12px; font-weight: 650; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--text-faint); margin: 20px 0 8px;
}

a { color: var(--accent); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); font-weight: 650; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
