/* Smartphone Italia — account dropdown panel (20260707-guest-hover-preview)
   Desktop hover: logged-in (Mio account + Esci) and guest (Accedi + Registrati). */

/* ── Account panel shell ── */
.tv-account-dropdown.si-account-panel,
body > .tv-account-dropdown.si-account-panel,
body > .tv-account-dropdown.open.si-account-panel {
    display: none;
    flex-direction: column !important;
    position: fixed !important;
    z-index: 99992 !important;
    min-width: min(320px, calc(100vw - 32px)) !important;
    max-width: min(360px, calc(100vw - 32px)) !important;
    max-height: min(70vh, calc(100dvh - 120px)) !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: #fff !important;
    background-clip: padding-box !important;
    border: 1px solid var(--si-line, rgba(0, 0, 0, 0.08)) !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.14) !important;
    list-style: none !important;
    font-family: var(--si-font, Inter, system-ui, sans-serif);
    -webkit-overflow-scrolling: touch;
}

.tv-account-dropdown.si-account-panel.open,
body > .tv-account-dropdown.si-account-panel.open {
    display: flex !important;
}

/* Header with close */
.tv-account-dropdown.si-account-panel .si-account-panel__header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 48px;
    padding: 8px 44px;
    border-bottom: 1px solid var(--si-line, rgba(0, 0, 0, 0.08));
    background: #fff;
}

.tv-account-dropdown.si-account-panel .si-account-panel__title {
    margin: 0;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--si-text, #1d1d1f);
}

.tv-account-dropdown.si-account-panel .si-account-panel__close {
    position: absolute;
    top: 50%;
    right: max(6px, env(safe-area-inset-right, 0px));
    transform: translateY(-50%);
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: transparent;
    cursor: pointer;
    color: var(--si-text, #1d1d1f);
    font-family: 'Material Icons';
    font-size: 24px;
    line-height: 44px;
    text-align: center;
}

.tv-account-dropdown.si-account-panel .si-account-panel__close:hover,
.tv-account-dropdown.si-account-panel .si-account-panel__close:focus {
    background: rgba(57, 181, 74, 0.08);
    outline: none;
}

/* Scrollable links area */
.tv-account-dropdown.si-account-panel {
    overflow-y: auto !important;
}

.tv-account-dropdown.si-account-panel > li:not(.si-account-panel__header) {
    display: block;
    margin: 0;
    padding: 0;
    border: none;
    list-style: none;
}

.tv-account-dropdown.si-account-panel > li:not(.si-account-panel__header):empty {
    display: none !important;
}

.tv-account-dropdown.si-account-panel a,
.tv-account-dropdown.si-account-panel .tvhedaer-sign-btn {
    display: flex !important;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 12px 20px !important;
    font-size: 0.9375rem !important;
    font-weight: 500 !important;
    line-height: 1.35 !important;
    color: var(--si-text, #1d1d1f) !important;
    text-decoration: none !important;
    background: transparent !important;
    border: none !important;
    width: 100%;
    box-sizing: border-box;
    transition: background 0.2s ease;
}

.tv-account-dropdown.si-account-panel a:hover,
.tv-account-dropdown.si-account-panel a:focus,
.tv-account-dropdown.si-account-panel .tvhedaer-sign-btn:hover,
.tv-account-dropdown.si-account-panel .tvhedaer-sign-btn:focus {
    background: rgba(57, 181, 74, 0.08) !important;
    color: var(--si-accent, #39b54a) !important;
    outline: none;
}

.tv-account-dropdown.si-account-panel a i,
.tv-account-dropdown.si-account-panel .tvhedaer-sign-btn i {
    font-size: 22px !important;
    color: var(--si-text-secondary, #6e6e73) !important;
    flex-shrink: 0;
}

.tv-account-dropdown.si-account-panel a:hover i,
.tv-account-dropdown.si-account-panel .tvhedaer-sign-btn:hover i {
    color: var(--si-accent, #39b54a) !important;
}

.tv-account-dropdown.si-account-panel .tvhedaer-sign-span,
.tv-account-dropdown.si-account-panel a span:not(.material-icons) {
    color: inherit !important;
    font-size: inherit !important;
    font-weight: inherit !important;
}

/* Flatten ps_customersignin wrapper inside dropdown list */
.tv-account-dropdown.si-account-panel .si-account-dropdown-signout,
.tv-account-dropdown.si-account-panel .si-account-dropdown-signout .tvcms-header-sign,
.tv-account-dropdown.si-account-panel .si-account-dropdown-signout #tvcmsdesktop-user-info {
    display: block;
    margin: 0;
    padding: 0;
    border: none;
}

.tv-account-dropdown.si-account-panel .si-account-dropdown-signout .tvcms-header-sign {
    width: 100%;
}

.tv-account-dropdown.si-account-panel .si-account-dropdown-signout a.logout {
    border-top: 1px solid var(--si-line, rgba(0, 0, 0, 0.08));
}

/* Undo ThemeVolty offsets when portaled */
body > .tv-account-dropdown.si-account-panel {
    right: auto !important;
    left: auto !important;
    top: auto !important;
}

/* Account icon stays visible on white header */
body.si-account-open #header .tv-myaccount-btn-desktop svg g path,
body.si-account-open #header .tv-myaccount-btn-desktop svg circle,
body.si-account-hover-preview #header .tv-myaccount-btn-desktop svg g path,
body.si-account-hover-preview #header .tv-myaccount-btn-desktop svg circle,
.tv-account-wrapper.open .tv-myaccount-btn-desktop svg g path,
.tv-account-wrapper.open .tv-myaccount-btn-desktop svg circle,
.tv-account-wrapper.si-account-hover .tv-myaccount-btn-desktop svg g path,
.tv-account-wrapper.si-account-hover .tv-myaccount-btn-desktop svg circle {
    fill: none !important;
    stroke: var(--si-accent, #39b54a) !important;
}

/* ── Mobile: panel above bottom nav ── */
@media (max-width: 991px) {
    .tv-account-dropdown.si-account-panel,
    body > .tv-account-dropdown.si-account-panel.open {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%);
        bottom: var(--si-bottom-nav-offset, calc(var(--si-bottom-nav-height, 56px) + env(safe-area-inset-bottom, 0px) + 8px)) !important;
        top: auto !important;
        width: min(360px, calc(100vw - 24px)) !important;
        max-width: calc(100vw - 24px) !important;
        max-height: min(60vh, calc(100dvh - var(--si-bottom-nav-offset, 80px) - 24px)) !important;
    }

    body.si-account-open #tvcmsmobile-account-button .tv-myaccount-btn svg path,
    body.si-account-open #tvcmsmobile-account-button .tv-myaccount-btn svg circle,
    body.si-account-open #tvcmsmobile-account-button .tv-myaccount-btn-desktop svg path,
    body.si-account-open #tvcmsmobile-account-button .tv-myaccount-btn-desktop svg circle {
        stroke: var(--si-accent, #39b54a) !important;
    }
}

@media (min-width: 992px) {
    /* ── Desktop: pure CSS hover (dropdown stays in wrapper) ── */
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover {
        position: relative;
        display: inline-flex !important;
        flex-direction: column;
        align-items: flex-end;
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        vertical-align: middle;
    }

    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover > .tv-myaccount-btn,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover > a.tv-myaccount-btn,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover > .tv-myaccount-btn,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover > a.tv-myaccount-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        min-width: 44px;
        min-height: 44px;
        margin: 0 !important;
        padding: 0 !important;
    }

    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover > .tv-account-dropdown.si-account-preview-dropdown,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover > .tv-account-dropdown.si-account-preview-dropdown {
        position: absolute !important;
        top: 100% !important;
        right: 0 !important;
        left: auto !important;
        bottom: auto !important;
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
        opacity: 0 !important;
        min-width: 200px !important;
        max-width: 240px !important;
        max-height: none !important;
        width: max-content !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        transform: none !important;
        height: auto !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12) !important;
        border-radius: 12px !important;
        z-index: 99992 !important;
    }

    /* Invisible bridge — keeps hover zone contiguous icon → panel */
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover > .tv-account-dropdown.si-account-preview-dropdown::before,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover > .tv-account-dropdown.si-account-preview-dropdown::before {
        content: '';
        position: absolute;
        top: -6px;
        right: 0;
        left: 0;
        height: 6px;
        background: transparent;
        pointer-events: auto;
    }

    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover:hover > .tv-account-dropdown.si-account-preview-dropdown,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover:focus-within > .tv-account-dropdown.si-account-preview-dropdown,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover:hover > .tv-account-dropdown.si-account-preview-dropdown,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover:focus-within > .tv-account-dropdown.si-account-preview-dropdown {
        display: flex !important;
        visibility: visible !important;
        pointer-events: auto !important;
        opacity: 1 !important;
    }

    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover:hover > .si-account-preview-dropdown .si-account-panel__header,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover:hover > .si-account-preview-dropdown .si-account-panel__close,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover:focus-within > .si-account-preview-dropdown .si-account-panel__header,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover:focus-within > .si-account-preview-dropdown .si-account-panel__close,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover:hover > .si-account-preview-dropdown .si-account-panel__header,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover:hover > .si-account-preview-dropdown .si-account-panel__close,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover:focus-within > .si-account-preview-dropdown .si-account-panel__header,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover:focus-within > .si-account-preview-dropdown .si-account-panel__close {
        display: none !important;
    }

    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover:hover .tv-myaccount-btn-desktop svg g path,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover:hover .tv-myaccount-btn-desktop svg circle,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover:focus-within .tv-myaccount-btn-desktop svg g path,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-logged-hover:focus-within .tv-myaccount-btn-desktop svg circle,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover:hover .tv-myaccount-btn-desktop svg g path,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover:hover .tv-myaccount-btn-desktop svg circle,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover:focus-within .tv-myaccount-btn-desktop svg g path,
    #tvcmsdesktop-account-button .tv-account-wrapper.si-account-guest-hover:focus-within .tv-myaccount-btn-desktop svg circle {
        fill: none !important;
        stroke: var(--si-accent, #39b54a) !important;
    }

    /* Never show portaled desktop account preview (legacy JS path) */
    body > .tv-account-dropdown.si-account-preview-dropdown {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    /* Hide unmanaged account dropdowns when not hovered (mobile header etc.) */
    body:not(.si-account-open) .tv-account-dropdown:not(.si-account-preview-dropdown),
    body:not(.si-account-open) .tv-account-wrapper:not(.si-account-logged-hover):not(.si-account-guest-hover) .tv-account-dropdown {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    /* Legacy body-class gate (click-pinned / JS fallback) */
    body.si-account-hover-preview:not(.si-account-open) .tv-account-dropdown.si-account-panel.open,
    body.si-account-hover-preview:not(.si-account-open) > .tv-account-dropdown.si-account-panel.open {
        display: flex !important;
        visibility: visible !important;
        pointer-events: auto !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12) !important;
    }

    body.si-account-hover-preview:not(.si-account-open) .si-account-panel__close,
    body.si-account-hover-preview:not(.si-account-open) .si-account-panel__header {
        display: none !important;
    }

    body.si-account-hover-preview:not(.si-account-open) .tv-account-dropdown.si-account-preview-dropdown.si-account-panel.open,
    body.si-account-hover-preview:not(.si-account-open) > .tv-account-dropdown.si-account-preview-dropdown.si-account-panel.open {
        min-width: 200px !important;
        max-width: 240px !important;
        max-height: none !important;
        border-radius: 12px !important;
        overflow: visible !important;
    }

    body.si-account-hover-preview:not(.si-account-open) .tv-account-dropdown.si-account-preview-dropdown.si-account-panel a,
    body.si-account-hover-preview:not(.si-account-open) .tv-account-dropdown.si-account-preview-dropdown.si-account-panel .tvhedaer-sign-btn {
        pointer-events: auto !important;
        cursor: pointer !important;
    }

    /* ThemeVolty hover adds body.dropdown-open — hide legacy backdrop on account hover */
    body.dropdown-open:not(.si-account-open):not(.si-cart-open):not(.classicCartOpen):not(.search-open):not(.si-search-open) .tv-main-div .half-wrapper-backdrop,
    body.dropdown-open:not(.si-account-open):not(.si-cart-open):not(.classicCartOpen) .full-wrapper-backdrop,
    body.si-account-hover-preview:not(.si-account-open) .tv-main-div .half-wrapper-backdrop,
    body.si-account-hover-preview:not(.si-account-open) .full-wrapper-backdrop,
    body.si-account-hover-preview:not(.si-account-open) .si-page-backdrop,
    body.si-account-hover-preview:not(.si-account-open) .si-cart-backdrop {
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    body.si-account-hover-preview:not(.si-account-open) {
        overflow: auto !important;
    }

    .tv-account-dropdown.si-account-panel:not(.si-account-preview-dropdown) {
        border-radius: 0 0 12px 12px !important;
    }
}
