/* ——— Pilote ——— */
/*
 * Les tailles suivent la largeur ET la hauteur de l'écran (unités vw / vh) :
 * sur une tablette en paysage, où la barre du navigateur laisse peu de hauteur,
 * tout le panneau de commande tient sans défiler.
 */
.pilot {
  --gap: clamp(12px, 3vh, 32px);
  display: flex;
  flex-direction: column;
  padding: clamp(12px, 3vh, 32px) clamp(14px, 3vw, 40px) clamp(14px, 4vh, 48px);
  padding-top: max(clamp(12px, 3vh, 32px), env(safe-area-inset-top));
  padding-bottom: max(clamp(14px, 4vh, 48px), env(safe-area-inset-bottom));
}
.pilot-inner {
  flex: 1 1 auto;
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar__start {
  display: flex;
  align-items: center;
  gap: 20px;
}
.topbar__end {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.page-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(36px, min(7vh, 8vw), 59px);
  line-height: 0.9;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  background: var(--placeholder);
}
.status-dot[data-state='live'] {
  background: var(--teal-deep);
  animation: ping 1.6s ease-out infinite;
}
.status-dot[data-state='wait'] {
  background: var(--amber);
}
@keyframes ping {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 162, 163, 0.55);
  }
  100% {
    box-shadow: 0 0 0 10px rgba(34, 162, 163, 0);
  }
}

/*
 * Panneaux :
 * - paysage (tablette couchée, ordinateur) : rythme à gauche, saturation et tension à droite ;
 * - portrait : rythme en haut, saturation et tension côte à côte dessous (ou empilées sur téléphone).
 */
.panels {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
  align-items: stretch;
}
.panel-col {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
  align-content: stretch;
}
@media (min-width: 820px) and (orientation: landscape) {
  .panels {
    grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr);
  }
}
@media (min-width: 540px) and (orientation: portrait), (min-width: 540px) and (max-width: 819px) {
  .panel-col {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}
.panel {
  min-width: 0;
  background: var(--surface);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-card);
  padding: clamp(16px, min(3vw, 3.4vh), 36px);
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2.2vh, 20px);
  container-type: inline-size;
}
.panel--heart {
  gap: clamp(12px, 2.8vh, 28px);
}
.panel__head {
  display: flex;
  align-items: center;
  gap: 14px;
}
.panel__head--split {
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 12px;
}
.panel__head-main {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Interrupteur « Transition douce » */
.soft-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 6px 18px 6px 8px;
  border: 1px solid var(--track);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  transition:
    border-color 0.2s ease,
    background 0.2s ease,
    box-shadow 0.2s ease;
}
.soft-switch:hover {
  border-color: var(--teal-deep);
}
.soft-switch__track {
  width: 52px;
  height: 32px;
  flex: none;
  padding: 3px;
  border-radius: 16px;
  background: var(--track);
  display: flex;
  align-items: center;
  transition: background 0.25s ease;
}
.soft-switch__knob {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(50, 57, 78, 0.3);
  transition: transform 0.35s var(--ease-back);
}
.soft-switch__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.soft-switch__label {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.1;
}
.soft-switch__hint {
  font-size: 13px;
  line-height: 1.2;
  color: var(--text-muted);
}
.soft-switch[aria-checked='true'] {
  border-color: var(--teal-ink);
  background: #eaf6f6;
  box-shadow: 0 0 0 3px rgba(23, 108, 109, 0.12);
}
.soft-switch[aria-checked='true'] .soft-switch__track {
  background: var(--teal-ink);
}
.soft-switch[aria-checked='true'] .soft-switch__knob {
  transform: translateX(20px);
}

.panel__dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: none;
}
.panel__dot--fc {
  background: var(--teal-deep);
}
.panel__dot--sp {
  background: var(--amber);
}
.panel__dot--bp {
  background: var(--blue);
}
.panel__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(24px, 4.6vh, 32px);
  line-height: 0.9;
  font-weight: 600;
}

/* Aperçu de l'écran patient */
.monitor-preview {
  flex: 1 1 auto;
  min-height: clamp(84px, min(18vh, 24vw), 180px);
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-tab);
  background: var(--night);
}
.monitor-preview__label {
  position: absolute;
  top: 18px;
  left: 22px;
  z-index: 1;
  display: flex;
  gap: 14px;
  align-items: baseline;
  font-size: 16px;
  color: var(--teal);
}
.monitor-preview__lead {
  font-weight: 500;
}
.monitor-preview__rhythm {
  font-weight: 400;
}
.monitor-preview__fc {
  position: absolute;
  top: 14px;
  right: 22px;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--teal);
  font-variant-numeric: tabular-nums;
}
.monitor-preview__fc-label {
  font-size: 14px;
  font-weight: 600;
}
.monitor-preview__fc-value {
  font-size: 26px;
  font-weight: 500;
  line-height: 1;
}
.monitor-preview__fc-target {
  font-size: 15px;
  color: var(--mist);
}
.monitor-preview canvas {
  position: absolute;
  left: 0;
  top: 44px;
  width: 100%;
  height: calc(100% - 60px);
}

/* Troubles du rythme */
.rhythms {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(clamp(84px, 15cqw, 112px), 1fr));
  gap: clamp(8px, 1.6vh, 12px);
}
.chip {
  border: 0;
  border-radius: var(--radius-tab);
  padding: clamp(8px, 1.6vh, 16px) 6px clamp(8px, 1.4vh, 14px);
  min-height: clamp(60px, min(11vh, 14vw), 96px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1vh, 10px);
  background: var(--control);
  color: var(--ink);
  transition:
    background 0.2s ease,
    color 0.2s ease,
    transform 0.15s ease;
}
.chip:hover {
  transform: translateY(-2px);
}
/* Pas de fondu tant que l'état de la session n'est pas reçu. */
.pilot:not([data-synced]) .chip {
  transition: none;
}
.chip svg {
  width: 100%;
  height: clamp(20px, 4.4vh, 36px);
  display: block;
}
.chip path {
  stroke: var(--teal-deep);
}
.chip[aria-pressed='true'] {
  background: var(--teal-ink);
  color: var(--surface);
}
.chip[aria-pressed='true'] path {
  stroke: var(--surface);
}
.chip__label {
  font-size: clamp(14px, 2.3cqw, 17px);
  line-height: 1.2;
  font-weight: 500;
}

/* Valeurs et réglages */
.reading {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.reading__row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.reading__main {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.reading__caption {
  font-size: clamp(15px, 2.6vh, 19px);
  line-height: 1.2;
  font-weight: 400;
  color: var(--text-muted);
}
.reading__value {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.big-number {
  font-size: clamp(52px, min(12.5vh, 16cqw), 112px);
  line-height: 0.9;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.big-number--fc {
  color: var(--teal-ink);
}
.big-number--sp {
  color: var(--amber-ink);
}
.big-number--bp {
  font-size: clamp(40px, min(8.8vh, 17cqw), 80px);
  color: var(--blue);
}
.unit {
  font-size: clamp(18px, 3.4vh, 24px);
  font-weight: 400;
  color: var(--text-muted);
}

.steppers {
  display: flex;
  gap: 12px;
  padding-bottom: clamp(2px, 1vh, 8px);
}
.step {
  width: clamp(48px, 8.5vh, 64px);
  height: clamp(48px, 8.5vh, 64px);
  border: 0;
  border-radius: 50%;
  background: var(--control);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition:
    background 0.15s ease,
    transform 0.1s ease;
}
.step:hover {
  background: var(--control-hover);
}
.step:active {
  transform: scale(0.94);
}
.step--md {
  width: clamp(48px, 7.6vh, 56px);
  height: clamp(48px, 7.6vh, 56px);
}
.step--sm {
  width: 48px;
  height: 48px;
}

.range {
  width: 100%;
  height: clamp(32px, 6vh, 44px);
  margin: 0;
  accent-color: var(--teal-ink);
  cursor: pointer;
  touch-action: pan-y;
}
.range--sp {
  accent-color: var(--amber-ink);
}

/* Tension */
.bp-reading {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 14px;
}
/* Réglage en attente : le grand chiffre montre ce qu'affiche le Scope. */
.reading__target {
  font-size: 17px;
  color: var(--mist);
  white-space: nowrap;
}
.big-number[data-off] {
  color: var(--text-muted);
}
.bp-mean {
  font-size: 19px;
  font-weight: 400;
  color: var(--text-muted);
}
.bp-rows {
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 1.2vh, 10px);
}
.bp-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
}
.bp-row__label {
  font-size: clamp(16px, 2.6vh, 19px);
  font-weight: 400;
  color: var(--text-muted);
}
.bp-row__ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bp-row__value {
  width: clamp(52px, 9cqw, 64px);
  text-align: center;
  font-size: clamp(22px, 3.8vh, 27px);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ——— Écran bas (tablette couchée avec la barre du navigateur) ——— */
@media (max-height: 640px) {
  .soft-switch__hint {
    display: none;
  }
  .soft-switch {
    min-height: 44px;
    gap: 8px;
    padding: 4px 14px 4px 6px;
  }
  .soft-switch__label {
    font-size: 15px;
  }
  .back-btn {
    width: 44px;
    height: 44px;
  }
  .pill {
    min-height: 44px;
    padding: 4px 18px;
  }
}

/* ——— Téléphones ——— */
@media (max-width: 600px) {
  .pilot {
    --gap: 16px;
  }
  .back-btn {
    width: 48px;
    height: 48px;
  }
  .pill {
    min-height: 44px;
    padding: 4px 16px;
  }
  .panel {
    border-radius: var(--radius-tile);
  }
  .step--sm {
    width: 44px;
    height: 44px;
  }
  .bp-row__ctrl {
    gap: 6px;
  }
  .bp-row__value {
    width: 52px;
    font-size: 24px;
  }
  .bp-row__label {
    font-size: 17px;
  }
}

/* ——— Apparition de la page (motion design) ———
   Le titre arrive depuis la carte de l'accueil (view-transition), puis les
   éléments entrent en cascade. Remplissage « backwards » : une fois l'animation
   finie, les effets de survol et d'appui reprennent normalement. */
.page-title {
  view-transition-name: pilot-title;
}

@media (prefers-reduced-motion: no-preference) {
  .topbar .back-btn {
    animation: pilot-pop 0.6s var(--ease-back) 0.1s backwards;
  }
  .topbar__end .pill {
    animation: pilot-slide-left 0.7s var(--ease-out) backwards;
  }
  .topbar__end .pill:nth-child(1) {
    animation-delay: 0.15s;
  }
  .topbar__end .pill:nth-child(2) {
    animation-delay: 0.25s;
  }

  .panel {
    animation: pilot-rise 0.85s var(--ease-out) backwards;
    animation-delay: calc(0.2s + var(--order, 0) * 0.11s);
  }
  .panel-col > .panel:nth-child(1) {
    --order: 1;
  }
  .panel-col > .panel:nth-child(2) {
    --order: 2;
  }
  .panel__dot {
    animation: pilot-pop 0.55s var(--ease-back) backwards;
    animation-delay: calc(0.45s + var(--order, 0) * 0.11s);
  }

  .monitor-preview {
    animation: pilot-reveal 1s var(--ease-out) 0.45s backwards;
  }

  .chip {
    animation: pilot-pop 0.55s var(--ease-back) backwards;
    animation-delay: calc(0.55s + var(--n, 0) * 0.06s);
  }
  .chip:nth-child(2) {
    --n: 1;
  }
  .chip:nth-child(3) {
    --n: 2;
  }
  .chip:nth-child(4) {
    --n: 3;
  }
  .chip:nth-child(5) {
    --n: 4;
  }

  .big-number,
  .range {
    animation: pilot-fade-up 0.7s var(--ease-out) backwards;
    animation-delay: calc(0.5s + var(--order, 0) * 0.11s);
  }
}

@keyframes pilot-rise {
  from {
    opacity: 0;
    transform: translateY(48px) scale(0.96);
  }
}
@keyframes pilot-slide-left {
  from {
    opacity: 0;
    transform: translateX(28px);
  }
}
@keyframes pilot-pop {
  from {
    opacity: 0;
    transform: scale(0.5);
  }
}
@keyframes pilot-fade-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}
@keyframes pilot-reveal {
  from {
    clip-path: inset(0 100% 0 0 round 24px);
  }
  to {
    clip-path: inset(0 0 0 0 round 24px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .status-dot[data-state='live'] {
    animation: none;
  }
  .chip,
  .chip:hover,
  .step,
  .step:active {
    transition: none;
    transform: none;
  }
}
