/* ==========================================================================
   B-Fit styles: mobile-first, large touch targets, automatic dark mode.
   All colours are CSS variables so dark mode only swaps the variables.
   ========================================================================== */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #15171a;
  --muted: #5f6670;
  --border: #d9dde2;
  --accent: #0f7b6c;
  --accent-text: #ffffff;
  --accent-soft: #dcf1ec;
  --danger: #b42318;
  --danger-soft: #fde7e5;
  --cardio: #8a4b00;
  --cardio-soft: #fbeedc;
  /* Activity graph: one colour per category (checked for colour-blind safety
     with every pair adjacent; slices also keep a fixed order + gap) */
  --cat-upper: #2a78d6;
  --cat-lower: #008300;
  --cat-core: #eda100;
  --cat-cardio: #e87ba4;
  --cat-other: var(--muted);
  --radius: 14px;
  --tap: 48px;               /* minimum touch target size */
  --nav-h: 64px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1113;
    --surface: #1a1d21;
    --surface-2: #24282d;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --border: #30353b;
    --accent: #3fc1a8;
    --accent-text: #06201b;
    --accent-soft: #143a33;
    --danger: #ff8a80;
    --danger-soft: #3a1c1a;
    --cardio: #f5b76b;
    --cardio-soft: #3a2a15;
    --cat-upper: #3987e5;
    --cat-lower: #008300;
    --cat-core: #c98500;
    --cat-cardio: #d55181;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  outline: none;
}

h1 { font-size: 1.5rem; margin: 4px 0 16px; }
h2 { font-size: 1.15rem; margin: 24px 0 8px; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 0 0 12px; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

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

label.field { display: block; }
label.field > span { display: block; font-size: .875rem; color: var(--muted); margin-bottom: 4px; }

input, select, textarea {
  font: inherit;
  font-size: 1rem;           /* >=16px prevents zoom on focus on mobile */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: var(--tap);
  padding: 10px 12px;
  width: 100%;
}
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

/* ---------- Buttons ---------- */

button, .btn {
  font: inherit;
  font-weight: 600;
  min-height: var(--tap);
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  touch-action: manipulation;
}
button:active, .btn:active { transform: scale(.98); }
button:disabled { opacity: .5; }

.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-block { width: 100%; }
.btn-big { min-height: 56px; font-size: 1.1rem; }
.btn-dashed { border-style: dashed; background: transparent; color: var(--accent); border-color: var(--accent); }

/* Square icon button (remove set, close, ...) */
.icon-btn {
  width: var(--tap);
  padding: 0;
  flex: none;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  font-weight: 400;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }

a.card { display: block; color: inherit; text-decoration: none; }
a.card:active { background: var(--surface-2); }

.card-head { display: flex; align-items: flex-start; gap: 8px; margin: -4px -6px 8px 0; }
.card-head h3 { font-size: 1.1rem; padding-top: 10px; }

/* ---------- Tags and chips ---------- */

.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag {
  font-size: .75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.tag.strength { background: var(--accent-soft); color: var(--accent); }
.tag.cardio { background: var(--cardio-soft); color: var(--cardio); }

/* Toggle chips (filters, muscle group selection). Uses real checkboxes/radios. */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.chip span {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  user-select: none;
}
.chip input:checked + span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Segmented control (Strength / Cardio) */
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; min-height: 0; width: 1px; }
.segmented span { display: flex; align-items: center; justify-content: center; min-height: var(--tap); font-weight: 600; cursor: pointer; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -4px; }

.group-label { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 12px 0 6px; }

/* ---------- Record screen ---------- */

.record-top { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 16px; }
.date-input { font-size: 1.1rem; font-weight: 600; }

.edit-banner {
  display: flex; align-items: center; gap: 8px;
  background: var(--accent-soft); color: var(--text);
  border-radius: 12px; padding: 4px 4px 4px 14px; margin-bottom: 12px;
}

/* One set row: "1  [kg]  ×  [reps]  (remove)" */
.set-row {
  display: grid;
  grid-template-columns: 28px 1fr 16px 1fr var(--tap);
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}
.set-num { color: var(--muted); font-weight: 700; text-align: center; }
.set-x { color: var(--muted); text-align: center; }
.unit-input { position: relative; }
.unit-input input { padding-right: 44px; text-align: right; font-weight: 600; font-size: 1.1rem; }
.unit-input em {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-style: normal; font-size: .85rem; color: var(--muted); pointer-events: none;
}
.cardio-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.date-time { display: grid; grid-template-columns: 3fr 2fr; gap: 10px; }

/* Reorder buttons in an exercise card are a bit narrower than other icon buttons. */
.icon-btn.move-btn { width: 40px; font-size: 1.2rem; }
.icon-btn:disabled { opacity: .25; }
/* Warm-up mark on an exercise card (Record page) */
.warmup-toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px;
  font-size: .9rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.warmup-toggle input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--accent); }
.card.is-warmup { border-style: dashed; }
.card.is-warmup .warmup-toggle { color: var(--text); }
.tag.warmup { background: transparent; border: 1px dashed var(--border); }

.note-toggle { min-height: 40px; padding: 6px 0; margin-top: 6px; font-size: .9rem; }
.entry-note { color: var(--muted); font-size: .88rem; font-style: italic; margin: 4px 0 0; }
table.data td.entry-note { padding-top: 0; }
table.data tr.has-note td { border-bottom: none; }
.version-badge {
  font-size: .85rem; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.save-bar { margin-top: 20px; display: grid; gap: 8px; }

/* ---------- Add-exercise sheet (<dialog>) ---------- */

dialog.sheet {
  border: none;
  padding: 0;
  margin: auto auto 0;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  max-height: 92dvh;
  border-radius: 20px 20px 0 0;
  background: var(--bg);
  color: var(--text);
}
dialog.sheet::backdrop { background: rgb(0 0 0 / .45); }
.sheet-inner { display: flex; flex-direction: column; max-height: inherit; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 8px 8px 16px; }
.sheet-head h2 { margin: 0; flex: 1; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(16px + env(safe-area-inset-bottom)); }

.suggestions { list-style: none; margin: 8px 0 0; padding: 0; }
.suggestions li + li { margin-top: 6px; }
.suggestions button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  padding: 10px 14px;
  font-weight: 400;
}
.suggestions button strong { font-weight: 600; }

/* ---------- History / lists ---------- */

.filters { display: grid; gap: 10px; margin-bottom: 16px; }
.session-date { font-weight: 700; }
.session-lines { margin: 6px 0 0; padding: 0; list-style: none; color: var(--muted); font-size: .92rem; }
.session-lines li { display: flex; gap: 8px; }
.session-lines li b { color: var(--text); font-weight: 600; }

.detail-entry + .detail-entry { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.sets-list { margin: 6px 0 0; padding-left: 20px; }

table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data th { color: var(--muted); font-weight: 600; font-size: .8rem; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Progress chart ---------- */

.chart { position: relative; margin-top: 8px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .dot.active { r: 6; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip {
  position: absolute; top: 0;
  background: var(--text); color: var(--bg);
  font-size: .8rem; padding: 4px 8px; border-radius: 6px;
  pointer-events: none; white-space: nowrap; transform: translateX(-50%);
}
.chart-title { font-weight: 700; font-size: .95rem; }

.chart .bar { fill: var(--accent); }
.chart .bar.active { fill: var(--text); }

/* ---------- Stats: activity graph ---------- */

:root { --cell: 14px; --cell-gap: 3px; }
.activity-scroll { overflow-x: auto; margin: 8px -4px 0 0; padding: 0 4px 6px 0; scrollbar-width: thin; }
.activity-inner { display: inline-block; min-width: 100%; }
.activity-months { display: flex; gap: var(--cell-gap); height: 16px; }
.activity-months span {
  flex: none; width: var(--cell); overflow: visible; white-space: nowrap;
  font-size: 11px; color: var(--muted);
}
.activity-years { height: 14px; }
.activity-years span { font-weight: 700; }
.activity-body { display: flex; }
/* Weekday labels (and the corner above them) stay fixed on the left while the
   weeks scroll sideways underneath. The card background hides scrolled cells. */
.activity-weekdays {
  display: grid; grid-auto-rows: var(--cell); gap: var(--cell-gap); width: 32px; flex: none;
  position: sticky; left: 0; z-index: 1; background: var(--surface);
  box-shadow: -2px 0 0 var(--surface); /* covers sub-pixel slivers of scrolled squares */
}
.activity-months span.activity-corner {
  /* As wide as the weekday column; the negative margin cancels the flex gap
     so the first month label sits exactly above the first week. */
  width: 32px; margin-right: calc(-1 * var(--cell-gap));
  position: sticky; left: 0; z-index: 1; background: var(--surface);
  box-shadow: -2px 0 0 var(--surface);
}
.activity-weekdays span { font-size: 10px; line-height: var(--cell); color: var(--muted); }
.activity-grid { display: flex; gap: var(--cell-gap); }
.activity-week { display: grid; grid-auto-rows: var(--cell); gap: var(--cell-gap); }
.day {
  display: inline-block; width: var(--cell); height: var(--cell); min-height: 0;
  padding: 0; border: none; border-radius: 3px; background: var(--surface-2);
}
button.day { cursor: pointer; }
.day.outside { background: transparent; }
/* Days still to come (rest of this week / this year): faint, so a calendar
   year keeps its full Jan–Dec shape. */
.day.future { opacity: .4; }

/* Stats: ‹ 2026 › year picker for the calendar-year view */
.year-stepper { display: flex; align-items: center; justify-content: center; gap: 8px; margin: -4px 0 12px; }
.year-stepper .icon-btn { font-size: 1.8rem; color: var(--accent); }
.year-stepper .icon-btn:disabled { color: var(--muted); }
.year-value { font-size: 1.25rem; font-weight: 700; min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
/* A trained day is split into equal slices, stacked in rows; --slices (set in
   stats.js) switches to 2 columns for quarters. The 1px gap between slices
   shows the card background. */
.day.trained {
  display: grid; grid-template-columns: repeat(var(--slices, 1), 1fr); grid-auto-rows: 1fr; gap: 1px;
  align-items: stretch; /* buttons centre their content by default (see button rule) */
  background: var(--surface); overflow: hidden;
}
.day .slice { min-width: 0; }
.cat-upper { background: var(--cat-upper); }
.cat-lower { background: var(--cat-lower); }
.cat-core { background: var(--cat-core); }
.cat-cardio { background: var(--cat-cardio); }
.cat-other { background: var(--cat-other); }
.day.today { outline: 1.5px solid var(--muted); outline-offset: 1px; }
.day.selected { outline: 2px solid var(--text); outline-offset: 1px; }
button.day:active { transform: none; }
.activity-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 8px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }

/* Settings: activity colours */
.color-row { display: flex; align-items: center; gap: 12px; min-height: 52px; border-top: 1px solid var(--border); }
.color-row input[type=color] {
  width: 64px; min-height: 40px; height: 40px; padding: 2px; flex: none; cursor: pointer;
}
.day.color-preview { width: 32px; height: 32px; border-radius: 4px; }
.activity-info { margin-top: 10px; min-height: 40px; }
.activity-info b { color: var(--text); }

/* ---------- Stats: tiles and lists ---------- */

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 12px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: .78rem; color: var(--muted); }
.top-list { list-style: none; margin: 8px 0 0; padding: 0; }
.top-list li + li { margin-top: 10px; }
.top-list a { color: var(--text); font-weight: 600; text-decoration: none; min-height: 32px; display: flex; align-items: center; }
.top-bar { height: 6px; border-radius: 0 3px 3px 0; background: var(--accent); margin-top: 2px; }

/* ---------- Bottom navigation ---------- */

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 10;
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600;
}
.bottom-nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bottom-nav a.active { color: var(--accent); }

/* ---------- Toast ---------- */

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100% - 32px); z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
