/* ImageOptimizer — éditeur de photos. Chargé uniquement sur /photo-editor.
   Les jetons de couleur viennent de app.css ; ce fichier n'en redéfinit que pour le mode sombre local. */

.editor-page {
  /* Hauteur de l'en-tête du site (64 px de barre + 1 px de bordure) : l'éditeur prend le reste de la fenêtre. */
  --ed-header: 65px;
  --ed-bg: #F1F0F7;
  --ed-panel: var(--surface);
  --ed-line: var(--line);
  --ed-ink: var(--ink);
  --ed-ink-2: var(--ink-2);
  --ed-ink-3: var(--ink-3);
  --ed-canvas: #E9E7F3;
  --ed-check: #DFDCEF;
}

.editor-page[data-theme="dark"] {
  --ed-bg: #14131F;
  --ed-panel: #1C1B2B;
  --ed-line: #2B2940;
  --ed-ink: #F4F3FA;
  --ed-ink-2: #C3C1D6;
  --ed-ink-3: #9A98B2;
  --ed-canvas: #0E0D17;
  --ed-check: #232137;
  color-scheme: dark;
}

.editor-page[data-theme="dark"] .editor__bar,
.editor-page[data-theme="dark"] .editor__rail,
.editor-page[data-theme="dark"] .editor__panel,
.editor-page[data-theme="dark"] .editor__status,
.editor-page[data-theme="dark"] .editor__dialog {
  background: var(--ed-panel);
  border-color: var(--ed-line);
  color: var(--ed-ink);
}

.editor-page[data-theme="dark"] .btn--secondary {
  background: transparent;
  color: var(--ed-ink);
  border-color: var(--ed-line);
}

.editor-page[data-theme="dark"] .btn--ghost { color: var(--ed-ink-2); }
.editor-page[data-theme="dark"] .input,
.editor-page[data-theme="dark"] .select {
  background: #12111C;
  color: var(--ed-ink);
  border-color: var(--ed-line);
}

/* Le texte de présentation vient sous l'éditeur, pour que celui-ci occupe la fenêtre dès l'arrivée. */
.editor-hero { padding: var(--s-6) 0 var(--s-5); }
.editor-hero__title { font-size: var(--t-h1); font-weight: 750; letter-spacing: -0.02em; margin: var(--s-2) 0 var(--s-2); }
.editor-hero__lead { max-width: 68ch; color: var(--ink-2); margin: 0; }

.editor-shell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - var(--ed-header));
  min-height: calc(100dvh - var(--ed-header));
  background: var(--ed-bg);
  border-block: 1px solid var(--line);
  padding: var(--s-4) 0;
}

/* ---------- État vide ---------- */
.editor__empty { width: 100%; max-width: 880px; margin: 0 auto; padding: 0 var(--s-4); }
.editor__drop {
  display: grid;
  justify-items: center;
  gap: var(--s-3);
  text-align: center;
  padding: var(--s-7) var(--s-5);
  background: var(--surface);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--r-lg);
  transition: border-color var(--ease), background var(--ease);
}
.editor__drop.is-over { border-color: var(--primary); border-style: solid; background: var(--primary-tint); }
.editor__dropTitle { font-size: var(--t-h3); font-weight: 700; margin: 0; }
.editor__dropText { margin: 0; max-width: 52ch; color: var(--ink-2); }
.editor__dropActions { display: flex; gap: var(--s-2); flex-wrap: wrap; justify-content: center; }
.editor__privacy { display: flex; align-items: center; gap: var(--s-2); margin: 0; color: var(--ink-3); font-size: var(--t-small); }

/* ---------- Coquille ---------- */
.editor__app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  /* Remplit la fenêtre sous l'en-tête, une fois retirés la marge de la coquille et ses deux bordures. */
  height: calc(100vh - var(--ed-header) - 2 * var(--s-4) - 2px);
  height: calc(100dvh - var(--ed-header) - 2 * var(--s-4) - 2px);
  min-height: 420px;
}
.editor__bar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  padding: var(--s-2) var(--s-3);
  background: var(--ed-panel);
  border: 1px solid var(--ed-line);
  border-radius: var(--r-md) var(--r-md) 0 0;
}
.editor__barGroup { display: flex; align-items: center; gap: var(--s-1); }
.editor__barGroup:last-child { margin-left: auto; }
.editor__zoomValue { min-width: 4.5ch; font-size: var(--t-small); color: var(--ed-ink-3); font-variant-numeric: tabular-nums; text-align: center; }

.editor__body {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 316px;
  min-height: 0;
  border-inline: 1px solid var(--ed-line);
  background: var(--ed-bg);
}

/* ---------- Rail ---------- */
.editor__rail {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--s-2) var(--s-1);
  background: var(--ed-panel);
  border-right: 1px solid var(--ed-line);
  overflow-y: auto;
}
.editor__railBtn {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: var(--s-2) 2px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ed-ink-2);
  font: inherit;
  font-size: 11px;
  line-height: 1.2;
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
}
.editor__railBtn:hover { background: var(--primary-tint); color: var(--primary); }
.editor__railBtn[aria-pressed="true"] { background: var(--primary-tint); color: var(--primary); font-weight: 650; }
.editor__railBtn .icon { width: 20px; height: 20px; }

/* ---------- Scène ---------- */
.editor__stage { display: grid; grid-template-rows: 1fr auto; min-width: 0; min-height: 0; }
.editor__scroll {
  overflow: auto;
  display: grid;
  place-items: center;
  padding: var(--s-4);
  background:
    linear-gradient(45deg, var(--ed-check) 25%, transparent 25%, transparent 75%, var(--ed-check) 75%) 0 0 / 18px 18px,
    linear-gradient(45deg, var(--ed-check) 25%, transparent 25%, transparent 75%, var(--ed-check) 75%) 9px 9px / 18px 18px,
    var(--ed-canvas);
  touch-action: none;
}
.editor__wrap { position: relative; display: block; line-height: 0; box-shadow: 0 1px 3px rgb(22 21 43 / 12%); }
.editor__canvas { display: block; max-width: 100%; height: auto; cursor: default; background: transparent; }
.editor__canvas[data-cursor="move"] { cursor: move; }
.editor__canvas[data-cursor="crosshair"] { cursor: crosshair; }
.editor__canvas[data-cursor="draw"] { cursor: crosshair; }
.editor__canvas[data-cursor="crop"] { cursor: crosshair; }
.editor__hint {
  margin: 0;
  padding: var(--s-2) var(--s-3);
  font-size: var(--t-small);
  color: var(--ed-ink-2);
  background: var(--ed-panel);
  border-top: 1px solid var(--ed-line);
}

/* ---------- Panneau ---------- */
.editor__panel {
  background: var(--ed-panel);
  border-left: 1px solid var(--ed-line);
  overflow-y: auto;
  max-height: 100%;
}
.editor__section { display: grid; gap: var(--s-3); padding: var(--s-4); align-content: start; }
.editor__section[hidden] { display: none; }
.editor__panelTitle { font-size: var(--t-h3); font-weight: 700; margin: 0; color: var(--ed-ink); }
.editor__section .field__label,
.editor__section label,
.editor__section .check__text { color: var(--ed-ink-2); }
.editor__section .field__help { color: var(--ed-ink-3); margin: 0; }
.editor-page[data-theme="dark"] .editor__section .input,
.editor-page[data-theme="dark"] .editor__section .select { color: var(--ed-ink); }

.editor__row { display: flex; flex-wrap: wrap; gap: var(--s-1); }

.editor__slider { display: grid; gap: 4px; }
.editor__sliderHead { display: flex; justify-content: space-between; gap: var(--s-2); font-size: var(--t-small); color: var(--ed-ink-2); }
.editor__sliderHead output { font-variant-numeric: tabular-nums; color: var(--ed-ink-3); }
.editor__range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
.editor__range::-webkit-slider-runnable-track { height: 4px; border-radius: 999px; background: var(--line-strong); }
.editor__range::-moz-range-track { height: 4px; border-radius: 999px; background: var(--line-strong); }
.editor__range::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: var(--primary); border: 2px solid #fff; box-shadow: 0 1px 2px rgb(22 21 43 / 25%); }
.editor__range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--primary); border: 2px solid #fff; }
.editor__range:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 40%, transparent); outline-offset: 2px; }

.editor__textarea { resize: vertical; min-height: 64px; font: inherit; }

/* ---------- Filtres ---------- */
.editor__filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-1); }
.editor__filter {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px var(--s-2);
  font: inherit;
  font-size: var(--t-micro);
  text-align: left;
  color: var(--ed-ink-2);
  background: transparent;
  border: 1px solid var(--ed-line);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.editor__filter:hover { border-color: var(--primary); }
.editor__filter[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-tint); color: var(--primary); font-weight: 650; }
.editor__filterDot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; background: #C7C4DA; }
.editor__filterDot--none { background: linear-gradient(135deg, #C0392B 0 50%, #27AE60 50%); }
.editor__filterDot--bw { background: linear-gradient(90deg, #111 0 50%, #fff 50%); }
.editor__filterDot--grayscale { background: linear-gradient(90deg, #777, #ddd); }
.editor__filterDot--sepia { background: #B08A5A; }
.editor__filterDot--vintage { background: #A98E6B; }
.editor__filterDot--warm { background: #E58B4C; }
.editor__filterDot--cool { background: #5B9BD5; }
.editor__filterDot--cinematic { background: linear-gradient(135deg, #175E6E, #E0913F); }
.editor__filterDot--strong { background: linear-gradient(90deg, #000 0 50%, #f5f5f5 50%); }
.editor__filterDot--soft { background: #EADFD8; }
.editor__filterDot--vivid { background: linear-gradient(135deg, #E0195B, #F7D117); }
.editor__filterDot--fade { background: #CFC9BA; }

/* ---------- Autocollants ---------- */
.editor__stickers { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-1); }
.editor__sticker {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: var(--s-2);
  background: transparent;
  border: 1px solid var(--ed-line);
  border-radius: var(--r-sm);
  color: var(--ed-ink-2);
  cursor: pointer;
}
.editor__sticker:hover { border-color: var(--primary); color: var(--primary); }
.editor__sticker svg { width: 26px; height: 26px; fill: currentColor; stroke: currentColor; stroke-width: 1.75; }

/* ---------- Listes (calques, zones) ---------- */
.editor__layers, .editor__regionList { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.editor__layerItem {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  padding: 6px var(--s-2);
  font: inherit;
  font-size: var(--t-small);
  text-align: left;
  color: var(--ed-ink-2);
  background: transparent;
  border: 1px solid var(--ed-line);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.editor__layerItem:hover { border-color: var(--primary); }
.editor__layerItem[aria-current="true"] { border-color: var(--primary); background: var(--primary-tint); color: var(--primary); }
.editor__layerItem span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor__layerItem .editor__layerKind { margin-left: auto; font-size: var(--t-micro); color: var(--ed-ink-3); text-transform: none; }
.editor__layerEmpty { font-size: var(--t-small); color: var(--ed-ink-3); margin: 0; }

/* ---------- Barre d'état ---------- */
.editor__status {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  background: var(--ed-panel);
  border: 1px solid var(--ed-line);
  border-radius: 0 0 var(--r-md) var(--r-md);
  flex-wrap: wrap;
}
.editor__statusText { display: flex; align-items: baseline; gap: var(--s-2); font-size: var(--t-small); color: var(--ed-ink-3); min-width: 0; }
.editor__statusText strong { color: var(--ed-ink); max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor__thumbs { display: flex; gap: var(--s-1); list-style: none; margin: 0 0 0 auto; padding: 0; overflow-x: auto; }
.editor__thumbBtn { position: relative; display: block; padding: 0; border: 2px solid transparent; border-radius: var(--r-sm); background: var(--ed-bg); cursor: pointer; line-height: 0; }
.editor__thumbBtn img { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; }
.editor__thumbBtn[aria-pressed="true"] { border-color: var(--primary); }
.editor__thumbClose { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--ink-2); font-size: 11px; line-height: 1; cursor: pointer; }

/* ---------- Boîte d'export ---------- */
.editor__dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-pop);
  color: var(--ink);
  background: var(--surface);
}
.editor__dialog::backdrop { background: rgb(22 21 43 / 45%); }
.editor__dialogBody { display: grid; gap: var(--s-3); padding: var(--s-5); }
.editor__dialogTitle { margin: 0; font-size: var(--t-h3); font-weight: 700; }
.editor__dialogActions { display: flex; flex-wrap: wrap; gap: var(--s-2); justify-content: flex-end; }
.editor__dialogNote { margin: 0; font-size: var(--t-small); color: var(--ink-2); }
.editor__dialogNote:empty { display: none; }

/* ---------- Raccourcis ---------- */
.editor__keys { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--s-3); margin: 0; font-size: var(--t-small); }
.editor__keys dt { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--t-micro); color: var(--ed-ink); background: var(--ed-bg); border: 1px solid var(--ed-line); border-radius: 4px; padding: 1px 6px; justify-self: start; }
.editor__keys dd { margin: 0; color: var(--ed-ink-2); }

/* ---------- Réactif ---------- */
@media (max-width: 1100px) {
  .editor__body { grid-template-columns: 64px minmax(0, 1fr) 280px; }
}

@media (max-width: 900px) {
  /* Sur mobile, l'éditeur s'empile et la page défile : pas de hauteur imposée. */
  .editor-shell { min-height: 0; }
  .editor__app { height: auto; min-height: 0; }
  .editor__bar { position: sticky; top: 0; z-index: 5; border-radius: 0; }
  .editor__barGroup:last-child { margin-left: 0; }
  .editor__body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(240px, 46vh) auto; border-inline: 0; }
  .editor__rail { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--ed-line); padding: var(--s-1); }
  .editor__railBtn { min-width: 62px; }
  .editor__panel { border-left: 0; border-top: 1px solid var(--ed-line); max-height: 46vh; }
  .editor__section { padding: var(--s-3); }
  .editor__status { border-radius: 0; }
  .editor__thumbs { margin-left: 0; width: 100%; }
  .editor__zoom { display: none; }
}

@media (max-width: 640px) {
  .editor__drop { padding: var(--s-6) var(--s-4); }
  .editor__bar { gap: var(--s-1); padding: var(--s-1); }
  .editor__bar .btn span { display: none; }
  .editor__filters { grid-template-columns: minmax(0, 1fr); }
  .editor__dialogBody { padding: var(--s-4); }
}

@media (prefers-reduced-motion: reduce) {
  .editor-page *, .editor-page *::before, .editor-page *::after { transition-duration: 0.01ms !important; }
}

.editor__canvas:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 3px; }
.editor__layerItem svg { flex: 0 0 auto; width: 16px; height: 16px; }

