/* onlyauto — phone-first. One thumb, one hand, in the middle of an upload. */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #12161d;
  --muted: #626c7d;
  --faint: #9aa3b2;
  --line: #dfe3ea;
  --accent: #1d6f6a;
  --accent-soft: #e2efed;
  --warn: #b0521c;
  --warn-soft: #f8eae0;
  --danger: #a32f2f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabs-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #171c24;
    --ink: #e6eaf1;
    --muted: #8c96a8;
    --faint: #6a7385;
    --line: #262e3a;
    --accent: #57c3b3;
    --accent-soft: #14282b;
    --warn: #e19158;
    --warn-soft: #2a1e16;
    --danger: #e0736e;
  }
}

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

/* `hidden` must beat any display a class sets. The browser's own [hidden] rule
   ties on specificity with a class selector and loses to it, so .lock's
   display:grid kept the lock screen painted on top of the app forever. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ── lock ─────────────────────────────────────────────────────────────────── */

.lock {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.lock-form { display: flex; flex-direction: column; gap: 12px; width: min(280px, 100%); }
.lock-title { margin: 0 0 8px; font-size: 20px; font-weight: 600; text-align: center; }

.pin {
  padding: 14px;
  text-align: center;
  font-size: 24px;
  letter-spacing: 0.3em;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.lock-error { margin: 0; text-align: center; color: var(--danger); font-size: 13px; }

/* ── shell ────────────────────────────────────────────────────────────────── */

.app { padding-bottom: calc(var(--tabs-h) + var(--safe-bottom)); }

.view { display: none; }
.view.is-active { display: block; }

.head {
  padding: calc(var(--safe-top) + 14px) 16px 10px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid var(--line);
}

.head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.head-day { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.head-hint { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }

.counter {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.slots { display: flex; gap: 6px; margin-top: 10px; }

.slot {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
}

.slot.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.select {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: 13px;
}

/* ── run bar ──────────────────────────────────────────────────────────────── */

.run {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.run-fields { display: flex; gap: 10px; flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }

.field-label {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.field-input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}

.trial {
  flex: none;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
}

.trial[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ── feed ─────────────────────────────────────────────────────────────────── */

.feed, .measure, .history { list-style: none; margin: 0; padding: 0; }

/* The save bar floats above the tabs, so the last row needs room to clear it. */
.measure { padding-bottom: 60px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.row.is-done { background: var(--accent-soft); }
.row.is-out { opacity: 0.55; }

.mark {
  flex: none;
  width: 22px;
  text-align: center;
  font-size: 15px;
  color: var(--faint);
}

.row.is-done .mark { color: var(--accent); }
.row.is-out .mark { color: var(--warn); }

.row-main { flex: 1; min-width: 0; }

.row-handle {
  display: block;
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-sub {
  display: block;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-act {
  flex: none;
  min-width: 74px;
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: 9px;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.row.is-done .row-act {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.row-act:disabled { opacity: 0.4; }

/* ── measure ──────────────────────────────────────────────────────────────── */

.m-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.m-main { flex: 1; min-width: 0; }

.m-views {
  flex: none;
  width: 96px;
  padding: 9px 10px;
  text-align: right;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}

.bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabs-h) + var(--safe-bottom));
  padding: 10px 16px;
  background: var(--card);
  border-top: 1px solid var(--line);
  z-index: 6;
}

/* ── stats ────────────────────────────────────────────────────────────────── */

.stats { padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 18px; }

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

.tile {
  padding: 11px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.tile-n { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-l { font-size: 11px; color: var(--muted); }

.group h3 {
  margin: 0 0 7px;
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
}

.bars { display: flex; flex-direction: column; gap: 7px; }

.bar-row { display: grid; grid-template-columns: 1fr 56px; gap: 10px; align-items: center; }
.bar-label { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-n { font-size: 11px; color: var(--faint); }

.bar-track {
  grid-column: 1 / -1;
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.bar-val { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; font-weight: 600; }

.list-plain { list-style: none; margin: 0; padding: 0; font-size: 13px; }

.list-plain li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.list-plain b { font-variant-numeric: tabular-nums; }

.admin { padding: 0 16px 28px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.admin-msg { font-size: 12.5px; color: var(--muted); }

.empty { padding: 34px 24px; text-align: center; color: var(--muted); font-size: 14px; }

/* ── tabs ─────────────────────────────────────────────────────────────────── */

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabs-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  z-index: 7;
}

.tab { flex: 1; border: 0; background: transparent; color: var(--muted); font-size: 13px; }
.tab.is-active { color: var(--accent); font-weight: 600; }

/* ── account sheet ────────────────────────────────────────────────────────── */

.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.42); }

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 8px 16px calc(20px + var(--safe-bottom));
  background: var(--card);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sheet-grab { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 2px; }
.sheet-handle { margin: 0; font-size: 18px; font-weight: 600; word-break: break-all; }

.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }

.sheet-block { display: flex; flex-direction: column; gap: 6px; }
.states { display: flex; flex-wrap: wrap; gap: 6px; }

.state-btn {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.state-btn.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.state-btn.is-bad.is-active { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }

.note {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  resize: vertical;
}

.history { font-size: 12.5px; max-height: 190px; overflow-y: auto; }

.history li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
}

.history span { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ── buttons, toast ───────────────────────────────────────────────────────── */

.btn {
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  font-size: 14px;
}

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-wide { width: 100%; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabs-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%);
  padding: 9px 15px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 10px;
  font-size: 13px;
  z-index: 30;
  max-width: 84vw;
  text-align: center;
}

@media (prefers-reduced-motion: no-preference) {
  .row, .row-act, .trial, .slot, .state-btn { transition: background-color .12s ease, color .12s ease, border-color .12s ease; }
}
