/* Uplift — paper surfaces, hairlines, accent as marks. No flat color panels. */
:root {
  --paper: #F7F5F0;
  --surface: #FFFFFF;
  --ink: #1C1F24;
  --muted: #6B7076;
  --faint: #9AA0A6;
  --hair: #E4E0D8;
  --hair-strong: #CFC9BE;
  --brand: #16332C;
  --accent: #7FC8A9;
  --accent-ink: #2F7A5E;
  --warn: #B4533A;
  --radius: 12px;
  --tabbar-h: 64px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.5 var(--sans);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .06em; }
[hidden] { display: none !important; }

/* ── top bar ─────────────────────────────────────────────────────────── */
.top {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 16px; border-bottom: 1px solid var(--hair); background: var(--paper);
  position: sticky; top: 0; z-index: 5;
}
.wordmark { font: 600 22px/1 var(--serif); color: var(--brand); text-decoration: none; letter-spacing: .2px; }
.wordmark.big { font-size: 34px; }
.wm-sub { font: 500 12px var(--sans); color: var(--accent-ink); letter-spacing: .1em; text-transform: uppercase; margin-left: 6px; vertical-align: middle; }
.tabs { display: none; gap: 4px; flex: 1; }
.tabs a { text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); font-size: 15px; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }
.tab-phantom { margin-left: auto; color: var(--accent-ink) !important; }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }
.who-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who form { margin: 0; }
button.link { background: none; border: 0; padding: 0; color: var(--accent-ink); cursor: pointer; font-size: 14px; }
button.link:hover { text-decoration: underline; }

/* ── bottom tab bar (phones) ─────────────────────────────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--surface); border-top: 1px solid var(--hair); z-index: 5;
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--muted); text-decoration: none;
}
.tabbar a .ico { display: block; line-height: 0; }
.tabbar a.active { color: var(--brand); }
.tabbar a.active .ico { color: var(--accent-ink); }

@media (min-width: 820px) {
  body { padding-bottom: 32px; }
  .tabs { display: flex; }
  .tabbar { display: none; }
}

/* ── layout ──────────────────────────────────────────────────────────── */
.view { max-width: 720px; margin: 0 auto; padding: 16px; }
.view.wide { max-width: 1100px; }
.card { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { margin-bottom: 10px; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.empty { color: var(--faint); font-size: 14px; padding: 10px 0; }

/* ── date strip ──────────────────────────────────────────────────────── */
.datestrip { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.datestrip .label { font: 600 18px var(--sans); }
.datestrip .sub { font-size: 13px; color: var(--muted); }
.datestrip .today-mark { color: var(--accent-ink); }
.datestrip button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--hair); background: var(--surface); cursor: pointer; }
.datestrip input[type=date] { border: 0; background: none; font: inherit; color: var(--muted); font-size: 13px; padding: 0; }

/* ── stat tiles ──────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border: 1px solid var(--hair); border-radius: var(--radius); background: var(--surface); overflow: hidden; margin-bottom: 14px; }
.stat { padding: 12px 10px; border-right: 1px solid var(--hair); }
.stat:last-child { border-right: 0; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font: 600 22px/1.2 var(--sans); font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .u { font-size: 12px; color: var(--faint); margin-left: 2px; font-weight: 400; }
.stat.net .v { color: var(--accent-ink); }
.macros { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin: -6px 0 14px 2px; }
.macros b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── lists ───────────────────────────────────────────────────────────── */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--hair); }
.list li:first-child { border-top: 0; }
.list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { font-size: 12px; color: var(--muted); display: block; white-space: normal; }
.list .val { font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
.list .val small { color: var(--faint); font-size: 12px; margin-left: 2px; }
.list.tap li { cursor: pointer; }
.list.tap li:hover { background: linear-gradient(90deg, transparent, #faf9f6 20%, #faf9f6 80%, transparent); }
.mark { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); vertical-align: middle; margin-right: 6px; }
.mark.mine { background: var(--brand); }
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; border: 1px solid var(--hair); flex: none; }
.mealhead { display: flex; align-items: baseline; justify-content: space-between; margin: 14px 0 4px; }
.mealhead:first-child { margin-top: 0; }
.mealhead .sum { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ── controls ────────────────────────────────────────────────────────── */
.btn { border: 1px solid var(--hair-strong); background: var(--surface); border-radius: 10px; padding: 9px 14px; cursor: pointer; font-size: 15px; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: #0f241f; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--warn); }
.btn:disabled { opacity: .5; cursor: default; }
.x { border: 0; background: none; color: var(--faint); font-size: 20px; line-height: 1; padding: 4px 6px; cursor: pointer; border-radius: 6px; }
.x:hover { color: var(--warn); background: #fbf3f0; }
input[type=text], input[type=number], input[type=email], input[type=search], input[type=date], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--hair-strong); border-radius: 10px; background: var(--surface); min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
input[type=number] { font-variant-numeric: tabular-nums; }
textarea { resize: vertical; min-height: 60px; }
label.f { display: block; font-size: 12px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 480px) { .grid4 { grid-template-columns: 1fr 1fr; } }
.seg { display: inline-flex; border: 1px solid var(--hair-strong); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 12px; cursor: pointer; font-size: 14px; color: var(--muted); border-left: 1px solid var(--hair); }
.seg button:first-child { border-left: 0; }
.seg button.on { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); font-weight: 500; }
.seg.full { display: flex; width: 100%; }
.seg.full button { flex: 1; }
details.card { padding: 0; }
details.card summary { padding: 14px 16px; cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: "+"; margin-left: auto; color: var(--faint); font-weight: 400; font-size: 20px; }
details.card[open] summary::after { content: "–"; }
details.card .body { padding: 0 16px 16px; }
.hint { font-size: 12px; color: var(--faint); }
.err { color: var(--warn); font-size: 13px; }

/* ── sheet (inline picker) ───────────────────────────────────────────── */
.sheet { border: 1px solid var(--accent); border-radius: var(--radius); padding: 14px 16px; background: var(--surface); margin-bottom: 14px; }
.sheet h2 { margin-bottom: 6px; }

/* ── chart ───────────────────────────────────────────────────────────── */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--hair); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 1.5; }
.chart text { font: 11px var(--sans); fill: var(--faint); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; padding-top: 6px; }
.bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 1px; }
.bars .in { background: var(--brand); opacity: .85; border-radius: 2px 2px 0 0; }
.bars .out { background: var(--accent); border-radius: 0 0 2px 2px; }
.bars-x { display: flex; gap: 4px; font-size: 10px; color: var(--faint); }
.bars-x span { flex: 1; text-align: center; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-right: 5px; }

/* ── toast ───────────────────────────────────────────────────────────── */
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px); transform: translateX(-50%) translateY(10px); background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 20; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--warn); }
@media (min-width: 820px) { .toast { bottom: 24px; } }

/* ── auth ────────────────────────────────────────────────────────────── */
body.auth { padding: 0; min-height: 100vh; display: grid; place-items: center; }
.auth-card { width: min(380px, calc(100% - 32px)); background: var(--surface); border: 1px solid var(--hair); border-radius: 16px; padding: 32px 28px; text-align: center; }
.auth-sub { color: var(--muted); margin: 8px 0 22px; font-size: 14px; }
.auth-form { text-align: left; display: grid; gap: 12px; }
.auth-form label { font-size: 13px; color: var(--muted); display: grid; gap: 4px; }
.auth-form input { font-size: 17px; }
.auth-form input[name=code] { letter-spacing: .3em; text-align: center; font-family: var(--mono); font-size: 24px; }
.auth-form .btn { width: 100%; padding: 12px; }
.auth-hint { margin: 0; font-size: 14px; color: var(--muted); }
.auth-msg { font-size: 14px; color: var(--accent-ink); margin: -10px 0 16px; }
.auth-status { min-height: 1.4em; font-size: 13px; color: var(--muted); margin: 14px 0 0; }

/* ── phantom tables ──────────────────────────────────────────────────── */
table.t { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); overflow: hidden; }
table.t th, table.t td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--hair); vertical-align: middle; }
table.t th { border-top: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 500; }
table.t td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t tr.off td { color: var(--faint); }
table.t input, table.t select { padding: 5px 8px; border-radius: 6px; }
.twrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.pill { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--hair-strong); color: var(--muted); }
.pill.admin { border-color: var(--accent); color: var(--accent-ink); }
.pill.off { border-color: var(--warn); color: var(--warn); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; }

/* ── balance ledger (Today) + effect card (Weight) ───────────────────── */
.balance-line { margin: 0 0 12px; font-size: 15px; }
.balance-line b { font-size: 26px; font-variant-numeric: tabular-nums; font-weight: 600; }
.balance-line b.under { color: var(--accent-ink); }
.balance-line b.over { color: var(--warn); }
.ledger { border-top: 1px solid var(--hair); }
.led { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--hair); font-size: 14px; color: var(--muted); }
.led:last-child { border-bottom: 0; }
.led .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); }
.led.total { font-weight: 600; color: var(--ink); border-bottom: 0; border-top: 1px solid var(--hair-strong); margin-top: 2px; }
.sheet .val.personal { color: var(--accent-ink); }
.sheet .val.personal::after { content: "·you"; font-size: 10px; letter-spacing: .04em; margin-left: 4px; color: var(--faint); vertical-align: 2px; }

/* ── workout routines ────────────────────────────────────────────────── */
.days { display: flex; gap: 6px; margin-top: 4px; }
.days button {
  flex: 1; max-width: 44px; aspect-ratio: 1; border: 1px solid var(--hair-strong);
  background: var(--surface); border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--muted);
}
.days button.on { border-color: var(--brand); background: var(--brand); color: #fff; font-weight: 600; }
.list li.done .name { color: var(--faint); }
.list li.done .val { color: var(--accent-ink); }
.list li input[type=number] { flex: none; text-align: center; }

/* "Last time" line in the log sheet */
.lastline { margin: 0 0 10px; font-size: 13px; color: var(--ink); }
.lastline b { font-weight: 600; }
.lastline.faint { color: var(--faint); }

/* ── drag-to-reorder handle in the routine editor ────────────────────── */
.list li.sortable { gap: 8px; }
.grip {
  border: 0; background: none; color: var(--faint); padding: 6px 2px; cursor: grab;
  line-height: 0; border-radius: 6px; flex: none;
  touch-action: none; /* claim the gesture so dragging does not scroll the page */
}
.grip:hover { color: var(--muted); }
.grip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; color: var(--accent-ink); }
.list li.dragging { background: #faf9f6; box-shadow: 0 2px 10px rgba(0,0,0,.10); border-radius: 8px; }
.list li.dragging .grip { cursor: grabbing; color: var(--accent-ink); }

/* Sub-label on a collapsible card's summary, so the row says what it is for */
details.card summary .sum-hint { font-weight: 400; font-size: 13px; color: var(--muted); margin-left: 8px; }

/* ── running a workout ───────────────────────────────────────────────── */
.row.finish { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--hair); }
.done-note { font-size: 13px; color: var(--accent-ink); font-weight: 500; }
.card.done-card { border-color: var(--accent); }
.session-line { margin: 0 0 8px; font-size: 14px; }
.session-line b { font-weight: 600; }
