/* Sidebar & Home Page Mobile Optimization */
/* Enhanced mobile experience for navigation and dashboard */

/* ===== MOBILE LAYOUT FIX - PREVENT CONTENT SHIFT ===== */
@media (max-width: 768px) {
    /* CRITICAL: Force content to stay in place regardless of sidebar state */
    body .main-header,
    body .content-wrapper,
    body .main-footer,
    body.sidebar-open .main-header,
    body.sidebar-open .content-wrapper,
    body.sidebar-open .main-footer,
    body.sidebar-collapse .main-header,
    body.sidebar-collapse .content-wrapper,
    body.sidebar-collapse .main-footer {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        transform: none !important;
        -webkit-transform: none !important;
        left: 0 !important;
        right: 0 !important;
        transition: none !important;
    }
    
    /* Ensure wrapper doesn't shift */
    .wrapper {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        overflow-x: hidden !important;
    }
    
    /* Prevent any inline styles from AdminLTE */
    body[style*="margin"],
    .main-header[style*="margin"],
    .content-wrapper[style*="margin"],
    .main-footer[style*="margin"] {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    /* Override AdminLTE sidebar-collapse behavior on mobile */
    body.sidebar-collapse .main-sidebar {
        transform: translateX(-280px) !important;
    }
    
    /* Ensure navbar doesn't shift */
    body.sidebar-collapse .main-header .navbar {
        margin-left: 0 !important;
    }
    
    /* Force all content to full width on mobile */
    .content-wrapper,
    .main-header,
    .main-footer {
        position: relative !important;
    }
}

/* ===== SIDEBAR MOBILE OPTIMIZATION ===== */
@media (max-width: 768px) {
    /* ===== SIDEBAR STRUCTURE ===== */
    .main-sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: 280px !important;
        height: 100vh !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        z-index: 10000 !important;
        transform: translateX(-280px) !important;
        transition: transform 0.3s ease-in-out !important;
        -webkit-overflow-scrolling: touch !important;
        box-shadow: none !important;
    }
    
    /* Sidebar open state */
    body.sidebar-open .main-sidebar {
        transform: translateX(0) !important;
        box-shadow: 5px 0 20px rgba(0,0,0,0.3) !important;
    }
    
    /* Overlay element (created by JavaScript) */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1039; /* Below Bootstrap modals (1050) and modal-backdrop (1040) */
        display: none;
        opacity: 0;
        transition: opacity 0.3s;
    }
    
    /* CRITICAL: Hide sidebar overlay when modal is open */
    body.modal-open .sidebar-overlay {
        display: none !important;
        z-index: -1 !important;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    /* ===== SIDEBAR LOGO ===== */
    .sidebar-logo {
        height: 60px !important;
        padding: 0 15px !important;
        display: flex !important;
        align-items: center !important;
        background: rgba(0,0,0,0.2) !important;
        border-bottom: 1px solid rgba(255,255,255,0.1) !important;
    }
    
    .logo-container {
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
        width: 100% !important;
    }
    
    .logo-icon {
        font-size: 24px !important;
        color: #ff3366 !important;
        flex-shrink: 0 !important;
    }
    
    .logo-text {
        display: flex !important;
        flex-direction: column !important;
        line-height: 1.2 !important;
        overflow: hidden !important;
    }
    
    .logo-main {
        font-size: 18px !important;
        font-weight: 800 !important;
        color: #fff !important;
        white-space: nowrap !important;
    }
    
    .logo-sub {
        font-size: 11px !important;
        color: rgba(255,255,255,0.7) !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    /* ===== SIDEBAR MENU ===== */
    .sidebar-menu-wrapper {
        padding: 10px 0 !important;
    }
    
    .sidebar-menu {
        list-style: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .sidebar-menu > li {
        margin-bottom: 2px !important;
    }
    
    .sidebar-menu > li > a {
        display: flex !important;
        align-items: center !important;
        padding: 14px 20px !important;
        color: rgba(255,255,255,0.8) !important;
        font-size: 15px !important;
        font-weight: 500 !important;
        text-decoration: none !important;
        border-left: 4px solid transparent !important;
        transition: all 0.2s !important;
    }
    
    .sidebar-menu > li > a i {
        font-size: 18px !important;
        width: 28px !important;
        margin-right: 12px !important;
        text-align: center !important;
        flex-shrink: 0 !important;
    }
    
    .sidebar-menu > li > a .pull-right {
        margin-left: auto !important;
        font-size: 12px !important;
    }
    
    /* Active/Hover states */
    .sidebar-menu > li.active > a,
    .sidebar-menu > li:hover > a {
        background: rgba(255,255,255,0.1) !important;
        color: #fff !important;
        border-left-color: #ff3366 !important;
    }
    
    /* Treeview (submenu) */
    .sidebar-menu > li.treeview > a::after {
        content: '\f105';
        font-family: 'Font Awesome 5 Free';
        font-weight: 900;
        margin-left: auto;
        transition: transform 0.2s;
    }
    
    .sidebar-menu > li.treeview.active > a::after {
        transform: rotate(90deg);
    }
    
    .treeview-menu {
        list-style: none !important;
        padding: 0 !important;
        margin: 0 !important;
        background: rgba(0,0,0,0.2) !important;
        max-height: 0 !important;
        overflow: hidden !important;
        transition: max-height 0.3s ease-in-out !important;
    }
    
    .treeview.active > .treeview-menu {
        max-height: 1000px !important;
    }
    
    .treeview-menu > li > a {
        display: flex !important;
        align-items: center !important;
        padding: 12px 20px 12px 60px !important;
        color: rgba(255,255,255,0.7) !important;
        font-size: 14px !important;
        text-decoration: none !important;
        transition: all 0.2s !important;
    }
    
    .treeview-menu > li > a i {
        font-size: 14px !important;
        width: 20px !important;
        margin-right: 10px !important;
        text-align: center !important;
    }
    
    .treeview-menu > li.active > a,
    .treeview-menu > li:hover > a {
        color: #fff !important;
        background: rgba(255,255,255,0.05) !important;
    }
    
    /* Badges in menu */
    .sidebar-menu .label {
        padding: 3px 8px !important;
        font-size: 11px !important;
        border-radius: 10px !important;
        margin-left: auto !important;
    }
}

/* ===== HOME PAGE / DASHBOARD MOBILE OPTIMIZATION ===== */
@media (max-width: 768px) {
    /* ===== CONTENT HEADER ===== */
    .modern-content-header {
        margin-bottom: 20px !important;
        padding: 0 !important;
    }
    
    .header-content {
        display: block !important;
        padding: 0 !important;
    }
    
    .welcome-section {
        margin-bottom: 15px !important;
    }
    
    .welcome-title {
        font-size: 22px !important;
        font-weight: 800 !important;
        color: #012e57 !important;
        margin: 0 0 8px 0 !important;
        line-height: 1.3 !important;
    }
    
    .welcome-title i {
        font-size: 20px !important;
        margin-right: 8px !important;
        color: #ff3366 !important;
    }
    
    .welcome-subtitle {
        font-size: 14px !important;
        color: #64748b !important;
        margin: 0 !important;
    }
    
    /* ===== FILTERS ROW ===== */
    .filters-row {
        margin-bottom: 20px !important;
    }
    
    .filters-row .col-md-4,
    .filters-row .col-md-8 {
        width: 100% !important;
        padding: 0 5px !important;
        margin-bottom: 10px !important;
    }
    
    .filter-group {
        background: #fff !important;
        padding: 12px !important;
        border-radius: 8px !important;
        border: 1px solid #e2e8f0 !important;
        margin-bottom: 10px !important;
    }
    
    .filter-label {
        font-size: 12px !important;
        font-weight: 700 !important;
        text-transform: uppercase !important;
        color: #64748b !important;
        margin-bottom: 8px !important;
        display: block !important;
    }
    
    .filter-label i {
        margin-right: 5px !important;
    }
    
    .btn-filter {
        width: 100% !important;
        background: #fff !important;
        border: 1px solid #e2e8f0 !important;
        padding: 12px 15px !important;
        border-radius: 8px !important;
        color: #64748b !important;
        font-weight: 600 !important;
        font-size: 14px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        text-align: left !important;
    }
    
    .btn-filter i {
        font-size: 16px !important;
    }
    
    .btn-filter:hover,
    .btn-filter:focus {
        border-color: #012e57 !important;
        color: #012e57 !important;
        background: #f8fafc !important;
    }
    
    /* ===== DASHBOARD STATS GRID ===== */
    .dashboard-stats-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 12px !important;
        margin-bottom: 20px !important;
    }
    
    /* ===== MODERN STAT CARDS ===== */
    .modern-stat-card {
        background: #fff !important;
        border-radius: 12px !important;
        padding: 16px !important;
        display: flex !important;
        align-items: center !important;
        gap: 15px !important;
        border: 1px solid #e2e8f0 !important;
        box-shadow: 0 2px 4px rgba(0,0,0,0.04) !important;
        transition: transform 0.2s, box-shadow 0.2s !important;
        margin-bottom: 0 !important;
    }
    
    .modern-stat-card:active {
        transform: scale(0.98) !important;
        box-shadow: 0 1px 2px rgba(0,0,0,0.08) !important;
    }
    
    .stat-icon {
        width: 50px !important;
        height: 50px !important;
        border-radius: 10px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 22px !important;
        flex-shrink: 0 !important;
    }
    
    .stat-content {
        display: flex !important;
        flex-direction: column !important;
        flex: 1 !important;
        min-width: 0 !important;
    }
    
    .stat-label {
        font-size: 11px !important;
        font-weight: 700 !important;
        color: #64748b !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
        margin-bottom: 4px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    .stat-value {
        font-size: 20px !important;
        font-weight: 800 !important;
        color: #012e57 !important;
        line-height: 1.2 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    .stat-value i.fa-sync {
        font-size: 16px !important;
    }
    
    /* Stat variants */
    .stat-primary .stat-icon {
        background: rgba(1,46,87,0.1) !important;
        color: #012e57 !important;
    }
    
    .stat-info .stat-icon {
        background: rgba(59,130,246,0.1) !important;
        color: #3b82f6 !important;
    }
    
    .stat-warning .stat-icon {
        background: rgba(245,158,11,0.1) !important;
        color: #f59e0b !important;
    }
    
    .stat-danger .stat-icon {
        background: rgba(255,51,102,0.1) !important;
        color: #ff3366 !important;
    }
    
    /* ===== CHARTS & TABLES ===== */
    .modern-chart-box,
    .modern-table-box {
        background: #fff !important;
        border-radius: 12px !important;
        border: 1px solid #e2e8f0 !important;
        box-shadow: 0 2px 4px rgba(0,0,0,0.04) !important;
        overflow: hidden !important;
        margin-bottom: 15px !important;
    }
    
    .modern-chart-box .box-header,
    .modern-table-box .box-header {
        background: transparent !important;
        padding: 15px !important;
        border-bottom: 1px solid #e2e8f0 !important;
    }
    
    .modern-chart-box .box-title,
    .modern-table-box .box-title {
        font-size: 16px !important;
        font-weight: 700 !important;
        color: #012e57 !important;
        display: flex !important;
        align-items: center !important;
    }
    
    .modern-chart-box .box-title i,
    .modern-table-box .box-title i {
        font-size: 18px !important;
        margin-right: 8px !important;
        color: #ff3366 !important;
    }
    
    .modern-chart-box .box-body,
    .modern-table-box .box-body {
        padding: 15px !important;
    }
    
    /* Chart container */
    .chart-container {
        position: relative !important;
        height: 250px !important;
        width: 100% !important;
    }
    
    canvas {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* ===== MODERN TABLE ===== */
    .modern-table {
        width: 100% !important;
        font-size: 13px !important;
        margin-bottom: 0 !important;
    }
    
    .modern-table thead th {
        background: #f8fafc !important;
        padding: 10px 12px !important;
        font-size: 11px !important;
        font-weight: 700 !important;
        text-transform: uppercase !important;
        color: #64748b !important;
        border-bottom: 1px solid #e2e8f0 !important;
        white-space: nowrap !important;
    }
    
    .modern-table tbody td {
        padding: 12px !important;
        border-bottom: 1px solid #e2e8f0 !important;
        vertical-align: middle !important;
        font-size: 13px !important;
        color: #1e293b !important;
    }
    
    .modern-table tbody tr:last-child td {
        border-bottom: none !important;
    }
    
    /* Make table scrollable */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* ===== WIDGETS ===== */
    .widget {
        margin-bottom: 15px !important;
    }
    
    /* ===== ROW SPACING ===== */
    .row {
        margin-left: -5px !important;
        margin-right: -5px !important;
    }
    
    .row > [class*="col-"] {
        padding-left: 5px !important;
        padding-right: 5px !important;
    }
    
    /* ===== ANIMATIONS ===== */
    @keyframes slideUpFade {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    .dashboard-stats-grid > div {
        animation: slideUpFade 0.4s ease-out forwards;
        opacity: 0;
    }
    
    .dashboard-stats-grid > div:nth-child(1) { animation-delay: 0.05s; }
    .dashboard-stats-grid > div:nth-child(2) { animation-delay: 0.1s; }
    .dashboard-stats-grid > div:nth-child(3) { animation-delay: 0.15s; }
    .dashboard-stats-grid > div:nth-child(4) { animation-delay: 0.2s; }
    .dashboard-stats-grid > div:nth-child(5) { animation-delay: 0.25s; }
    .dashboard-stats-grid > div:nth-child(6) { animation-delay: 0.3s; }
    .dashboard-stats-grid > div:nth-child(7) { animation-delay: 0.35s; }
}

/* ===== TABLET (768px - 1024px) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .dashboard-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
    }
    
    .modern-stat-card {
        padding: 18px !important;
    }
    
    .stat-icon {
        width: 54px !important;
        height: 54px !important;
        font-size: 24px !important;
    }
    
    .stat-value {
        font-size: 22px !important;
    }
}

/* ===== LANDSCAPE MODE ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .dashboard-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    
    .modern-stat-card {
        padding: 12px !important;
    }
    
    .stat-icon {
        width: 45px !important;
        height: 45px !important;
        font-size: 20px !important;
    }
    
    .stat-label {
        font-size: 10px !important;
    }
    
    .stat-value {
        font-size: 18px !important;
    }
    
    .chart-container {
        height: 200px !important;
    }
}
