/* Editor di modifica localizzata delle foto. Consuma solo i token di tokens.css. */

.photo-edit-dialog {
  box-sizing: border-box;
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
  overflow: hidden;
}
.photo-edit-dialog[open] { display: flex; flex-direction: column; }
.photo-edit-dialog::backdrop { background: var(--scrim); }
.photo-edit-dialog *, .photo-edit-dialog *::before, .photo-edit-dialog *::after { box-sizing: border-box; }
.photo-edit-dialog [hidden] { display: none !important; }

/* Header */
.pe-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: calc(var(--space-2) + var(--safe-t)) var(--space-4) var(--space-2);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.pe-icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap-min);
  height: var(--tap-min);
  margin-left: calc(-1 * var(--space-2));
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.pe-icon-btn:hover { background: var(--surface2); }
.pe-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.pe-title h2 { margin: 0; font-size: var(--text-lg); font-weight: 750; letter-spacing: var(--tracking-tight); }
.pe-subtitle { color: var(--hint); font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pe-cost {
  flex: 0 0 auto;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--credit-plan-soft);
  color: var(--credit-plan);
  font-size: var(--text-xs);
  font-weight: 700;
}

.pe-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.pe-editor { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* Stage */
.pe-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 220px;
  margin: var(--space-3) var(--space-4) 0;
  border-radius: var(--radius);
  background: var(--surface2);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: none;
}
.pe-stage.is-panning { cursor: grab; }
.pe-canvas-wrap {
  position: absolute;
  transform-origin: 50% 50%;
  will-change: transform;
}
.pe-photo, .pe-mask {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}
.pe-photo { object-fit: contain; border-radius: var(--radius-xs); }
.pe-mask { opacity: .55; mix-blend-mode: normal; }
.pe-cursor {
  position: absolute;
  border: 1.5px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .45);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.pe-stage-loading, .pe-stage-hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: rgba(18, 17, 32, .72);
  color: #fff;
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}
.pe-stage-loading { top: 50%; transform: translate(-50%, -50%); }
.pe-stage-hint { bottom: var(--space-3); }

/* Toolbar */
.pe-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin: var(--space-2) var(--space-4) 0;
  padding: var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  flex: 0 0 auto;
}
.pe-tool {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.pe-tool:hover:not(:disabled) { background: var(--surface2); }
.pe-tool.is-active { background: var(--primary-soft); color: var(--primary); }
.pe-tool:disabled { opacity: .38; cursor: default; }
.pe-size { flex: 1 1 auto; min-width: 60px; accent-color: var(--primary); }

/* Panel */
.pe-panel {
  flex: 0 0 auto;
  max-height: 40dvh; /* the photo gets the space; the panel scrolls */
  overflow-y: auto;
  margin-top: var(--space-3);
  padding: var(--space-4) var(--space-4) calc(var(--space-4) + var(--safe-b));
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 -4px 20px rgba(22, 22, 29, .05);
}
.pe-form { display: flex; flex-direction: column; gap: var(--space-2); }
.pe-label { font-weight: 700; font-size: var(--text-md); }
.pe-textarea {
  width: 100%;
  min-height: 60px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* niente zoom automatico su iOS */
  resize: vertical;
}
.pe-textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.pe-tip { margin: 0; color: var(--hint); font-size: var(--text-sm); line-height: 1.4; }
.pe-refs { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-2); }
.pe-refs-label { font-weight: 700; font-size: var(--text-sm); }
.pe-refs-list { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.pe-ref, .pe-ref-add {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex: 0 0 auto;
}
.pe-ref img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pe-ref-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(18, 17, 32, .72);
  color: #fff;
  cursor: pointer;
}
.pe-ref-add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1.5px dashed var(--border-strong);
  background: var(--surface2);
  color: var(--text-2);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
}
.pe-ref-add:hover { border-color: var(--primary); color: var(--primary); }
.pe-error {
  margin: 0;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--red-soft);
  color: var(--red);
  font-size: var(--text-sm);
  font-weight: 600;
}
.pe-submit, .pe-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 0 var(--space-5);
  border: 0;
  border-radius: var(--radius-pill);
  font: inherit;
  font-weight: 700;
  font-size: var(--text-md);
  cursor: pointer;
}
.pe-submit { margin-top: var(--space-2); background: var(--gradient-cta); color: var(--on-primary); box-shadow: var(--shadow-cta); }
.pe-submit:hover:not(:disabled) { background: var(--gradient-cta-hover); }
.pe-submit:disabled { opacity: .5; cursor: default; box-shadow: none; }
.pe-secondary { background: var(--surface2); color: var(--text); }
.pe-secondary.is-quiet { background: transparent; color: var(--hint); }
.pe-secondary:disabled { opacity: .5; }
.pe-truth { margin: 0; color: var(--hint); font-size: var(--text-xs); text-align: center; }

/* Progress */
.pe-progress, .pe-result {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4) calc(var(--space-5) + var(--safe-b));
  overflow-y: auto;
  text-align: center;
}
.pe-progress-preview {
  position: relative;
  width: min(340px, 70vw);
  aspect-ratio: 3 / 4;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface2);
}
.pe-progress-preview img { width: 100%; height: 100%; object-fit: cover; display: block; filter: saturate(.85); }
.pe-progress-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, .45) 50%, transparent 70%);
  background-size: 250% 100%;
  animation: pe-shimmer 1.6s linear infinite;
}
@keyframes pe-shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
@media (prefers-reduced-motion: reduce) { .pe-progress-shimmer { animation: none; opacity: .3; } }
.pe-progress-text { margin: 0; font-weight: 700; font-size: var(--text-lg); }
.pe-progress-sub { margin: 0; max-width: 360px; color: var(--hint); font-size: var(--text-sm); line-height: 1.45; }

/* Compare */
.pe-compare {
  position: relative;
  width: min(420px, 100%);
  aspect-ratio: 3 / 4;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface2);
  touch-action: pan-y;
}
.pe-compare-img, .pe-compare-after { position: absolute; inset: 0; width: 100%; height: 100%; }
.pe-compare-img { object-fit: contain; display: block; }
.pe-compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
  pointer-events: none;
}
.pe-compare-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-md);
  transform: translate(-50%, -50%);
}
.pe-compare-tag {
  position: absolute;
  top: var(--space-2);
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: rgba(18, 17, 32, .66);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 700;
  pointer-events: none;
}
.pe-compare-tag.is-before { left: var(--space-2); }
.pe-compare-tag.is-after { right: var(--space-2); }
.pe-compare-range {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
}
.pe-compare-range:focus-visible + .pe-compare-handle,
.pe-compare:focus-within .pe-compare-handle::after { outline: 2px solid var(--primary); }
.pe-result-note { margin: 0; color: var(--hint); font-size: var(--text-sm); }
.pe-result-actions { display: flex; flex-direction: column; gap: var(--space-2); width: min(420px, 100%); }
.pe-failure { display: flex; flex-direction: column; gap: var(--space-2); max-width: 380px; }
.pe-failure strong { font-size: var(--text-lg); }
.pe-failure p { margin: 0; color: var(--text-2); }
.pe-failure .pe-refund { color: var(--green); font-weight: 600; font-size: var(--text-sm); }

/* Leave room for header, note and the three actions so they stay visible. */
.pe-compare-outer { position: relative; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); width: min(420px, 100%, calc((100dvh - 330px) * .75)); min-width: 200px; flex: 0 0 auto; }
.pe-compare .pe-compare-img { transition: transform var(--motion-dur-normal) ease; }
@media (prefers-reduced-motion: reduce) { .pe-compare .pe-compare-img { transition: none; } }
.pe-compare-zoom {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
}
.pe-compare-zoom:hover { border-color: var(--primary); color: var(--primary); }

/* Ingresso nella scheda prodotto: a tutta larghezza sopra Scarica / Assistenza */
#details-form .pub-quick .publication-photo-edit-btn { grid-column: 1 / -1; }

/* Storico nella scheda prodotto */
.pe-history { margin-top: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.pe-history-title { margin: 0 0 var(--space-2); font-size: var(--text-md); font-weight: 750; }
.pe-history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.pe-history-row { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-2) 0; border-top: 1px solid var(--border); }
.pe-history-row:first-child { border-top: 0; }
.pe-history-main { flex: 1; min-width: 0; }
.pe-history-top { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.pe-history-text { margin: 2px 0 0; color: var(--text-2); font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pe-history-error { margin: 2px 0 0; color: var(--red); font-size: var(--text-xs); }
.pe-history-actions { display: flex; gap: var(--space-1); flex: 0 0 auto; }
.pe-chip { white-space: nowrap; padding: 1px 8px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 700; background: var(--gray-soft); color: var(--hint); }
.pe-chip.is-live { background: var(--green-soft); color: var(--green); }
.pe-chip.is-failed { background: var(--red-soft); color: var(--red); }
.pe-chip.is-queued, .pe-chip.is-processing { background: var(--primary-soft); color: var(--primary); }
.pe-link { min-height: 36px; padding: 0 10px; border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--primary); font: inherit; font-size: var(--text-sm); font-weight: 700; cursor: pointer; }
.pe-link:hover:not(:disabled) { background: var(--primary-soft); }
.pe-link.is-danger { color: var(--red); }
.pe-link.is-danger:hover:not(:disabled) { background: var(--red-soft); }
.pe-link:disabled { opacity: .5; }

@media (max-width: 899px) {
  .pe-panel { padding-top: var(--space-3); }
  .pe-ref, .pe-ref-add { width: 56px; height: 56px; }
  .pe-refs { flex-direction: row; align-items: center; gap: var(--space-3); }
  .pe-textarea { min-height: 48px; }
}

/* Desktop: editor a fianco del pannello */
@media (min-width: 900px) {
  .photo-edit-dialog:not(.pe-compare-dialog) { width: min(1120px, calc(100vw - 48px)); height: min(860px, calc(100dvh - 48px)); margin: auto; border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); }
  .pe-compare-dialog { width: min(560px, calc(100vw - 48px)); height: auto; max-height: calc(100dvh - 48px); margin: auto; border-radius: var(--radius-xl); }
  .pe-editor { display: grid; grid-template-columns: 1fr 360px; grid-template-rows: 1fr auto; }
  .pe-stage { grid-column: 1; grid-row: 1; margin: var(--space-4) 0 0 var(--space-4); }
  .pe-toolbar { grid-column: 1; grid-row: 2; margin: var(--space-3) 0 var(--space-4) var(--space-4); }
  .pe-panel { grid-column: 2; grid-row: 1 / span 2; max-height: none; margin: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: none; }
}
@media (hover: none) { .pe-stage { cursor: default; } }

/* Popup novità "Modifica foto" (una volta per account, solo con la funzione attiva) */
dialog.pe-news { width: min(92vw, 400px); max-height: calc(100dvh - 32px); padding: 0; overflow: auto; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.pe-news__content { padding: var(--space-5) var(--space-5) var(--space-5); }
.pe-news__topline { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.pe-news__tag { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--radius-pill); background: var(--primary-soft); color: var(--primary); font-size: var(--text-xs); font-weight: 700; }
.pe-news__tag svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.pe-news__close { display: grid; place-items: center; flex: 0 0 auto; width: 36px; height: 36px; border: 0; border-radius: var(--radius-pill); background: var(--surface2); color: var(--hint); cursor: pointer; }
.pe-news__close svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.pe-news__carousel { margin-bottom: var(--space-4); }
.pe-news__track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain; }
.pe-news__track::-webkit-scrollbar { display: none; }
.pe-news__slide { display: flex; flex: 0 0 100%; flex-direction: column; gap: var(--space-2); margin: 0; scroll-snap-align: center; }
.pe-news__slide img { display: block; width: 100%; height: min(40dvh, 280px); border-radius: var(--radius-lg); background: #0c0e14; object-fit: contain; }
.pe-news__slide figcaption { color: var(--text); font-size: var(--text-sm); font-weight: 700; text-align: center; }
.pe-news__dots { display: flex; justify-content: center; gap: 6px; margin-top: var(--space-2); }
.pe-news__dot { width: 7px; height: 7px; padding: 0; border: 0; border-radius: var(--radius-pill); background: var(--border-strong); cursor: pointer; transition: width .2s ease, background-color .2s ease; }
.pe-news__dot.is-active { width: 20px; background: var(--primary); }
@media (prefers-reduced-motion: reduce) { .pe-news__dot { transition: none; } }
.pe-news h2 { margin: 0 0 var(--space-2); color: var(--text); font-size: var(--text-lg); font-weight: 800; line-height: 1.2; letter-spacing: var(--tracking-tight, -.02em); }
#pe-news-description { margin: 0 0 var(--space-4); color: var(--text-2); font-size: var(--text-sm); line-height: 1.5; }
.pe-news__note { margin: 0 0 var(--space-4); color: var(--hint); font-size: var(--text-xs); line-height: 1.4; }
.pe-news__actions { display: grid; gap: var(--space-2); }
.pe-news__cta, .pe-news__dismiss { width: 100%; min-height: var(--tap-min, 48px); padding: 0 var(--space-4); border: 0; border-radius: var(--radius); font: inherit; font-size: var(--text-md, 15px); font-weight: 700; cursor: pointer; }
.pe-news__cta { background: var(--primary); color: #fff; }
.pe-news__dismiss { background: var(--surface2); color: var(--text); }
.pe-news__cta[hidden] { display: none; }
.pe-news button:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 2px; }
