/* GymTrack — style volontairement minimaliste (sera remplacé par la charte définitive). */

:root {
  --bg: #f6f6f7;
  --surface: #ffffff;
  --text: #17181a;
  --muted: #6b6f76;
  --border: #e3e4e7;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --accent-soft: #e8effd;
  --danger: #c93a3a;
  --up: #1d8a4e;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --surface: #1d1e20;
    --text: #ececee;
    --muted: #9a9ea6;
    --border: #2e3034;
    --accent: #6d9bff;
    --accent-text: #0b1530;
    --accent-soft: #1f2a44;
    --danger: #ff7a7a;
    --up: #5fd08e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px calc(96px + env(safe-area-inset-bottom));
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; padding: 48px 0; }
.error { color: var(--danger); margin: 0; }
svg:not(.chart) { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Boutons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
}
.btn.small { padding: 6px 12px; min-height: 40px; font-size: .9rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; min-height: 0; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: none;
  color: var(--text);
  cursor: pointer;
  flex: none;
}
.icon-btn:hover, .btn:hover:not(:disabled) { filter: brightness(.96); }
.icon-btn:active { background: var(--accent-soft); }

/* ---------- Images ---------- */
.thumb, .avatar, .photo-img {
  display: grid;
  place-items: center;
  object-fit: cover;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  flex: none;
}
.thumb { width: 56px; height: 56px; border-radius: 10px; font-size: 1.3rem; }
.avatar { width: 72px; height: 72px; border-radius: 50%; font-size: 1.6rem; }
.avatar.small { width: 36px; height: 36px; font-size: 1rem; }
.avatar svg { width: 28px; height: 28px; }

/* ---------- Hub ---------- */
.hub-header { text-align: center; padding: 40px 0 24px; }
.hub-header h1 { font-size: 2rem; margin-bottom: 4px; }
.profiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}
.profile-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
  font: inherit;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.profile-card.new { border-style: dashed; background: transparent; box-shadow: none; }
.profile-name { font-weight: 600; text-align: center; word-break: break-word; }
.profile-card .lock { position: absolute; top: 10px; right: 10px; color: var(--muted); }
.profile-card .lock svg { width: 16px; height: 16px; }

/* ---------- Barre du haut + recherche ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
}
.topbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync { font-size: .75rem; color: var(--muted); }
.sync[data-state="offline"] { color: var(--danger); }

.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 8px 0 10px;
}
.search {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-top: 10px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- Tableau des exercices ----------
   Mobile : chaque ligne est une carte compacte.
   Large écran : vraie grille de tableur (cf. media query plus bas). */
.table-head { display: none; }
.group-title {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 18px 0 8px;
}
.row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  column-gap: 12px;
  row-gap: 4px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.row .thumb { grid-row: span 2; align-self: start; }
.row-main, .row-muscles { grid-column: 2 / -1; min-width: 0; }
.row-main h3 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main span { display: block; }
.row-muscles { color: var(--muted); align-self: start; }
.row-stats { grid-column: 1 / 3; display: flex; gap: 16px; padding-top: 8px; }
.row-actions { grid-column: 3; display: flex; align-items: center; gap: 2px; padding-top: 8px; }
.stat { display: flex; flex-direction: column; line-height: 1.1; }
.stat b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: .75rem; }

.empty { text-align: center; padding: 48px 16px; }

.fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 999px;
  padding: 14px 20px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgb(0 0 0 / .2);
}

@media (min-width: 760px) {
  .table {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-top: 6px;
  }
  .table-head, .row {
    display: grid;
    grid-template-columns: 56px minmax(160px, 1.4fr) minmax(140px, 1fr) 80px 70px 70px 190px;
    column-gap: 16px;
    align-items: center;
    padding: 10px 16px;
  }
  .table-head {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
  }
  .row {
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    margin: 0;
    box-shadow: none;
  }
  .row .thumb { grid-row: auto; align-self: center; }
  .row-main, .row-muscles { grid-column: auto; align-self: center; }
  .row-stats { display: contents; }
  .row .stat small { display: none; } /* l'en-tête de colonne suffit */
  .row-actions { grid-column: auto; padding: 0; justify-content: flex-end; }
  .group-title { margin: 0; padding: 14px 16px 6px; background: var(--bg); border-bottom: 1px solid var(--border); }
  .rows > .row:last-child { border-bottom: 0; }
}

/* ---------- Modale ---------- */
dialog {
  border: 0;
  padding: 0;
  width: min(520px, 100vw);
  max-height: 92dvh;
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 40px rgb(0 0 0 / .25);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
@media (max-width: 600px) {
  /* Sur téléphone, la modale remonte depuis le bas (plus facile au pouce) */
  dialog {
    margin: auto 0 0;
    width: 100vw;
    max-width: 100vw;
    border-radius: 18px 18px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}
.modal-inner { padding: 20px 16px; outline: none; }
dialog { overflow-y: auto; overscroll-behavior: contain; }
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.modal-head .thumb { width: 44px; height: 44px; font-size: 1.1rem; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; font-weight: 500; }
.form label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 400; }
.form label.check input { width: 20px; height: 20px; }
.form input:not([type=checkbox]):not([type=file]) {
  font: inherit;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
.form p { margin: 0; }
.form hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; width: 100%; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 6px; }
.form-actions .danger { margin-right: auto; }
.settings-extra { display: flex; flex-direction: column; gap: 8px; }

.photo-field { display: flex; align-items: center; gap: 14px; }
.photo-preview { cursor: pointer; position: relative; }
.photo-img { width: 88px; height: 88px; border-radius: 14px; font-size: 2rem; }
.photo-field.round .photo-img { border-radius: 50%; }
.photo-field.loading .photo-preview { opacity: .4; }
.photo-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }

.steppers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stepper { display: flex; flex-direction: column; gap: 6px; }
.stepper-label { font-size: .85rem; font-weight: 500; }
.stepper-ctrl {
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
}
.stepper-ctrl .step {
  border: 0;
  background: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  min-height: 48px;
}
.stepper-ctrl .step:active { background: var(--accent-soft); }
.form .stepper-ctrl input:not([type=checkbox]) {
  border: 0;
  border-radius: 0;
  padding: 0;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 600;
  min-width: 0;
  background: transparent;
}

.pin-form { align-items: center; text-align: center; }
.pin-input {
  font: 600 2rem/1 ui-monospace, monospace !important;
  letter-spacing: .6em;
  text-align: center;
  width: 9ch !important;
  padding-left: .6em !important;
}
.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ---------- Évolution ---------- */
.history { display: flex; flex-direction: column; gap: 14px; }
.history h3 { margin-top: 4px; }
.summary { display: flex; gap: 20px; flex-wrap: wrap; }
.summary .up { color: var(--up); }
.summary .down { color: var(--danger); }
.segmented { display: inline-flex; align-self: flex-start; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.segmented button { border: 0; background: none; color: var(--text); font: inherit; padding: 6px 14px; cursor: pointer; }
.segmented button.active { background: var(--text); color: var(--bg); }
.chart-caption { margin: -6px 0 0; }
.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 12px; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-focus { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip {
  position: absolute;
  transform: translate(-50%, calc(-100% - 12px));
  background: var(--text);
  color: var(--bg);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: .8rem;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  white-space: nowrap;
}
.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.history-list li div { display: flex; flex-direction: column; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: .9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
