/* Workout Log — mobile-first */

:root {
  --bg: #0f1419;
  --surface: #1a2129;
  --surface-2: #232c37;
  --border: #2f3a47;
  --text: #e8eef5;
  --text-dim: #98a4b3;
  --accent: #4a90e2;
  --accent-2: #6dabe8;
  --good: #5cb85c;
  --warn: #f0ad4e;
  --bad: #d9534f;
  --w1: #4a6fa5;
  --w2: #4caf7a;
  --w3: #a665c0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

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

button { cursor: pointer; }

/* App shell */
header.app-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}
header.app-bar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}
header.app-bar .nav-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 14px;
}
header.app-bar .back-btn {
  background: transparent;
  border: none;
  color: var(--accent-2);
  padding: 6px 0;
  font-size: 16px;
}

main {
  padding: 16px;
  padding-bottom: 100px;
  max-width: 720px;
  margin: 0 auto;
}

/* Home — workout list */
.phase-card {
  background: var(--surface);
  border-radius: 10px;
  margin-bottom: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.phase-header {
  padding: 12px 16px;
  font-weight: 600;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.phase-header .phase-label {
  font-size: 13px;
  opacity: 0.85;
  font-weight: 400;
}
.workout-row {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  background: var(--surface);
}
.workout-row:hover, .workout-row:active { background: var(--surface-2); }
.workout-row.suggested {
  background: linear-gradient(90deg, rgba(74,144,226,0.18), transparent);
}
.workout-row .day-tag {
  background: var(--surface-2);
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  min-width: 50px;
  text-align: center;
}
.workout-row .workout-name {
  flex: 1;
  font-weight: 500;
}
.workout-row .last-done {
  color: var(--text-dim);
  font-size: 13px;
}
.workout-row .suggested-pill {
  background: var(--accent);
  color: white;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Section heading */
.section-title {
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 12px;
  color: var(--text-dim);
  margin: 24px 0 10px 4px;
  font-weight: 600;
}

/* Workout view */
.workout-meta {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.workout-meta label {
  font-size: 12px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
}
.workout-meta input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
.workout-meta .full {
  grid-column: 1 / -1;
}

.exercise-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
  overflow: hidden;
}
.exercise-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.exercise-head-body { flex: 1; min-width: 0; }
.exercise-name {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 4px;
}
.exercise-prescription {
  color: var(--text-dim);
  font-size: 13px;
}
.exercise-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--border);
  flex: 0 0 auto;
  cursor: zoom-in;
}
.exercise-thumb:active { opacity: 0.85; }

/* Image modal */
.img-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  cursor: zoom-out;
}
.img-modal h3 {
  color: white;
  margin: 0 0 16px;
  text-align: center;
  font-size: 18px;
}
.img-modal-frames {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 100%;
}
.img-modal-frames img {
  max-width: 45vw;
  max-height: 65vh;
  background: #fff;
  border-radius: 8px;
}
@media (max-width: 600px) {
  .img-modal-frames img { max-width: 90vw; max-height: 40vh; }
}
.img-modal-close {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
}
.last-time {
  background: rgba(74,144,226,0.08);
  border-left: 3px solid var(--accent);
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-dim);
}
.last-time strong { color: var(--text); }

.sets-table {
  width: 100%;
  border-collapse: collapse;
}
.sets-table th, .sets-table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.sets-table th {
  background: var(--surface-2);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.sets-table th:first-child, .sets-table td:first-child { padding-left: 14px; width: 36px; text-align: center; }
.sets-table th:last-child, .sets-table td:last-child { padding-right: 14px; }
.sets-table .target { color: var(--text-dim); font-size: 13px; width: 70px; }
.sets-table input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 7px 8px;
  font-size: 15px;
  min-width: 0;
}
.sets-table input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg);
}
.sets-table .col-weight { width: 90px; }
.sets-table .col-reps   { width: 70px; }
.sets-table .col-notes  { min-width: 60px; }
.sets-table .set-done input { background: rgba(92,184,92,0.12); border-color: var(--good); }

/* ---------- Paged workout view ---------- */
.app-bar.workout-bar { padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
.workout-bar .back-btn { font-size: 24px; padding: 4px 10px; }
.workout-bar-title { flex: 1; min-width: 0; }
.workout-bar-name { font-size: 15px; font-weight: 600; margin-top: 2px; }

.page-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 12px 16px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: calc(56px + env(safe-area-inset-top));
  z-index: 9;
}
.page-dots .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.page-dots .dot:active { transform: scale(0.85); }
.page-dots .dot.on { background: var(--accent); border-color: var(--accent); width: 24px; border-radius: 6px; }
.page-dots .dot.done { background: var(--good); border-color: var(--good); }

main.workout-main {
  padding: 16px;
  padding-bottom: 110px;
}

/* Meta page */
.meta-page { max-width: 560px; margin: 0 auto; }
.page-title { margin: 0 0 4px; font-size: 22px; }
.page-sub { margin: 0 0 18px; color: var(--text-dim); font-size: 14px; }
.workout-summary {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.summary-title {
  padding: 10px 14px;
  background: var(--surface-2);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  font-weight: 600;
}
.summary-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.summary-row:active { background: var(--surface-2); }
.summary-num {
  background: var(--surface-2);
  color: var(--text-dim);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex: 0 0 auto;
}
.summary-name { flex: 1; font-weight: 500; }
.summary-prescription { color: var(--text-dim); font-size: 13px; }

/* Single-exercise page */
.exercise-page { max-width: 640px; margin: 0 auto; }
.exercise-page-head {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
}
.exercise-thumb-lg {
  width: 96px;
  height: 96px;
  object-fit: cover;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border);
  flex: 0 0 auto;
  cursor: zoom-in;
}
.exercise-page-name { font-size: 22px; font-weight: 700; line-height: 1.2; }
.exercise-page-prescription { color: var(--text-dim); font-size: 14px; margin-top: 4px; }
.exercise-page-counter {
  margin-top: 6px;
  display: inline-block;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.last-time.first-time {
  background: rgba(240,173,78,0.08);
  border-left-color: var(--warn);
}
.exercise-page .last-time {
  margin-bottom: 12px;
  border-radius: 6px;
}
.exercise-page .sets-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.exercise-page .sets-table input.prefilled {
  color: var(--text-dim);
  font-style: italic;
}

/* Superset page */
.superset-page .superset-banner {
  background: linear-gradient(90deg, #b8860b, #cd853f);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  text-align: center;
}
.superset-heads {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.superset-head-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  position: relative;
}
.slot-letter {
  background: var(--accent);
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex: 0 0 auto;
}
.superset-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
  cursor: zoom-in;
  flex: 0 0 auto;
}
.superset-head-body { flex: 1; min-width: 0; }
.superset-head-name { font-weight: 600; font-size: 14px; line-height: 1.2; }
.superset-head-prescription { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.superset-last { color: var(--text-dim); font-size: 11px; margin-top: 4px; }
.superset-last.first-time { color: var(--warn); }

.round-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.round-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  font-weight: 700;
  margin-bottom: 8px;
}
.round-row {
  display: grid;
  grid-template-columns: 28px 1fr 60px 70px auto 70px 70px;
  gap: 6px;
  align-items: center;
  padding: 6px 0;
  border-top: 1px solid var(--border);
}
.round-row:first-of-type { border-top: none; }
.round-row .slot-letter { width: 22px; height: 22px; font-size: 12px; }
.round-row .round-name { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.round-row .round-target { font-size: 11px; color: var(--text-dim); text-align: right; }
.round-row input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 6px 8px; font-size: 14px; min-width: 0; width: 100%; }
.round-row input:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.round-row input.prefilled { color: var(--text-dim); font-style: italic; }
.round-row .round-x { color: var(--text-dim); text-align: center; font-size: 13px; }
.round-row.set-done input { background: rgba(92,184,92,0.12); border-color: var(--good); }
.round-row.absent { opacity: 0.4; }
.round-row.absent .round-skip { grid-column: 3 / -1; font-size: 12px; font-style: italic; color: var(--text-dim); }

@media (max-width: 480px) {
  .round-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }
  .round-row .round-target { display: none; }
  .round-row .round-name { flex: 1 1 100%; font-size: 13px; color: var(--text); margin-left: 28px; }
  .round-row .slot-letter { order: -1; }
  .round-row .round-weight { width: 72px; flex: 0 0 72px; }
  .round-row .round-x { font-size: 13px; }
  .round-row .round-reps { width: 60px; flex: 0 0 60px; }
  .round-row .round-notes { width: 70px; flex: 1 1 70px; min-width: 0; }
}

/* Summary row for supersets */
.summary-row.is-super {
  background: rgba(184,134,11,0.06);
}
.super-tag {
  display: inline-block;
  background: #b8860b;
  color: white;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
}
.super-amp { color: var(--text-dim); margin: 0 6px; font-size: 12px; }

/* Bottom nav */
.page-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  z-index: 20;
}
.page-nav button {
  flex: 1;
  padding: 14px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  font-size: 16px;
}
.page-nav .nav-prev {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  flex: 0 0 35%;
}
.page-nav .nav-prev:disabled { opacity: 0.4; }
.page-nav .nav-next { background: var(--accent); color: white; }
.page-nav .nav-next:active { background: #3a7bc8; }
.page-nav .nav-finish { background: var(--good); color: white; }
.page-nav .nav-finish:active { background: #4a9d4a; }

/* Save button — legacy sticky footer (kept for non-workout views if needed) */
.save-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  z-index: 20;
}
.save-bar button {
  flex: 1;
  padding: 14px;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  font-size: 16px;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:active { background: #3a7bc8; }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border) !important;
  flex: 0 0 auto;
  padding: 14px 18px;
}
.btn-danger { background: transparent; color: var(--bad); border: 1px solid var(--bad) !important; }

/* History */
.history-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.history-row .date {
  font-weight: 600;
  font-size: 14px;
  min-width: 90px;
}
.history-row .info {
  flex: 1;
  font-size: 14px;
  color: var(--text-dim);
}
.history-row .info .wname { color: var(--text); display: block; font-weight: 500; margin-bottom: 2px; }
.history-row .chev { color: var(--text-dim); }

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
  font-size: 14px;
}

/* Phase chip on workout view */
.phase-chip {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

/* Detail (read-only history) */
.detail-set {
  display: flex;
  gap: 10px;
  padding: 4px 0;
  font-size: 14px;
}
.detail-set .num { color: var(--text-dim); width: 30px; }
.detail-set .vals { flex: 1; }
.detail-set .note { color: var(--text-dim); font-style: italic; font-size: 13px; }

/* RPE help — header trigger + banner button + modal */
.sets-table th.rpe-help {
  cursor: help;
  user-select: none;
  white-space: nowrap;
}
.sets-table th.rpe-help .qmark,
.rpe-help-btn {
  display: inline-block;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  line-height: 14px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  margin-left: 4px;
}
.rpe-help-btn {
  background: rgba(255,255,255,0.18);
  color: white;
  border-color: rgba(255,255,255,0.3);
  width: auto;
  height: auto;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  cursor: pointer;
  margin-left: 8px;
  vertical-align: middle;
}
.rpe-help-btn:active { background: rgba(255,255,255,0.3); }

.info-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 110;
  padding: 20px;
  cursor: zoom-out;
}
.info-modal-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  max-width: 420px;
  width: 100%;
  cursor: auto;
  position: relative;
}
.info-modal-body h3 { margin: 0 0 10px; font-size: 18px; }
.info-modal-body p { margin: 0 0 12px; line-height: 1.5; font-size: 14px; }
.rpe-table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.rpe-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
.rpe-table tr:last-child td { border-bottom: none; }
.rpe-table td:first-child { font-weight: 700; width: 36px; color: var(--accent); text-align: center; background: var(--surface-2); border-radius: 4px; }
.info-note { color: var(--text-dim); font-size: 13px; padding-top: 4px; }
.info-modal-ok {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.info-modal-ok:active { background: #3a7bc8; }

/* Exercise library */
.library-intro {
  color: var(--text-dim);
  font-size: 14px;
  margin: 4px 0 14px;
}
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.library-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform 0.1s;
}
.library-card:active { transform: scale(0.97); }
.library-img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--surface-2);
  display: block;
  border-bottom: 1px solid var(--border);
}
.library-img-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 12px;
}
.library-body {
  padding: 8px 10px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.library-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
}
.library-slots {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.3px;
}

/* Numeric inputs — strip arrows & enable proper mobile keypad */
input[type="number"] {
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

@media (min-width: 600px) {
  .sets-table .col-weight { width: 110px; }
  .sets-table .col-reps   { width: 90px; }
}
