/* ============================================================
   BIOMAGNETISMO PARA TODOS — ZOOM STAGE v16.0
   ============================================================
   ESCENARIO SOLIDARIO: imagen + marcadores en un único elemento
   transformado. Los marcadores NO pueden desincronizarse porque
   comparten la misma matriz de transformación que la imagen.

   Jerarquía:
     .zst-viewport   → ventana con recorte (overflow hidden)
       .zst-stage    → recibe translate3d() scale()  [origen 0 0]
         img.zst-img → 100% del escenario, SIN object-fit
         .zst-layer  → marcadores en % del escenario
     .zst-hud        → controles, FUERA del escenario (sin escalar)

   Variable clave:
     --zst-inv = 1/escala → contra-escala de los marcadores para que
     conserven un tamaño visual constante a cualquier zoom.
   ============================================================ */

/* ------------------------------------------------------------
   0. NEUTRALIZACIÓN DEL ZOOM ANTIGUO
   ------------------------------------------------------------
   El contenedor del modal usaba `overflow:auto` + scroll manual.
   Con el escenario solidario el recorte y el desplazamiento los
   gestiona .zst-viewport, así que el contenedor deja de desplazarse
   (si no, aparecería un doble sistema de coordenadas). */
.zoom-image-container:has(.zst-viewport) {
    overflow: hidden;
    display: block;
    padding: 0;
    min-height: 0;
}

/* Reserva para navegadores sin :has() */
.zoom-image-container.zst-host {
    overflow: hidden;
    display: block;
    padding: 0;
    min-height: 0;
}

/* ------------------------------------------------------------
   1. VENTANA (VIEWPORT)
   ------------------------------------------------------------ */
.zst-viewport {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 240px;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 40%, rgba(99, 102, 241, .10), transparent 70%),
        #0b1020;
    border-radius: 14px;
    touch-action: none;              /* gestionamos pinza y arrastre en JS */
    cursor: grab;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    contain: layout paint;
}

.zst-viewport.is-grabbing {
    cursor: grabbing;
}

/* Rejilla técnica sutil: ayuda a percibir el desplazamiento */
.zst-viewport::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, .028) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .028) 1px, transparent 1px);
    background-size: 40px 40px;
    z-index: 0;
}

/* ------------------------------------------------------------
   2. ESCENARIO — el ÚNICO elemento transformado
   ------------------------------------------------------------ */
.zst-stage {
    --zst-inv: 1;
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;           /* imprescindible: matemática lineal simple */
    will-change: transform;
    backface-visibility: hidden;
    z-index: 1;
}

/* ------------------------------------------------------------
   3. IMAGEN — llena el escenario exactamente
   ------------------------------------------------------------ */
.zst-stage > .zst-img,
.zst-stage > img {
    display: block;
    width: 100%;
    height: 100%;
    /* SIN object-fit: el escenario ya tiene la relación de aspecto
       natural de la imagen (calculada en JS), de modo que el 0-100 %
       del escenario ES la imagen. Cero letterboxing. */
    object-fit: fill;
    transform: none;                 /* neutraliza reglas heredadas antiguas */
    max-width: none;
    max-height: none;
    border-radius: 0;
    pointer-events: none;
    -webkit-user-drag: none;
    user-select: none;
    image-rendering: -webkit-optimize-contrast;
    filter: drop-shadow(0 0 22px rgba(0, 0, 0, .45));
}

/* ------------------------------------------------------------
   4. CAPA DE MARCADORES — dentro del escenario
   ------------------------------------------------------------ */
.zst-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;            /* los hijos la reactivan */
    z-index: 2;
}

/* ------------------------------------------------------------
   5. MARCADOR
   ------------------------------------------------------------
   left/top en % del escenario → anclaje absoluto a la anatomía.
   La contra-escala se aplica en el mismo transform que el centrado,
   por lo que el punto (left,top) permanece EXACTO a cualquier zoom. */
.zst-mk {
    position: absolute;
    width: 34px;
    height: 34px;
    margin: 0;
    transform: translate(-50%, -50%) scale(var(--zst-inv));
    transform-origin: 50% 50%;
    pointer-events: auto;
    cursor: help;
    z-index: 3;
    transition: filter .18s ease;
}

.zst-mk:focus-visible {
    outline: none;
}

/* Núcleo: el disco con la letra N / S */
.zst-mk-core {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 15px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: .5px;
    color: #fff;
    border: 2.5px solid #fff;
    box-shadow:
        0 2px 10px rgba(0, 0, 0, .5),
        0 0 0 1px rgba(0, 0, 0, .35);
    z-index: 2;
}

/* Punto de precisión: marca el píxel exacto del punto anatómico */
.zst-mk-core::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 3px;
    height: 3px;
    margin: -1.5px 0 0 -1.5px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .5);
}

/* Anillo pulsante: halo de localización */
.zst-mk-ring {
    position: absolute;
    inset: -7px;
    border-radius: 50%;
    z-index: 1;
    pointer-events: none;
}

/* ------------------------------------------------------------
   6. POLARIDAD
   ------------------------------------------------------------ */
.zst-mk.pol-neg .zst-mk-core {
    background: linear-gradient(145deg, #2563eb, #1e3a8a);
}

.zst-mk.pol-neg .zst-mk-ring {
    background: radial-gradient(circle, rgba(37, 99, 235, .34), transparent 68%);
    animation: zstPulseNeg 2.1s ease-in-out infinite;
}

.zst-mk.pol-pos .zst-mk-core {
    background: linear-gradient(145deg, #dc2626, #7f1d1d);
}

.zst-mk.pol-pos .zst-mk-ring {
    background: radial-gradient(circle, rgba(220, 38, 38, .34), transparent 68%);
    animation: zstPulsePos 2.1s ease-in-out infinite;
}

@keyframes zstPulseNeg {
    0%, 100% { transform: scale(1);    opacity: .85; }
    50%      { transform: scale(1.42); opacity: .28; }
}

@keyframes zstPulsePos {
    0%, 100% { transform: scale(1);    opacity: .85; }
    50%      { transform: scale(1.42); opacity: .28; }
}

/* ------------------------------------------------------------
   7. JERARQUÍA CLÍNICA DE MARCADORES
   ------------------------------------------------------------
   primary    → COLOCAR el imán aquí
   alternate  → abordaje válido por la cara opuesta
   projection → sólo referencia; colocar aquí sería un error clínico */
.zst-mk.mk-primary {
    /* estado por defecto: máxima presencia visual */
    z-index: 5;
}

.zst-mk.mk-alternate {
    width: 30px;
    height: 30px;
    z-index: 4;
}

.zst-mk.mk-alternate .zst-mk-core {
    border-style: dashed;
    border-width: 2.5px;
    font-size: 13px;
}

.zst-mk.mk-alternate .zst-mk-ring {
    animation: none;
    opacity: .45;
}

.zst-mk.mk-projection {
    width: 26px;
    height: 26px;
    opacity: .55;
    z-index: 3;
}

.zst-mk.mk-projection .zst-mk-core {
    border-style: dotted;
    border-width: 2px;
    font-size: 11px;
    background-image: repeating-linear-gradient(
        45deg,
        rgba(255, 255, 255, .22) 0 3px,
        transparent 3px 6px
    );
    box-shadow: 0 1px 5px rgba(0, 0, 0, .4);
}

.zst-mk.mk-projection .zst-mk-ring {
    display: none;
}

.zst-mk.mk-projection:hover,
.zst-mk.mk-projection:focus-visible {
    opacity: 1;
}

/* Gemelo bilateral: marca discreta de duplicidad anatómica */
.zst-mk.is-twin .zst-mk-core {
    border-color: rgba(255, 255, 255, .8);
    box-shadow:
        0 2px 10px rgba(0, 0, 0, .5),
        0 0 0 3.5px rgba(255, 255, 255, .16);
}

/* Marcador enfocado por el botón «siguiente imán» */
.zst-mk.is-focus {
    z-index: 9;
}

.zst-mk.is-focus .zst-mk-core {
    border-color: #fbbf24;
    box-shadow:
        0 0 0 3px rgba(251, 191, 36, .55),
        0 3px 14px rgba(0, 0, 0, .6);
}

.zst-mk.is-focus .zst-tip,
.zst-mk:hover .zst-tip,
.zst-mk:focus-visible .zst-tip {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0) scale(1);
}

/* ------------------------------------------------------------
   8. ETIQUETA FLOTANTE (TOOLTIP)
   ------------------------------------------------------------ */
.zst-tip {
    position: absolute;
    bottom: calc(100% + 9px);
    left: 50%;
    transform: translate(-50%, 5px) scale(.94);
    transform-origin: 50% 100%;
    min-width: 92px;
    max-width: 230px;
    padding: 6px 10px;
    border-radius: 9px;
    background: rgba(9, 12, 24, .95);
    border: 1px solid rgba(255, 255, 255, .16);
    color: #f1f5f9;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.35;
    text-align: center;
    white-space: normal;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .55);
    transition: opacity .16s ease, transform .16s ease, visibility .16s;
    z-index: 10;
}

.zst-tip em {
    display: block;
    margin-top: 2px;
    font-style: normal;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: .3px;
    text-transform: uppercase;
    color: #a5b4fc;
}

/* Punta del bocadillo */
.zst-tip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border: 5px solid transparent;
    border-top-color: rgba(9, 12, 24, .95);
}

/* Marcadores muy altos: la etiqueta se muestra debajo */
.zst-mk.tip-below .zst-tip {
    bottom: auto;
    top: calc(100% + 9px);
    transform-origin: 50% 0;
    transform: translate(-50%, -5px) scale(.94);
}

.zst-mk.tip-below:hover .zst-tip,
.zst-mk.tip-below:focus-visible .zst-tip,
.zst-mk.tip-below.is-focus .zst-tip {
    transform: translate(-50%, 0) scale(1);
}

.zst-mk.tip-below .zst-tip::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: rgba(9, 12, 24, .95);
}

/* ------------------------------------------------------------
   9. HUD DE CONTROLES — fuera del escenario, nunca se escala
   ------------------------------------------------------------ */
.zst-hud {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 999px;
    background: rgba(9, 12, 24, .82);
    border: 1px solid rgba(255, 255, 255, .14);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 20;
}

.zst-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 50%;
    background: rgba(255, 255, 255, .07);
    color: #e2e8f5;
    font-size: 13px;
    cursor: pointer;
    transition: background .16s ease, color .16s ease, transform .12s ease;
}

.zst-btn:hover {
    background: rgba(99, 102, 241, .32);
    color: #fff;
}

.zst-btn:active {
    transform: scale(.92);
}

.zst-btn:focus-visible {
    outline: 2px solid #818cf8;
    outline-offset: 2px;
}

.zst-btn-wide {
    width: auto;
    min-width: 36px;
    padding: 0 13px;
    border-radius: 999px;
    background: rgba(99, 102, 241, .26);
    border-color: rgba(129, 140, 248, .45);
}

.zst-level {
    min-width: 54px;
    text-align: center;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #c7d2fe;
    letter-spacing: .4px;
    user-select: none;
}

/* ------------------------------------------------------------
   10. AJUSTES RESPONSIVOS
   ------------------------------------------------------------ */
@media (max-width: 640px) {
    .zst-mk               { width: 30px; height: 30px; }
    .zst-mk-core          { font-size: 13px; border-width: 2px; }
    .zst-mk.mk-alternate  { width: 27px; height: 27px; }
    .zst-mk.mk-projection { width: 24px; height: 24px; }

    .zst-hud   { bottom: 10px; gap: 4px; padding: 5px 7px; }
    .zst-btn   { width: 34px; height: 34px; font-size: 12px; }
    .zst-level { min-width: 46px; font-size: 11px; }
    .zst-tip   { font-size: 10.5px; max-width: 170px; }
}

@media (max-width: 380px) {
    .zst-btn-wide { padding: 0 9px; }
}

/* ------------------------------------------------------------
   11. ACCESIBILIDAD
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
    .zst-mk-ring,
    .zst-mk.pol-neg .zst-mk-ring,
    .zst-mk.pol-pos .zst-mk-ring {
        animation: none !important;
    }
    .zst-tip,
    .zst-btn,
    .zst-mk {
        transition: none !important;
    }
}

@media (prefers-contrast: more) {
    .zst-mk-core { border-width: 3px; }
    .zst-tip     { background: #000; border-color: #fff; }
}

/* ------------------------------------------------------------
   12. IMPRESIÓN
   ------------------------------------------------------------ */
@media print {
    .zst-hud                { display: none !important; }
    .zst-viewport           { background: #fff; overflow: visible; }
    .zst-viewport::before   { display: none; }
    .zst-mk-ring            { display: none; }
    .zst-mk-core            { color: #000; background: #fff !important; border-color: #000; }
}
