/* drawer-menu.css */

/* Variabili */
:root{
  --drawer-breakpoint: 800;
  --drawer-width: clamp(320px, 78vw, 420px);
  --drawer-z: 99999;
}

/* Default: drawer/overlay nascosti (visivamente fuori schermo) */
.mobile-drawer,
.drawer-overlay { display: none; }

@media (max-width: 800px) {

  /* Nasconde nav desktop */
  #site-navigation { display: none !important; }

  /* Hamburger fisso */
  .menu-toggle {
    display:inline-flex !important;
    position: fixed !important;
    right: 18px !important;
    top: 12px !important;
    width: 48px; height: 48px;
    align-items:center; justify-content:center;
    z-index: calc(var(--drawer-z) + 300) !important;
    background: transparent; border: none; cursor: pointer;
  }
  .menu-toggle .menu-label { display: none; }

  /* Fallback */
  .menu-toggle .menu-icon {
    display: inline-block !important;
    position: relative !important;
    width: 22px !important;
    height: 18px !important;
    background: transparent !important;
    box-sizing: border-box !important;
  }
  /* pseudo lines */
  .menu-toggle .menu-icon::before,
  .menu-toggle .menu-icon::after {
    content: "";
    position: absolute;
    left: 0; right: 0;
    height: 2px;
    background-color: var(--color-primary, #0b5fff);
    border-radius: 2px;
  }
  .menu-toggle .menu-icon::before { top: 0; }
  .menu-toggle .menu-icon::after { bottom: 0; }
  /* middle line fallback */
  .menu-toggle .menu-icon .mi-line {
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    height: 2px !important;
    background-color: var(--color-primary, #0b5fff) !important;
    border-radius: 2px !important;
    display: block !important;
  }
  .menu-toggle .menu-icon .mi-line:nth-child(1) { top: 0; }
  .menu-toggle .menu-icon .mi-line:nth-child(2) { top: 8px; }
  .menu-toggle .menu-icon .mi-line:nth-child(3) { top: 16px; }

  /* When header is at top (transparent), make hamburger white for contrast */
  .site-header.at-top .menu-toggle .menu-icon::before,
  .site-header.at-top .menu-toggle .menu-icon::after,
  .site-header.at-top .menu-toggle .menu-icon .mi-line,
  .header.at-top .menu-toggle .menu-icon::before,
  .header.at-top .menu-toggle .menu-icon::after,
  .header.at-top .menu-toggle .menu-icon .mi-line {
    background-color: #ffffff !important;
  }

  /* Overlay: gradient dark -> transparent */
  .drawer-overlay {
    display:block;
    position: fixed;
    inset: 0;
    background: linear-gradient(180deg, rgba(0,0,0,0.45) 0%, rgba(0,0,0,0.28) 30%, rgba(0,0,0,0.08) 60%, rgba(0,0,0,0.02) 100%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
    z-index: calc(var(--drawer-z) + 50);
  }
  body.drawer-open .drawer-overlay { opacity:1; pointer-events:auto; }
  body.drawer-closing .drawer-overlay { opacity:0; pointer-events:none; }

  /* DRAWER */
  .mobile-drawer {
    display:block;
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: var(--drawer-width);
    background: linear-gradient(180deg, rgba(255,255,255,0.98) 0%, rgba(255,255,255,0.95) 30%, rgba(255,255,255,0.88) 60%, rgba(255,255,255,0.80) 100%);
    box-shadow: 0 28px 80px rgba(2,10,30,0.12);
    transform: translateX(110%);                    
    opacity: 0;
    transition: transform 320ms cubic-bezier(.2,.9,.18,1), opacity 240ms ease;
    z-index: calc(var(--drawer-z) + 200);
    padding: 18px;
    box-sizing: border-box;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    border-left: 1px solid rgba(2,10,30,0.03);
    pointer-events: none;
  }
  /* open */
  body.drawer-open .mobile-drawer {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }
  /* closing */
  body.drawer-closing .mobile-drawer {
    transform: translateX(110%);
    opacity: 0;
    pointer-events: none;
  }

  /* close button */
  .mobile-drawer-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: auto;
    height: auto;
    padding: 6px 8px;
    border: none;
    background: transparent;
    box-shadow: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: calc(var(--drawer-z) + 210);
  }
  /* hide inner svg if present; use text X (bolder) */
  .mobile-drawer-close svg { display: none !important; }
  .mobile-drawer-close .close-x {
    font-size: 22px;
    line-height: 1;
    color: var(--color-primary, #0b5fff);
    font-weight: 700;
    display: inline-block;
    transform-origin: center center;
  }
  .mobile-drawer-close:focus { outline: 2px solid rgba(11,95,255,0.18); outline-offset: 3px; }

  /* Drawer inner wrapper */
  .mobile-drawer-inner { padding-top: 18px; padding-bottom: 48px; }

  /* Menu vertical */
  .mobile-drawer .menu, .mobile-drawer .menu ul { list-style:none; margin:0; padding:0; }
  .mobile-drawer .menu li { display:block; }
  .mobile-drawer .menu li > .row {
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap: 12px;
  }

  .mobile-drawer .menu li > .row > a {
    display:block;
    flex: 1 1 auto;
    padding: 14px 10px;
    color: #0f172a;
    text-decoration:none;
    font-size:1rem;
    box-sizing:border-box;
  }

  .mobile-drawer .row > .submenu-toggle {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 6px;
    box-sizing: border-box;
  }
  .mobile-drawer .row > .submenu-toggle .drawer-caret {
    display:inline-block;
    width: 10px; height:10px;
    border: solid currentColor;
    border-width: 0 1.4px 1.4px 0;
    padding: 5px;
    transform: rotate(45deg);
    transition: transform .15s ease;
    color: #566374;
  }
  .mobile-drawer li.open > .row > .submenu-toggle .drawer-caret {
    transform: rotate(-135deg);
  }

  .mobile-drawer .sub-menu {
    display:none;
    padding-left: 18px;
    margin-bottom: 8px;
  }
  .mobile-drawer li.open > .sub-menu { display:block; }

  .mobile-drawer .drawer-cta {
    display:block;
    margin: 18px 0;
    padding: 12px;
    background: var(--color-primary, #2050f2);
    color: #fff !important;
    border-radius: 10px;
    text-align:center;
    font-weight:700;
    box-shadow: 0 8px 20px rgba(11,95,255,0.12);
    text-decoration:none;
  }

  .mobile-drawer a::after,
  .mobile-drawer a::before,
  .mobile-drawer .menu > li > a::after,
  .mobile-drawer .menu > li > a::before {
    content: none !important;
    display: none !important;
    visibility: hidden !important;
  }
  .mobile-drawer a > .caret,
  .mobile-drawer a i[class*="caret"],
  .mobile-drawer a svg[class*="caret"],
  .mobile-drawer a span[class*="caret"] {
    display: none !important;
  }

  .mobile-drawer a:focus, .mobile-drawer button:focus { outline: 3px solid rgba(11,95,255,0.14); outline-offset: 2px; }

  .mobile-drawer .row > .submenu-toggle { z-index: 9999 !important; }
}

/* ensure hamburger visible on top */
@media (max-width: 800px) {
  .menu-toggle { z-index: 300000 !important; }
}

/* ===== Override: hamburger 3 linee robusto + X "cicciotta" + shift X left ===== */

/* Forza comportamento del .menu-icon: usa background per le 3 linee quando chiuso */
.menu-toggle .menu-icon {
  display: inline-block !important;
  position: relative !important;
  width: 22px !important;
  height: 18px !important;
  background: linear-gradient(
    to bottom,
    var(--color-primary, #0b5fff) 0 2px,
    transparent 2px 6px,
    var(--color-primary, #0b5fff) 6px 8px,
    transparent 8px 12px,
    var(--color-primary, #0b5fff) 12px 14px,
    transparent 14px 100%
  ) no-repeat center center !important;
  background-size: 100% 100% !important;
  opacity: 1 !important;
  visibility: visible !important;
}

/* When header is at top (transparent), make hamburger white for contrast */
.site-header.at-top .menu-toggle .menu-icon,
.header.at-top .menu-toggle .menu-icon {
  background: linear-gradient(
    to bottom,
    #ffffff 0 2px,
    transparent 2px 6px,
    #ffffff 6px 8px,
    transparent 8px 12px,
    #ffffff 12px 14px,
    transparent 14px 100%
  ) no-repeat center center !important;
}

/* Nascondi pseudo-elementi o righe create altrove (evitiamo doppioni) */
.menu-toggle .menu-icon::before,
.menu-toggle .menu-icon::after,
.menu-toggle .menu-icon .mi-line {
  /* lasciamo i .mi-line visibili se presenti, ma rimuoviamo eventuali posizionamenti conflittuali */
  content: none !important;
  display: none !important;
  visibility: hidden !important;
}

/* Quando menu è aperto: rimuoviamo il background a righe e mostriamo la X con ::before/::after */
.menu-toggle[aria-expanded="true"] .menu-icon {
  background: transparent !important;
}

/* X: create con pseudo-elementi, centrati verticalmente */
.menu-toggle[aria-expanded="true"] .menu-icon::before,
.menu-toggle[aria-expanded="true"] .menu-icon::after {
  content: "" !important;
  position: absolute !important;
  left: 0 !important;
  right: 0 !important;
  height: 3px !important;                    /* "cicciotta" - rendi più visibile */
  background-color: var(--color-primary, #0b5fff) !important;
  border-radius: 3px !important;
  top: 50% !important;
  margin-top: -1.5px !important;             /* verticalmente centrata */
  transform-origin: center center !important;
  transition: transform .18s ease, opacity .12s ease;
  opacity: 1 !important;
}

/* When open on top, keep the X white */
.site-header.at-top .menu-toggle[aria-expanded="true"] .menu-icon::before,
.site-header.at-top .menu-toggle[aria-expanded="true"] .menu-icon::after,
.header.at-top .menu-toggle[aria-expanded="true"] .menu-icon::before,
.header.at-top .menu-toggle[aria-expanded="true"] .menu-icon::after {
  background-color: #ffffff !important;
}

/* rotazione per ottenere la X */
.menu-toggle[aria-expanded="true"] .menu-icon::before { transform: rotate(45deg); }
.menu-toggle[aria-expanded="true"] .menu-icon::after  { transform: rotate(-45deg); }

/* Se vuoi una X ancora più "cicciotta", aumenta height a 4px */

/* ===== Adjust close (X) inside drawer: remove box, show single X char, shift slightly left ===== */
.mobile-drawer-close {
  position: absolute !important;
  top: 10px !important;
  right: 18px !important;   /* spostata leggermente verso sinistra (aumentando right) */
  padding: 6px 8px !important;
  background: transparent !important;    /* nessun riquadro */
  border: none !important;
  box-shadow: none !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  z-index: calc(var(--drawer-z) + 210) !important;
}

/* usa il carattere × (times) più grosso e bold, nessun svg/box */
.mobile-drawer-close svg { display: none !important; }
.mobile-drawer-close .close-x {
  font-size: 22px !important;
  line-height: 1 !important;
  color: var(--color-primary, #0b5fff) !important;
  font-weight: 800 !important;
  display: inline-block !important;
  transform-origin: center center !important;
}

/* Focus discreto per accessibilità */
.mobile-drawer-close:focus {
  outline: 2px solid rgba(11,95,255,0.18) !important;
  outline-offset: 3px !important;
}

/* Safety: se nel DOM esistono le .mi-line create da JS, rendile non invasive (non sovrappongano) */
.menu-toggle .mi-line { display: none !important; }

/* Se vuoi che la X ruoti leggermente al focus (opzionale)
.mobile-drawer-close:focus .close-x { transform: rotate(10deg); }
*/
