/* =========================================================
   CHIAVE DEL MARE — HEADER V2
   Desktop, tablet e mobile
   ========================================================= */

:root {
    --cdm-header-height: 124px;
    --cdm-header-height-scrolled: 88px;
    --cdm-header-inline: clamp(28px, 4.2vw, 72px);
    --cdm-header-bg: rgba(3, 24, 45, 0.90);
    --cdm-header-border: rgba(255, 255, 255, 0.13);
    --cdm-header-accent: #00d4ff;
}

.cdm-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    background: transparent;
    border-bottom: 1px solid transparent;
    transition:
        min-height 0.3s ease,
        background-color 0.3s ease,
        border-color 0.3s ease,
        box-shadow 0.3s ease,
        backdrop-filter 0.3s ease;
}

.admin-bar .cdm-header {
    top: 32px;
}

.cdm-header.is-scrolled {
    position: fixed;
    background: var(--cdm-header-bg);
    border-bottom-color: var(--cdm-header-border);
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.18);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
}

.cdm-header-inner {
    width: 100%;
    max-width: 1600px;
    min-height: var(--cdm-header-height);
    margin: 0 auto;
    padding: 12px var(--cdm-header-inline);
    display: grid;
    grid-template-columns: minmax(210px, 270px) minmax(0, 1fr) auto;
    align-items: center;
    column-gap: clamp(24px, 3vw, 54px);
    transition: min-height 0.3s ease, padding 0.3s ease;
}

.cdm-header.is-scrolled .cdm-header-inner {
    min-height: var(--cdm-header-height-scrolled);
    padding-top: 7px;
    padding-bottom: 7px;
}

/* =========================================================
   LOGO
   ========================================================= */

.cdm-logo-wrap {
    grid-column: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin: 0;
    padding: 0;
    line-height: 0;
}

.cdm-logo-wrap .custom-logo-link {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    margin: 0;
    padding: 0;
    line-height: 0;
}

.cdm-logo-wrap .custom-logo {
    display: block;
    width: clamp(210px, 17vw, 268px);
    max-width: 100%;
    height: auto;
    max-height: 102px;
    object-fit: contain;
    object-position: left center;
    transition: width 0.3s ease, max-height 0.3s ease, transform 0.3s ease;
}

.cdm-header.is-scrolled .cdm-logo-wrap .custom-logo {
    width: clamp(180px, 14vw, 224px);
    max-height: 72px;
}

.cdm-site-name {
    color: #fff;
    font-family: var(--cdm-font-heading, "Poppins", Arial, sans-serif);
    font-size: 26px;
    font-weight: 700;
    line-height: 1.1;
    text-decoration: none;
}

/* =========================================================
   MENU DESKTOP
   ========================================================= */

.cdm-nav {
    grid-column: 2;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
}

.cdm-menu {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap;
    gap: clamp(18px, 1.7vw, 34px);
    margin: 0;
    padding: 0;
    list-style: none;
}

.cdm-menu > li {
    display: flex;
    align-items: center;
    margin: 0;
    padding: 0;
    white-space: nowrap;
}

.cdm-menu a {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    padding: 4px 0;
    color: #fff;
    font-family: var(--cdm-font-heading, "Poppins", Arial, sans-serif);
    font-size: clamp(12px, 0.82vw, 15px);
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.045em;
    text-decoration: none;
    text-transform: uppercase;
    transition: color 0.22s ease, opacity 0.22s ease;
}

.cdm-menu a::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 1px;
    width: 0;
    height: 2px;
    background: var(--cdm-header-accent);
    border-radius: 999px;
    transform: translateX(-50%);
    transition: width 0.24s ease;
}

.cdm-menu a:hover,
.cdm-menu a:focus-visible,
.cdm-menu .current-menu-item > a,
.cdm-menu .current_page_item > a {
    color: #fff;
}

.cdm-menu a:hover::after,
.cdm-menu a:focus-visible::after,
.cdm-menu .current-menu-item > a::after,
.cdm-menu .current_page_item > a::after {
    width: 100%;
}

/* =========================================================
   SELETTORE LINGUA
   ========================================================= */

.cdm-language-switcher {
    grid-column: 3;
    position: relative;
    z-index: 1100;
    flex: 0 0 auto;
    margin-left: clamp(20px, 2.3vw, 42px);
}

.cdm-language-toggle {
    appearance: none;
    -webkit-appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 92px;
    min-height: 44px;
    margin: 0;
    padding: 8px 14px;
    color: #fff;
    background: rgba(255, 255, 255, 0.11) !important;
    border: 1px solid rgba(255, 255, 255, 0.38) !important;
    border-radius: 999px;
    box-shadow: none !important;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.cdm-language-toggle:hover,
.cdm-language-toggle:focus,
.cdm-language-toggle:focus-visible,
.cdm-language-toggle:active {
    color: #fff;
    background: rgba(255, 255, 255, 0.19) !important;
    border-color: rgba(255, 255, 255, 0.7) !important;
    box-shadow: none !important;
    outline: none;
}

.cdm-language-toggle:focus-visible {
    outline: 2px solid rgba(0, 212, 255, 0.8);
    outline-offset: 3px;
}

.cdm-language-flag {
    font-size: 21px;
    line-height: 1;
}

.cdm-language-code {
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.08em;
}

.cdm-language-arrow {
    font-size: 11px;
    line-height: 1;
    transition: transform 0.2s ease;
}

.cdm-language-switcher.is-open .cdm-language-arrow {
    transform: rotate(180deg);
}

.cdm-language-menu {
    position: absolute;
    top: calc(100% + 11px);
    right: 0;
    width: 178px;
    padding: 7px;
    background: rgba(4, 25, 48, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 14px;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-7px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

.cdm-language-switcher.is-open .cdm-language-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.cdm-language-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 11px;
    color: #fff;
    text-decoration: none;
    border-radius: 9px;
    font-size: 14px;
    line-height: 1.25;
    transition: background-color 0.18s ease;
}

.cdm-language-option:hover,
.cdm-language-option:focus,
.cdm-language-option.is-current {
    color: #fff;
    background: rgba(0, 212, 255, 0.18);
}

/* =========================================================
   BURGER
   ========================================================= */

.cdm-burger {
    display: none;
}

/* =========================================================
   LAPTOP / TABLET ORIZZONTALE
   ========================================================= */

@media (min-width: 1025px) and (max-width: 1280px) {
    .cdm-header-inner {
        grid-template-columns: minmax(178px, 220px) minmax(0, 1fr) auto;
        column-gap: 18px;
        padding-right: 28px;
        padding-left: 28px;
    }

    .cdm-logo-wrap .custom-logo {
        width: clamp(180px, 16vw, 220px);
    }

    .cdm-menu {
        gap: clamp(13px, 1.25vw, 21px);
    }

    .cdm-menu a {
        font-size: 12px;
        letter-spacing: 0.025em;
    }

    .cdm-language-switcher {
        margin-left: 18px;
    }

    .cdm-language-toggle {
        min-width: 82px;
        padding-right: 11px;
        padding-left: 11px;
    }
}

/* =========================================================
   TABLET E MOBILE
   ========================================================= */

@media (max-width: 1024px) {
    :root {
        --cdm-header-height: 106px;
        --cdm-header-height-scrolled: 82px;
    }

    .cdm-header-inner {
        min-height: var(--cdm-header-height);
        padding: 10px clamp(18px, 4vw, 34px);
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto auto;
        align-items: center;
        column-gap: 12px;
    }

    .cdm-header.is-scrolled .cdm-header-inner {
        min-height: var(--cdm-header-height-scrolled);
    }

    .cdm-logo-wrap {
        grid-column: 1;
        min-width: 0;
        height: auto;
    }

    .cdm-logo-wrap .custom-logo-link {
        max-width: 100%;
    }

    .cdm-logo-wrap .custom-logo {
        width: clamp(150px, 27vw, 210px) !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: 82px !important;
    }

    .cdm-header.is-scrolled .cdm-logo-wrap .custom-logo {
        width: clamp(138px, 24vw, 184px) !important;
        max-height: 66px !important;
    }

    .cdm-language-switcher {
        grid-column: 2;
        margin: 0;
    }

    .cdm-language-toggle {
        min-width: 44px;
        min-height: 42px;
        padding: 7px 10px;
    }

    .cdm-language-code,
    .cdm-language-arrow {
        display: none;
    }

    .cdm-language-menu {
        position: fixed;
        top: 92px;
        right: 66px;
        width: 180px;
    }

    .cdm-header.is-scrolled .cdm-language-menu {
        top: 74px;
    }

    .cdm-nav {
        position: fixed;
        inset: 0;
        z-index: 999;
        grid-column: auto;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0;
        padding: 112px 24px 44px;
        background: rgba(2, 24, 43, 0.985);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transform: translateY(-8px);
        transition: opacity 0.28s ease, visibility 0.28s ease, transform 0.28s ease;
    }

    .cdm-nav.is-open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transform: translateY(0);
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    .cdm-menu {
        width: min(100%, 420px);
        flex-direction: column;
        align-items: stretch;
        gap: 5px;
        text-align: center;
    }

    .cdm-menu > li {
        width: 100%;
        justify-content: center;
    }

    .cdm-menu a {
        width: 100%;
        min-height: 54px;
        justify-content: center;
        padding: 12px 8px;
        font-size: clamp(18px, 4.8vw, 24px);
        letter-spacing: 0.045em;
    }

    .cdm-menu a::after {
        bottom: 4px;
        max-width: 150px;
    }

    .cdm-burger,
    .cdm-burger:hover,
    .cdm-burger:focus,
    .cdm-burger:focus-visible,
    .cdm-burger:active,
    .cdm-burger.is-open {
        appearance: none;
        -webkit-appearance: none;
        position: relative;
        z-index: 1001;
        grid-column: 3;
        flex: 0 0 40px;
        width: 40px;
        height: 30px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-items: stretch;
        margin: 0;
        padding: 3px 0;
        color: #fff;
        background: transparent !important;
        background-color: transparent !important;
        background-image: none !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        outline: none;
        cursor: pointer;
    }

    .cdm-burger:focus-visible {
        outline: 2px solid rgba(0, 212, 255, 0.8) !important;
        outline-offset: 6px;
    }

    .cdm-burger span,
    .cdm-burger:hover span,
    .cdm-burger:focus span,
    .cdm-burger:active span {
        display: block;
        width: 100%;
        height: 3px;
        margin: 0;
        background: #fff;
        border-radius: 999px;
        transform-origin: center;
        transition: transform 0.28s ease, opacity 0.2s ease;
    }

    .cdm-burger.is-open span:nth-child(1) {
        transform: translateY(10.5px) rotate(45deg);
    }

    .cdm-burger.is-open span:nth-child(2) {
        opacity: 0;
    }

    .cdm-burger.is-open span:nth-child(3) {
        transform: translateY(-10.5px) rotate(-45deg);
    }

    html.cdm-menu-open,
    body.cdm-menu-open {
        overflow: hidden !important;
        overscroll-behavior: none;
    }

    body.cdm-menu-open {
        position: fixed;
        left: 0;
        width: 100%;
    }
}

@media (max-width: 782px) {
    .admin-bar .cdm-header {
        top: 46px;
    }
}

@media (max-width: 520px) {
    :root {
        --cdm-header-height: 100px;
        --cdm-header-height-scrolled: 78px;
    }

    .cdm-header-inner {
        padding-right: 18px;
        padding-left: 18px;
        column-gap: 10px;
    }

    .cdm-logo-wrap .custom-logo {
        width: clamp(142px, 43vw, 174px) !important;
        max-height: 76px !important;
    }

    .cdm-header.is-scrolled .cdm-logo-wrap .custom-logo {
        width: clamp(130px, 39vw, 158px) !important;
        max-height: 62px !important;
    }

    .cdm-language-toggle {
        min-width: 40px;
        min-height: 40px;
        padding: 6px 8px;
    }

    .cdm-language-flag {
        font-size: 20px;
    }

    .cdm-language-menu {
        top: 86px;
        right: 62px;
    }

    .cdm-header.is-scrolled .cdm-language-menu {
        top: 70px;
    }

    .cdm-burger,
    .cdm-burger:hover,
    .cdm-burger:focus,
    .cdm-burger:focus-visible,
    .cdm-burger:active,
    .cdm-burger.is-open {
        width: 36px;
        height: 28px;
    }

    .cdm-burger.is-open span:nth-child(1) {
        transform: translateY(9.5px) rotate(45deg);
    }

    .cdm-burger.is-open span:nth-child(3) {
        transform: translateY(-9.5px) rotate(-45deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .cdm-header,
    .cdm-header-inner,
    .cdm-logo-wrap .custom-logo,
    .cdm-nav,
    .cdm-language-menu,
    .cdm-burger span {
        transition: none !important;
    }
}

/* =========================================================
   SOCIAL HEADER — Instagram + Facebook
   Desktop: tra menu e lingua. Mobile/tablet: centro esatto viewport.
   ========================================================= */
.cdm-header-social {
    grid-column: 3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    justify-self: end;
    z-index: 1101;
}

.cdm-social-link {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 38px;
    border: 1px solid rgba(255,255,255,.32);
    border-radius: 50%;
    background: rgba(255,255,255,.08);
    text-decoration: none;
    transition: transform .2s ease, background-color .2s ease, border-color .2s ease;
}

.cdm-social-link:hover,
.cdm-social-link:focus-visible {
    transform: translateY(-2px);
    background: rgba(255,255,255,.16);
    border-color: rgba(255,255,255,.65);
    outline: none;
}

.cdm-social-link img {
    display: block;
    width: 22px;
    height: 22px;
    object-fit: contain;
}

/* Desktop: aggiunge una colonna dedicata senza alterare il menu centrale. */
@media (min-width: 1025px) {
    .cdm-header-inner {
        grid-template-columns: minmax(210px,270px) minmax(0,1fr) auto auto;
        column-gap: clamp(18px,2vw,34px);
    }
    .cdm-language-switcher {
        grid-column: 4;
        margin-left: 0;
    }
}

@media (min-width: 1025px) and (max-width: 1280px) {
    .cdm-header-inner {
        grid-template-columns: minmax(178px,220px) minmax(0,1fr) auto auto;
        column-gap: 14px;
    }
    .cdm-header-social { gap: 7px; }
    .cdm-social-link { width: 34px; height: 34px; flex-basis: 34px; }
    .cdm-social-link img { width: 19px; height: 19px; }
}

/* Tablet/mobile: il gruppo non occupa colonne della griglia e resta centrato sullo schermo. */
@media (max-width: 1024px) {
    .cdm-header-inner { position: relative; }
    .cdm-header-social {
        position: absolute;
        left: 50%;
        top: 12px;
        transform: translateX(-50%);
        grid-column: auto;
        justify-self: auto;
        gap: 8px;
    }
    .cdm-social-link {
        width: 32px;
        height: 32px;
        flex-basis: 32px;
        background: rgba(3,24,45,.34);
    }
    .cdm-social-link img { width: 18px; height: 18px; }
}

/* Telefoni stretti: riserva una piccola fascia superiore alle icone per evitare sovrapposizioni. */
@media (max-width: 520px) {
    :root {
        --cdm-header-height: 112px;
        --cdm-header-height-scrolled: 88px;
    }
    .cdm-header-inner {
        padding-top: 25px;
    }
    .cdm-header.is-scrolled .cdm-header-inner {
        padding-top: 20px;
    }
    .cdm-header-social { top: 6px; gap: 7px; }
    .cdm-social-link { width: 28px; height: 28px; flex-basis: 28px; }
    .cdm-social-link img { width: 16px; height: 16px; }
}

/* =========================================================
   FIX MOBILE SOCIAL + LOGO — 2026-09-18
   Tutti gli elementi sulla stessa linea; social centrati nel viewport.
   Desktop invariato.
   ========================================================= */
@media (max-width: 1024px) {
    .cdm-header-inner {
        position: relative;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .cdm-header-social {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        margin: 0;
        gap: 8px;
    }

    .cdm-logo-wrap {
        overflow: visible;
    }

    .cdm-logo-wrap .custom-logo-link {
        overflow: visible;
    }

    .cdm-logo-wrap .custom-logo {
        width: clamp(190px, 31vw, 245px) !important;
        max-width: none !important;
        max-height: 96px !important;
        object-fit: contain;
        object-position: left center;
    }

    .cdm-header.is-scrolled .cdm-logo-wrap .custom-logo {
        width: clamp(168px, 27vw, 210px) !important;
        max-height: 76px !important;
    }
}

@media (max-width: 520px) {
    :root {
        --cdm-header-height: 106px;
        --cdm-header-height-scrolled: 82px;
    }

    .cdm-header-inner,
    .cdm-header.is-scrolled .cdm-header-inner {
        padding-top: 7px;
        padding-bottom: 7px;
    }

    .cdm-header-social {
        top: 50%;
        transform: translate(-50%, -50%);
        gap: 7px;
    }

    .cdm-social-link {
        width: 30px;
        height: 30px;
        flex-basis: 30px;
    }

    .cdm-social-link img {
        width: 17px;
        height: 17px;
    }

    .cdm-logo-wrap .custom-logo {
        width: clamp(172px, 44vw, 205px) !important;
        max-height: 90px !important;
    }

    .cdm-header.is-scrolled .cdm-logo-wrap .custom-logo {
        width: clamp(150px, 39vw, 180px) !important;
        max-height: 70px !important;
    }
}
