/* Mobile-First Responsive Styles for Consulente */

/* ============================================
   General Mobile Improvements
   ============================================ */
@media (max-width: 767.98px) {
    /* Previeni scroll orizzontale */
    html, body {
        overflow-x: hidden;
        max-width: 100%;
    }
    
    /* Migliora il rendering su mobile */
    * {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
}

/* ============================================
   Mobile Sidebar Improvements
   ============================================ */
@media (max-width: 991.98px) {
    /* Disabilita il comportamento default di AdminLTE su mobile */
    body.sidebar-mini .main-sidebar {
        transform: none !important;
        width: 250px !important;
    }
    
    /* Sidebar overlay quando aperto su mobile */
    /* IMPORTANTE: Nascondi la sidebar di default su mobile */
    .main-sidebar {
        position: fixed !important;
        left: -250px !important;
        top: 0;
        height: 100vh;
        width: 250px !important;
        transition: left 0.3s ease-in-out !important;
        z-index: 1040 !important;
        box-shadow: 2px 0 10px rgba(0,0,0,0.3);
        overflow-y: auto;
        overflow-x: hidden;
        /* Previeni che AdminLTE interferisca */
        transform: none !important;
        margin-left: 0 !important;
    }
    
    /* Quando la sidebar è aperta su mobile */
    .main-sidebar.sidebar-open {
        left: 0 !important;
    }
    
    /* Previeni che AdminLTE mostri la sidebar su mobile */
    body:not(.sidebar-open) .main-sidebar {
        left: -250px !important;
    }
    
    /* Overlay per chiudere sidebar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1039;
        opacity: 0;
        transition: opacity 0.3s ease-in-out;
    }
    
    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }
    
    /* Previeni scroll del body quando sidebar è aperto */
    body.sidebar-open {
        overflow: hidden !important;
        position: fixed;
        width: 100%;
    }
    
    /* Content wrapper su mobile */
    .content-wrapper {
        margin-left: 0 !important;
        width: 100%;
    }
    
    /* Header su mobile */
    .main-header {
        margin-left: 0 !important;
        width: 100%;
        z-index: 1030;
    }
    
    /* Footer su mobile */
    .main-footer {
        margin-left: 0 !important;
        width: 100%;
    }
    
    /* Assicura che il sidebar sia sopra tutto */
    .main-sidebar {
        z-index: 1040 !important;
    }
    
    /* Disabilita transizioni AdminLTE su mobile */
    body.sidebar-mini .main-sidebar {
        transform: none !important;
    }
    
    /* Assicura che il sidebar non sia nascosto da AdminLTE */
    body.sidebar-collapse .main-sidebar {
        margin-left: 0 !important;
        transform: none !important;
    }
    
    /* Previeni che AdminLTE nasconda il sidebar su mobile */
    .main-sidebar.collapse {
        display: block !important;
        visibility: visible !important;
    }
}

/* ============================================
   Desktop - Assicura che AdminLTE funzioni normalmente
   ============================================ */
@media (min-width: 992px) {
    /* IMPORTANTE: Su desktop, tutte le regole mobile vengono ignorate */
    /* Ripristina completamente il comportamento normale di AdminLTE */
    
    /* Sidebar sempre visibile e posizionata correttamente su desktop */
    .main-sidebar {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        height: 100vh !important;
        width: 250px !important;
        transform: none !important;
        z-index: 1028 !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        margin-left: 0 !important;
        /* Rimuovi qualsiasi left negativo che potrebbe venire da regole mobile */
    }
    
    /* AdminLTE usa sidebar-mini per nascondere il sidebar */
    /* Ma su desktop con sidebar-mini, la sidebar dovrebbe essere visibile di default */
    /* Solo quando viene cliccato il toggle, AdminLTE aggiunge sidebar-collapse */
    body.sidebar-mini:not(.sidebar-collapse) .main-sidebar {
        transform: none !important;
        left: 0 !important;
    }
    
    /* Quando sidebar-collapse è attivo, nascondi la sidebar */
    body.sidebar-mini.sidebar-collapse .main-sidebar {
        transform: translateX(-250px) !important;
    }
    
    /* AdminLTE usa sidebar-collapse per collassare */
    body.sidebar-collapse .main-sidebar {
        margin-left: 0 !important;
        transform: translateX(-250px) !important;
    }
    
    /* Rimuovi completamente le classi mobile su desktop */
    .main-sidebar.sidebar-open {
        left: 0 !important;
        transform: none !important;
        margin-left: 0 !important;
    }
    
    /* Nascondi overlay su desktop */
    .sidebar-overlay {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
    
    /* Content wrapper su desktop - ripristina margin */
    .content-wrapper {
        margin-left: 250px !important;
    }
    
    /* Header su desktop - ripristina margin */
    .main-header {
        margin-left: 250px !important;
    }
    
    /* Footer su desktop - ripristina margin */
    .main-footer {
        margin-left: 250px !important;
    }
    
    /* Rimuovi body.sidebar-open su desktop */
    body.sidebar-open {
        overflow: auto !important;
        position: static !important;
        width: auto !important;
    }
    
    /* Assicura che il brand-link sia normale su desktop */
    .brand-link {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
    }
}

/* ============================================
   Mobile Navbar Improvements
   ============================================ */
@media (max-width: 991.98px) {
    .main-header .navbar-nav {
        flex-direction: row;
    }
    
    .main-header .navbar-nav .nav-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
    
    /* Nascondi username su schermi piccoli, mostra solo icona */
    .main-header .navbar-nav .nav-item.dropdown .nav-link span {
        display: none;
    }
    
    /* Dropdown menu più largo su mobile */
    .dropdown-menu {
        min-width: 200px;
        right: 0;
        left: auto;
    }
}

/* ============================================
   Mobile Forms and Inputs
   ============================================ */
@media (max-width: 767.98px) {
    /* Form groups full width su mobile */
    .form-group {
        margin-bottom: 1rem;
    }
    
    /* Input fields più grandi per touch */
    .form-control,
    .form-select {
        font-size: 16px; /* Previene zoom su iOS */
        padding: 0.75rem;
        min-height: 44px; /* Touch target minimo */
    }
    
    /* Bottoni più grandi per touch */
    .btn {
        min-height: 44px;
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        touch-action: manipulation;
    }
    
    /* Bottoni icona più grandi */
    .btn-tool {
        min-width: 44px;
        min-height: 44px;
        padding: 0.5rem;
    }
    
    /* Row con colonne stack su mobile */
    .row .col-md-6,
    .row .col-md-4,
    .row .col-md-3 {
        margin-bottom: 1rem;
    }
    
    /* Card padding ridotto su mobile */
    .card-body {
        padding: 1rem;
    }
    
    .card-header {
        padding: 0.75rem 1rem;
    }
    
    .card-header h3 {
        font-size: 1.1rem;
    }
}

/* ============================================
   Mobile Tables (Tabulator)
   ============================================ */
@media (max-width: 767.98px) {
    /* Container tabelle scrollabile orizzontalmente */
    .table-responsive,
    .tabulator-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: block;
        width: 100%;
    }
    
    /* Tabulator responsive */
    .tabulator {
        min-width: 600px; /* Larghezza minima per mantenere colonne */
    }
    
    /* Celle tabulator più compatte su mobile */
    .tabulator .tabulator-cell {
        padding: 0.5rem 0.25rem;
        font-size: 0.875rem;
    }
    
    /* Header tabulator più compatto */
    .tabulator .tabulator-header {
        font-size: 0.875rem;
    }
    
    /* Nascondi colonne meno importanti su mobile */
    .tabulator .tabulator-col[data-field="id"],
    .tabulator .tabulator-col[data-field="created_at"],
    .tabulator .tabulator-col[data-field="updated_at"] {
        display: none;
    }
}

/* ============================================
   Mobile Cards and Containers
   ============================================ */
@media (max-width: 767.98px) {
    /* Container fluid padding ridotto */
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    /* Content padding ridotto */
    .content {
        padding: 0.5rem 0;
    }
    
    /* Card margin ridotto */
    .card {
        margin-bottom: 1rem;
    }
    
    /* Dashboard cards stack su mobile */
    .dashboard-container {
        padding: 1rem;
    }
    
    .focus-container {
        padding: 1.5rem;
        margin-bottom: 1.5rem;
    }
    
    .focus-task-card {
        padding: 1rem;
    }
    
    .focus-task-title {
        font-size: 1.25rem;
    }
    
    .focus-task-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
}

/* ============================================
   Mobile Typography
   ============================================ */
@media (max-width: 767.98px) {
    h1 {
        font-size: 1.75rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    h3 {
        font-size: 1.25rem;
    }
    
    h4 {
        font-size: 1.1rem;
    }
    
    /* Content header più compatto */
    .content-header h1 {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }
    
    /* Breadcrumb più compatto */
    .breadcrumb {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }
}

/* ============================================
   Mobile Modals
   ============================================ */
@media (max-width: 767.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 0.5rem;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }
    
    .modal-title {
        font-size: 1.25rem;
    }
}

/* ============================================
   Mobile Alerts and Messages
   ============================================ */
@media (max-width: 767.98px) {
    .alert {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }
    
    .alert-dismissible .close {
        padding: 0.75rem 1rem;
        font-size: 1.5rem;
    }
}

/* ============================================
   Mobile Buttons and Actions
   ============================================ */
@media (max-width: 767.98px) {
    /* Button groups stack su mobile */
    .btn-group-vertical {
        width: 100%;
    }
    
    .btn-group-vertical .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    /* Action buttons più visibili */
    .btn-action {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Icon buttons più grandi */
    .btn i {
        font-size: 1.1rem;
    }
}

/* ============================================
   Mobile Calendar
   ============================================ */
@media (max-width: 767.98px) {
    .fc-toolbar {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .fc-toolbar-chunk {
        width: 100%;
        text-align: center;
    }
    
    .fc-button {
        padding: 0.5rem;
        font-size: 0.875rem;
    }
    
    .fc-dayGridMonth-view .fc-day {
        min-height: 60px;
    }
}

/* ============================================
   Mobile Navigation Menu
   ============================================ */
@media (max-width: 991.98px) {
    /* Menu items più grandi per touch */
    .nav-sidebar .nav-link {
        padding: 0.875rem 1rem;
        min-height: 48px;
        display: flex;
        align-items: center;
        touch-action: manipulation;
    }
    
    .nav-sidebar .nav-icon {
        width: 2rem;
        font-size: 1.2rem;
    }
    
    /* Brand link più compatto */
    .brand-link {
        padding: 0.75rem 1rem;
        position: sticky;
        top: 0;
        z-index: 10;
        background: inherit;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    .brand-text {
        font-size: 1.1rem;
        flex: 1;
    }
    
    .brand-image {
        height: 32px;
        width: 32px;
    }
    
    /* Pulsante chiusura sidebar su mobile */
    .sidebar-close-btn {
        background: rgba(255, 255, 255, 0.2) !important;
        border: none !important;
        color: #fff !important;
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        transition: all 0.3s ease !important;
        margin-left: auto !important;
        flex-shrink: 0 !important;
        touch-action: manipulation !important;
        z-index: 1000 !important;
        position: relative !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    .sidebar-close-btn:hover,
    .sidebar-close-btn:focus {
        background: rgba(255, 255, 255, 0.3);
        transform: scale(1.1);
        outline: none;
    }
    
    .sidebar-close-btn:active {
        transform: scale(0.95);
        background: rgba(255, 255, 255, 0.4);
    }
    
    .sidebar-close-btn i {
        font-size: 1.2rem;
        pointer-events: none;
    }
    
    /* Previeni che il click sul pulsante attivi il link del brand */
    .brand-link .sidebar-close-btn {
        pointer-events: auto;
    }
    
    /* Assicura che il pulsante sia sempre cliccabile */
    .brand-link {
        position: relative;
    }
    
    .brand-link .sidebar-close-btn {
        position: relative;
        z-index: 100;
    }
    
    /* Assicura che il pulsante sia sempre visibile su mobile */
    @media (max-width: 991.98px) {
        .sidebar-close-btn.d-md-none {
            display: flex !important;
        }
    }
    
    /* Nascondi pulsante su desktop */
    @media (min-width: 992px) {
        .sidebar-close-btn {
            display: none !important;
        }
    }
    
    /* Menu hamburger sempre visibile e touch-friendly */
    [data-widget="pushmenu"] {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        touch-action: manipulation;
        cursor: pointer;
    }
    
    [data-widget="pushmenu"] i {
        font-size: 1.2rem;
    }
    
    /* Submenu animati */
    .nav-sidebar .nav-treeview {
        display: none;
        padding-left: 0;
    }
    
    .nav-sidebar .nav-item.menu-open > .nav-treeview {
        display: block;
    }
    
    /* Migliora la visibilità dei submenu su mobile */
    .nav-sidebar .nav-treeview .nav-link {
        padding-left: 3rem;
        font-size: 0.9rem;
        min-height: 44px;
    }
}

/* ============================================
   Mobile Utilities
   ============================================ */
@media (max-width: 767.98px) {
    /* Nascondi elementi non essenziali su mobile */
    .d-mobile-none {
        display: none !important;
    }
    
    /* Mostra solo su mobile */
    .d-mobile-block {
        display: block !important;
    }
    
    /* Text alignment su mobile */
    .text-mobile-center {
        text-align: center;
    }
    
    /* Margin utilities per mobile */
    .mb-mobile-2 {
        margin-bottom: 0.5rem;
    }
    
    .mb-mobile-3 {
        margin-bottom: 1rem;
    }
}

/* ============================================
   Touch Improvements
   ============================================ */
/* Migliora l'esperienza touch su tutti i dispositivi */
@media (hover: none) and (pointer: coarse) {
    /* Aumenta area di tocco per link */
    a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
    
    /* Migliora feedback touch */
    .btn,
    .nav-link,
    .card {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
    
    /* Disabilita hover effects su touch devices */
    .btn:hover,
    .nav-link:hover {
        transform: none;
    }
}

/* ============================================
   Landscape Mobile Optimization
   ============================================ */
@media (max-width: 991.98px) and (orientation: landscape) {
    .main-sidebar {
        width: 200px;
    }
    
    .content-wrapper {
        margin-left: 0;
    }
    
    .main-sidebar.sidebar-open {
        left: 0;
    }
}

/* ============================================
   Home Page Mobile Styles
   ============================================ */
@media (max-width: 767.98px) {
    .hero-section {
        padding: 60px 0 !important;
    }
    
    .hero-content h1 {
        font-size: 2rem !important;
    }
    
    .hero-content p {
        font-size: 1rem !important;
    }
    
    .benefit-item {
        flex-direction: column;
        text-align: center;
        margin-bottom: 2rem;
    }
    
    .benefit-icon {
        margin-bottom: 1rem;
        margin-right: 0 !important;
    }
    
    .feature-card {
        margin-bottom: 1.5rem;
    }
    
    .cta-section {
        padding: 3rem 1rem !important;
    }
}

/* ============================================
   ConsulenteWeb Mobile Styles
   ============================================ */

/* Django Tables2 Responsive */
@media (max-width: 767.98px) {
    /* Tabella responsive con scroll orizzontale */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border: 1px solid #dee2e6;
        border-radius: 0.375rem;
    }
    
    /* Tabella base */
    table.table {
        width: 100%;
        min-width: 600px; /* Larghezza minima per mantenere colonne */
        margin-bottom: 0;
    }
    
    /* Header tabella più compatto */
    table.table thead th {
        padding: 0.5rem 0.25rem;
        font-size: 0.875rem;
        white-space: nowrap;
        vertical-align: middle;
    }
    
    /* Celle tabella più compatte */
    table.table tbody td {
        padding: 0.5rem 0.25rem;
        font-size: 0.875rem;
        vertical-align: middle;
    }
    
    /* Bottoni nelle celle più piccoli ma touch-friendly */
    table.table .btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
        min-height: 36px;
        min-width: 36px;
        touch-action: manipulation;
    }
    
    /* Button group nelle celle - stack verticale su mobile se necessario */
    table.table .btn-group {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    
    table.table .btn-group .btn {
        flex: 1 1 auto;
        min-width: 44px;
    }
    
    /* Badge più piccoli */
    table.table .badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }
    
    /* Nascondi colonne meno importanti su mobile - ID se presente */
    table.table th:first-child,
    table.table td:first-child {
        /* Prima colonna (ID) - nascondi se non essenziale */
        display: none;
    }
    
    /* Se la tabella ha troppe colonne, nascondi alcune meno importanti */
    table.table th:nth-child(n+8),
    table.table td:nth-child(n+8) {
        /* Colonne oltre la 7a - nascondi su schermi molto piccoli */
        display: none;
    }
    
    /* Su schermi più grandi (tablet) mostra più colonne */
    @media (min-width: 576px) and (max-width: 767.98px) {
        table.table th:nth-child(n+8),
        table.table td:nth-child(n+8) {
            display: table-cell;
        }
    }
    
    /* Link nelle celle */
    table.table a {
        word-break: break-word;
        font-size: 0.875rem;
    }
    
    /* Form consulenteweb - stack verticale su mobile */
    .consulenteweb-form .row {
        margin-left: 0;
        margin-right: 0;
    }
    
    .consulenteweb-form .row > [class*="col-"] {
        padding-left: 0;
        padding-right: 0;
        margin-bottom: 1rem;
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }
    
    /* Card form più compatte */
    .card.card-primary .card-body {
        padding: 1rem;
    }
    
    /* Label più leggibili */
    .consulenteweb-form label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
        display: block;
    }
    
    /* Input più grandi per touch */
    .consulenteweb-form .form-control,
    .consulenteweb-form .form-select {
        font-size: 16px; /* Previene zoom su iOS */
        padding: 0.75rem;
        min-height: 44px;
    }
    
    /* Textarea più leggibili */
    .consulenteweb-form textarea {
        font-size: 16px;
        padding: 0.75rem;
    }
    
    /* Bottoni form full width su mobile */
    .consulenteweb-form button[type="submit"] {
        width: 100%;
        margin-top: 1rem;
    }
}

/* Modal VPS Responsive */
@media (max-width: 767.98px) {
    .modal-dialog.modal-lg {
        max-width: calc(100% - 1rem);
        margin: 0.5rem;
    }
    
    .modal-content {
        border-radius: 0.5rem;
    }
    
    .modal-body .row {
        margin-left: 0;
        margin-right: 0;
    }
    
    .modal-body .row > [class*="col-"] {
        padding-left: 0;
        padding-right: 0;
        margin-bottom: 1rem;
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }
    
    .modal-body .form-group {
        margin-bottom: 1rem;
    }
    
    .modal-body label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    .modal-body .form-control {
        font-size: 16px;
        padding: 0.75rem;
        min-height: 44px;
    }
    
    .modal-footer {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
}

/* Tree View Mobile */
@media (max-width: 767.98px) {
    #tree-container {
        min-height: 400px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    #jstree {
        min-height: 400px;
        padding: 10px;
        font-size: 0.9rem;
    }
    
    .jstree-default .jstree-anchor {
        font-size: 0.9rem;
        padding: 4px 8px;
        min-height: 36px;
        display: flex;
        align-items: center;
    }
    
    .jstree-default .jstree-icon {
        width: 20px;
        height: 20px;
    }
    
    /* Migliora l'area di tocco per i nodi */
    .jstree-default .jstree-node {
        min-height: 36px;
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .main-sidebar,
    .main-header,
    .main-footer,
    .btn,
    .navbar {
        display: none !important;
    }
    
    .content-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
    }
}





