/* ===================================
   Mobile Responsive Optimization
   Studio Legale Avv. Domenico Sarcina
   =================================== */

/* ========== NAVBAR MOBILE OPTIMIZATION ========== */

/* Aumenta dimensione target touch per accessibilità mobile (min 44px x 44px) */
@media (max-width: 991px) {
    /* Container navbar mobile */
    .navbar-professional {
        padding: 0.75rem 0 !important;
        box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
    }

    .navbar-professional .container-fluid {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    /* Logo e brand ridotti ma leggibili */
    .navbar-brand-professional {
        margin-left: 0 !important;
        gap: 0.75rem !important;
        flex: 1;
    }

    .brand-logo-img {
        height: 45px !important;
        max-width: 200px;
    }

    .brand-text-name {
        display: flex !important;
    }

    .brand-first-line {
        font-size: 0.95rem !important;
    }

    .brand-second-line {
        font-size: 1.5rem !important;
    }

    /* Hamburger menu ottimizzato per touch */
    .navbar-toggler-professional {
        display: block !important;
        min-width: 44px !important;
        min-height: 44px !important;
        padding: 0.5rem !important;
        margin-right: 0;
        background: rgba(1, 67, 117, 0.05);
        border-radius: 8px;
        transition: all 0.3s ease;
        z-index: 1;
    }

    /* NASCONDI hamburger quando menu è aperto */
    .navbar-toggler-professional[aria-expanded="true"] {
        opacity: 0;
        pointer-events: none;
    }

    .navbar-toggler-professional:active {
        background: rgba(1, 67, 117, 0.15);
        transform: scale(0.95);
    }

    .toggler-line {
        background: var(--brand-blue);
        height: 3px !important;
        margin: 4px auto !important;
    }

    /* SIDE DRAWER MENU - SLIDE DA DESTRA */
    .navbar-collapse {
        position: fixed !important;
        top: 0;
        right: -100%;
        width: 85%;
        max-width: 350px;
        height: 100vh;
        background: white;
        box-shadow: -5px 0 25px rgba(0, 0, 0, 0.2);
        z-index: 1050 !important; /* SOPRA overlay */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        transition: right 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
        margin-top: 0 !important;
        padding-top: 0 !important;
        border: none !important;
        display: block !important;
        visibility: visible !important;
        pointer-events: auto !important; /* Sempre cliccabile */
    }

    .navbar-collapse.show {
        right: 0 !important;
    }

    .navbar-collapse.collapsing {
        right: -100% !important;
        transition: right 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
        height: 100vh !important;
    }

    /* OVERLAY RIMOSSO - NON SERVE PIÙ */

    /* Header del drawer con bottone chiusura */
    .mobile-menu-header {
        display: block;
        width: 100%;
        height: 70px;
        background: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-blue-dark) 100%);
        position: relative;
        padding: 1rem 1.5rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .mobile-menu-close {
        background: rgba(255, 255, 255, 0.2);
        border: none;
        color: white;
        width: 44px;
        height: 44px;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        cursor: pointer;
        transition: all 0.2s ease;
        margin-left: auto;
    }

    .mobile-menu-close:hover,
    .mobile-menu-close:active {
        background: rgba(255, 255, 255, 0.3);
        transform: scale(0.95);
    }

    .mobile-menu-title {
        color: white;
        font-size: 1.1rem;
        font-weight: 600;
        margin: 0;
    }

    /* Links con separatori */
    .navbar-nav-professional {
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100%;
        gap: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .nav-item-professional {
        width: 100%;
        border-bottom: 1px solid #e5e7eb !important;
        margin: 0 !important;
    }

    .nav-link-professional {
        padding: 1.1rem 1.5rem !important;
        font-size: 1rem !important;
        font-weight: 500;
        color: var(--dark-color) !important;
        display: flex !important;
        align-items: center;
        width: 100%;
        text-align: left;
        min-height: 52px;
        transition: all 0.2s ease;
        background: white;
        border-left: 3px solid transparent;
    }

    .nav-link-professional:hover,
    .nav-link-professional:active {
        background: #f9fafb !important;
        border-left-color: var(--brand-blue) !important;
        color: var(--brand-blue) !important;
    }

    .nav-link-professional::before {
        display: none !important;
    }

    /* Dropdown mobile */
    .dropdown-professional {
        position: relative;
    }

    .dropdown-professional > .nav-link-professional::after {
        content: '\F285';
        font-family: 'bootstrap-icons';
        margin-left: auto;
        font-size: 0.875rem;
        transition: transform 0.3s ease;
    }

    .dropdown-professional.show > .nav-link-professional::after {
        transform: rotate(90deg);
    }

    .dropdown-menu-professional {
        position: static !important;
        display: none !important;
        flex-direction: column !important; /* FORZA COLONNA */
        opacity: 0;
        visibility: hidden;
        transform: none !important;
        box-shadow: none !important;
        background: #f8f9fa !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        border-left: 3px solid var(--brand-blue) !important;
        width: 100% !important;
        max-height: 0;
        overflow: hidden;
        transition: all 0.3s ease;
        list-style: none !important;
    }

    .dropdown-professional.show .dropdown-menu-professional {
        display: flex !important; /* FLEX COLUMN */
        flex-direction: column !important;
        opacity: 1;
        visibility: visible;
        max-height: 500px;
        overflow: visible;
    }

    /* Li del dropdown */
    .dropdown-menu-professional > li {
        display: block !important;
        width: 100% !important;
        flex: none !important;
    }

    .dropdown-item-professional {
        padding: 0.95rem 1.5rem 0.95rem 3rem !important; /* Più indentato */
        font-size: 0.9rem !important;
        color: #6b7280 !important;
        min-height: 48px;
        display: block !important; /* BLOCK per stare sotto */
        width: 100% !important;
        white-space: normal !important;
        word-wrap: break-word;
        border-bottom: 1px solid #e5e7eb;
        transition: all 0.2s ease;
        background: #f8f9fa;
        position: relative;
        line-height: 1.5;
    }

    /* Pallino o linea per sub-item */
    .dropdown-item-professional::before {
        content: '•';
        position: absolute;
        left: 2rem;
        color: var(--brand-blue);
        font-size: 1.2rem;
        line-height: 1;
    }

    .dropdown-item-professional:last-child {
        border-bottom: none;
    }

    .dropdown-item-professional:hover,
    .dropdown-item-professional:active {
        background: #e5e7eb !important;
        color: var(--brand-blue) !important;
        padding-left: 3.25rem !important;
    }

    .dropdown-item-professional i {
        min-width: 24px;
        margin-right: 0.5rem;
    }

    /* Bottoni CTA mobile */
    .btn-navbar-cta {
        display: block !important;
        width: calc(100% - 3rem) !important;
        text-align: center !important;
        margin: 1rem 1.5rem !important;
        padding: 0.95rem 1.5rem !important;
        font-size: 1rem !important;
        min-height: 50px;
        border-radius: 8px;
        background: var(--brand-blue) !important;
        color: white !important;
        border: none;
        font-weight: 600;
    }

    .nav-item-professional.ms-lg-3 {
        margin-left: 0 !important;
        margin-top: 0 !important;
        border-bottom: none !important;
    }

    /* User dropdown */
    .dropdown-professional.dropdown-right .dropdown-menu-professional {
        left: 0 !important;
        right: 0 !important;
    }
}

/* Extra ottimizzazioni per schermi molto piccoli */
@media (max-width: 576px) {
    .brand-logo-img {
        height: 40px !important;
    }

    .brand-first-line {
        font-size: 0.85rem !important;
    }

    .brand-second-line {
        font-size: 1.3rem !important;
    }

    .navbar-professional .container-fluid {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
}

/* ========== FOOTER MOBILE OPTIMIZATION ========== */

@media (max-width: 991px) {
    .footer {
        padding-top: 2rem !important;
        padding-bottom: 1.5rem !important;
        margin-top: 2rem !important;
    }

    .footer .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Footer brand - inline su mobile */
    .footer-brand {
        flex-direction: row !important;
        align-items: center !important;
        gap: 0.5rem !important;
        margin-bottom: 0.75rem !important;
    }

    .footer-logo-img {
        height: 40px !important;
    }

    .footer-brand-text {
        margin-left: 0 !important;
    }

    .footer-first-line {
        font-size: 1rem !important;
    }

    .footer-second-line {
        font-size: 1.6rem !important;
    }

    /* Colonne footer - SPAZI RIDOTTI */
    .footer .row > div {
        margin-bottom: 1.25rem !important;
    }

    .footer .col-lg-4 p {
        margin-bottom: 0.5rem !important;
        font-size: 0.9rem !important;
        line-height: 1.5 !important;
    }

    .footer .col-lg-4,
    .footer .col-lg-2,
    .footer .col-lg-3 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* Link footer touch-friendly - SPAZI RIDOTTI */
    .footer ul li {
        margin-bottom: 0.4rem;
    }

    .footer ul li a {
        display: inline-block;
        padding: 0.35rem 0;
        font-size: 0.95rem;
        min-height: 40px;
        line-height: 1.4;
        transition: all 0.2s ease;
    }

    .footer h5 {
        font-size: 1.1rem !important;
        margin-bottom: 0.75rem !important;
    }

    .footer ul li a:active {
        transform: translateX(8px);
    }

    /* Social links - spazio ridotto */
    .social-links {
        display: flex;
        gap: 1rem;
        margin-top: 0.75rem !important;
    }

    .social-links a {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 48px;
        min-height: 48px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.1);
        transition: all 0.3s ease;
    }

    .social-links a:active {
        transform: scale(0.9);
        background: rgba(255, 255, 255, 0.2);
    }

    .social-links a i {
        font-size: 1.5rem !important;
    }

    /* Contatti info - spazio ridotto */
    .footer .small {
        font-size: 0.9rem !important;
    }

    .footer ul li {
        line-height: 1.5;
    }

    /* Newsletter mobile - spazio ridotto */
    .footer .row.mt-4 {
        margin-top: 1.25rem !important;
        padding-top: 1.25rem !important;
    }

    #footerNewsletterForm .col-md-8,
    #footerNewsletterForm .col-md-4 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    #footerNewsletterForm .col-md-4 {
        margin-top: 0.75rem;
    }

    #footerNewsletterForm input,
    #footerNewsletterForm button {
        font-size: 1rem;
        padding: 0.875rem 1rem;
        min-height: 48px;
        border-radius: 8px;
    }

    #footerNewsletterForm button {
        width: 100% !important;
    }

    /* Back to top button - già gestito in footer.php */
    #backToTop {
        bottom: 20px !important;
        right: 20px !important;
        width: 50px !important;
        height: 50px !important;
    }

    /* Copyright - spazio ridotto */
    .footer .row.mt-4.pt-3 {
        margin-top: 1rem !important;
        padding-top: 1rem !important;
    }

    .footer .text-center {
        text-align: center !important;
        font-size: 0.8rem !important;
    }

    .footer .text-center p {
        margin-bottom: 0 !important;
        line-height: 1.4;
    }
}

@media (max-width: 576px) {
    .footer {
        padding-top: 1.5rem !important;
        padding-bottom: 1rem !important;
    }

    .footer-logo-img {
        height: 35px !important;
    }

    .footer-first-line {
        font-size: 0.9rem !important;
    }

    .footer-second-line {
        font-size: 1.4rem !important;
    }

    .footer h5 {
        font-size: 1rem !important;
        margin-bottom: 0.6rem !important;
    }

    .footer .container {
        padding-left: 0.875rem;
        padding-right: 0.875rem;
    }

    .footer .row > div {
        margin-bottom: 1rem !important;
    }

    .social-links {
        margin-top: 0.5rem !important;
        gap: 0.75rem;
    }

    .social-links a {
        min-width: 44px;
        min-height: 44px;
    }

    #backToTop {
        width: 48px !important;
        height: 48px !important;
        bottom: 15px !important;
        right: 15px !important;
    }
}

/* ========== GENERAL MOBILE IMPROVEMENTS ========== */

/* Impedisci zoom su input focus (iOS) */
@media (max-width: 991px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px !important; /* Previene zoom automatico iOS */
    }
}

/* Smooth scrolling ottimizzato */
@media (max-width: 991px) {
    html {
        scroll-padding-top: 80px;
    }

    body {
        padding-top: 0;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Safe area per iPhone con notch */
@supports (padding: max(0px)) {
    .navbar-professional .container-fluid {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .footer .container {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
}

/* Focus visible per accessibilità keyboard */
@media (max-width: 991px) {
    a:focus-visible,
    button:focus-visible,
    input:focus-visible,
    select:focus-visible,
    textarea:focus-visible {
        outline: 3px solid var(--brand-blue);
        outline-offset: 2px;
    }
}

/* Ottimizzazione performance mobile */
@media (max-width: 991px) {
    * {
        -webkit-tap-highlight-color: rgba(1, 67, 117, 0.1);
    }

    a, button {
        touch-action: manipulation; /* Rimuove delay 300ms su tap */
    }
}
