:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #d74c2f;
  --ok-bg: #eff6ff;
  --warn-bg: #fff3da;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 2.75rem;
  line-height: 0.98;
}

h2 {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.dev-banner {
  background: var(--accent);
  color: white;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.4rem 5vw;
  position: sticky;
  text-align: center;
  top: 0;
  z-index: 6;
}

.topbar {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-inner {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin: 0 auto;
  max-width: 1120px;
  min-height: 64px;
  padding: 0 5vw;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand {
  font-weight: 800;
}

.topbar nav {
  display: flex;
  gap: 0.75rem;
}

.topbar nav a {
  color: var(--muted);
  font-weight: 650;
}

.topbar-username {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.topbar-logout {
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
  transition: border-color 0.15s, color 0.15s;
}

.topbar-logout:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.topbar-admin-btn {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  opacity: 0.6;
  text-decoration: none;
  transition: opacity 0.15s;
}

.topbar-admin-btn:hover {
  opacity: 1;
}

/* ── Pages auth ─────────────────────────────────────────────── */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem 5vw;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.07);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
}

.auth-brand {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--ink);
  margin: 0 0 0.25rem;
}

.auth-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 2rem;
}

.auth-form {
  display: grid;
  gap: 1rem;
}

.auth-form label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.auth-submit {
  margin-top: 0.5rem;
  width: 100%;
}

.auth-footer {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.auth-footer a {
  color: var(--primary);
  font-weight: 600;
}

.page {
  display: grid;
  gap: 2rem;
  margin: 0 auto;
  max-width: 1120px;
  padding: 2rem 5vw 4rem;
}

.hero,
.session-header {
  align-items: end;
  display: flex;
  gap: 1.5rem;
  justify-content: space-between;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 0.5rem;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 1.25rem;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stack {
  display: grid;
  gap: 0.75rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  padding: 1.25rem;
}

.panel.narrow {
  margin: 0 auto;
  max-width: 520px;
  width: 100%;
}

.button {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 750;
  justify-content: center;
  min-height: 44px;
  padding: 0.65rem 1rem;
}

.button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  transition: background 0.15s ease;
}

.button.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.button.compact {
  min-height: 40px;
  padding: 0.45rem 0.85rem;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.session-row,
.history-row {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  display: flex;
  justify-content: space-between;
  min-height: 64px;
  padding: 1rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.session-row:hover,
.history-row:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 10px rgba(37,99,235,0.10);
  transform: translateY(-1px);
}

.session-row.active {
  border-color: var(--primary);
  background: var(--ok-bg);
}

.history-row small {
  color: var(--muted);
  display: block;
  margin-top: 0.2rem;
}

.workout {
  display: grid;
  gap: 1.5rem;
}

.rest-timer {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  padding: 1rem 1.25rem;
}

.rest-timer.finished {
  background: var(--warn-bg);
}

.rest-timer-value {
  font-size: 1.6rem;
  font-weight: 800;
}

.exercise-block {
  display: grid;
  gap: 0.75rem;
}

.exercise-block .rest-timer {
  margin: 0.25rem 0;
}

.exercise-title {
  align-items: center;
  display: flex;
  gap: 0.75rem;
}

.exercise-order-form {
  align-items: center;
  display: flex;
  gap: 0.6rem;
}

.order {
  align-items: center;
  background: var(--ink);
  border-radius: 999px;
  color: white;
  display: inline-flex;
  font-weight: 800;
  height: 32px;
  justify-content: center;
  width: 32px;
}

.order-inline {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 0.8rem;
  font-weight: 750;
  gap: 0.45rem;
}

.order-inline input {
  min-height: 38px;
  width: 72px;
}

.order-submit {
  height: 0;
  opacity: 0;
  overflow: hidden;
  padding: 0;
  pointer-events: none;
  position: absolute;
  width: 0;
}

.order-fallback {
  min-height: 38px;
}

.series-list {
  display: grid;
  gap: 0.5rem;
}

.series-row {
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: minmax(220px, 1.7fr) repeat(3, minmax(84px, 0.55fr)) auto minmax(140px, 0.8fr);
  padding: 0.75rem;
}

.series-row.done {
  background: var(--ok-bg);
}

.series-row.error {
  background: var(--warn-bg);
}

.series-meta {
  display: grid;
  gap: 0.2rem;
}

.series-meta span,
.line-status {
  color: var(--muted);
  font-size: 0.9rem;
}

.line-feedback {
  display: grid;
  gap: 0.2rem;
  min-width: 120px;
}

.line-rest {
  color: var(--muted);
  font-size: 0.8rem;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 0.8rem;
  font-weight: 750;
  gap: 0.25rem;
}

input,
select,
textarea {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  min-height: 42px;
  padding: 0.55rem 0.65rem;
  width: 100%;
}

input.locked {
  background: #f2f5f1;
  color: var(--muted);
}

input:disabled,
select:disabled,
textarea:disabled {
  background: #f2f5f1;
  color: var(--muted);
  cursor: not-allowed;
}

textarea {
  resize: vertical;
}

.form p {
  display: grid;
  gap: 0.35rem;
  margin: 0;
}

.form.compact-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form.compact-grid p:first-of-type,
.form.compact-grid button {
  grid-column: 1 / -1;
}

.messages {
  display: grid;
  gap: 0.5rem;
}

.message {
  border-radius: 8px;
  margin: 0;
  padding: 0.75rem 1rem;
}

.message.success {
  background: var(--ok-bg);
}

.message.error {
  background: var(--warn-bg);
}

@media (max-width: 820px) {
  h1 {
    font-size: 2rem;
  }

  .topbar-inner {
    flex-direction: column;
    align-items: flex-start;
    min-height: unset;
    padding-top: 0.8rem;
    padding-bottom: 0.8rem;
    gap: 0.4rem;
  }

  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .hero,
  .session-header {
    align-items: start;
    flex-direction: column;
  }

  .exercise-title {
    align-items: start;
    flex-direction: column;
  }

  .grid.two {
    grid-template-columns: 1fr;
  }

  .series-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .series-meta,
  .line-feedback {
    grid-column: 1 / -1;
  }
}

/* ── Mensurations ─────────────────────────────────────────── */

.mensuration-list {
  display: grid;
  gap: 1rem;
}

.mensuration-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.mensuration-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.5rem 1rem;
}

.mensuration-cell {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.mensuration-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mensuration-value {
  font-weight: 600;
  font-size: 1rem;
}

.delta {
  font-size: 0.8rem;
  font-weight: 700;
  margin-left: 0.3rem;
}

.delta.positive { color: var(--primary); }
.delta.negative { color: var(--accent); }

.mensuration-notes {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
}

.mensuration-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.form-field {
  display: grid;
  gap: 0.25rem;
}

/* ── Hub Planifier ───────────────────────────────────────── */

.hub-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 820px) {
  .hub-grid { grid-template-columns: 1fr; }
}

.seance-type-row {
  align-items: center;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}

.seance-type-row:last-child { border-bottom: none; }

.seance-type-meta {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.1rem;
}

.btn-icon {
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
}

.btn-icon:hover { border-color: var(--primary); color: var(--primary); }
.btn-icon.danger:hover { border-color: var(--accent); color: var(--accent); }

/* ── Panel exercices ─────────────────────────────────────── */

.exercice-panel-header {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.exercice-search-input {
  min-height: 36px;
  width: 220px;
  font-size: 0.88rem;
}

.exercice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.5rem;
}

.exercice-card {
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.6rem 0.85rem;
  transition: border-color 0.15s;
}

.exercice-card:hover { border-color: var(--primary); }

.exercice-card-nom {
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--ink);
  width: 100%;
}

.exercice-card-cat {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  width: 100%;
}

/* ── Formset TemplateLigne ────────────────────────────────── */

.formset-wrap {
  overflow-x: auto;
}

.formset-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.formset-table th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.4rem 0.5rem;
  text-align: left;
  text-transform: uppercase;
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}

.formset-table td {
  padding: 0.3rem 0.5rem;
  vertical-align: middle;
}

.formset-table tbody tr:hover td { background: #f9faff; }

.formset-table input,
.formset-table select {
  min-height: 36px;
  font-size: 0.88rem;
}

input.tl-xs, select.tl-xs { width: 58px; }
input.tl-sm, select.tl-sm { width: 78px; }
select.tl-exercice          { width: 200px; }

.formset-delete-col { text-align: center; width: 36px; }
.formset-delete-col input[type="checkbox"] { width: auto; min-height: unset; }

.formset-add-btn {
  background: none;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  margin-top: 0.75rem;
  padding: 0.5rem 1rem;
  transition: border-color 0.15s, color 0.15s;
  width: 100%;
}

.formset-add-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Mensuration form layout ─────────────────────────────── */

.mensuration-form-layout {
  display: grid;
  gap: 2rem;
  grid-template-columns: 1fr auto;
  align-items: start;
}

.mensuration-guide-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 0.5rem;
}

.body-guide-img {
  width: 200px;
  height: auto;
}

@media (max-width: 720px) {
  .mensuration-form-layout {
    grid-template-columns: 1fr;
  }

  .mensuration-guide-panel {
    order: -1;
  }

  .body-guide-img {
    width: 160px;
  }
}

/* ── Pages d'erreur ───────────────────────────────────────── */

.error-page {
  max-width: 640px;
  margin: 4rem auto 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.error-page h1 {
  margin-bottom: 0.25rem;
}

/* ── Dashboard ────────────────────────────────────────────── */

.dashboard-grid {
  display: grid;
  grid-template-columns: 3fr 7fr;
  grid-template-rows: auto auto auto;
  column-gap: 2.5rem;
  row-gap: 2rem;
  align-items: start;
}

.db-encours     { grid-column: 1; grid-row: 1; }
.db-planifiees  { grid-column: 1; grid-row: 2; }
.db-recentes    { grid-column: 1; grid-row: 3; }
.db-progression { grid-column: 2; grid-row: 1 / span 2; }
.db-mensurations{ grid-column: 2; grid-row: 3; }

.mensuration-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.15s;
}

.mensuration-card:hover {
  border-color: var(--primary);
}

.mensuration-date {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.mensuration-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
}

.mensuration-row span {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.mensuration-row strong {
  font-size: 1.1rem;
}

.mensuration-row em {
  font-size: 0.75rem;
  color: var(--muted);
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

@media (max-width: 720px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    grid-template-rows: unset;
  }
  .db-encours     { grid-column: 1; grid-row: 1; }
  .db-planifiees  { grid-column: 1; grid-row: 3; }
  .db-progression { grid-column: 1; grid-row: 4; }
  .db-mensurations{ grid-column: 1; grid-row: 5; }
  .db-recentes    { grid-column: 1; grid-row: 6; }
}

/* ── Progression ──────────────────────────────────────────── */

.progression-header {
  align-items: baseline;
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.exercice-select {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-size: 1rem;
  padding: 0.4rem 0.75rem;
  background: var(--surface);
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  padding: 1.5rem;
}

.chart-empty {
  color: var(--muted);
  padding: 2rem 0;
  text-align: center;
}

.chart-meta {
  align-items: baseline;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.chart-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.chart-pr {
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
}

.chart-wrap {
  position: relative;
}

/* ── Media queries ────────────────────────────────────────── */

@media (max-width: 520px) {
  .topbar nav {
    justify-content: space-between;
    width: 100%;
  }

  .series-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .button.compact {
    width: 100%;
  }

  .rest-timer {
    align-items: start;
    flex-direction: column;
  }
}
