/* workout — minimal v0.1 styling. Mobile-first, dark by default. */

:root {
  color-scheme: dark light;
  --bg: #0f0f10;
  --bg-elev: #1a1a1c;
  --bg-card: #18181a;
  --fg: #f0f0f1;
  --fg-muted: #9a9a9e;
  --fg-dim: #66666a;
  --accent: #6cf2c1;
  --accent-fg: #062018;
  --danger: #ff6961;
  --warning: #f5c87b;
  --border: #2a2a2d;
  --tap: 48px;
  --radius: 12px;
  --radius-sm: 8px;
  --fs-base: 16px;
  --fs-sm: 14px;
  --fs-lg: 20px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafaf9;
    --bg-elev: #ffffff;
    --bg-card: #ffffff;
    --fg: #14141a;
    --fg-muted: #5a5a60;
    --fg-dim: #9a9aa0;
    --accent: #16a672;
    --accent-fg: #ffffff;
    --border: #e5e5e2;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font-size: var(--fs-base); line-height: 1.4; }
input, select, button, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; }

.app-root { min-height: 100%; }
.loading-shell { padding: var(--space-5); color: var(--fg-muted); }
.centered { text-align: center; padding: var(--space-5); color: var(--fg-muted); }
.muted { color: var(--fg-muted); }

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100dvh;
  /* No top bar anymore, so the shell itself clears the iOS status bar / notch. */
  padding-top: env(safe-area-inset-top);
}
/* Opaque guard pinned over the status-bar / notch area. Without a top bar, scrolled
   content would otherwise bleed under the translucent iOS status bar (viewport-fit=cover).
   Height collapses to 0 on devices without a notch, so it's a no-op there. */
.app-shell::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: env(safe-area-inset-top);
  background: var(--bg);
  z-index: 10;
}
/* Connectivity strip — only rendered while offline. */
.offline-bar {
  background: var(--warning);
  color: #1a1a1a;
  font-size: var(--fs-sm);
  font-weight: 600;
  text-align: center;
  padding: var(--space-1) var(--space-3);
}
.content { padding: var(--space-4); padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
.page-title { margin: 0 0 var(--space-4) 0; font-size: var(--fs-lg); }
.section-heading { margin-top: var(--space-5); }

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  gap: 2px;
}
.tabbar a.active, .tabbar a:focus-visible { color: var(--accent); outline: none; }
.tab-icon { font-size: 22px; line-height: 1; }
.tab-label { font-size: 11px; }

/* Auth pages */
.auth-shell {
  max-width: 360px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}
.auth-title { font-size: 28px; margin: 0 0 var(--space-4); }
.auth-form { display: flex; flex-direction: column; gap: var(--space-3); }
.auth-meta { margin-top: var(--space-4); color: var(--fg-muted); }

label { display: flex; flex-direction: column; gap: 4px; }
label > span { font-size: var(--fs-sm); color: var(--fg-muted); }
input, select, textarea {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-3);
  min-height: var(--tap);
  font-size: var(--fs-base);
  width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}
/* Placeholders must read as hints, not entered values. */
::placeholder { color: var(--fg-muted); opacity: 0.55; font-style: italic; }

button {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: var(--radius-sm);
  min-height: var(--tap);
  padding: 0 var(--space-4);
  font-weight: 600;
  cursor: pointer;
}
button[disabled] { opacity: 0.5; cursor: progress; }
button.secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
}
button.big { width: 100%; font-size: var(--fs-lg); margin-top: var(--space-3); }
.form-error { color: var(--danger); margin: 0; }
.form-message { color: var(--fg-muted); margin: 0; }
.banner-error {
  background: rgba(255, 105, 97, 0.12);
  color: var(--danger);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-3);
}
button.danger { background: var(--danger); color: #fff; }
.hidden { display: none !important; }

/* Log page */
.log-page .add-set-form {
  background: var(--bg-card);
  padding: var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.row { display: flex; gap: var(--space-3); }
.col { flex: 1; }
/* Exercise picker row: bottom-align the Trend shortcut with the <select> (the label's
   caption sits above it), and keep the button from stretching. */
.exercise-row { align-items: flex-end; }
.trend-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--accent);
  border-color: var(--accent);
}
.trend-btn .trend-ico { display: inline-flex; }
.trend-btn .trend-ico svg { display: block; }
.set-type-row { gap: var(--space-2); }
.chip {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 999px;
  min-height: 40px;
  padding: 0 var(--space-3);
  font-weight: 500;
}
.chip.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.new-exercise { margin-top: var(--space-4); }
.new-exercise summary { color: var(--accent); cursor: pointer; padding: var(--space-2) 0; }
.new-exercise form { display: flex; flex-direction: column; gap: var(--space-3); padding-top: var(--space-3); }
.checkbox-row { flex-direction: row; align-items: center; gap: var(--space-2); cursor: pointer; }
.checkbox-row input { width: auto; flex: 0 0 auto; margin: 0; }
.checkbox-row span { color: var(--fg-muted); font-size: 0.9em; }
.exercise-manage-list { list-style: none; margin: var(--space-3) 0 0 0; padding: 0; display: flex; flex-direction: column; }
.exercise-manage-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
}

/* Date picker bar (Log page) */
.date-bar { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); }
.date-bar .date-input { width: auto; flex: 1; }
.date-bar a { white-space: nowrap; font-size: var(--fs-sm); }

.bw-row { gap: var(--space-2); align-items: center; }
.bw-row .chip { flex: 0 0 auto; min-width: 56px; }
.bw-row input { flex: 1; }
.hint { display: block; margin-top: var(--space-1); color: var(--fg-muted); font-size: var(--fs-sm); }

.exercise-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-top: var(--space-3);
}
.exercise-block h4 { margin: 0 0 var(--space-2) 0; }
.exercise-block h4.clickable { cursor: pointer; color: var(--accent); }
.sets-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.set-row { display: flex; gap: var(--space-2); align-items: center; padding: var(--space-2) 0; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: none; }
.set-index { flex: 0 0 auto; min-width: 1.75ch; text-align: right; color: var(--fg-muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.set-load { flex: 1; font-variant-numeric: tabular-nums; }
.set-x { color: var(--fg-muted); }
.set-reps { min-width: 2ch; text-align: right; font-variant-numeric: tabular-nums; }
.set-tag { font-size: var(--fs-sm); color: var(--fg-muted); }
.set-del { background: transparent; color: var(--fg-muted); border: none; min-height: auto; padding: 4px 8px; font-size: var(--fs-base); display: inline-flex; align-items: center; justify-content: center; }
.set-del svg { display: block; }
/* Tap-to-edit: the value area is one big button that flips the row into edit mode. */
.set-view {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  min-height: auto;
  padding: var(--space-2);
  margin: 0 calc(-1 * var(--space-2));
  color: inherit;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.set-view:active { background: var(--bg-elev); }
@media (hover: hover) { .set-view:hover { background: var(--bg-elev); } }
/* Inline set editing */
.set-row.editing { gap: var(--space-2); flex-wrap: wrap; }
.set-edit-load { flex: 1; min-width: 80px; min-height: 38px; }
.set-edit-reps { width: 72px; flex: 0 0 auto; min-height: 38px; }
.set-save, .set-cancel { min-height: 38px; padding: 0 var(--space-3); font-size: var(--fs-sm); flex: 0 0 auto; }
.set-cancel { background: transparent; border: 1px solid var(--border); color: var(--fg); }

/* History */
.session-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.session-list a { color: var(--fg); display: block; }
.session-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.session-row .date { font-weight: 600; }
.session-row .meta { color: var(--fg-muted); font-size: var(--fs-sm); }
.edit-day { margin: 0 0 var(--space-4) 0; }
.day-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); margin: 0 0 var(--space-4) 0; }
.day-actions-left { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2); }
.day-actions-left a { font-weight: 600; }
.day-actions-right { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.day-actions .confirm-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.day-actions button { min-height: 38px; padding: 0 var(--space-3); font-size: var(--fs-sm); }
.set-tip { font-size: var(--fs-sm); }
/* Quieter destructive control — red, but ghosted until you commit in the confirm row. */
.btn-ghost-danger { background: transparent; color: var(--danger); border: 1px solid rgba(255, 105, 97, 0.45); }
@media (hover: hover) { .btn-ghost-danger:hover { background: rgba(255, 105, 97, 0.12); } }
/* Generic inline confirm (manage-exercises delete, etc.) */
.confirm-row { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.confirm-row button { min-height: 32px; padding: 0 var(--space-3); font-size: var(--fs-sm); }
/* History "By date / By exercise" toggle */
.seg-toggle { display: flex; width: fit-content; margin: 0 0 var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg-toggle button { background: transparent; color: var(--fg-muted); border: none; border-radius: 0; min-height: auto; padding: 6px 14px; font-size: var(--fs-sm); font-weight: 500; }
.seg-toggle button.active { background: var(--accent); color: var(--accent-fg); }
/* Exercise catalog list (T1) */
.exercise-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.exercise-list a { color: var(--fg); display: block; }
.exercise-row { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3) var(--space-4); display: flex; justify-content: space-between; align-items: center; }
.exercise-row .name { font-weight: 600; }
.exercise-row .chev { color: var(--fg-muted); }

/* Feedback (T3) */
.feedback-form { display: flex; flex-direction: column; gap: var(--space-3); margin: var(--space-3) 0 var(--space-4); }
.feedback-form textarea { resize: vertical; padding: var(--space-2) var(--space-3); min-height: 88px; }
.feedback-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.feedback-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3) var(--space-4); }
.fb-head { display: flex; align-items: center; gap: var(--space-2); }
.fb-date { font-size: var(--fs-sm); }
.fb-body { margin: var(--space-2) 0 0 0; white-space: pre-wrap; }
.fb-thumbs { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.fb-thumb { width: 72px; height: 72px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; }
.badge { font-size: var(--fs-sm); font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.badge-open { background: rgba(255, 176, 32, 0.18); color: #b3791a; }
.badge-done { background: rgba(46, 160, 67, 0.20); color: #2ea043; }

/* Maintainer reply (T17) — set off from the submitter's own text with an accent rail. */
.fb-reply { margin-top: var(--space-3); padding: var(--space-2) var(--space-3); border-left: 3px solid var(--accent); background: var(--bg-elev); border-radius: var(--radius-sm); }
.fb-reply-head { display: flex; align-items: baseline; gap: var(--space-2); }
.fb-reply-label { font-size: var(--fs-sm); font-weight: 600; color: var(--accent); }
.fb-reply-body { margin: var(--space-2) 0 0 0; white-space: pre-wrap; }

/* Data export / import (T6) */
.data-actions { display: flex; gap: var(--space-2); margin-bottom: var(--space-3); }
.btn-link {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-4);
  min-height: var(--tap);
  line-height: var(--tap);
  font-weight: 600;
  text-decoration: none;
}

/* Delete account (T10) */
.danger-zone { border-top: 1px solid var(--border); margin-top: var(--space-4); padding-top: var(--space-3); }
.danger-zone h3 { color: var(--danger); }
.danger-zone .confirm-row { margin-top: var(--space-2); }

.chart {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  color: var(--accent);
}
.sparkline { width: 100%; height: auto; max-width: 100%; display: block; }
.sparkline .spark-line { stroke: currentColor; }
.sparkline .dot-mark { fill: currentColor; pointer-events: none; }
.sparkline .dot { fill: transparent; cursor: pointer; }
/* Decorative marker must not intercept taps on the hit dot underneath. */
.sparkline .dot-selected { fill: var(--accent); stroke: var(--bg-card); stroke-width: 1.5; pointer-events: none; }
.sparkline .grid { stroke: var(--border); stroke-width: 0.5; }
.sparkline .axis-label { fill: var(--fg-muted); font-size: 9px; }
.chart-meta { color: var(--fg-muted); font-size: var(--fs-sm); margin: var(--space-2) 0 0 0; }

/* Exercise detail page */
/* Top bar: back link left, Log-this-exercise shortcut right. */
.detail-topbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.detail-topbar p { margin: 0; }
.exercise-detail .section-heading {
  margin: var(--space-5) 0 var(--space-3) 0;
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.history-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
}
.history-table thead {
  background: var(--bg-elev);
  position: sticky;
  top: 0;
}
.history-table th {
  text-align: left;
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
}
.history-table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.history-table tbody tr:last-child td { border-bottom: none; }
/* Each body row taps through to that day's editable detail (T19). */
.history-table tbody tr.row-link { cursor: pointer; }
.history-table tbody tr.row-link:hover td,
.history-table tbody tr.row-link:active td { background: var(--bg-elev); }
/* Tappable column headers (sort by date / load). Negative margin makes the whole cell the hit target. */
.th-sort {
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  min-height: auto;
  padding: var(--space-2) var(--space-3);
  margin: calc(-1 * var(--space-2)) calc(-1 * var(--space-3));
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.th-sort.active { color: var(--accent); }
.sort-arrow { font-variant-numeric: tabular-nums; }
.history-table .date-cell { white-space: nowrap; color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.history-table .load-cell { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.history-table .reps-cell { color: var(--fg); font-variant-numeric: tabular-nums; }

/* Settings */
.settings-page section {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}
.settings-page section:first-of-type { border-top: none; padding-top: 0; }
.settings-page form { display: flex; flex-direction: column; gap: var(--space-3); }

/* Skeleton loading — shown while a day's sets are fetched, so the content area has shape
   instead of going blank. Honors reduced-motion (no shimmer). */
.skeleton-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-top: var(--space-3);
}
.skeleton-line {
  height: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--bg-elev) 25%, var(--border) 37%, var(--bg-elev) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}
.skeleton-line + .skeleton-line { margin-top: var(--space-2); }
.skeleton-line.title { width: 40%; height: 16px; margin-bottom: var(--space-2); }
.skeleton-line.short { width: 60%; }
@keyframes skeleton-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton-line { animation: none; }
}
