/* ============================================================
   mesa-header-fix.css — global header improvements (all pages)
   Complements mu-plugins/mesa-fixed-header-offset.php (offset,
   admin-bar, cpel dropdown, flex min-width, overflow-x guard).
   Driven by mesa-header-sensor.js states:
     body.mhs-compact      = scrolled >120px, slim header
     header[data-mhs-mode] = burger | inline
   ============================================================ */

header.elementor-location-header {
    --mhs-hpad: 12px;
    --mhs-logo-h: 80px;
    --mhs-logo-h-compact: 44px;
}

/* ---------- structural normalization ---------- */

/* fixed container: consistent horizontal padding + min-width guard */
header.elementor-location-header .e-con.e-parent {
    padding-left: var(--mhs-hpad) !important;
    padding-right: var(--mhs-hpad) !important;
    box-sizing: border-box !important;
    max-width: 100vw !important;
}

/* children must never force the row wider than the viewport */
header.elementor-location-header .e-con > * {
    min-width: 0 !important;
}

/* logo: cap height, keep aspect */
header.elementor-location-header .elementor-widget-image img,
header.elementor-location-header [class*="site-logo"] img {
    max-height: var(--mhs-logo-h);
    width: auto;
    max-width: 100%;
    transition: max-height .25s ease;
}

/* nav container: right-aligned, wraps cleanly */
header.elementor-location-header .e-con.e-child:has(.elementor-widget-nav-menu) {
    flex: 1 1 auto;
    justify-content: flex-end;
    align-items: center;
}

/* ---------- compact mode (scrolled) ---------- */
body.mhs-compact header.elementor-location-header .e-con.e-parent {
    --padding-top: 3px !important;
    --padding-bottom: 3px !important;
    padding-top: 3px !important;
    padding-bottom: 3px !important;
    box-shadow: 0 2px 10px rgba(0,0,0,.18) !important;
}
body.mhs-compact header.elementor-location-header .elementor-widget-image img,
body.mhs-compact header.elementor-location-header [class*="site-logo"] img {
    max-height: var(--mhs-logo-h-compact);
}

/* ---------- tap targets (WCAG 44px) ---------- */
/* NOTA: il display del burger NON va forzato fuori da media query:
   Elementor mostra l'inline nav su desktop e nasconde il toggle via CSS;
   un display:inline-flex non scopato lo rende visibile (e vuoto) su desktop. */
@media (max-width: 1024px) {
    header.elementor-location-header .elementor-menu-toggle {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}
/* lang switcher (94626c4): real tap target was ~36px @1440, expand */
header.elementor-location-header .elementor-element-94626c4,
header.elementor-location-header .elementor-element-94626c4 .elementor-widget-container {
    flex: 0 0 auto;
    width: auto !important;
    min-width: 0 !important;
}
header.elementor-location-header .cpel-switcher__toggle,
header.elementor-location-header [class*="cpel-switcher"] .cpel-switcher__toggle {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
/* phone/text-editor (2b99dc6): keep number on one line, full width target */
header.elementor-location-header .elementor-element-2b99dc6 {
    flex: 0 0 auto;
    width: auto !important;
    min-width: 0 !important;
    white-space: nowrap;
}
header.elementor-location-header .elementor-element-2b99dc6 a[href^="tel:"],
header.elementor-location-header .elementor-widget-text-editor a[href^="tel:"] {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    white-space: nowrap;
}
/* nav-menu widget (236faf4): keep right-aligned but may shrink */
header.elementor-location-header .elementor-element-236faf4 {
    flex: 0 1 auto;
    min-width: 0 !important;
}

/* ---------- dropdown containment (all widths) ---------- */
header.elementor-location-header [class*="cpel-switcher__list"],
header.elementor-location-header .elementor-nav-menu--dropdown {
    max-width: min(320px, calc(100vw - 16px)) !important;
    box-sizing: border-box;
}
header.elementor-location-header .elementor-nav-menu--dropdown {
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ---------- mobile refinements ---------- */
@media (max-width: 767px) {
    header.elementor-location-header {
        --mhs-hpad: 8px;
    }
    /* logo container may shrink so burger+phone+lang fit the first row */
    header.elementor-location-header .e-con.e-child:has(.elementor-widget-image) {
        flex: 0 1 auto;
    }
    /* phone text stays one line, smaller */
    header.elementor-location-header .elementor-widget-text-editor a[href^="tel:"],
    header.elementor-location-header .elementor-widget-text-editor {
        font-size: 13px;
    }
    /* burger stays visible and reachable */
    header.elementor-location-header .elementor-menu-toggle {
        font-size: 22px;
    }
}
@media (max-width: 430px) {
    /* very small phones: let phone collapse to icon-only width gracefully */
    header.elementor-location-header .elementor-widget-text-editor {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* ---------- sensor report (debug aid, ?mhs=1) ---------- */
#mhs-report { display: none; }
