/* Clefdoc — vue « édition » (#/edit/:pageId).
   Thème sombre forcé par data-theme="dark" posé sur la racine de la vue (jetons de base.css).
   Toutes les classes propres à la vue sont préfixées .edit-. */

.edit {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ------------------------------------------------------------------ aperçu */

.edit-preview {
  position: relative;
  display: flex;
  /* Base 0 : l'aperçu prend la place RESTANTE. En base auto, la hauteur naturelle du canvas
     (jusqu'à 1100 px) écrasait les commandes (vignettes de filtres rognées sur 375 × 667). */
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  min-height: 96px;
  padding: 14px calc(14px + var(--safe-r)) 14px calc(14px + var(--safe-l));
  overflow: hidden;
  background: var(--bg);
}

.edit-preview__canvas {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  transition: opacity .18s var(--ease);
}

/* Tant qu'aucun aperçu n'a été peint, le canvas vide reste invisible. */
.edit-preview:not(.is-ready) .edit-preview__canvas {
  visibility: hidden;
}

/* Recalcul : l'image précédente reste lisible, légèrement atténuée. */
.edit-preview.is-rendering .edit-preview__canvas {
  opacity: .62;
}

.edit-preview__busy {
  position: absolute;
  top: 14px;
  right: calc(14px + var(--safe-r));
  display: none;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.edit-preview.is-rendering .edit-preview__busy {
  display: flex;
}

/* ---------------------------------------------------------------- commandes */

.edit-controls {
  /* Peut rétrécir (et défiler) sur un écran court : la barre d'action reste visible. */
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  max-height: 58vh;    /* repli Safari < 15.4 (pas de dvh) */
  max-height: 58dvh;
  padding: 10px calc(4px + var(--safe-r)) 4px calc(4px + var(--safe-l));
  overflow-y: auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* Le bandeau (conteneur défilant, donc compressible) ne doit jamais être rogné : c'est le panneau qui défile. */
.edit-controls > * {
  flex: none;
}

/* --- bandeau de filtres --- */

.edit-filters {
  display: flex;
  gap: 8px;
  padding: 2px 8px 4px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.edit-filters::-webkit-scrollbar {
  display: none;
}

.edit-filter {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 80px;
  padding: 4px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  scroll-snap-align: center;
  transition: color .15s var(--ease), transform .12s var(--ease);
}

.edit-filter:active {
  transform: scale(.96);
}

.edit-filter[disabled] {
  opacity: .45;
  pointer-events: none;
}

.edit-filter__frame {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 64px;
  overflow: hidden;
  border: 2px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  transition: border-color .15s var(--ease);
}

.edit-filter__thumb {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

/* Libellé traduit (« Blanco y negro ») : deux lignes au plus plutôt qu'une coupure par ellipse. */
.edit-filter__label {
  display: -webkit-box;
  max-width: 100%;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: break-word;
  hyphens: auto;
}

.edit-filter[aria-pressed="true"] {
  color: var(--text);
}

.edit-filter[aria-pressed="true"] .edit-filter__frame {
  border-color: var(--accent);
}

/* --- rotation et bascule des réglages --- */

.edit-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
}

.edit-toggle {
  min-height: var(--tap);
  margin-left: auto;
  padding: 0 14px;
  font-size: 15px;
}

.edit-toggle[aria-expanded="true"] {
  background: var(--surface-2);
  color: var(--accent);
}

/* --- panneau « Réglages » --- */

.edit-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 6px 14px 10px;
}

.edit-panel[hidden] {
  display: none;
}

.edit-panel__reset {
  align-self: flex-start;
  min-height: var(--tap);
  padding: 0 14px;
  color: var(--accent);
  font-size: 14px;
}

.edit-panel__reset[hidden] {
  display: none;
}

.edit-slider {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.edit-slider__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
  color: var(--text-dim);
}

.edit-slider__label {
  font-weight: 600;
}

.edit-slider__value {
  color: var(--text);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.edit-slider__input {
  width: 100%;
  height: var(--tap);
  margin: 0;
  padding: 0;
  background: transparent;
  touch-action: none;   /* le glissement horizontal règle la valeur, il ne fait pas défiler */
  -webkit-appearance: none;
  appearance: none;
}

/* Piste bordée de --text-dim : lisible sur --surface (la bordure --border y était quasi invisible). */
.edit-slider__input::-webkit-slider-runnable-track {
  box-sizing: content-box;   /* fixe la base du margin-top de la pastille (l'agent utilisateur varie) */
  height: 8px;
  border: 1px solid var(--text-dim);
  border-radius: 999px;
  background: var(--surface-2);
}

/* Pastille visible de 26 px, cible de 48 px : sur iOS, seul le curseur lui-même s'attrape
   (un appui sur la piste ne le déplace pas). La bordure transparente agrandit la zone d'appui. */
.edit-slider__input::-webkit-slider-thumb {
  box-sizing: border-box;
  width: var(--tap);
  height: var(--tap);
  margin-top: -20px;   /* (8 - 48) / 2 : centré sur la piste */
  border: 11px solid transparent;
  border-radius: 50%;
  background: var(--accent);
  background-clip: content-box;
  -webkit-appearance: none;
  appearance: none;
}

.edit-slider__input::-moz-range-track {
  height: 8px;
  border: 1px solid var(--text-dim);
  border-radius: 999px;
  background: var(--surface-2);
}

.edit-slider__input::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: var(--shadow);
}

.edit-slider__input[disabled] {
  opacity: .45;
}

/* ----------------------------------------------------------- petits écrans */

@media (max-height: 560px) {
  .edit-filter {
    width: 68px;
  }

  .edit-filter__frame {
    height: 48px;
  }

  .edit-controls {
    gap: 6px;
    max-height: 64vh;
    max-height: 64dvh;
  }
}

@media (min-width: 720px) {
  .edit-controls {
    align-items: stretch;
    padding-right: calc(16px + var(--safe-r));
    padding-left: calc(16px + var(--safe-l));
  }

  .edit-filters {
    padding-right: 16px;
    padding-left: 16px;
  }
}
