/* ============================================================
   Visor de proyecto: mejoras (carga después de styles.css)
   Accesibilidad, gestos, ficha técnica, chips de tipo,
   comparador antes/después y modelo 3D.
   ============================================================ */

/* ---------- Escenario y diapositiva ---------- */
.viewer__stage {
  touch-action: pan-y pinch-zoom; /* el navegador gestiona scroll vertical y zoom; el swipe horizontal, el JS */
}
.viewer__slide {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  will-change: transform;
}
/* marco que se ajusta al medio para colocar el chip sobre la imagen */
.vframe { position: relative; display: block; max-width: 100%; max-height: 100%; }
.vframe:not(.vframe--box) img {
  display: block;
  background-color: #000;
  background-size: contain; background-position: center; background-repeat: no-repeat; /* miniatura como marcador */
}
/* cajas 16:9 para comparador y modelo */
.vframe--box { width: 100%; aspect-ratio: 16 / 9; background: #000; }

@media (min-width: 768px) {
  /* el escenario mide la fila del grid; sus hijos se limitan con unidades de contenedor */
  .viewer__stage { container-type: size; }
  .viewer__slide { height: 100cqh; }
  .vframe:not(.vframe--box) img { max-width: 100cqw; max-height: calc(100dvh - 260px); max-height: 100cqh; }
  .vframe--box { width: min(100cqw, 100cqh * 16 / 9); }
}
@media (max-width: 767px) {
  .viewer__slide { height: auto; display: block; }
  .vframe:not(.vframe--box) img { width: 100%; height: auto; }
}

/* ---------- Chip de tipo de imagen ---------- */
.kind-chip, .thumb__kind, .thumb__badge {
  position: absolute; z-index: 2; pointer-events: none;
  font-family: var(--mono); text-transform: uppercase; letter-spacing: .06em; line-height: 1;
  background: rgb(9 9 10 / 0.82); color: var(--text); border: 1px solid var(--line-strong);
}
.kind-chip { top: 10px; left: 10px; font-size: .68rem; padding: .3rem .5rem; }
.kind-chip::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-right: .4rem; background: var(--accent); vertical-align: .05em; }
.thumb__kind { left: 2px; bottom: 2px; font-size: .5rem; padding: .15rem .25rem; }
.thumb__badge { right: 2px; top: 2px; font-size: .55rem; padding: .15rem .25rem; color: var(--accent); }

/* ---------- Miniaturas ---------- */
.thumb { opacity: .78; } /* inactivas >= 0,75 para que sigan siendo legibles */
.thumb:hover, .thumb:focus-visible { opacity: 1; }
.thumb.is-active, .thumb[aria-current="true"] { opacity: 1; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.thumb:focus-visible { outline-offset: 2px; }

/* ---------- Ficha técnica ---------- */
.specs {
  margin-top: .75rem;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, max-content)); gap: 0;
  font-family: var(--mono); font-size: .72rem;
  border: 1px solid var(--line-strong);
  width: fit-content; max-width: 100%;
}
.specs[hidden] { display: none; }
.specs > div { padding: .4rem .65rem; border-right: 1px solid var(--line); }
.specs > div:last-child { border-right: 0; }
.specs dt { color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-size: .62rem; }
.specs dd { margin: .15rem 0 0; color: var(--text); white-space: nowrap; }

/* ---------- Comparador antes / después ---------- */
.cmp { overflow: hidden; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.viewer__stage .cmp__img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; aspect-ratio: auto; object-fit: contain; display: block; }
.cmp__before { clip-path: inset(0 calc(100% - var(--pos, 50%)) 0 0); }
.cmp__handle {
  position: absolute; top: 0; bottom: 0; left: var(--pos, 50%); width: 2px; translate: -1px 0;
  background: var(--accent); pointer-events: none;
}
.cmp__handle::after {
  content: ''; position: absolute; top: 50%; left: 50%; width: 28px; height: 28px; translate: -50% -50%;
  background: var(--accent); border: 2px solid var(--accent-ink);
}
.cmp__label {
  position: absolute; bottom: 10px; z-index: 1; pointer-events: none;
  font-family: var(--mono); font-size: .68rem; text-transform: uppercase; letter-spacing: .06em;
  padding: .3rem .5rem; background: rgb(9 9 10 / 0.82); border: 1px solid var(--line-strong);
}
.cmp__label--before { left: 10px; }
.cmp__label--after { right: 10px; }
/* el range cubre toda la imagen: se arrastra en cualquier punto y responde a flechas/Inicio/Fin */
.cmp__range {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  opacity: 0; cursor: ew-resize; touch-action: pan-y;
  -webkit-appearance: none; appearance: none; background: transparent;
}
.cmp:has(.cmp__range:focus-visible) { outline: 2px solid var(--accent); outline-offset: 3px; }
.cmp:has(.cmp__range:focus-visible) .cmp__handle::after { background: var(--text); }

/* ---------- Modelo 3D ---------- */
.vmodel model-viewer {
  display: block; width: 100%; height: 100%;
  background: #000;
  --poster-color: #000;
  --progress-bar-color: var(--accent);
}
.viewer__stage .vmodel__poster { width: 100%; max-height: none; aspect-ratio: auto; height: 100%; object-fit: contain; display: block; }
model-viewer:not(:defined) > .vmodel__poster { position: absolute; inset: 0; }
.vmodel__error {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 2;
  font-size: .85rem; padding: .5rem .75rem; background: rgb(9 9 10 / 0.9); border: 1px solid var(--danger); color: var(--text);
}
.vmodel__error[hidden] { display: none; }

/* ---------- Flechas de navegación ---------- */
.viewer__nav { min-width: 44px; min-height: 44px; z-index: 3; }
/* Tablet (768-1024): flechas visibles y de 48 px, por encima del escenario */
@media (min-width: 768px) and (max-width: 1024px) {
  .viewer__nav { display: grid; width: 48px; height: 48px; }
  .viewer__nav[hidden] { display: none; }
  .viewer__nav--prev { left: 8px; }
  .viewer__nav--next { right: 8px; }
}

/* ---------- Movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  .viewer__slide { will-change: auto; transition: none; }
  .thumb { transition: none; }
}
