:root {
  --bg: #0f0f10;
  --surface: #18181b;
  --surface-2: #232327;
  --border: #2c2c30;
  --text: #f4f4f5;
  --muted: #9ca3af;
  --accent: #dc2626;
  --accent-hover: #ef4444;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 12px;
  --pad: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px var(--pad);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
  color: var(--accent);
}
.brand:hover { text-decoration: none; }
.topbar nav {
  display: flex;
  gap: 18px;
  flex: 1;
}
.topbar nav a {
  color: var(--muted);
  font-weight: 500;
  font-size: 15px;
}
.topbar nav a:hover {
  color: var(--text);
  text-decoration: none;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}
.user-name {
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}
.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}
.logout-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
@media (max-width: 600px) {
  .topbar nav { gap: 12px; font-size: 13px; }
  .topbar nav a { font-size: 13px; }
  .user-menu { gap: 6px; padding-left: 8px; }
  .user-name { font-size: 12px; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--pad);
  padding-bottom: 80px;
}

h1 { font-size: 28px; margin: 8px 0 16px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; color: var(--muted); font-weight: 600; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 16px;
}
.card.hero {
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
}
.danger-zone {
  border-color: rgba(239, 68, 68, 0.3);
}

.pill {
  display: inline-block;
  background: var(--surface-2);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Forms */
label {
  display: block;
  margin: 12px 0;
  font-size: 14px;
  color: var(--muted);
}
label.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
input, select, textarea, button {
  font: inherit;
  color: inherit;
}
input[type="number"], input[type="text"], input[type="password"], input[type="email"], input[type="date"], select, textarea {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  color-scheme: dark;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 60px; }
fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px var(--pad) 16px;
  margin: 16px 0;
}
fieldset legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Buttons */
button, .btn {
  display: inline-block;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  transition: background 0.1s ease;
  text-decoration: none;
}
button:hover, .btn:hover { background: var(--border); text-decoration: none; }
button.primary, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover, .btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
button.danger, .btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}
button.small {
  padding: 4px 10px;
  font-size: 13px;
}
button.big, .btn.big {
  padding: 16px 24px;
  font-size: 18px;
  width: 100%;
  margin-top: 8px;
}
button.icon-btn {
  padding: 4px 10px;
  font-size: 18px;
  line-height: 1;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
button.icon-btn:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: stretch;
}
.inline-form input, .inline-form select {
  width: auto;
  flex: 1;
  margin: 0;
}
.inline-form button { white-space: nowrap; }

.banner {
  padding: 10px 14px;
  border-radius: 8px;
  margin: 8px 0 16px;
}
.banner-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--danger);
  color: #fca5a5;
}
.banner-info {
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: #c7d2fe;
}

/* Auth pages */
.auth-body { background: var(--bg); }
.container.narrow { max-width: 420px; }
.auth-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 32px 0 24px;
}
.auth-brand .brand-mark {
  font-weight: 800;
  font-size: 26px;
  color: var(--accent);
  letter-spacing: -0.02em;
}
.auth-page h1 { margin: 0 0 16px; }
.auth-page .card { padding: 20px; }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
tr:last-child td { border-bottom: none; }
table.mini { font-size: 13px; }
table.mini th, table.mini td { padding: 4px 6px; }

.tm-table td:first-child { font-weight: 600; }

/* Workout header */
.workout-header {
  margin-bottom: 16px;
}
.workout-header h1 { margin: 8px 0 4px; }

/* Set rows */
.set-row {
  display: grid;
  grid-template-columns: 56px 1fr auto 44px;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  margin: 0;
}
.set-row:last-child { border-bottom: none; }
.set-row.done {
  background: linear-gradient(90deg, rgba(34, 197, 94, 0.10) 0%, transparent 60%);
}
.set-row.amrap .set-num {
  color: var(--accent);
  font-weight: 700;
}
.set-num {
  font-weight: 600;
  color: var(--muted);
  font-size: 14px;
}
.set-prescribed {
  font-weight: 600;
  font-size: 15px;
}
.set-actual {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
}
.set-actual input {
  width: 64px;
  padding: 8px 4px;
  margin: 0;
  text-align: center;
  font-size: 16px;
}
.set-actual span { color: var(--muted); }

.done-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 20px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.done-btn:hover {
  border-color: var(--success);
  color: var(--success);
  background: rgba(34, 197, 94, 0.1);
}
.done-btn.is-done {
  border-color: var(--success);
  background: var(--success);
  color: #fff;
}
.done-btn.is-done:hover {
  background: rgba(34, 197, 94, 0.85);
}

@media (max-width: 480px) {
  .set-row {
    grid-template-columns: 50px 1fr 40px;
    grid-template-rows: auto auto;
    row-gap: 6px;
  }
  .set-actual {
    grid-column: 1 / 3;
  }
  .done-btn {
    grid-column: 3;
    grid-row: 1 / 3;
    width: 40px;
    height: 40px;
    align-self: center;
  }
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 0 0 12px;
}
.tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Accessories */
.accessory-form {
  display: grid;
  grid-template-columns: 1fr 80px 80px auto;
  gap: 8px;
  margin: 8px 0 12px;
  align-items: stretch;
}
.accessory-form select, .accessory-form input {
  margin: 0;
  padding: 10px;
}
.accessory-form button { padding: 10px 16px; }
.accessory-hint { margin: 4px 0 12px; font-size: 12px; line-height: 1.4; }

.manual-pr-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}
.manual-pr-form label { margin: 0; }
.manual-pr-form button { margin-top: 4px; }
.manual-pr-form input[type="date"] {
  /* Input[date] in dark theme needs explicit color-scheme so the calendar icon is visible */
  color-scheme: dark;
}

.pr-target {
  color: var(--accent);
  font-weight: 600;
  margin-left: 4px;
}
.accessory-list { display: flex; flex-direction: column; gap: 6px; }
.accessory-row {
  display: grid;
  grid-template-columns: 22px 1fr auto auto auto auto;
  gap: 6px;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 14px;
}
.accessory-row.done {
  background: linear-gradient(90deg, rgba(34, 197, 94, 0.10) 0%, var(--surface-2) 60%);
}
.accessory-row.is-paired {
  border-left: 3px solid var(--accent);
  padding-left: 9px;
}
.accessory-row.is-drop {
  border-left: 3px solid #6366f1;
  padding-left: 9px;
}
.accessory-row.is-paired.is-drop {
  /* When both, show a vertical split: red on top half, indigo on bottom */
  border-left: 3px solid;
  border-image: linear-gradient(180deg, var(--accent) 0 50%, #6366f1 50% 100%) 1;
}
.superset-icon {
  color: var(--accent);
  font-size: 13px;
  margin-right: 4px;
}
.drop-icon {
  color: #a5b4fc;
  font-size: 13px;
  margin-right: 4px;
  font-weight: 700;
}
.failure-tag {
  display: inline-block;
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Recommendation chips (workout + settings) */
.recommendations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 4px 0 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}
.recommendations > .muted { width: 100%; margin-bottom: 2px; }
.recommendation-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.1s ease;
}
.recommendation-chip:hover {
  border-color: var(--accent);
  background: rgba(220, 38, 38, 0.1);
}
.recommendation-chip.static { cursor: default; }
.recommendation-chip.static:hover { border-color: var(--border); background: var(--surface-2); }
.chip-x {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0 0 0 4px;
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
}
.chip-x:hover { color: var(--danger); background: transparent; }
.recommendation-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}
.accessory-pair-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 4px 0 12px 18px;
  padding: 10px 12px;
  background: rgba(220, 38, 38, 0.06);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  align-items: stretch;
}
.accessory-pair-form .pair-form-hint {
  grid-column: 1 / -1;
  margin-bottom: 4px;
}
.accessory-pair-form select { grid-column: 1 / -1; margin: 0; }
.accessory-pair-form input { margin: 0; }
.accessory-pair-form button { margin: 0; padding: 8px 12px; }
.pair-btn { font-size: 14px; padding: 4px 8px; }
.pair-btn:hover { color: var(--accent); background: rgba(220, 38, 38, 0.1); }
.drop-btn { font-size: 16px; padding: 4px 8px; line-height: 1; font-weight: 700; }
.drop-btn:hover { color: #a5b4fc; background: rgba(99, 102, 241, 0.1); }

.accessory-drop-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 4px 0 12px 18px;
  padding: 10px 12px;
  background: rgba(99, 102, 241, 0.06);
  border-left: 3px solid #6366f1;
  border-radius: 0 8px 8px 0;
  align-items: stretch;
}
.accessory-drop-form .drop-form-hint { grid-column: 1 / -1; margin-bottom: 4px; }
.accessory-drop-form input { margin: 0; }
.accessory-drop-form button { margin: 0; padding: 8px 12px; }
.acc-check {
  color: var(--success);
  font-weight: 700;
  font-size: 16px;
}
.acc-name { font-weight: 600; }
.acc-vol { color: var(--muted); }
.acc-vol strong { color: var(--text); }

/* Finish bar */
.finish-bar {
  position: sticky;
  bottom: 16px;
  margin-top: 24px;
}

/* Per-lift stat grid */
.lift-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 600px) {
  .lift-grid { grid-template-columns: 1fr 1fr; }
}
.lift-stat {
  background: var(--surface-2);
  padding: 12px;
  border-radius: 8px;
}
.lift-stat h3 { margin: 0 0 8px; color: var(--text); font-size: 16px; }
.lift-stat dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0 0 12px;
  font-size: 13px;
}
.lift-stat dt { color: var(--muted); }
.lift-stat dd { margin: 0; font-weight: 600; }

/* Accessory history */
.records {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 0;
}
@media (min-width: 500px) {
  .records { grid-template-columns: repeat(3, 1fr); }
}
.records dt {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.records dd { margin: 0; font-weight: 600; font-size: 16px; }

.date-group { margin-bottom: 16px; }
.date-group h3 { margin: 12px 0 4px; color: var(--text); }
.set-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.set-list li {
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: 6px;
  font-size: 14px;
}

/* Week strip on home */
.week-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}
.day-cell {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
  min-height: 60px;
}
.day-cell.is-today {
  border-color: var(--accent);
  background: rgba(220, 38, 38, 0.08);
}
.day-cell.is-rest {
  opacity: 0.55;
}
.day-name {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.day-lift {
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
  line-height: 1.2;
}

.rest-card { background: linear-gradient(180deg, #1a2334 0%, var(--surface) 100%); }
.rest-card .pill { background: rgba(99, 102, 241, 0.2); color: #a5b4fc; }

/* Extra-training (off-schedule) form */
.extra-card details > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  padding: 4px 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  list-style: none;
}
.extra-card details > summary::-webkit-details-marker { display: none; }
.extra-card details > summary::before {
  content: '▸';
  color: var(--muted);
  font-size: 12px;
  display: inline-block;
  transition: transform 0.15s ease;
}
.extra-card details[open] > summary::before { transform: rotate(90deg); }
.extra-card summary:hover .extra-summary-label { color: var(--text); }
.extra-summary-label {
  font-weight: 600;
  color: var(--muted);
}
.extra-card details[open] .extra-summary-label { color: var(--text); }
.extra-form { margin-top: 10px; }

.badge-extra {
  display: inline-block;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  vertical-align: middle;
}

.cal-workout.is-extra {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.4);
  border-style: dashed;
}
.cal-workout.is-extra .cal-check { color: #a5b4fc; }

/* Calendar */
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.cal-nav h1 { margin: 0; font-size: 22px; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-head {
  text-align: center;
  padding: 6px 0;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.cal-cell {
  min-height: 70px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}
.cal-cell.is-blank {
  background: transparent;
  border: none;
}
.cal-cell.is-today {
  border-color: var(--accent);
  background: rgba(220, 38, 38, 0.08);
}
.cal-cell.is-future { opacity: 0.85; }
.cal-cell.is-past:not(.has-workout):not(.is-rest) {
  opacity: 0.5;
}
.cal-cell.is-rest { opacity: 0.6; }
.cal-date {
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
}
.cal-cell.is-today .cal-date { color: var(--accent); }
.cal-workout {
  display: block;
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.4);
  border-radius: 4px;
  padding: 3px 5px;
  font-size: 11px;
  line-height: 1.25;
  color: var(--text);
  text-decoration: none;
}
.cal-workout:hover { background: rgba(34, 197, 94, 0.25); text-decoration: none; }
.cal-workout.in-progress {
  background: rgba(220, 38, 38, 0.15);
  border-color: rgba(220, 38, 38, 0.4);
}
.cal-check { font-weight: 700; color: var(--success); margin-right: 2px; }
.cal-workout.in-progress .cal-check { color: var(--accent); }
.cal-scheduled {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.cal-rest { color: var(--muted); font-size: 11px; }

@media (max-width: 600px) {
  .cal-cell { min-height: 56px; padding: 4px; }
  .cal-scheduled, .cal-workout { font-size: 10px; }
}

/* Charts */
.sparkline {
  display: block;
  color: var(--accent);
  width: 100%;
  height: auto;
  max-height: 50px;
}
.sparkline.empty { color: var(--muted); }
.lift-sparkline {
  margin: 8px 0 12px;
}
.chart-wrap {
  margin: 8px 0;
  color: var(--text);
}
.line-chart {
  width: 100%;
  height: auto;
  display: block;
  color: var(--text);
}
.chart-empty {
  padding: 32px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 14px;
}
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.stat-row > div { background: var(--surface-2); padding: 10px; border-radius: 8px; }
.stat-row dt {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}
.stat-row dd { margin: 0; font-weight: 600; font-size: 15px; }

/* HTMX request indicator */
.htmx-request { opacity: 0.6; }
.htmx-swapping { opacity: 0; transition: opacity 0.1s; }
