/* Performance app. One stylesheet. Light by default, dark via prefers-color-scheme. */
:root {
  --bg: #f3f2ee; --surface: #ffffff; --surface-2: #ebe9e3; --text: #17181a; --muted: #5a5d63;
  --line: #d6d3cc; --accent: #e8a83e; --accent-ink: #17181a; --accent-text: #9a5c06;
  --ok: #23804d; --ok-bg: #dcefe3; --warn: #9a5c06; --warn-bg: #fbeed6; --danger: #b3261e;
  --run: #2d6fb5; --amrap: #8a3fb0;
  --tap: 52px; --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --nav-h: calc(60px + var(--safe-b));
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121314; --surface: #1b1d1f; --surface-2: #26292c; --text: #eeede9; --muted: #a5a8ad;
    --line: #33373c; --accent-text: #f0b85a; --ok: #63cf8f; --ok-bg: #173323; --warn: #f0b85a; --warn-bg: #3a2c12;
    --danger: #ff8a80; --run: #7fb2ea; --amrap: #d29cf0;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.4 -apple-system, system-ui, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--nav-h) + 150px); /* room for action bar */
  overscroll-behavior-y: none;
}
body.sheet-open { overflow: hidden; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 22px; } h3 { font-size: 18px; }
p { margin: .4em 0; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
.muted { color: var(--muted); } .small { font-size: 14px; } .pad { padding: 4px 16px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-t)) 16px 8px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .02em; }
.sync-pill {
  min-height: 36px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px;
}
.sync-pill::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.sync-pill[data-kind="pending"]::before { background: var(--accent); }
.sync-pill[data-kind="offline"]::before { background: var(--muted); }
.sync-pill[data-kind="error"]::before { background: var(--danger); }

main { padding: 12px 12px 0; max-width: 640px; margin: 0 auto; outline: none; }
.day-title { padding: 8px 4px 10px; }

/* bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: var(--nav-h); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600; min-height: 56px; }
.tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab.on { color: var(--text); }
.tab.on svg { stroke: var(--accent-text); }

/* action bar: primary actions in the thumb zone, just above the tabs */
.action-bar {
  position: fixed; left: 0; right: 0; bottom: var(--nav-h); z-index: 15; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px; background: linear-gradient(to top, var(--bg) 75%, transparent);
}
.action-bar > * { max-width: 616px; width: 100%; margin: 0 auto; }

/* buttons */
.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 650; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.secondary { background: var(--surface-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.big { min-height: 60px; font-size: 19px; width: 100%; }
.btn.wide { width: 100%; margin: 4px 0 12px; }
.btn.icon { min-width: 48px; padding: 0; }
.btn.small { min-height: 44px; padding: 0 12px; font-size: 15px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.card-head h3 { flex: 1 1 auto; }
.card.live { border-color: var(--accent); }
.card.run { border-left: 5px solid var(--run); }
.tag { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 3px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.tag.main { color: var(--accent-text); } .tag.amrap { color: var(--amrap); } .tag.run { color: var(--run); }
.tag.done, .tag.approved, .tag.applied { color: var(--ok); } .tag.rejected, .tag.skipped { color: var(--danger); }
.tag.pr { background: var(--ok-bg); color: var(--ok); margin-left: 8px; }
.chip { min-height: 40px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); font-size: 14px; font-weight: 600; }
.chip.ref { min-height: 0; display: inline-block; margin: 2px 4px 2px 0; font-family: ui-monospace, Menlo, monospace; font-size: 12px; font-weight: 500; }
.note { padding: 10px 12px; border-radius: 10px; font-size: 15px; }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* week strip: three weeks, swipe with scroll snap */
.week-strip { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; margin: 0 -12px 8px; }
.week-strip::-webkit-scrollbar { display: none; }
.week { flex: 0 0 100%; display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 4px 12px; scroll-snap-align: start; }
.day {
  min-height: 72px; border-radius: 12px; border: 1px solid transparent; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px 0;
}
.day .dow { font-size: 12px; color: var(--muted); font-weight: 600; }
.day .dnum { font-size: 19px; font-weight: 700; }
.day.past .dnum { color: var(--muted); }
.day.today { border-color: var(--line); }
.day.today .dnum { color: var(--accent-text); }
.day.sel { background: var(--surface); border-color: var(--accent); }
.marks { display: flex; gap: 4px; height: 8px; }
.mk { width: 8px; height: 8px; border-radius: 50%; display: block; }
.mk.lift { background: var(--accent); } .mk.lift.done { background: var(--ok); } .mk.runm { border: 2px solid var(--run); }
.plan-list { list-style: none; margin: 6px 0 0; padding: 0; }
.plan-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.pl-name { font-weight: 650; flex: 1 1 100%; }
.pl-sets { color: var(--muted); font-size: 15px; }

/* logger */
.log-head { display: flex; align-items: baseline; justify-content: space-between; padding: 6px 4px 10px; }
.card.ex { padding: 12px 10px; }
.card.ex .card-head { padding: 0 4px; }
.card.ex > p { padding: 0 4px; margin: 0 0 6px; }
.set-row {
  width: 100%; min-height: 56px; display: grid; grid-template-columns: 64px 1fr auto 44px; align-items: center; gap: 8px;
  border: 0; border-top: 1px solid var(--line); background: transparent; padding: 0 4px; text-align: left; cursor: pointer;
}
.set-row.open { background: var(--surface-2); border-radius: 12px 12px 0 0; border-top-color: transparent; }
.set-tag { font-size: 13px; font-weight: 800; color: var(--muted); text-align: center; border-radius: 8px; padding: 4px 0; background: var(--surface-2); }
.set-row.open .set-tag { background: var(--surface); }
.set-row.amrap .set-tag { color: var(--amrap); outline: 2px solid var(--amrap); outline-offset: -2px; }
.set-row.warm .set-main { color: var(--muted); }
.set-main { font-size: 20px; font-weight: 700; }
.set-rir { font-size: 14px; color: var(--muted); }
.set-check { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-weight: 900; justify-self: end; }
.set-row.done .set-check { background: var(--ok); border-color: var(--ok); color: var(--bg); }
.set-row.done .set-main { color: var(--ok); }
.set-panel { background: var(--surface-2); border-radius: 0 0 12px 12px; padding: 6px 10px 12px; display: flex; flex-direction: column; gap: 10px; margin-bottom: 6px; }
.amrap-note { color: var(--amrap); font-weight: 650; margin: 2px 0; }
.stepper { display: grid; grid-template-columns: 84px 1fr 84px; gap: 8px; align-items: center; }
.btn.step { min-height: 56px; font-size: 19px; padding: 0; background: var(--surface); }
.btn.step.sm { min-height: 48px; min-width: 48px; }
.step-mid { display: flex; align-items: baseline; justify-content: center; gap: 6px; }
.step-val { width: 100%; max-width: 120px; text-align: center; font-size: 30px; font-weight: 800; border: 0; background: transparent; padding: 4px 0; }
.step-unit { color: var(--muted); font-size: 15px; }
.rir-row { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 8px; }
.seg { display: flex; gap: 6px; }
.seg.wrap { flex-wrap: wrap; }
.seg-btn { flex: 1; min-height: 50px; min-width: 48px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: 17px; padding: 0 10px; }
.seg-btn.on { background: var(--text); color: var(--bg); border-color: var(--text); }
main > .seg { margin: 0 0 12px; }
.lift-pick .seg-btn { font-size: 15px; }
.plates { display: flex; flex-direction: column; gap: 6px; }
.plate-chips { display: flex; align-items: center; gap: 3px; min-height: 64px; padding-left: 10px; position: relative; }
.plate-chips::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 6px; margin-top: -3px; background: var(--line); border-radius: 3px; }
.pc { position: relative; display: grid; place-items: center; width: 30px; border-radius: 5px; font-size: 11px; font-weight: 800; background: var(--text); color: var(--bg); }
.pc.bumper { background: #2a2c2f; color: #fff; outline: 2px solid var(--accent); outline-offset: -2px; }
.pc.p45 { height: 64px; } .pc.p35 { height: 56px; } .pc.p25 { height: 48px; } .pc.p15 { height: 42px; }
.pc.p10 { height: 36px; } .pc.p5 { height: 28px; width: 24px; } .pc.p2_5 { height: 22px; width: 20px; font-size: 9px; }
.plate-text { margin: 0; font-weight: 600; }
.panel-actions { display: flex; gap: 8px; }
.panel-actions .btn.ghost { flex: 0 0 auto; }
.panel-actions .done-btn { flex: 1; }
.finish-small { min-height: 48px; color: var(--muted); }
.add-set { width: 100%; margin-top: 4px; color: var(--muted); }
.log-actions { gap: 6px; }
.timer { display: none; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px 6px 6px 14px; }
.timer.on { display: flex; }
.timer.over { border-color: var(--accent); }
.timer-main { display: flex; align-items: baseline; gap: 8px; flex: 1; }
.timer-label { color: var(--muted); font-weight: 600; }
.timer-val { font-size: 28px; font-weight: 800; }
.timer.over .timer-val { color: var(--accent-text); }
.timer-target { color: var(--muted); font-size: 14px; }
body[data-route="body"] { padding-bottom: calc(var(--nav-h) + 200px); }
body[data-route="log"] { padding-bottom: calc(var(--nav-h) + 230px); }

/* sheets */
.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + var(--safe-b));
  max-width: 640px; margin: 0 auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 8px; position: sticky; top: -8px; background: var(--surface); }
.sheet-body { display: flex; flex-direction: column; gap: 12px; }
.sheet-body form, .finish { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 14px; color: var(--muted); font-weight: 600; }
.input { width: 100%; min-height: var(--tap); border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 10px 12px; font-size: 18px; }
textarea.input { min-height: 90px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pick-list { display: flex; flex-direction: column; }
.pick { min-height: 56px; display: flex; justify-content: space-between; align-items: center; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; padding: 0 4px; font-weight: 600; }

/* charts */
.chart-wrap { margin: 4px -4px; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick, .chart .unit { fill: var(--muted); font-size: 11px; }
.chart .chart-empty { fill: var(--muted); font-size: 14px; }
.chart .line-e1rm { stroke: var(--accent); stroke-width: 2.5; }
.chart .line-e1rm-pt { fill: var(--accent); }
.chart .dot-top { fill: none; stroke: var(--text); stroke-width: 1.6; }
.chart .dot-raw { fill: var(--muted); opacity: .55; }
.chart .line-trend { stroke: var(--accent); stroke-width: 3; }
.legend { display: flex; gap: 16px; font-size: 14px; color: var(--muted); }
.lg::before { content: ""; display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-right: 6px; vertical-align: middle; background: var(--accent); }
.lg.top::before { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--text); background: none; }
.lg.raw::before { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: 13px; padding: 4px 4px; }
.tbl td { padding: 8px 4px; border-top: 1px solid var(--line); }

/* stats + summary */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 8px; margin-bottom: 8px; }
.stat { display: flex; flex-direction: column; }
.stat-v { font-size: 24px; font-weight: 800; }
.stat-l { font-size: 13px; color: var(--muted); }
.sum-lifts { list-style: none; padding: 0; margin: 4px 0; }
.sum-lifts li { padding: 10px 0; border-top: 1px solid var(--line); }
.sum-name { font-weight: 700; }
.delta.up { color: var(--ok); font-weight: 650; } .delta.down { color: var(--danger); font-weight: 650; }
.pr-line { color: var(--ok); font-weight: 650; font-size: 15px; }

/* body */
.mass-bar { gap: 8px; }
.mass-row { display: grid; grid-template-columns: 84px 1fr 84px; gap: 8px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 6px; }
.mass-in { border: 0; background: transparent; text-align: center; font-size: 30px; font-weight: 800; max-width: 130px; padding: 0; }

/* manage */
.menu { display: flex; flex-direction: column; margin-bottom: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.menu-item { min-height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; text-decoration: none; font-weight: 650; }
.menu-item + .menu-item { border-top: 1px solid var(--line); }
.badge { min-width: 28px; height: 28px; border-radius: 14px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; padding: 0 8px; }
.eq-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.eq-row.off .eq-name { opacity: .5; }
.eq-name { display: flex; flex-direction: column; font-weight: 600; }
.eq-count { display: flex; align-items: center; gap: 6px; }
.count { min-width: 28px; text-align: center; font-weight: 800; font-size: 19px; }
.switch { width: 58px; height: 36px; border-radius: 18px; border: 0; background: var(--line); position: relative; padding: 0; margin: 6px 0; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch.on { background: var(--ok); }
.switch.on::after { left: 26px; }
.change h3 { margin: 4px 0; }
.decide { margin-top: 10px; }
.diff { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.diff pre { margin: 0; font-size: 12px; white-space: pre-wrap; word-break: break-word; background: var(--surface-2); padding: 8px; border-radius: 8px; }
details summary { min-height: 44px; display: flex; align-items: center; color: var(--muted); font-weight: 600; }
.rejected .rej { border-top: 1px solid var(--line); padding: 8px 0; }

/* token gate */
.gate { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; justify-content: flex-end; gap: 12px; padding: 24px 20px calc(32px + var(--safe-b)); }
.gate h1 { font-size: 32px; }

/* toast */
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 160px); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 60;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 650; transition: .2s; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.warn { background: var(--warn); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
