/* ============================================================
   Workout Logger — styles
   Mobile-first, dark, thumb-friendly. Design tokens from the
   build contract. Content centers at ~560px on wider screens.
   ============================================================ */

:root {
  /* ---- design tokens (contract) ---- */
  --bg:      #0d1117;
  --surface: #161b22;
  --border:  #30363d;
  --text:    #e6edf3;
  --muted:   #8b949e;
  --accent:  #1f6feb;
  --up:      #3fb950;  /* green  */
  --same:    #d29922;  /* amber  */
  --down:    #f85149;  /* red    */

  --radius: 12px;
  --tap:    44px;      /* minimum tap target */
  --maxw:   560px;

  /* safe-area insets (notch / home indicator) */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h:    58px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
               Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* App fills the viewport; scroll lives inside each screen body. */
#app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom));
}

.screen { display: block; }
.is-hidden { display: none !important; }

/* ---------------- header ---------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(var(--safe-top) + 14px) 16px 12px;
  background: linear-gradient(var(--bg) 78%, rgba(13, 17, 23, 0));
  background-color: var(--bg);
}
.app-header h1 { margin: 0; font-size: 1.35rem; font-weight: 700; }

.header-dates { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; }
.header-dates .today { font-size: 1.35rem; font-weight: 700; }
.header-dates .meta  { font-size: 0.82rem; color: var(--muted); }
.header-dates .meta b { color: var(--text); font-weight: 600; }

.screen-body { padding: 4px 16px 28px; }

/* ---------------- generic card ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
}
.card h2 { margin: 0 0 4px; font-size: 1.15rem; }
.card .sub { color: var(--muted); font-size: 0.85rem; margin: 0 0 8px; }

/* exercise position badge */
.ex-head { display: flex; align-items: center; gap: 10px; }
.ex-num {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 0.9rem;
}
.ex-title { flex: 1 1 auto; }
.ex-title h2 { font-size: 1.15rem; line-height: 1.2; }
.muscles { color: var(--muted); font-size: 0.8rem; }
.cue {
  margin: 10px 0 0;
  font-size: 0.85rem; color: var(--text);
  border-left: 3px solid var(--accent);
  padding: 6px 0 6px 10px;
  background: rgba(31, 111, 235, 0.08);
  border-radius: 0 6px 6px 0;
}

/* last-session target line */
.targets {
  margin: 12px 0;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}
.targets .lbl { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.targets .row { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 4px; font-variant-numeric: tabular-nums; }
.targets .row span { white-space: nowrap; }
.targets .beat { margin-top: 6px; color: var(--muted); font-size: 0.82rem; }
.targets .beat b { color: var(--text); }

/* ---------------- set inputs ---------------- */
.sets { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.set-row {
  display: grid;
  grid-template-columns: 26px 1fr 1fr;
  align-items: center;
  gap: 10px;
}
.set-row .set-lbl { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.field { position: relative; }
.field input {
  width: 100%;
  height: var(--tap);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 0 8px;
  -moz-appearance: textfield;
}
.field input::-webkit-outer-spin-button,
.field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(31,111,235,0.35); }
.field .cap {
  position: absolute; top: -8px; left: 10px;
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); background: var(--surface); padding: 0 4px;
}

/* inline indicators shown after submit */
.inline-ind { display: flex; gap: 12px; margin-top: 10px; font-size: 0.85rem; color: var(--muted); flex-wrap: wrap; }
.inline-ind .ipair { display: inline-flex; gap: 4px; align-items: center; font-variant-numeric: tabular-nums; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem; font-weight: 600;
  cursor: pointer;
  -webkit-appearance: none;
  width: 100%;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost   { background: transparent; }
.btn-danger  { color: var(--down); border-color: rgba(248,81,73,0.4); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: auto; flex: 1 1 0; }
.btn-sm { width: auto; min-height: 34px; padding: 0 12px; font-size: 0.85rem; flex: 0 0 auto; }

/* ---------------- review (swipe-back) hint ---------------- */
.review-hint {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 12px; padding: 8px 12px;
  border: 1px dashed var(--border); border-radius: 10px;
  color: var(--muted); font-size: 0.82rem;
}
.review-hint span { flex: 1 1 auto; }

/* ---------------- knee gate ---------------- */
.knee-gate { text-align: center; }
.knee-gate .q { font-size: 1.05rem; font-weight: 600; margin-bottom: 4px; }
.knee-gate .hint { color: var(--muted); font-size: 0.85rem; margin-bottom: 14px; }
.knee-gate .btn-row { gap: 12px; }

/* ---------------- progress dots (stepper) ---------------- */
.stepper { display: flex; gap: 6px; justify-content: center; margin: 6px 0 0; }
.stepper .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.stepper .dot.done   { background: var(--up); }
.stepper .dot.active { background: var(--accent); transform: scale(1.3); }
.stepper .dot.skip   { background: var(--muted); opacity: 0.5; }

/* ---------------- summary ---------------- */
.sum-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.sum-row:last-child { border-bottom: none; }
.sum-row .name { font-weight: 600; }
.sum-row .str  { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.sum-row .sets-line { grid-column: 1 / -1; display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.sum-row .sets-line .setcell { white-space: nowrap; }
.sum-skip { color: var(--muted); font-style: italic; }

.tally { display: flex; gap: 16px; justify-content: center; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.tally .t { display: inline-flex; gap: 6px; align-items: center; font-weight: 600; }
.total-str { text-align: center; font-size: 1.1rem; margin-top: 6px; }
.total-str b { font-size: 1.3rem; }

/* ---------------- history ---------------- */
.sess {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 12px 0;
  overflow: hidden;
}
.sess-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 14px 16px; cursor: pointer; min-height: var(--tap);
}
.sess-head .d { font-weight: 700; }
.sess-head .s { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.sess-head .chev { color: var(--muted); transition: transform 0.15s; }
.sess.open .chev { transform: rotate(90deg); }
.sess-body { display: none; padding: 0 16px 12px; }
.sess.open .sess-body { display: block; }
.sess-ex { padding: 8px 0; border-top: 1px solid var(--border); }
.sess-ex .exn { font-weight: 600; font-size: 0.92rem; }
.sess-ex .exs { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; display: flex; gap: 14px; flex-wrap: wrap; margin-top: 2px; }

/* chart */
.chart-card { padding: 14px 10px 10px; }
.chart-card h2 { padding: 0 6px; }
.chart-wrap { width: 100%; overflow: hidden; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 8px; padding: 8px 4px 2px; }
/* Interactive toggles: expand the clickable box to meet the tap-target
   guidance (the swatch stays small; the hit area is what grows). */
.legend .lg { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 6px 8px; font-size: 0.78rem; color: var(--muted); cursor: pointer; user-select: none; border-radius: 8px; }
.legend .lg .sw { width: 12px; height: 3px; border-radius: 2px; }
.legend .lg.off { opacity: 0.35; }
.legend .lg.off .sw { background: var(--muted) !important; }

/* ---------------- export ---------------- */
.export-info { color: var(--muted); font-size: 0.88rem; margin: 6px 0 14px; }
.stat-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.stat-line:last-child { border-bottom: none; }
.stat-line .k { color: var(--muted); }
input[type="file"] { display: none; }

/* ---------------- session note ---------------- */
.note-card textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
}
.note-card textarea:focus { outline: none; border-color: var(--accent); }

/* ---------------- indicators ---------------- */
.ind { font-size: 0.95em; }
.dash { color: var(--muted); }

/* ---------------- empty / misc ---------------- */
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.divider { height: 1px; background: var(--border); margin: 18px 0; border: none; }

/* ---------------- bottom tab bar ---------------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  max-width: var(--maxw);
  margin: 0 auto;
}
.tab {
  flex: 1 1 0;
  min-height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  background: none; border: none; cursor: pointer;
  color: var(--muted);
  font-size: 0.7rem; font-weight: 600;
  -webkit-appearance: none;
  padding: 6px 0;
}
.tab .tab-ico { font-size: 1.25rem; line-height: 1; }
.tab.is-active { color: var(--accent); }

/* ---------------- toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: #1c2330;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  max-width: calc(100% - 32px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

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