/* ==================================================== */
/* LAYOUT ELLISSE: STRUTTURA TASSATIVA E INTEGRAZIONE   */
/* ==================================================== */

:root {
    --overlay-bg: rgba(220, 220, 220, 0.72);
    --dot-size: 10px;
    --orbit-radius: 42px;
    --animation-duration: 1.2s;
}

body,
html {
    background-color: var(--primary) !important;
}

.layout-contenitore {
    display: flex;
    width: 100vw;
    /* Lascia sempre spazio in fondo per l'AD globale se presente */
    height: calc(100dvh - var(--footer-ad-height, 0px)) !important;
    overflow: hidden;
}

/* --- OVERLAY CARICAMENTO ORBITALE --- */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: grid;
    place-items: center;
    background: var(--overlay-bg);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 220ms ease, visibility 220ms ease;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.loader {
    position: relative;
    width: calc(var(--orbit-radius) * 2 + var(--dot-size));
    height: calc(var(--orbit-radius) * 2 + var(--dot-size));
}

.dot {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--dot-size);
    height: var(--dot-size);
    margin: calc(var(--dot-size) / -2);
    border-radius: 50%;
    background: #707070;
    transform: rotate(var(--angle)) translateY(calc(var(--orbit-radius) * -1));
    animation: woosh var(--animation-duration) infinite ease-in-out;
    animation-delay: var(--delay);
}

.dot:nth-child(1) {
    --angle: 0deg;
    --delay: -1s;
}

.dot:nth-child(2) {
    --angle: 60deg;
    --delay: -0.8s;
}

.dot:nth-child(3) {
    --angle: 120deg;
    --delay: -0.6s;
}

.dot:nth-child(4) {
    --angle: 180deg;
    --delay: -0.4s;
}

.dot:nth-child(5) {
    --angle: 240deg;
    --delay: -0.2s;
}

.dot:nth-child(6) {
    --angle: 300deg;
    --delay: 0s;
}

@keyframes woosh {

    0%,
    100% {
        opacity: 0.3;
        background: #707070;
        filter: blur(0);
        transform: rotate(var(--angle)) translateY(calc(var(--orbit-radius) * -1)) scale(0.75);
    }

    35% {
        opacity: 1;
        background: #ffffff;
        filter: blur(1px);
        box-shadow: 0 0 6px #ffffff, 0 0 14px rgba(255, 255, 255, 0.9);
        transform: rotate(var(--angle)) translateY(calc(var(--orbit-radius) * -1)) scale(1.45);
    }

    60% {
        opacity: 0.45;
        background: #8a8a8a;
        filter: blur(0);
        transform: rotate(var(--angle)) translateY(calc(var(--orbit-radius) * -1)) scale(0.9);
    }
}

/* --- SIDEBAR DI SINISTRA --- */
.layout-sidebar {
    display: var(--display-side) !important;
    width: var(--sidebar-width) !important;
    height: 100% !important;
    box-sizing: border-box !important;
    background-color: transparent !important;
    color: #ffffff;
    padding: 30px 20px;
    flex-direction: column;
    overflow-y: auto;
    z-index: 1010;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    color: white;
}

.sidebar-header h2 {
    font-size: 20px;
    color: #ffffff;
}

.sidebar-header a,
.sidebar-footer a {
    color: white !important;
}

.sidebar-nav {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.layout-sidebar a,
.layout-sidebar .sidebar-btn {
    color: rgba(255, 255, 255, 0.85) !important;
    background: transparent !important;
    border: none !important;
    padding: 10px 12px !important;
    border-radius: 6px;
    font-weight: bold;
    font-size: 1em;
    text-decoration: none;
    display: block;
    transition: background 0.2s, color 0.2s;
}

.layout-sidebar a:hover,
.layout-sidebar .sidebar-btn:hover {
    color: #ffffff !important;
    background: rgba(255, 255, 255, 0.15) !important;
}

.sidebar-footer {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 0.9em;
}

/* --- AREA ELLISSE --- */
.layout-ellipse-right {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    width: calc(100vw - var(--sidebar-width, 0px)) !important;
    height: 100% !important;
    overflow: hidden;
    background-color: var(--bg-main) !important;
    border-radius: 45px 0 0 45px !important;
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.4) !important;
    position: relative;
    z-index: 10;
    transition: transform 0.4s ease, border-radius 0.4s ease;
    padding-left: 0 !important;
}

#topbar.ellipse-topbar {
    display: var(--display-top) !important;
    height: var(--top-height) !important;
    box-sizing: border-box !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    padding-left: 40px !important;
    padding-right: 40px !important;
    position: sticky !important;
    top: 0 !important;
    background: transparent !important;
    border-bottom: 1px solid var(--border-main) !important;
    box-shadow: none !important;
    justify-content: space-between !important;
    align-items: center !important;
    width: 100% !important;
    color: var(--text-light);
}

.layout-body {
    height: calc(100dvh - var(--top-height, 0px) - var(--footer-height, 0px) - var(--footer-ad-height, 0px)) !important;
    box-sizing: border-box !important;
    overflow-y: auto !important;
    padding: 40px;
    width: 100%;
}

#footer.ellipse-footer {
    display: var(--display-foot) !important;
    height: var(--footer-height) !important;
    box-sizing: border-box !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    padding-left: 40px !important;
    padding-right: 40px !important;
    position: relative !important;
    width: 100% !important;
    background-color: var(--bg-panel) !important;
    border-top: 1px solid var(--border-main) !important;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    bottom: auto !important;
    left: auto !important;
}

.footer-cols {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 20px;
    font-size: 0.9em;
    color: var(--text-muted);
}

.footer-bottom {
    text-align: center;
    font-size: 0.8em;
    color: var(--text-muted);
    padding-top: 15px;
    border-top: 1px dashed var(--border-main);
}

/* --- MOBILE --- */
.layout-hamburger-mobile {
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1000;
    background: var(--primary);
    border-radius: 4px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}

.hamburger-icon {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 20px;
    height: 14px;
}

.hamburger-icon span {
    display: block;
    height: 2px;
    width: 100%;
    background: #ffffff;
}

#sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1005;
    display: none;
}

.toggle-close-btn {
    cursor: pointer;
    font-size: 24px;
    font-weight: bold;
    background: none;
    border: none;
    color: white;
}

@media (max-width: 900px) {
    .layout-hamburger-mobile {
        display: flex;
    }

    .layout-ellipse-right {
        width: 100vw !important;
        border-radius: 0 !important;
    }

    .layout-sidebar {
        position: fixed !important;
        left: -100%;
        top: 0;
        height: 100dvh !important;
        background: var(--bg-main) !important;
        z-index: 1010;
        box-shadow: 5px 0 25px rgba(0, 0, 0, 0.6);
        transition: left 0.4s;
    }

    .layout-sidebar a,
    .layout-sidebar .sidebar-btn,
    .sidebar-header {
        color: var(--text-light) !important;
    }

    .layout-sidebar a:hover,
    .layout-sidebar .sidebar-btn:hover {
        background: var(--bg-panel) !important;
    }

    .toggle-close-btn {
        display: block;
        color: var(--text-light);
    }

    #menu-toggle:checked~.layout-contenitore .layout-sidebar {
        left: 0;
    }

    #menu-toggle:checked~#sidebar-overlay {
        display: block;
    }
}