/* ============================================================
   ELISEE SCOUT — MOBILE WEB APP EXPERIENCE (< 768px)
   Solo ed esclusivamente per smartphone: trasforma l'interfaccia
   in una vera e propria Web App nativa con Top Bar, Bottom Bar,
   Slide-over Drawer e layout fluido per il pollice.
   ============================================================ */

/* Su Desktop e schermi larghi (>= 769px), la shell mobile è completamente nascosta */
@media screen and (min-width: 769px) {
  #es-mobile-app-shell,
  .es-m-topbar,
  .es-m-bottombar,
  .es-m-drawer-backdrop {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }
}

/* ============================================================
   ATTIVAZIONE MOBILE WEB APP (< 768px)
   ============================================================ */
@media screen and (max-width: 768px) {
  /* 1. Nascondiamo l'header desktop tradizionale */
  header.main-header.portfolio-header,
  header.main-header,
  .portfolio-header {
    display: none !important;
  }

  /* 2. Struttura globale mobile: scorrimento naturale fluido & scrollbar pulite */
  html {
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  @supports (scrollbar-gutter: auto) {
    html {
      scrollbar-gutter: auto !important;
    }
  }

  @supports (scrollbar-width: none) {
    html,
    body {
      scrollbar-width: none !important;
    }
  }

  html::-webkit-scrollbar,
  body::-webkit-scrollbar,
  *::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
  }

  body {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 100% !important;
    height: auto !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    position: relative !important;
    -webkit-tap-highlight-color: transparent;
  }

  body.layout-portfolio {
    padding-top: calc(52px + env(safe-area-inset-top, 0px)) !important;
    padding-bottom: calc(58px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Schermata Hero calzata alla perfezione su mobile senza micro-scroll forzato */
  #hero,
  .hero-section,
  .hero-portfolio {
    min-height: calc(100dvh - 52px - 58px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
    height: auto !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 1.5rem 1rem !important;
    box-sizing: border-box !important;
  }

  .hero-portfolio-stage {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
  }

  .hero-typography-left {
    width: 100% !important;
    text-align: center !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .hero-buttons-row {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    gap: 0.65rem !important;
  }

  .hero-buttons-row .btn {
    width: 100% !important;
    max-width: 260px !important;
  }

  /* Padding dinamico per tutte le viste e modali */
  .container.pf-page-inner,
  .pf-page-inner,
  #user-dossier-portal .pf-page-inner,
  #account-portal .pf-page-inner,
  #admin-portal .pf-page-inner,
  #ambassador-portal .pf-page-inner,
  #persone-portal .pf-page-inner,
  #bacheca-annunci .pf-page-inner,
  #stampa-portal .pf-page-inner,
  #mappa-portal .pf-page-inner,
  #view-about .about-dossier,
  .es-pd-body {
    padding-top: 0.75rem !important;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* 3. Top App Bar Mobile (Fissa in alto, 52px + Safe Area Top) */
  #es-mobile-app-shell,
  #es-mobile-app-shell::before,
  #es-mobile-app-shell::after,
  .es-m-topbar,
  .es-m-topbar::before,
  .es-m-topbar::after {
    border: 0 none !important;
    border-bottom: 0 none !important;
    border-top: 0 none !important;
    box-shadow: none !important;
    outline: none !important;
    background-image: none !important;
  }

  .es-m-topbar::before,
  .es-m-topbar::after {
    content: none !important;
    display: none !important;
  }

  .es-m-topbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: calc(52px + env(safe-area-inset-top, 0px)) !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
    padding-left: max(0.75rem, env(safe-area-inset-left, 0px)) !important;
    padding-right: max(0.75rem, env(safe-area-inset-right, 0px)) !important;
    background: #050810 !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    z-index: 10050 !important;
    box-sizing: border-box !important;
  }

  /* Azzeramento linee divisorie su tutte le sezioni portfolio + contenitori hero */
  .portfolio-section,
  .portfolio-about,
  .portfolio-resume,
  .portfolio-works,
  .portfolio-access,
  #home-about,
  #home-resume,
  #home-portfolio,
  #home-views-group,
  #view-home,
  main,
  .site-main,
  #hero,
  .hero-section,
  .hero-portfolio,
  .hero-portfolio-stage,
  .hero-portfolio-inner,
  .hero-typography-left,
  .hero-name,
  .hero-name-bold,
  .hero-role {
    border: 0 none !important;
    border-top: 0 none !important;
    border-bottom: 0 none !important;
    box-shadow: none !important;
    outline: none !important;
    text-decoration: none !important;
    background-image: none !important;
  }

  .hero-name::before,
  .hero-name::after,
  .hero-name-bold::before,
  .hero-name-bold::after,
  .hero-typography-left::after,
  .hero-portfolio-stage::before,
  .hero-portfolio-stage::after {
    content: none !important;
    display: none !important;
  }

  .es-verify-banner[hidden] {
    display: none !important;
    border: 0 !important;
    height: 0 !important;
  }

  /* Su telefono la barra anti-fake sta nel flusso della pagina: spinge giù il contenuto invece di coprirlo. */
  .es-verify-banner:not([hidden]) {
    position: relative !important;
    top: auto !important;
  }

  .es-m-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: #fff;
  }

  .es-m-brand-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
  }

  .es-m-topbar .es-m-brand-txt {
    display: none !important;
  }

  .es-m-drawer-head .es-m-brand-txt {
    font-family: Outfit, Inter, system-ui, sans-serif;
    font-weight: 800;
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    color: #f8fafc;
  }

  .es-m-drawer-head .es-m-brand-txt span {
    color: #38bdf8;
  }

  .es-m-top-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
  }

  .es-m-btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #e2e8f0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    padding: 0;
    touch-action: manipulation;
  }

  .es-m-btn-icon svg {
    width: 18px;
    height: 18px;
  }

  .es-m-btn-icon .es-m-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #38bdf8;
    box-shadow: 0 0 6px #38bdf8;
  }

  .es-m-btn-user-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 999px;
    padding: 0.22rem 0.55rem;
    color: #7dd3fc;
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    max-width: 105px;
    touch-action: manipulation;
  }

  .es-m-btn-user-pill span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .es-m-btn-hamburger {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    touch-action: manipulation;
  }

  .es-m-btn-hamburger svg {
    width: 20px;
    height: 20px;
  }

  /* 4. Bottom Navigation Bar Mobile (Fissa in basso, 58px + Safe Area Bottom) */
  .es-m-bottombar {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: calc(58px + env(safe-area-inset-bottom, 0px)) !important;
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    padding-left: max(0.5rem, env(safe-area-inset-left, 0px)) !important;
    padding-right: max(0.5rem, env(safe-area-inset-right, 0px)) !important;
    background: rgba(4, 7, 14, 0.96) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    backdrop-filter: blur(20px) !important;
    border-top: 1px solid rgba(56, 189, 248, 0.2) !important;
    display: grid !important;
    grid-template-columns: repeat(5, 1fr) !important;
    align-items: center !important;
    z-index: 10050 !important;
    box-sizing: border-box !important;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.5) !important;
  }

  .es-m-tab-item {
    -webkit-appearance: none;
    appearance: none;
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    height: 100%;
    color: #94a3b8;
    text-decoration: none;
    padding: 0.25rem 0;
    cursor: pointer;
    transition: color 0.15s ease, transform 0.12s ease;
    touch-action: manipulation;
  }

  .es-m-tab-item svg {
    width: 20px;
    height: 20px;
    stroke-width: 2;
    transition: transform 0.15s ease;
  }

  .es-m-tab-item span {
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0;
    line-height: 1.1;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .es-m-tab-item.is-active {
    color: #38bdf8 !important;
  }

  .es-m-tab-item.is-active svg {
    transform: translateY(-2px);
    filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.6));
  }

  .es-m-tab-item:active {
    transform: scale(0.94);
  }

  /* 5. Slide-over App Drawer Laterale */
  .es-m-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    z-index: 10100;
    display: flex;
    justify-content: flex-end;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    will-change: opacity;
  }

  .es-m-drawer-backdrop.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .es-m-drawer {
    width: min(84vw, 320px);
    height: 100%;
    background: #070c18;
    border-left: 1px solid rgba(56, 189, 248, 0.25);
    display: flex;
    flex-direction: column;
    box-shadow: -12px 0 36px rgba(0, 0, 0, 0.7);
    transform: translate3d(100%, 0, 0);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: transform;
    padding: calc(1rem + env(safe-area-inset-top, 0px)) 1.25rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
    overflow-y: auto;
    touch-action: pan-y;
  }

  .es-m-drawer-backdrop.is-open .es-m-drawer {
    transform: translate3d(0, 0, 0);
  }

  /* Micro-Interaction Touch Feedback Ultra-Smooth (40ms scale 0.96) */
  .es-m-brand,
  .es-m-btn-icon,
  .es-m-btn-hamburger,
  .es-m-tab-item,
  .es-m-drawer-link,
  .es-m-drawer-close {
    transition: transform 40ms cubic-bezier(0.4, 0, 0.2, 1), opacity 0.12s ease !important;
    touch-action: manipulation;
  }

  .es-m-brand:active,
  .es-m-btn-icon:active,
  .es-m-btn-hamburger:active,
  .es-m-tab-item:active,
  .es-m-drawer-link:active,
  .es-m-drawer-close:active {
    transform: scale(0.96) !important;
  }

  .es-m-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 1rem;
  }

  .es-m-drawer-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: #fff;
    font-size: 1.2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .es-m-drawer-nav {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
  }

  .es-m-drawer-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.9rem;
    border-radius: 12px;
    color: #e2e8f0;
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    touch-action: manipulation;
  }

  .es-m-drawer-link svg {
    width: 18px;
    height: 18px;
    color: #38bdf8;
  }

  .es-m-drawer-link:active,
  .es-m-drawer-link.is-active {
    background: rgba(56, 189, 248, 0.14);
    border-color: rgba(56, 189, 248, 0.35);
    color: #38bdf8;
  }

  .es-m-drawer-sep {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 0.75rem 0;
  }

  .es-m-drawer-footer {
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  /* 6. Gestione corretta Floating Cookie Badge su Mobile */
  #elisee-cookie-settings-btn,
  .elisee-cookie-badge-btn {
    bottom: calc(68px + env(safe-area-inset-bottom, 0px)) !important;
    left: 0.75rem !important;
    width: 36px !important;
    height: 36px !important;
    z-index: 10040 !important;
    opacity: 0.85;
  }

  #elisee-cookie-settings-btn svg,
  .elisee-cookie-badge-btn svg {
    width: 16px !important;
    height: 16px !important;
  }

  /* Nascondi il floating cookie quando il Drawer o un modale è aperto */
  .es-m-drawer-backdrop.is-open ~ #elisee-cookie-settings-btn,
  .es-m-drawer-backdrop.is-open ~ .elisee-cookie-badge-btn,
  body:has(.es-m-drawer-backdrop.is-open) #elisee-cookie-settings-btn,
  body:has(.es-m-drawer-backdrop.is-open) .elisee-cookie-badge-btn,
  body.modal-open #elisee-cookie-settings-btn {
    display: none !important;
  }

  /* 7. Tab Bar Orizzontali Touch & Anti-spezzamento parole */
  .es-user-tabs,
  .es-pd-nav,
  .es-dash-tabs,
  .es-obs-nav,
  .es-ds-tabs,
  .es-mk-tabs,
  .es-tc-tabs,
  .es-sp-tabs,
  .es-role-tabs {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    gap: 0.65rem !important;
    padding: 0.35rem 0.25rem 0.6rem !important;
    border-bottom: 1px solid rgba(56, 189, 248, 0.2) !important;
  }

  @supports (scrollbar-width: none) {
    .es-user-tabs,
    .es-pd-nav,
    .es-dash-tabs,
    .es-obs-nav,
    .es-ds-tabs,
    .es-mk-tabs,
    .es-tc-tabs,
    .es-sp-tabs,
    .es-role-tabs {
      scrollbar-width: none !important;
    }
  }

  .es-user-tabs::-webkit-scrollbar,
  .es-pd-nav::-webkit-scrollbar,
  .es-dash-tabs::-webkit-scrollbar,
  .es-obs-nav::-webkit-scrollbar,
  .es-ds-tabs::-webkit-scrollbar,
  .es-mk-tabs::-webkit-scrollbar,
  .es-tc-tabs::-webkit-scrollbar,
  .es-sp-tabs::-webkit-scrollbar,
  .es-role-tabs::-webkit-scrollbar {
    display: none !important;
  }

  .es-user-tab,
  .es-pd-tab,
  .es-dash-tab,
  .es-obs-tab,
  .es-ds-tab,
  .es-mk-tab,
  .es-tc-tab,
  .es-sp-tab,
  .es-role-tab {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    word-break: keep-all !important;
    font-size: 0.86rem !important;
    padding: 0.35rem 0.75rem !important;
    border-radius: 999px !important;
    background: rgba(255, 255, 255, 0.04) !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    color: #94a3b8 !important;
  }

  .es-user-tab.is-on,
  .es-pd-tab.is-on,
  .es-dash-tab.is-on,
  .es-obs-tab.is-on,
  .es-ds-tab.is-on,
  .es-mk-tab.is-on,
  .es-tc-tab.is-on,
  .es-sp-tab.is-on,
  .es-role-tab.is-on {
    color: #38bdf8 !important;
    background: rgba(56, 189, 248, 0.14) !important;
    border-color: rgba(56, 189, 248, 0.4) !important;
    box-shadow: none !important;
  }

  /* 8. Griglia Statistiche & Metriche Mobile Armoniosa */
  .portfolio-stat-row {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.65rem !important;
    margin-top: 1.5rem !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .portfolio-stat {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    background: rgba(10, 16, 30, 0.75) !important;
    border: 1px solid rgba(56, 189, 248, 0.2) !important;
    border-radius: 14px !important;
    padding: 0.85rem 0.5rem !important;
    box-sizing: border-box !important;
    width: 100% !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35) !important;
  }

  .portfolio-stat strong {
    font-family: Outfit, Inter, system-ui, sans-serif !important;
    font-size: 1.35rem !important;
    font-weight: 800 !important;
    color: #f8fafc !important;
    margin-bottom: 0.2rem !important;
    line-height: 1.1 !important;
  }

  .portfolio-stat span {
    font-size: 0.72rem !important;
    font-weight: 600 !important;
    color: #94a3b8 !important;
    letter-spacing: 0.03em !important;
    text-transform: uppercase !important;
    line-height: 1.25 !important;
    text-align: center !important;
  }

  /* Portfolio Cards Griglia su Mobile */
  .portfolio-cards {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.85rem !important;
    margin-top: 1.5rem !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .portfolio-card {
    background: rgba(10, 16, 30, 0.6) !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    border-radius: 14px !important;
    padding: 1.1rem 1rem !important;
    box-sizing: border-box !important;
  }
}
