/* ============================================
   ADMIN PANEL MOBILE OPTIMIZATION
   Load AFTER admin.css
   ============================================ */

/* ============================================
   SIDEBAR FIX - MOBILE
   ============================================ */

/* Hide sidebar by default on mobile */
@media (max-width: 768px) {
    .admin-sidebar {
        position: fixed !important;
        top: 0 !important;
        left: -280px !important;
        width: 280px !important;
        height: 100vh !important;
        z-index: 1000 !important;
        transition: left 0.3s ease !important;
        box-shadow: 2px 0 10px rgba(0,0,0,0.3) !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .admin-sidebar.open {
        left: 0 !important;
    }

    /* Sidebar overlay */
    .admin-sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .admin-sidebar-overlay.active {
        display: block;
    }

    /* X Close button */
    .admin-sidebar-close {
        display: flex !important;
        position: absolute;
        top: 1rem;
        right: 1rem;
        background: rgba(255,255,255,0.1);
        border: 1px solid #475569;
        color: #f1f5f9;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        font-size: 20px;
        transition: all 0.2s ease;
        z-index: 1001;
    }

    .admin-sidebar-close:hover {
        background: rgba(239, 68, 68, 0.2);
        border-color: #ef4444;
    }

    /* Main content full width */
    .admin-main {
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* Show menu toggle */
    .admin-menu-toggle {
        display: flex !important;
    }
}

/* Desktop: hide close button and overlay */
@media (min-width: 769px) {
    .admin-sidebar-close {
        display: none !important;
    }
    
    .admin-sidebar-overlay {
        display: none !important;
    }
    
    .admin-menu-toggle {
        display: none !important;
    }
}

/* ============================================
   SIDEBAR CONTENT FIX - SCATTERED ITEMS
   ============================================ */

/* Fix sidebar header spacing */
.admin-sidebar .sidebar-header {
    padding: 1.25rem 1rem !important;
    border-bottom: 1px solid #334155;
    position: relative;
}

.admin-sidebar .sidebar-header .logo {
    margin-right: 40px; /* Space for X button on mobile */
}

/* Fix navigation groups */
.admin-sidebar .nav-group {
    margin-bottom: 0.5rem !important;
    padding: 0.5rem 0 !important;
}

.admin-sidebar .nav-group-title {
    padding: 0.5rem 1.5rem !important;
    margin-bottom: 0.25rem !important;
    font-size: 10px !important;
    letter-spacing: 1.5px !important;
    color: #64748b !important;
    text-transform: uppercase !important;
    font-weight: 700 !important;
}

/* Fix navigation items - prevent scattering */
.admin-sidebar .nav-item {
    display: flex !important;
    align-items: center !important;
    padding: 0.75rem 1.5rem !important;
    margin: 0 !important;
    border-radius: 0 !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    transition: all 0.2s ease !important;
}

.admin-sidebar .nav-item:hover {
    background: #334155 !important;
}

.admin-sidebar .nav-item.active {
    background: #334155 !important;
    border-left: 3px solid #3b82f6 !important;
    padding-left: calc(1.5rem - 3px) !important;
}

/* Make nav scrollable on mobile */
.admin-sidebar .admin-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0.5rem 0;
}

/* Hide scrollbar on mobile sidebar */
@media (max-width: 768px) {
    .admin-sidebar .admin-nav::-webkit-scrollbar {
        width: 6px;
    }
    
    .admin-sidebar .admin-nav::-webkit-scrollbar-track {
        background: #1e293b;
    }
    
    .admin-sidebar .admin-nav::-webkit-scrollbar-thumb {
        background: #475569;
        border-radius: 3px;
    }
}

/* Fix sidebar footer */
.admin-sidebar-footer {
    padding: 1rem !important;
    border-top: 1px solid #334155;
    margin-top: auto;
}

.admin-sidebar-footer .admin-info {
    margin-bottom: 0.75rem;
    text-align: center;
}

.admin-sidebar-footer #adminName {
    display: block;
    font-weight: 600;
    font-size: 14px;
    color: #f1f5f9;
    margin-bottom: 2px;
}

.admin-sidebar-footer .admin-role {
    font-size: 11px;
    color: #64748b;
}

/* ============================================
   ADMIN HEADER - MOBILE
   ============================================ */

.admin-header {
    display: flex !important;
    align-items: center !important;
    gap: 0.75rem !important;
    padding: 1rem !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 50 !important;
}

@media (max-width: 768px) {
    .admin-header {
        flex-wrap: wrap !important;
        padding: 0.75rem 1rem !important;
    }

    .admin-header h1 {
        font-size: 1.25rem !important;
        flex: 1;
        margin: 0 !important;
    }

    .admin-header-actions {
        width: 100%;
        order: 3;
    }

    .admin-search {
        width: 100% !important;
    }

    .admin-search input {
        width: 100% !important;
        font-size: 14px !important;
    }
}

/* Menu toggle button */
.admin-menu-toggle {
    display: none;
    background: none;
    border: 1px solid #475569;
    color: #f1f5f9;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
    flex-shrink: 0;
}

/* ============================================
   ADMIN SECTIONS - MOBILE
   ============================================ */

.admin-section {
    padding: 1rem !important;
    width: 100% !important;
    overflow-x: hidden !important;
}

@media (max-width: 768px) {
    .admin-section {
        padding: 0.75rem !important;
    }
}

/* ============================================
   STATS GRID - MOBILE
   ============================================ */

.stats-grid {
    display: grid !important;
    gap: 0.75rem !important;
    width: 100% !important;
}

@media (min-width: 1025px) {
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    padding: 1rem !important;
    width: 100% !important;
}

.stat-card .stat-icon {
    font-size: 24px !important;
    width: 44px !important;
    height: 44px !important;
}

.stat-card .stat-value {
    font-size: 1.25rem !important;
}

.stat-card .stat-label {
    font-size: 11px !important;
}

/* ============================================
   ADMIN GRID - MOBILE
   ============================================ */

.admin-grid {
    display: grid !important;
    gap: 1rem !important;
    width: 100% !important;
}

@media (min-width: 769px) {
    .admin-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .admin-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   ADMIN CARDS - MOBILE
   ============================================ */

.admin-card {
    width: 100% !important;
    max-width: 100% !important;
    padding: 1rem !important;
    overflow: hidden !important;
}

@media (max-width: 768px) {
    .admin-card {
        padding: 0.875rem !important;
    }

    .admin-card h3 {
        font-size: 1rem !important;
        margin-bottom: 0.75rem !important;
    }
}

/* ============================================
   ADMIN TOOLBAR - MOBILE
   ============================================ */

.admin-toolbar {
    display: flex !important;
    gap: 0.5rem !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    margin-bottom: 1rem !important;
}

@media (max-width: 768px) {
    .admin-toolbar {
        flex-direction: column !important;
    }

    .admin-toolbar input,
    .admin-toolbar select {
        width: 100% !important;
        font-size: 14px !important;
        min-height: 40px !important;
    }

    .admin-toolbar button {
        width: 100% !important;
    }
}

/* ============================================
   ADMIN TABLES - MOBILE
   ============================================ */

.table-responsive {
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100% !important;
    min-width: 600px !important;
    font-size: 12px !important;
}

@media (max-width: 768px) {
    .data-table th,
    .data-table td {
        padding: 8px 10px !important;
        font-size: 11px !important;
    }

    .data-table th {
        font-size: 10px !important;
    }
}

/* ============================================
   ACTION BUTTONS - MOBILE
   ============================================ */

.action-buttons {
    display: flex !important;
    gap: 0.25rem !important;
    flex-wrap: wrap !important;
}

@media (max-width: 768px) {
    .action-buttons {
        flex-direction: column !important;
        width: 100% !important;
    }

    .action-buttons .btn {
        width: 100% !important;
        font-size: 11px !important;
        padding: 6px 10px !important;
    }
}

/* ============================================
   ADMIN FORMS - MOBILE
   ============================================ */

.admin-card .form-group {
    width: 100% !important;
    margin-bottom: 0.875rem !important;
}

.admin-card .form-row {
    display: grid !important;
    gap: 0.75rem !important;
    width: 100% !important;
}

@media (min-width: 769px) {
    .admin-card .form-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .admin-card .form-row {
        grid-template-columns: 1fr;
    }
}

.admin-card .form-group input,
.admin-card .form-group select,
.admin-card .form-group textarea {
    width: 100% !important;
    font-size: 14px !important;
    min-height: 40px !important;
}

/* ============================================
   SEARCH RESULTS DROPDOWN - MOBILE
   ============================================ */

.search-results {
    position: absolute !important;
    width: calc(100% - 2rem) !important;
    max-width: 400px !important;
    max-height: 200px !important;
    z-index: 100 !important;
}

.search-results .search-result-item {
    padding: 10px 14px !important;
    font-size: 13px !important;
}

/* ============================================
   SIMULATION GRID - MOBILE
   ============================================ */

.simulation-grid {
    display: grid !important;
    gap: 1rem !important;
    width: 100% !important;
}

@media (min-width: 769px) {
    .simulation-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .simulation-grid {
        grid-template-columns: 1fr;
    }
}

.sim-category {
    width: 100% !important;
}

.sim-category .btn-sim {
    width: 100% !important;
    margin-bottom: 0.5rem !important;
    justify-content: flex-start !important;
}

/* ============================================
   HEALTH INDICATORS - MOBILE
   ============================================ */

.health-indicators {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
    width: 100% !important;
}

.health-item {
    width: 100% !important;
    padding: 0.75rem 1rem !important;
}

/* ============================================
   USER DETAIL GRID - MOBILE
   ============================================ */

.user-detail-grid {
    display: grid !important;
    gap: 1rem !important;
    width: 100% !important;
}

@media (min-width: 769px) {
    .user-detail-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .user-detail-grid {
        grid-template-columns: 1fr;
    }
}

.user-info-card {
    width: 100% !important;
    padding: 1rem !important;
}

/* ============================================
   MODALS - MOBILE ADMIN
   ============================================ */

@media (max-width: 768px) {
    .modal {
        width: 95% !important;
        max-width: 95% !important;
        padding: 1.25rem !important;
    }

    .modal-lg {
        max-width: 95% !important;
    }

    .modal-header h3 {
        font-size: 1.1rem !important;
    }
}

/* ============================================
   BUTTONS - TOUCH FRIENDLY
   ============================================ */

.admin-card .btn {
    min-height: 40px !important;
    font-size: 13px !important;
}

.admin-card .btn-sm {
    min-height: 32px !important;
    font-size: 11px !important;
}

@media (max-width: 768px) {
    .admin-card .btn {
        min-height: 44px !important;
        font-size: 14px !important;
    }
}

/* ============================================
   ULTRA SMALL SCREENS (230px - 480px)
   ============================================ */

@media (max-width: 480px) {
    .admin-section {
        padding: 0.5rem !important;
    }

    .admin-card {
        padding: 0.75rem !important;
    }

    .admin-card h3 {
        font-size: 0.9rem !important;
    }

    .stat-card {
        padding: 0.75rem !important;
    }

    .stat-card .stat-value {
        font-size: 1rem !important;
    }

    .stat-card .stat-icon {
        width: 36px !important;
        height: 36px !important;
        font-size: 18px !important;
    }

    .admin-header h1 {
        font-size: 1.1rem !important;
    }

    .data-table {
        font-size: 10px !important;
    }

    .data-table th,
    .data-table td {
        padding: 6px 8px !important;
    }
}

@media (max-width: 320px) {
    .admin-sidebar {
        width: 260px !important;
    }

    .admin-sidebar .nav-item {
        padding: 0.625rem 1rem !important;
        font-size: 13px !important;
    }

    .stat-card .stat-value {
        font-size: 0.9rem !important;
    }
}

@media (max-width: 280px) {
    .admin-sidebar {
        width: 240px !important;
    }

    .admin-sidebar .nav-group-title {
        font-size: 9px !important;
        padding: 0.375rem 1rem !important;
    }

    .admin-sidebar .nav-item {
        font-size: 12px !important;
        padding: 0.5rem 1rem !important;
    }
}

/* ============================================
   LANDSCAPE MODE
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
    .admin-sidebar {
        height: 100vh !important;
    }

    .admin-sidebar .admin-nav {
        max-height: calc(100vh - 200px);
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* ============================================
   SCROLL FIX
   ============================================ */

.admin-main {
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
}

.admin-section {
    overflow-x: hidden !important;
}

/* Prevent body scroll when sidebar is open */
body.admin-sidebar-open {
    overflow: hidden !important;
}