/* Header sempre fisso in cima (tranne nella splash). Evita tearing iOS: no auto-hide su scroll. */
.menu-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    /* Blocco solido 100% opacità, si estende in safe-area (Dynamic Island / notch) */
    background-color: var(--header-bg);
    opacity: 1;
    border-bottom: 1px solid color-mix(in srgb, var(--header-text) 15%, transparent);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transition: box-shadow 0.4s ease, background-color 0.3s ease;
    color: var(--header-text);
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
    padding-right: calc(1.1rem + env(safe-area-inset-right, 0px));
    padding-bottom: 0.85rem;
    padding-left: calc(1.1rem + env(safe-area-inset-left, 0px));
    text-align: left;
    box-shadow: 0 2px 0 var(--header-bg), 0 4px 15px rgba(0,0,0,0.08);
    z-index: 9999;
    overflow: visible;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    /* Layer GPU fisso: previene glitch/tearing su iOS */
    transform: translateZ(0);
    pointer-events: auto;
}

/* Solo nella splash: header nascosto */
.menu-header.header-in-splash {
    transform: translateY(-100%) translateZ(0);
    opacity: 0;
    pointer-events: none;
}

/* Animazione slide-down: stato iniziale esplicito evita scattino su iOS */
.menu-header.header-appearing {
    transform: translateY(-100%) translateZ(0);
    opacity: 0;
    animation: header-slide-in 1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    -webkit-transform: translateY(-100%) translateZ(0);
}
@keyframes header-slide-in {
    to {
        transform: translateY(0) translateZ(0);
        opacity: 1;
    }
}

/* Estende lo sfondo sopra l'header per coprire eventuali gap sub-pixel con la notch */
.menu-header::before {
    content: "";
    position: absolute;
    top: -2px;
    left: 0;
    right: 0;
    height: calc(2px + env(safe-area-inset-top, 0px));
    background-color: inherit;
    z-index: -1;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.header-main {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.menu-header h1 {
    margin: 0;
    font-size: 1.5rem;
    letter-spacing: -0.03em;
    font-weight: 800;
    transition: font-size 0.4s ease;
    will-change: font-size;
}

.header-menu-subtitle {
    margin-top: 5px;
    font-size: 1.1rem;
    font-weight: 300;
    opacity: 0.8;
    max-height: 50px;
    overflow: hidden;
    transition: opacity 0.3s ease, max-height 0.3s ease, margin 0.3s ease;
}

.logo-wrapper {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}

#header-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Logo non quadrato: fondo bianco e respiro dentro il cerchio dell'header, che
   resta tondo. È la pagina del locale, quindi il marchio si mostra sempre —
   niente monogramma qui, a differenza di pin e righe della lista. */
.logo-wrapper[data-logo-fit="blur"] {
    position: relative;
    /* overflow: hidden è già sul .logo-wrapper */
    background: var(--logo-bg, transparent);
}

.logo-wrapper[data-logo-fit="blur"]::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: var(--logo-src);
    background-size: cover;
    background-position: center;
    filter: blur(7px) saturate(1.15);
    transform: scale(1.15);
    z-index: 0;
    pointer-events: none;
}

.logo-wrapper[data-logo-fit="blur"] #header-logo {
    position: relative;
    z-index: 1;
    box-sizing: border-box;
    padding: 6%;
}

/* Nessun logo caricato: iniziali invece di un cerchio vuoto. */
.logo-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--accent-color) 18%, var(--card-bg));
    color: var(--accent-color);
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1rem;
}

.menu-header.shrunk .logo-fallback {
    font-size: 0.85rem;
}

.menu-header.shrunk {
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.menu-header.shrunk .logo-wrapper {
    width: 40px;
    height: 40px;
}

.header-title-block {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}

/* Nello sticky mostriamo solo logo + nome locale; sottotitolo menu nascosto per layout pulito */
.menu-header .header-menu-subtitle {
    display: none;
}

.header-categories--hidden,
.header-categories[aria-hidden="true"] {
    display: none !important;
}

.header-categories {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding: 0 0.25rem 0.25rem 0.25rem;
    margin: 0;
    list-style: none;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
    min-width: 0;
    width: 100%;
    white-space: nowrap;
    /* Evita conflitti scroll su iOS/Android */
    -webkit-touch-callout: none;
    isolation: isolate;
}

.header-categories::-webkit-scrollbar {
    display: none;
}

/* Mobile < 768px: categorie mai a capo */
@media (max-width: 767px) {
    .header-categories {
        flex-wrap: nowrap;
        white-space: nowrap;
    }
    .header-category-pill {
        flex-shrink: 0;
        white-space: nowrap;
    }
}

.header-category-pill {
    flex: 0 0 auto;
    padding: 7px 14px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--header-text) 20%, transparent);
    background: color-mix(in srgb, var(--header-text) 8%, rgba(0,0,0,0.12));
    color: var(--header-text);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /* Migliora scroll touch: evita selezione testo durante drag */
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.header-category-pill:active {
    transform: scale(0.97);
}

/* Categoria attiva (scrollspy): pill invertito rispetto all'header. Usa il
   colore del testo dell'header come sfondo e viceversa: è una coppia già
   contrastante per design, quindi resta leggibile su qualsiasi tema (anche
   quando l'accent è simile allo sfondo dell'header). */
.header-category-pill.is-active {
    background: var(--header-text);
    color: var(--header-bg);
    font-weight: 700;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.28);
}

@media (hover: hover) {
    .header-category-pill:hover {
        background: color-mix(in srgb, var(--accent-color) 45%, rgba(0,0,0,0.2));
        box-shadow: 0 2px 12px rgba(0,0,0,0.12);
    }
}

/* Desktop: header più grande */
@media (min-width: 900px) {
    .menu-header {
        padding: calc(1.15rem + env(safe-area-inset-top, 0px)) calc(1.6rem + env(safe-area-inset-right, 0px)) 1rem calc(1.6rem + env(safe-area-inset-left, 0px));
        gap: 0.85rem;
    }

    .header-content,
    .header-main {
        gap: 1rem;
    }

    .menu-header h1 {
        font-size: 1.85rem;
    }

    .header-menu-subtitle {
        font-size: 1.2rem;
        margin-top: 6px;
    }

    .logo-wrapper {
        width: 56px;
        height: 56px;
    }

    .menu-header.shrunk .logo-wrapper {
        width: 46px;
        height: 46px;
    }

    .header-categories {
        gap: 0.75rem;
        padding: 0 0.4rem 0.4rem 0.4rem;
    }

    .header-category-pill {
        padding: 9px 18px;
        font-size: 0.92rem;
    }

    /* Quando le pill sono nascoste (< 2 categorie): più padding sull'header per ridurre lo spazio vuoto */
    .menu-header:has(.header-categories--hidden) {
        padding-bottom: 1.35rem !important;
    }

}