/* ==========================================================================
   MAGNET ZOOM v3.0 — Visor con imanes solidarios a la anatomía
   Clave: .mz-stage recibe TODA la transformación (zoom + paneo). La imagen y
   los marcadores son hijos suyos, por eso nunca se desalinean (deriva 0%).
   ========================================================================== */

/* Neutraliza el visor heredado que causaba la desalineación */
#zoomImageContainer.mz-host {
    overflow: hidden !important;
    padding: 0;
    /* El visor manda: la anatomía siempre recibe la mayor parte de la pantalla */
    flex: 1 1 auto;
    min-height: 62vh;
}
/* Panel de datos acotado para no comerse el visor */
.zoom-modal-content:has(.mz-viewport) .zoom-info {
    max-height: 30vh;
    transition: max-height .3s ease, padding .3s ease;
}
/* Panel de datos plegado (botón «información») */
.zoom-modal-content.mz-info-collapsed .zoom-info {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
}
.zoom-modal-content.mz-info-collapsed #zoomImageContainer.mz-host { min-height: 86vh; }
#zoomImageContainer.mz-host > #zoomImage,
#zoomImageContainer.mz-host > #zoomMagnets { display: none !important; }

/* ------------------------------------------------------------- viewport */
.mz-viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
    touch-action: none;
    cursor: grab;
    background: radial-gradient(ellipse at 50% 42%, rgba(139, 92, 246, .10) 0%, rgba(59, 130, 246, .06) 45%, transparent 78%);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.mz-viewport.mz-grabbing { cursor: grabbing; }

/* ---------------------------------------------------------------- stage */
.mz-stage {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;          /* imprescindible para la fórmula de ancla */
    will-change: transform;
    --mz-inv: 1;
}

/* ------------------------------------------------- paneles (1 o 2 siluetas) */
.mz-pane {
    position: absolute;
    top: 0;
    height: 100%;
    overflow: hidden;
}
.mz-pane-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;               /* el panel ya tiene la proporción exacta */
    clip-path: inset(0 0 3.4% 0);   /* oculta la marca del generador */
    pointer-events: none;
    -webkit-user-drag: none;
}
.mz-pane.is-mirror .mz-pane-img { transform: scaleX(-1); }
.mz-pane-label {
    position: absolute;
    top: 1.5%;
    left: 50%;
    transform: translateX(-50%) scale(var(--mz-inv));
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(11, 17, 32, .82);
    border: 1px solid rgba(255, 255, 255, .16);
    color: #dbeafe;
    font-size: .64rem;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    white-space: nowrap;
    pointer-events: none;
}

/* --------------------------------------------------- guías de precisión */
.mz-guide {
    position: absolute;
    background: rgba(255, 255, 255, .55);
    pointer-events: none;
    z-index: 3;
}
.mz-guide-h {
    left: 0; right: 0; top: 0;
    height: 1px;
    transform: scaleY(var(--mz-inv));
    box-shadow: 0 0 6px rgba(139, 92, 246, .8);
}
.mz-guide-v {
    top: 0; bottom: 0; left: 0;
    width: 1px;
    transform: scaleX(var(--mz-inv));
    box-shadow: 0 0 6px rgba(139, 92, 246, .8);
}

/* ------------------------------------------------------------- markers */
.mz-marker {
    position: absolute;
    top: 0; left: 0;
    width: 0; height: 0;
    /* contra-escala 1/z: tamaño constante en pantalla, ancla fija */
    transform: scale(var(--mz-inv));
    transform-origin: 50% 50%;
    z-index: 5;
    pointer-events: none;
}

.mz-halo {
    position: absolute;
    left: 50%; top: 50%;
    width: 52px; height: 52px;
    margin: -26px 0 0 -26px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    opacity: .38;
    animation: mzPulse 2.4s ease-out infinite;
}

.mz-dot {
    position: absolute;
    left: 50%; top: 50%;
    width: 34px; height: 34px;
    margin: -17px 0 0 -17px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: .82rem;
    line-height: 1;
    color: #fff;
    border: 2px solid rgba(255, 255, 255, .92);
}
/* punto de mira: el centro exacto del punto anatómico */
.mz-dot::after {
    content: '';
    position: absolute;
    width: 3px; height: 3px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .35);
}

.mz-neg { color: #3538cd; }
.mz-pos { color: #ce2c31; }
.mz-neg .mz-dot {
    background: var(--gradient-neg, linear-gradient(135deg, #4f52e8, #2a2ca8));
    box-shadow: 0 0 0 4px rgba(53, 56, 205, .26), 0 4px 18px rgba(53, 56, 205, .5);
}
.mz-pos .mz-dot {
    background: var(--gradient-pos, linear-gradient(135deg, #e8484d, #a81f24));
    box-shadow: 0 0 0 4px rgba(206, 44, 49, .26), 0 4px 18px rgba(206, 44, 49, .5);
}

.mz-marker.mz-proj .mz-dot { border-style: dashed; }
.mz-marker.mz-proj .mz-halo { border-style: dotted; }

.mz-marker.is-active .mz-dot {
    box-shadow: 0 0 0 5px rgba(255, 255, 255, .35), 0 6px 22px rgba(0, 0, 0, .55);
    transform: scale(1.12);
}
.mz-marker.is-active .mz-tag {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-color: rgba(255, 255, 255, .4);
}

.mz-tag {
    position: absolute;
    left: 50%;
    top: 26px;
    transform: translateX(-50%);
    max-width: 168px;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(11, 17, 32, .9);
    color: #f1f5ff;
    font-size: .68rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid rgba(255, 255, 255, .16);
    backdrop-filter: blur(6px);
}
/* anti-solapamiento: etiqueta arriba cuando hay otro imán cerca */
.mz-marker.mz-flip .mz-tag { top: auto; bottom: 26px; }

@keyframes mzPulse {
    0%   { transform: scale(.6);  opacity: .55; }
    70%  { transform: scale(1.25); opacity: 0; }
    100% { transform: scale(1.25); opacity: 0; }
}

/* ------------------------------------------------------------------ HUD */
.mz-hud {
    position: absolute;
    top: 12px; left: 12px; right: 74px;
    z-index: 12;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    pointer-events: none;
}
.mz-level {
    padding: 5px 11px;
    border-radius: 999px;
    background: rgba(11, 17, 32, .82);
    border: 1px solid rgba(255, 255, 255, .16);
    color: #dbeafe;
    font-size: .72rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    backdrop-filter: blur(8px);
}
.mz-hint {
    padding: 5px 11px;
    border-radius: 999px;
    background: rgba(11, 17, 32, .62);
    border: 1px solid rgba(255, 255, 255, .1);
    color: rgba(219, 234, 254, .82);
    font-size: .66rem;
    font-weight: 600;
    backdrop-filter: blur(8px);
    transition: opacity .3s ease;
}
.mz-viewport.mz-zoomed .mz-hint { opacity: 0; }

/* -------------------------------------------------- leyenda lateralidad */
.mz-lat {
    position: absolute;
    top: 48px; left: 12px; right: 12px;
    z-index: 11;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}
.mz-lat-side {
    font-size: .6rem;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: rgba(196, 214, 255, .75);
    background: rgba(11, 17, 32, .55);
    border: 1px solid rgba(255, 255, 255, .08);
    padding: 3px 8px;
    border-radius: 6px;
}

/* -------------------------------------------- barra de herramientas */
.mz-tools {
    position: absolute;
    top: 68px;
    right: 12px;
    z-index: 14;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.mz-tool {
    width: 38px; height: 38px;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 10px;
    background: rgba(11, 17, 32, .84);
    color: #dbeafe;
    font-size: .8rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    transition: background .18s ease, transform .18s ease, color .18s ease;
}
.mz-tool:hover { background: rgba(99, 102, 241, .38); color: #fff; }
.mz-tool:active { transform: scale(.93); }
.mz-tool.is-on {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    border-color: rgba(255, 255, 255, .35);
}

.mz-badge-mirror {
    padding: 5px 11px;
    border-radius: 999px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-size: .66rem;
    font-weight: 800;
    letter-spacing: .02em;
}

/* ------------------------------------------------------------ avisos */
.mz-toast {
    position: absolute;
    left: 50%;
    bottom: 150px;
    transform: translate(-50%, 8px);
    z-index: 20;
    padding: 9px 16px;
    border-radius: 999px;
    background: rgba(11, 17, 32, .94);
    border: 1px solid rgba(255, 255, 255, .18);
    color: #f1f5ff;
    font-size: .72rem;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease, transform .25s ease;
    backdrop-filter: blur(10px);
}
.mz-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* -------------------------------------------------------- mini-mapa */
.mz-map {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 62px;
    height: 111px;
    z-index: 12;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .18);
    background: rgba(11, 17, 32, .7);
    cursor: crosshair;
    opacity: .55;
    transition: opacity .25s ease, box-shadow .25s ease;
}
.mz-map.is-active {
    opacity: 1;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}
.mz-map-panes {
    position: absolute;
    inset: 0;
    display: flex;
}
.mz-map-img {
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    object-fit: fill;
    clip-path: inset(0 0 3.4% 0);
    opacity: .85;
    pointer-events: none;
}
.mz-map-img.is-mirror { transform: scaleX(-1); }
.mz-map-dots { position: absolute; inset: 0; pointer-events: none; }
.mz-map-dot {
    position: absolute;
    width: 6px; height: 6px;
    margin: -3px 0 0 -3px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, .9);
}
.mz-map-dot.neg { background: #3538cd; }
.mz-map-dot.pos { background: #ce2c31; }
.mz-map-dot.is-active { width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; }
.mz-map-rect {
    position: absolute;
    border: 1.5px solid #a78bfa;
    background: rgba(167, 139, 250, .16);
    border-radius: 2px;
    pointer-events: none;
    transition: all .15s linear;
}

/* ------------------------------------------------- chips de imanes */
.mz-chips {
    position: absolute;
    left: 12px; right: 82px;
    bottom: 108px;
    z-index: 12;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.mz-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 46%;
    padding: 5px 11px 5px 5px;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 999px;
    background: rgba(11, 17, 32, .86);
    color: #e8eefc;
    font-size: .68rem;
    font-weight: 700;
    cursor: pointer;
    backdrop-filter: blur(8px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: transform .16s ease, border-color .16s ease;
}
.mz-chip:hover { transform: translateY(-1px); border-color: rgba(255, 255, 255, .35); }
.mz-chip.is-active { border-color: #a78bfa; box-shadow: 0 0 0 2px rgba(167, 139, 250, .3); }
.mz-chip-pole {
    width: 20px; height: 20px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: .62rem;
    color: #fff;
    flex: 0 0 auto;
}
.mz-chip.neg .mz-chip-pole { background: linear-gradient(135deg, #4f52e8, #2a2ca8); }
.mz-chip.pos .mz-chip-pole { background: linear-gradient(135deg, #e8484d, #a81f24); }
.mz-chip-proj { opacity: .6; font-size: .6rem; }
.mz-chip-view {
    margin-left: 4px;
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .12);
    font-size: .58rem;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
    opacity: .85;
}

/* -------------------------------------------------- pestañas de vista */
.mz-views {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 62px;
    z-index: 12;
    display: flex;
    gap: 6px;
    padding: 5px;
    border-radius: 999px;
    background: rgba(11, 17, 32, .86);
    border: 1px solid rgba(255, 255, 255, .14);
    backdrop-filter: blur(10px);
}
.mz-tab {
    border: 0;
    background: transparent;
    color: rgba(219, 234, 254, .78);
    font-size: .72rem;
    font-weight: 800;
    padding: 7px 13px;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background .2s ease, color .2s ease;
}
.mz-tab:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.mz-tab.is-active {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    box-shadow: 0 3px 12px rgba(99, 102, 241, .45);
}

/* ------------------------------------------------------------ controles */
.mz-controls {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 10px;
    z-index: 14;
    display: flex;
    gap: 6px;
    padding: 5px;
    border-radius: 999px;
    background: rgba(11, 17, 32, .88);
    border: 1px solid rgba(255, 255, 255, .14);
    backdrop-filter: blur(10px);
}
.mz-btn {
    border: 0;
    background: rgba(255, 255, 255, .09);
    color: #e8eefc;
    width: 40px; height: 40px;
    border-radius: 999px;
    font-size: .85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background .18s ease, transform .18s ease;
}
.mz-btn:hover { background: rgba(255, 255, 255, .2); }
.mz-btn:active { transform: scale(.94); }
.mz-btn-wide { width: auto; padding: 0 15px; font-size: .74rem; font-weight: 800; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 520px) {
    .mz-dot { width: 30px; height: 30px; margin: -15px 0 0 -15px; font-size: .74rem; }
    .mz-halo { width: 46px; height: 46px; margin: -23px 0 0 -23px; }
    .mz-tag { top: 23px; font-size: .63rem; max-width: 128px; }
    .mz-marker.mz-flip .mz-tag { bottom: 23px; }
    .mz-btn { width: 38px; height: 38px; }
    .mz-btn-wide { padding: 0 11px; font-size: .69rem; }
    .mz-hint { display: none; }
    .mz-map { height: 86px; right: 8px; }
    .mz-chips { bottom: 100px; right: 60px; left: 8px; }
    .mz-chip { max-width: 100%; font-size: .64rem; }
    .mz-lat-side { font-size: .54rem; padding: 2px 6px; }
    .mz-tools { top: 60px; right: 8px; }
    .mz-tool { width: 34px; height: 34px; font-size: .74rem; }
    .mz-toast { bottom: 146px; font-size: .68rem; }
}

@media (prefers-reduced-motion: reduce) {
    .mz-halo { animation: none; }
    .mz-stage { transition: none !important; }
}

/* ==========================================================================
   FIGURAS IMPRIMIBLES — siluetas con imanes en la hoja de sesión
   Mismo sistema de coordenadas porcentual que la pantalla: lo impreso
   coincide exactamente con lo que ve el terapeuta.
   ========================================================================== */
.print-figs { display: none; }

@media print {
    body.printing-sheet .print-figs {
        display: flex !important;
        gap: 6mm;
        justify-content: center;
        margin: 4mm 0 3mm;
        page-break-inside: avoid;
    }
    body.printing-sheet .print-fig {
        margin: 0;
        text-align: center;
        flex: 0 0 auto;
    }
    body.printing-sheet .print-fig-body {
        position: relative;
        width: 34mm;
        aspect-ratio: 1536 / 2752;
    }
    body.printing-sheet .print-fig-body img {
        width: 100%;
        height: 100%;
        object-fit: fill;
        clip-path: inset(0 0 3.4% 0);
        filter: grayscale(1) contrast(1.06);   /* tinta y legibilidad */
    }
    body.printing-sheet .print-mag {
        position: absolute;
        transform: translate(-50%, -50%);
        width: 5.2mm;
        height: 5.2mm;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: system-ui, sans-serif;
        font-size: 7pt;
        font-weight: 900;
        color: #fff;
        border: 0.5mm solid #fff;
        box-shadow: 0 0 0 0.3mm #333;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    body.printing-sheet .print-mag.neg { background: #3538cd; }
    body.printing-sheet .print-mag.pos { background: #ce2c31; }
    body.printing-sheet .print-mag.is-proj { border-style: dashed; opacity: .9; }
    body.printing-sheet .print-fig figcaption {
        margin-top: 1.5mm;
        font-size: 8pt;
        font-weight: 700;
        letter-spacing: .04em;
        text-transform: uppercase;
        color: #333;
    }
}
