/* --- STILI BASE HEADER --- */
header {
  display: flex;
  flex-direction: column; 
  margin: 2rem auto 0 auto;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: calc(100% - 2rem);
  max-width: 1140px; 
  z-index: 100;
  
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);

  overflow: hidden; 
  border-radius: 44px; 
  max-height: 88px; 
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); 
}

/* Rimuove ogni decorazione dal link del logo e mantiene l'allineamento */
.personal-logo-link {
    text-decoration: none;
    display: flex;
    align-items: center;
}

@media (min-width: 750px) {
  header { width: calc(100% - 4rem); }
}

/* STATO APERTO (MOBILE) */
header.is-open {
  max-height: calc(100dvh - 3rem); 
  border-radius: 24px; 
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0.5rem 1.5rem 0.5rem 0.5rem; 
}

.personal-logo {
  width: 72px;
  height: 72px;
  border-radius: 999px;
  object-fit: fill;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem; /* Spazio base tra elementi */
}

/* --- MENU NAVIGATION (MOBILE) --- */
.header-nav {
  width: 100%;
  padding: 2.5rem 3rem 3rem 0; 
  opacity: 0; 
  pointer-events: none; 
  transform: translateY(-10px); 
  transition: all 0.3s ease;
  overflow-y: auto; 
  flex-grow: 1;     
}

header.is-open .header-nav {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.header-nav ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  align-items: end;
  gap: 1.25rem; 
}

/* --- STILE LINK E FIX ANTI-TREMOLIO --- */
.header-nav a, .header-home-link-desktop {
  text-decoration: none;
  color: #212121;
  font: var(--body-l-font); 
  display: block;
  padding: 0.5rem 0.5rem; 
  transition: all 0.2s ease;
}

/* Hover con -webkit-text-stroke per evitare che il grassetto sposti gli altri link */
.header-nav a:not(.button-default-m):hover, 
.header-home-link-desktop:hover {
  -webkit-text-stroke: 0.6px #212121;
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* --- HAMBURGER ICON ANIMATION --- */
.menu-button {
  display: flex;
  justify-content: center;
  align-items: center;
  background: transparent;
  border: none;
  cursor: pointer;
  width: 48px; 
  height: 48px;
  position: relative;
}

.menu-icon {
  position: absolute;
  width: 32px; 
  height: 32px;
  color: #212121;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.icon-close { opacity: 0; transform: rotate(-90deg) scale(0.5); }
header.is-open .icon-hamburger { opacity: 0; transform: rotate(90deg) scale(0.5); }
header.is-open .icon-close { opacity: 1; transform: rotate(0deg) scale(1); }

/* --- LOGICA DESKTOP (SOPRA 1080PX) --- */
.header-cta-desktop { display: none; }
.header-home-link-desktop { display: none; }

@media (min-width: 1080px) {
  .menu-button { display: none !important; }

  /* Il bottone Scrivimi è identico in entrambe le pagine */
  .header-cta-desktop {
    display: inline-flex !important;
    border-radius: 999px !important;
  }

  /* Distanza tra Home e Scrivimi nel CV */
  .header-actions { gap: 2.5rem; }

  .header-home-link-desktop {
    display: inline-block !important;
  }

  /* Navigazione orizzontale a destra nella INDEX */
  header.header-index .header-nav {
    display: block !important; 
    opacity: 1 !important;
    pointer-events: auto !important;
    padding: 0 !important;
    position: absolute;
    top: 44px; /* Metà esatta di 88px per allineamento perfetto */
    right: 10.5rem; /* Posizionato a sinistra del bottone */
    transform: translateY(-50%) !important;
    width: auto;
  }

  header.header-index .header-nav ul {
    flex-direction: row;
    gap: 2.5rem; 
  }

  /* Nasconde il link "Contatti" testuale nella index (perché c'è già il bottone Scrivimi) */
  header.header-index .mobile-link { display: none !important; }

  header, header.is-open { max-height: 88px !important; }
}