/* ── MSF Viewer Styles ────────────────────────────────────────────────── */
*,
*::before,
*::after { box-sizing: border-box; }

/* Quando il viewer è attivo, blocca lo scroll del body */
html.msf-html,
body.msf-active {
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: 100% !important;
}

/* ── Nascondi sidebar, header e footer del tema ─────────────────────────
   Copre i selettori più comuni di tutti i principali temi WordPress.
   Il viewer è fixed z-index:99999 quindi copre tutto comunque,
   ma nascondendo questi elementi evitiamo scroll spurio e artefatti. */
body.msf-active #sidebar,
body.msf-active .sidebar,
body.msf-active #secondary,
body.msf-active .widget-area,
body.msf-active aside,
body.msf-active #header,
body.msf-active .site-header,
body.msf-active header,
body.msf-active .site-footer,
body.msf-active #footer,
body.msf-active footer,
body.msf-active nav,
body.msf-active #nav,
body.msf-active .navbar,
body.msf-active .navigation,
body.msf-active .site-navigation,
body.msf-active #main-navigation,
body.msf-active .main-navigation,
body.msf-active #primary-menu,
body.msf-active .primary-menu,
body.msf-active #masthead,
body.msf-active .entry-header,
body.msf-active .page-header,
body.msf-active .breadcrumb,
body.msf-active .breadcrumbs,
body.msf-active #breadcrumbs {
    display: none !important;
}

/* Rimuovi padding/margin dai container tipici dei temi */
body.msf-active #page,
body.msf-active #wrapper,
body.msf-active .site,
body.msf-active #content,
body.msf-active .site-content,
body.msf-active #primary,
body.msf-active .content-area,
body.msf-active main,
body.msf-active #main,
body.msf-active .site-main,
body.msf-active article,
body.msf-active .hentry,
body.msf-active .entry-content,
body.msf-active .post-content,
body.msf-active .page-content {
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
    width: 100% !important;
    background: #000 !important;
    float: none !important;
}

.msf-viewer {
    /* Sfonda fuori da qualsiasi container WordPress */
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    z-index: 2147483647 !important; /* max z-index possibile */
    background: #000 !important;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    touch-action: pan-y;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

/* ── Stage ─────────────────────────────────────────────────────────────── */
.msf-stage {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.msf-slide {
    position: absolute;
    inset: 0;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    background-color: #000;
    will-change: opacity, transform;
    opacity: 0;
    pointer-events: none;
    transition: opacity .55s cubic-bezier(.4,0,.2,1),
                transform .55s cubic-bezier(.4,0,.2,1);
}
.msf-slide--active {
    opacity: 1;
    pointer-events: auto;
}

/* Transitions */
.msf-slide--enter-right  { transform: translateX(60px);  opacity: 0; }
.msf-slide--enter-left   { transform: translateX(-60px); opacity: 0; }
.msf-slide--exit-left    { transform: translateX(-60px); opacity: 0; }
.msf-slide--exit-right   { transform: translateX(60px);  opacity: 0; }

/* ── Navigation arrows ─────────────────────────────────────────────────── */
.msf-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12);
    color: #fff;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .2s, border-color .2s, transform .2s;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.msf-nav:hover {
    background: rgba(255,255,255,.18);
    border-color: rgba(255,255,255,.28);
}
.msf-nav:active { transform: translateY(-50%) scale(.94); }
.msf-nav--prev { left: 20px; }
.msf-nav--next { right: 20px; }

/* Hide arrows at extremes */
.msf-nav--hidden { opacity: 0; pointer-events: none; }

/* ── Indicator / counter ───────────────────────────────────────────────── */
.msf-indicator {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.msf-indicator__toggle {
    background: rgba(0,0,0,.55);
    border: 1px solid rgba(255,255,255,.15);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: .04em;
    padding: 6px 16px;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: background .2s, border-color .2s;
}
.msf-indicator__toggle:hover {
    background: rgba(255,255,255,.15);
    border-color: rgba(255,255,255,.3);
}
.msf-indicator__sep {
    opacity: .4;
    font-weight: 400;
    margin: 0 1px;
}

/* ── Thumbnail panel ───────────────────────────────────────────────────── */
.msf-thumb-panel {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: rgba(10,10,20,.92);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 14px;
    padding: 0;
    width: min(92vw, 640px);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease, transform .25s ease;
    box-shadow: 0 24px 64px rgba(0,0,0,.7);
}
.msf-thumb-panel.msf-thumb-panel--open {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}
.msf-thumb-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 8px;
    color: rgba(255,255,255,.5);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}
.msf-thumb-panel__header button {
    background: none;
    border: none;
    color: rgba(255,255,255,.4);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color .15s;
}
.msf-thumb-panel__header button:hover { color: #fff; }

.msf-thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 6px;
    padding: 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.msf-thumb-grid::-webkit-scrollbar { width: 4px; }
.msf-thumb-grid::-webkit-scrollbar-track { background: transparent; }
.msf-thumb-grid::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.msf-thumb-item {
    position: relative;
    aspect-ratio: 16/10;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color .15s, transform .15s;
    background: #111;
}
.msf-thumb-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.msf-thumb-item:hover { transform: scale(1.04); border-color: rgba(255,255,255,.3); }
.msf-thumb-item--active { border-color: #e94560; }
.msf-thumb-item__num {
    position: absolute;
    bottom: 3px;
    right: 5px;
    font-size: 10px;
    color: rgba(255,255,255,.8);
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(0,0,0,.9);
}

/* ── Loading ───────────────────────────────────────────────────────────── */
.msf-loading {
    position: absolute;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 50;
    color: rgba(255,255,255,.5);
    font-size: 13px;
    transition: opacity .4s ease;
}
.msf-loading--hidden {
    opacity: 0;
    pointer-events: none;
}
.msf-loading__spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255,255,255,.1);
    border-top-color: #e94560;
    border-radius: 50%;
    animation: msf-spin .7s linear infinite;
}
@keyframes msf-spin {
    to { transform: rotate(360deg); }
}

/* ── Error ─────────────────────────────────────────────────────────────── */
.msf-error {
    position: absolute;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,.5);
    gap: 16px;
    z-index: 50;
}
.msf-error button {
    background: #e94560;
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .msf-nav { width: 38px; height: 38px; }
    .msf-nav--prev { left: 10px; }
    .msf-nav--next { right: 10px; }
}
