/* =====================================
SOTUMA Dashboard - Senior Level Mobile Fix
Professional Mobile Responsive Solution
Author: Senior Developer
Version: 8.0 - Production Ready
===================================== */

/* ===== RESET SB ADMIN 2 MOBILE BEHAVIOR ===== */
/* SB Admin 2 collapses sidebar to 6.5rem on mobile - we need to override this */

/* Force sidebar to be visible and properly sized on ALL screen sizes */
.sidebar {
    width: 14rem !important; /* Override SB Admin 2's 6.5rem mobile default */
    min-height: 100vh !important;
    position: relative !important;
    display: block !important;
}

/* Ensure content wrapper accounts for sidebar width */
#content-wrapper {
    margin-left: 14rem !important;
    width: calc(100% - 14rem) !important;
}

/* Override any Bootstrap display utilities that might hide sidebar */
.sidebar.d-none,
.sidebar.d-md-none,
.sidebar.d-lg-none {
    display: block !important;
}

/* ===== MOBILE OPTIMIZATIONS ===== */
@media (max-width: 768px) {
    /* Scale down entire dashboard for mobile */
    #wrapper {
        zoom: 0.75;
        -webkit-transform: scale(0.75);
        -moz-transform: scale(0.75);
        -ms-transform: scale(0.75);
        transform: scale(0.75);
        transform-origin: 0 0;
        width: 133.33%; /* Compensate for 0.75 scale */
        height: 133.33%;
    }
    
    /* Ensure sidebar remains visible and properly sized */
    .sidebar {
        width: 12rem !important; /* Slightly smaller for mobile */
        position: relative !important;
        display: block !important;
        float: left !important;
        flex-shrink: 0 !important;
    }
    
    /* Adjust content wrapper for smaller sidebar */
    #content-wrapper {
        margin-left: 12rem !important;
        width: calc(100% - 12rem) !important;
        min-height: 100vh !important;
    }
    
    /* Hide mobile toggle since we keep sidebar visible */
    #sidebarToggleTop {
        display: none !important;
    }
    
    /* Optimize sidebar content for mobile */
    .sidebar .nav-item .nav-link {
        padding: 0.75rem 1rem !important;
        font-size: 0.875rem !important;
    }
    
    .sidebar .nav-item .nav-link i {
        font-size: 1rem !important;
        margin-right: 0.5rem !important;
    }
    
    .sidebar-brand {
        padding: 1rem 0.75rem !important;
    }
    
    .sidebar-brand-text {
        font-size: 1rem !important;
    }
    
    /* Optimize topbar for mobile */
    .topbar {
        padding: 0.5rem 0.75rem !important;
        width: 100% !important;
    }
    
    .topbar .btn {
        font-size: 0.75rem !important;
        padding: 0.375rem 0.5rem !important;
        margin: 0.125rem !important;
    }
    
    /* Make dashboard cards responsive */
    .col-xl-3,
    .col-xl-4 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }
    
    .col-xl-6,
    .col-xl-8,
    .col-lg-7,
    .col-lg-5 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
    
    /* Optimize cards for mobile */
    .card {
        margin-bottom: 1rem !important;
        border-radius: 0.5rem !important;
    }
    
    .card-body {
        padding: 1rem !important;
    }
    
    .card-header {
        padding: 0.75rem 1rem !important;
        font-size: 0.9rem !important;
    }
    
    /* Optimize statistics display */
    .text-xs {
        font-size: 0.7rem !important;
    }
    
    .h5.mb-0.font-weight-bold {
        font-size: 1.1rem !important;
    }
    
    .fa-2x {
        font-size: 1.5rem !important;
    }
    
    /* Container adjustments */
    .container-fluid {
        padding: 0.75rem !important;
    }
}

/* ===== SMALL MOBILE DEVICES ===== */
@media (max-width: 480px) {
    /* More aggressive scaling for small screens */
    #wrapper {
        zoom: 0.6;
        -webkit-transform: scale(0.6);
        transform: scale(0.6);
        width: 166.67%; /* Compensate for 0.6 scale */
        height: 166.67%;
    }
    
    /* Further reduce sidebar width */
    .sidebar {
        width: 10rem !important;
    }
    
    #content-wrapper {
        margin-left: 10rem !important;
        width: calc(100% - 10rem) !important;
    }
    
    /* Stack all cards vertically */
    .col-xl-3,
    .col-xl-4,
    .col-xl-6,
    .col-xl-8,
    .col-lg-4,
    .col-lg-5,
    .col-lg-7,
    .col-md-6 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
    
    /* Compact spacing */
    .container-fluid {
        padding: 0.5rem !important;
    }
    
    .card-body {
        padding: 0.75rem !important;
    }
    
    .sidebar .nav-item .nav-link {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.8rem !important;
    }
    
    .sidebar-brand {
        padding: 0.75rem 0.5rem !important;
    }
}

/* ===== LANDSCAPE MOBILE ===== */
@media (max-width: 768px) and (orientation: landscape) {
    #wrapper {
        zoom: 0.8;
        -webkit-transform: scale(0.8);
        transform: scale(0.8);
        width: 125%;
        height: 125%;
    }
    
    .sidebar {
        width: 11rem !important;
    }
    
    #content-wrapper {
        margin-left: 11rem !important;
        width: calc(100% - 11rem) !important;
    }
    
    /* Better use of horizontal space */
    .col-xl-3 {
        flex: 0 0 25% !important;
        max-width: 25% !important;
    }
    
    .col-xl-6 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }
}

/* ===== TABLE RESPONSIVENESS ===== */
@media (max-width: 768px) {
    .table-responsive {
        font-size: 0.8rem !important;
        border-radius: 0.5rem !important;
        box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075) !important;
    }
    
    .table th {
        font-size: 0.75rem !important;
        padding: 0.5rem 0.375rem !important;
        white-space: nowrap !important;
    }
    
    .table td {
        padding: 0.5rem 0.375rem !important;
        font-size: 0.8rem !important;
    }
    
    .table .btn {
        font-size: 0.7rem !important;
        padding: 0.25rem 0.5rem !important;
    }
}

/* ===== FORM RESPONSIVENESS ===== */
@media (max-width: 768px) {
    .form-control {
        font-size: 16px !important; /* Prevent iOS zoom */
        padding: 0.5rem 0.75rem !important;
        border-radius: 0.375rem !important;
    }
    
    .form-group {
        margin-bottom: 1rem !important;
    }
    
    .btn {
        font-size: 0.875rem !important;
        padding: 0.5rem 1rem !important;
        border-radius: 0.375rem !important;
        min-height: 38px !important; /* Touch-friendly */
    }
    
    .btn-primary {
        background: linear-gradient(45deg, #4e73df, #224abe) !important;
        border: none !important;
    }
    
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
    }
}

/* ===== CHART RESPONSIVENESS ===== */
@media (max-width: 768px) {
    .chart-area {
        height: 250px !important;
    }
    
    #pie_chart {
        width: 100% !important;
        height: 300px !important;
    }
    
    canvas {
        max-width: 100% !important;
        height: auto !important;
    }
}

/* ===== ALERT RESPONSIVENESS ===== */
@media (max-width: 768px) {
    .alert {
        font-size: 0.875rem !important;
        padding: 0.75rem 1rem !important;
        margin-bottom: 1rem !important;
        border-radius: 0.5rem !important;
    }
}

/* ===== PAGINATION RESPONSIVENESS ===== */
@media (max-width: 768px) {
    .pagination {
        font-size: 0.875rem !important;
        justify-content: center !important;
    }
    
    .page-link {
        padding: 0.375rem 0.5rem !important;
        min-width: 38px !important;
        text-align: center !important;
    }
}

/* ===== TOUCH OPTIMIZATIONS ===== */
@media (max-width: 768px) {
    /* Ensure all interactive elements are touch-friendly */
    .nav-link,
    .dropdown-item,
    .btn,
    .page-link,
    .close {
        min-height: 38px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Touch feedback */
    .card:active {
        transform: scale(0.98) !important;
        transition: transform 0.1s ease !important;
    }
    
    .btn:active {
        transform: scale(0.95) !important;
        transition: transform 0.1s ease !important;
    }
    
    .nav-link:active {
        background-color: rgba(255, 255, 255, 0.1) !important;
    }
}

/* ===== DEBUGGING HELPERS ===== */
@media (max-width: 768px) {
    /* Add visual indicators for debugging */
    .sidebar::before {
        content: "📱 Mobile Sidebar Active";
        position: absolute;
        top: -20px;
        left: 0;
        font-size: 10px;
        color: #28a745;
        background: rgba(40, 167, 69, 0.1);
        padding: 2px 5px;
        border-radius: 3px;
        z-index: 9999;
        display: none; /* Remove this line to see debug info */
    }
}

/* ===== FORCE VISIBILITY OVERRIDES ===== */
/* These are nuclear options to ensure sidebar is always visible */
@media (max-width: 768px) {
    .sidebar {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: relative !important;
        left: 0 !important;
        right: auto !important;
        top: 0 !important;
        bottom: auto !important;
        transform: none !important;
        -webkit-transform: none !important;
    }
    
    /* Ensure wrapper uses flexbox properly */
    #wrapper {
        display: flex !important;
        flex-direction: row !important;
    }
    
    .sidebar {
        flex: 0 0 12rem !important;
    }
    
    #content-wrapper {
        flex: 1 1 auto !important;
        margin-left: 0 !important;
        width: auto !important;
    }
}