/* ==========================================================================
   Cadence — black/white with orange accent. Mobile-first.
   ========================================================================== */

:root {
  --bg: #FFFFFF;
  --bg-soft: #FAFAFA;
  --ink: #111111;
  --ink-2: #333333;
  --muted: #6B6B6B;
  --line: #E6E6E6;
  --line-strong: #CFCFCF;
  --accent: #FF5A1F;
  --accent-dark: #E04A12;
  --accent-soft: #FFF1EA;
  --danger: #C0392B;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --tap: 44px;
  --display: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  --body: 'DM Sans', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-soft);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  max-width: 100vw;
}

.app { overflow-x: hidden; }

body { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }

h1, h2, h3, h4 {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }

/* ------- Layout ---------------------------------------------------------- */
.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.tab-view { display: none; padding: 20px 16px 16px; }
.tab-view.active { display: block; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.top .brand {
  font-family: var(--display);
  font-weight: 700;
  font-size: 24px;
  letter-spacing: 0.02em;
}
.top .brand .dot { color: var(--accent); }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--ink);
  font-size: 20px;
  padding: 0;
}
.icon-btn:active { background: var(--bg-soft); }

/* ------- Bottom tab bar -------------------------------------------------- */
.tabbar {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: center;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar-inner {
  max-width: 520px;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}
.tabbar button {
  background: none;
  border: none;
  padding: 10px 4px;
  color: var(--muted);
  font-family: var(--body);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  min-height: 60px;
}
.tabbar button .glyph { font-size: 20px; line-height: 1; }
.tabbar button.active { color: var(--accent); font-weight: 700; }

/* ------- Buttons --------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  font-family: var(--body);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.05s ease;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:active { background: var(--accent-dark); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.subtle { background: var(--bg-soft); border-color: var(--line); color: var(--ink); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.wide { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 13px; }

/* ------- Cards ----------------------------------------------------------- */
.card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card h3 { margin-bottom: 6px; }
.card .subtle { color: var(--muted); font-size: 13px; }
.card .row { display: flex; align-items: center; gap: 10px; }
.card .row + .row { margin-top: 8px; }
.card .row.between { justify-content: space-between; }

/* ------- Inputs ---------------------------------------------------------- */
.input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--body);
  font-size: 16px;
  background: var(--bg);
  color: var(--ink);
}
.input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ink);
}
textarea { min-height: 80px; resize: vertical; }
label.field { display: block; margin-bottom: 10px; }
label.field .lbl {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.pill.accent { background: var(--accent-soft); color: var(--accent-dark); border-color: var(--accent-soft); }
.pill.pr { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }

/* ------- Set rows -------------------------------------------------------- */
.exercise {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  margin-bottom: 12px;
  overflow: hidden;
}
.exercise.superset {
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent);
}
.exercise-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  gap: 8px;
}
.exercise-header .name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
}
.exercise-header .meta { color: var(--muted); font-size: 12px; }
.exercise-body { padding: 8px 12px 12px; }
.last-session {
  font-size: 13px;
  color: var(--muted);
  padding: 8px 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin: 4px 0 10px;
}
.last-session b { color: var(--ink); font-weight: 700; }

.set-row {
  display: grid;
  grid-template-columns: 32px 1fr 1fr 60px 44px 32px;
  gap: 6px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
}
.set-row:last-child { border-bottom: none; }
.set-row .idx {
  font-family: var(--display);
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}
.set-row .idx.pr { color: var(--accent); }
.set-row input {
  min-height: 40px;
  min-width: 0;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 15px;
  font-family: var(--body);
  text-align: center;
  background: var(--bg);
}
.set-row input:focus { outline: none; border-color: var(--ink); }
.set-row input:disabled { background: transparent; color: var(--ink); opacity: .85; border-color: transparent; }
.set-row .confirm {
  min-height: 40px; min-width: 40px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.set-row .confirm:active { transform: scale(0.94); }
.set-row .confirm.on {
  background: #2f9e5c;
  border-color: #2f9e5c;
  color: #fff;
}
.set-row.confirmed { background: rgba(47, 158, 92, 0.08); }
.set-row.confirmed .idx { color: #2f9e5c; }
.set-row.bw input[data-field="weight"]::placeholder { color: var(--muted); font-style: italic; }
.set-row .del {
  background: none; border: none; color: var(--muted); font-size: 22px;
  cursor: pointer; min-height: 40px; min-width: 32px; line-height: 1;
}
.set-row .del:active { color: var(--accent); }
.set-row.pr { background: var(--accent-soft); }
.set-row.pr.confirmed { background: var(--accent-soft); }

/* Full-screen flash when the rest timer hits zero. */
.rest-flash {
  position: fixed; inset: 0;
  background: var(--accent);
  opacity: 0;
  z-index: 9999;
  pointer-events: none;
  transition: opacity .12s ease-out;
}
.rest-flash.on { opacity: 0.85; }

/* Post-workout summary. */
.summary { padding: 4px 0 8px; }
.summary-hero {
  text-align: center;
  padding: 24px 12px 20px;
  background: linear-gradient(180deg, var(--accent-soft) 0%, transparent 100%);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.summary-vol {
  font-family: var(--display);
  font-weight: 800;
  font-size: 44px;
  color: var(--accent);
  line-height: 1;
}
.summary-vol-label {
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 6px;
}
.summary-comp {
  margin-top: 14px;
  font-size: 15px;
  color: var(--ink);
}
.summary-comp-eq { color: var(--muted); margin-right: 6px; }
.summary-comp-thing { font-weight: 700; }
.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.summary-stat {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-align: center;
  padding: 12px 8px;
}
.summary-stat-val {
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  color: var(--ink);
}
.summary-stat-lbl {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 3px;
}
.summary-note {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  font-style: italic;
}

.set-actions {
  display: flex;
  gap: 8px;
  padding: 8px 0 2px;
}
.set-actions .btn { flex: 1; }

/* ------- Exercise picker ------------------------------------------------- */
.picker-search {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 10px 0;
  z-index: 2;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 10px;
}
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.picker-list {
  max-height: 55vh;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}
.picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  gap: 8px;
}
.picker-item .name { font-weight: 600; }
.picker-item .meta { color: var(--muted); font-size: 12px; }
.picker-item.selected { background: var(--accent-soft); }
.picker-item .star {
  background: none; border: none; font-size: 18px;
  cursor: pointer; padding: 4px; color: var(--muted);
}
.picker-item .star.on { color: var(--accent); }
.picker-item .edit-btn {
  background: none; border: none; font-size: 16px;
  cursor: pointer; padding: 4px 6px; color: var(--muted);
}
.picker-item .edit-btn:hover { color: var(--accent); }

/* Sticky confirm bar inside the picker sheet */
.picker-action-bar {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 12px 0 4px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  z-index: 3;
}
.picker-action-bar .btn { min-width: 0; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

/* ------- Modal / sheet --------------------------------------------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: var(--bg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  animation: sheet-up 0.2s ease;
}
.sheet-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 20px;
  margin: 4px 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sheet-title .close {
  background: none; border: none; font-size: 24px; cursor: pointer;
  color: var(--muted);
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }

/* ------- Rest timer ------------------------------------------------------ */
.rest-timer {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 8px 10px 8px 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  z-index: 25;
  font-family: var(--display);
  font-weight: 700;
}
.rest-timer .rt-time {
  font-size: 20px;
  min-width: 52px;
  text-align: center;
  letter-spacing: 0.02em;
}
.rest-timer .rt-btn {
  background: rgba(255,255,255,0.14);
  border: none;
  color: #fff;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--body);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.rest-timer .rt-btn:active { background: rgba(255,255,255,0.32); }
.rest-timer.warn { background: var(--accent); }
.rest-timer.paused { background: var(--muted); }

/* ------- History --------------------------------------------------------- */
.history-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  margin-bottom: 10px;
  cursor: pointer;
}
.history-item .date {
  font-family: var(--display);
  font-weight: 700;
  color: var(--muted);
  font-size: 14px;
}
.history-item .title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
}
.history-item .summary { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ------- Progress -------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}
.stat .num {
  font-family: var(--display);
  font-weight: 700;
  font-size: 26px;
  color: var(--ink);
}
.stat .num.accent { color: var(--accent); }
.stat .lbl {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.chart-wrap { height: 220px; margin-top: 8px; }

.calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 32px));
  gap: 4px;
  margin-top: 8px;
  justify-content: start;
}
.calendar .day {
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}
.calendar .day.on { background: var(--accent); border-color: var(--accent); }
.calendar .day.hi { background: var(--accent-dark); border-color: var(--accent-dark); }
.calendar-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.calendar-legend .swatch {
  width: 12px; height: 12px; border-radius: 3px;
  background: var(--accent);
  display: inline-block;
}
.calendar-legend .swatch.off { background: var(--bg-soft); border: 1px solid var(--line); }

/* Monthly calendar (Progress tab) — compact, capped width */
.month-card {
  max-width: 340px;
}
.month-card .icon-btn { width: 32px; height: 32px; font-size: 16px; }
.month-card .icon-btn[disabled] { opacity: 0.35; pointer-events: none; }
.month-dow, .month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}
.month-dow { margin-bottom: 4px; }
.month-dow > div {
  font-family: var(--display);
  font-weight: 700;
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.06em;
  padding: 2px 0;
}
.month-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  font-family: var(--display);
  font-weight: 600;
  font-size: 12px;
  color: var(--ink);
  cursor: default;
  min-height: 0;
}
.month-day.empty { border-color: transparent; background: transparent; }
.month-day.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: pointer;
}
.month-day.on:active { background: var(--accent-dark); }
.month-day.today {
  box-shadow: inset 0 0 0 2px var(--ink);
}
.month-day.on.today {
  box-shadow: inset 0 0 0 2px #fff;
}

/* Progress two-column layout on wider screens */
.progress-grid {
  display: grid;
  gap: 12px;
}
@media (min-width: 768px) {
  .progress-grid {
    grid-template-columns: 340px 1fr;
    align-items: start;
  }
  .progress-grid .month-card { max-width: none; }
  .progress-grid > .month-card { grid-row: span 1; }
}

/* ------- Plan ------------------------------------------------------------ */
.plan-row {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  margin-bottom: 8px;
}
.plan-row .day {
  font-family: var(--display);
  font-weight: 700;
  color: var(--accent);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.plan-row .focus { font-family: var(--display); font-weight: 700; font-size: 16px; }
.plan-row .loc { color: var(--muted); font-size: 13px; }

.plan-week-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 4px;
}
.plan-week-tab {
  background: transparent;
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-family: var(--body);
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}
.plan-week-tab.active {
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

/* ------- Utility --------------------------------------------------------- */
.hstack { display: flex; align-items: center; gap: 8px; }
.hstack.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.center { text-align: center; }
.muted { color: var(--muted); }
.hr { height: 1px; background: var(--line); margin: 16px 0; }

.plates {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 8px 0;
}
.plate {
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
  font-family: var(--display);
  font-weight: 700;
  font-size: 14px;
}

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty .big {
  font-family: var(--display);
  font-weight: 700;
  font-size: 20px;
  color: var(--ink);
  margin-bottom: 4px;
}

.toast {
  position: fixed;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 100;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}
.toast.err { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ==========================================================================
   Desktop layout — top nav, wider column, two-column stats.
   ========================================================================== */
@media (min-width: 768px) {
  body { padding-bottom: 0; padding-top: 68px; }
  .app {
    max-width: 960px;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
  .tab-view { padding: 28px 32px 40px; }

  /* Move tab bar to top */
  .tabbar {
    top: 0;
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid var(--line);
    padding-bottom: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
  }
  .tabbar-inner {
    max-width: 960px;
    grid-template-columns: auto 1fr 1fr 1fr 1fr 1fr;
    align-items: center;
  }
  .tabbar-inner::before {
    content: 'Cadence.';
    font-family: var(--display);
    font-weight: 700;
    font-size: 20px;
    letter-spacing: 0.02em;
    padding-left: 24px;
    color: var(--ink);
  }
  .tabbar-inner::before .dot { color: var(--accent); }
  .tabbar button {
    flex-direction: row;
    gap: 8px;
    padding: 20px 12px;
    min-height: 68px;
    font-size: 14px;
  }
  .tabbar button .glyph { font-size: 16px; }
  .tabbar button.active {
    box-shadow: inset 0 -3px 0 var(--accent);
  }

  /* Hide the redundant Cadence brand on the Log tab on desktop */
  .top .brand { display: none; }

  /* Rest timer nudges up so it doesn't collide with bottom */
  .rest-timer { bottom: 24px; }

  /* Two-column stat grid becomes four */
  .stat-grid { grid-template-columns: repeat(4, 1fr); }

  /* Sheet becomes a centered modal instead of a bottom sheet */
  .sheet-backdrop { align-items: center; }
  .sheet {
    border-radius: 16px;
    max-width: 560px;
    max-height: 82vh;
    animation: sheet-in 0.15s ease;
  }
  @keyframes sheet-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

  /* Wider input rows */
  .set-row { grid-template-columns: 36px 1fr 1fr 100px 48px 36px; gap: 10px; }
}

