/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Tajawal', 'Segoe UI', sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 17px;
}

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
    color: var(--text-primary);
}

a {
    text-decoration: none;
    color: var(--primary-color);
}

a:hover {
    color: var(--primary-hover);
}

ul {
    list-style: none;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-primary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease-in-out;
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: 1000;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.05);
}

/* Enhanced Logo Area */
.sidebar-header-modern {
    padding: 1.5rem;
    background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 45px;
    height: 45px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.logo-text {
    flex: 1;
}

.logo-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    margin-bottom: 0.125rem;
}

.logo-subtitle {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
}

/* User Profile Card */
.user-profile-card {
    margin: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border: 1px solid var(--border-color);
    transition: all 0.3s;
}

.user-profile-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.user-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.75rem;
    flex-shrink: 0;
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    padding: 0.5rem;
    overflow-y: auto;
}

/* Custom Scrollbar for Sidebar */
.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Navigation Sections */
.nav-section {
    margin-bottom: 0.5rem;
}

.nav-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1rem;
    margin: 0.5rem 0.75rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    background-color: #f1f5f9; /* Distinct background for header */
    color: var(--text-primary); /* Darker text for header */
    font-weight: 700;
}

.nav-section.collapsible .nav-section-header:hover {
    background-color: #e2e8f0; /* Darker on hover */
    color: var(--primary-color);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.section-title i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    opacity: 0.8;
}

.section-arrow {
    font-size: 0.7rem;
    opacity: 0.7;
    transition: transform 0.3s ease;
}

.nav-section.collapsible.open .section-arrow {
    transform: rotate(180deg);
}

/* Non-collapsible headers (like "Main") */
.nav-section:not(.collapsible) .nav-section-header {
    cursor: default;
    background: none !important;
    padding-left: 1rem;
    margin-bottom: 0.25rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    opacity: 0.8;
}

.nav-section-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
}

.nav-section.collapsible.open .nav-section-content {
    max-height: 800px; /* Arbitrary large height */
    opacity: 1;
    transition: max-height 0.4s ease-in-out, opacity 0.3s ease-in;
}

/* Indent items inside sections */
.nav-section .nav-item {
    padding-right: 0.5rem; /* Indent in RTL */
}

.nav-item {
    margin-bottom: 2px;
}

/* Navigation Links */
.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    margin: 0 0.75rem;
    color: var(--text-secondary);
    border-radius: 12px; /* Modern Pill Shape */
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    border: 1px solid transparent;
}

.nav-link::before {
    display: none; /* Remove old border strip */
}

.nav-link:hover {
    background-color: var(--bg-secondary);
    color: var(--primary-color);
    transform: translateX(-3px); /* RTL move left */
}

.nav-link.active {
    background-color: rgba(37, 99, 235, 0.1); /* Soft primary tint */
    color: var(--primary-color);
    font-weight: 700;
    border: 1px solid rgba(37, 99, 235, 0.2);
}

.nav-link span {
    font-size: 0.95rem;
    font-weight: 500;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-link.active span {
    font-weight: 700;
}

/* Navigation Icons */
.nav-icon {
    margin-left: 0.75rem;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    border-radius: 8px;
    transition: all 0.2s;
}

.nav-link:hover .nav-icon {
    background-color: white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.nav-link.active .nav-icon {
    background-color: var(--primary-color);
}

.nav-link.active .nav-icon i {
    color: white !important; /* Force icon white in active state */
}

/* Colored Icons */
.nav-icon-success i {
    color: var(--success-color);
}

.nav-icon-danger i {
    color: var(--danger-color);
}

.nav-icon-warning i {
    color: var(--warning-color);
}

.nav-icon-primary i {
    color: var(--primary-color);
}

.nav-icon-info i {
    color: var(--info-color);
}

/* Enhanced Footer */
.sidebar-footer-modern {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.footer-content {
    text-align: center;
}

.version-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.version-info i {
    font-size: 0.75rem;
}

.copyright {
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.7;
}

/* Old Sidebar Header - Keep for backwards compatibility */
.sidebar-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo {
    font-weight: bold;
    font-size: 1.25rem;
    color: var(--primary-color);
}

.sidebar-footer {
    padding: var(--spacing-md);
    border-top: 1px solid var(--border-color);
}

/* ============================================
   DARK MODE SUPPORT FOR SIDEBAR
   ============================================ */

/* Sidebar Dark Mode */
[data-theme="dark"] .sidebar {
    background: var(--bg-primary);
    border-left-color: var(--border-color);
    box-shadow: -2px 0 15px rgba(0, 0, 0, 0.3);
}

/* Logo Area Dark Mode */
[data-theme="dark"] .sidebar-header-modern {
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
    border-bottom-color: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .logo-icon {
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* User Profile Card Dark Mode */
[data-theme="dark"] .user-profile-card {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
}

[data-theme="dark"] .user-profile-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .user-avatar {
    background: linear-gradient(135deg, #1e40af, #1e3a8a);
}

[data-theme="dark"] .user-name {
    color: var(--text-primary);
}

[data-theme="dark"] .user-role {
    color: var(--text-muted);
}

/* Navigation Dark Mode */
[data-theme="dark"] .nav-section-header {
    background-color: rgba(255, 255, 255, 0.03); /* Subtle background in dark mode */
    color: var(--text-secondary);
}

[data-theme="dark"] .nav-section.collapsible .nav-section-header:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

[data-theme="dark"] .nav-link {
    color: var(--text-secondary);
}

[data-theme="dark"] .nav-link:hover {
    background-color: rgba(255,255,255,0.05);
    color: var(--text-primary);
}

[data-theme="dark"] .nav-link.active {
    background-color: rgba(37, 99, 235, 0.2);
    color: #60a5fa; /* Lighter blue for dark mode */
    border-color: rgba(37, 99, 235, 0.3);
    box-shadow: none;
}

[data-theme="dark"] .nav-link:hover .nav-icon {
    background-color: rgba(255,255,255,0.1);
}

[data-theme="dark"] .nav-link.active .nav-icon {
    background-color: #60a5fa;
    color: #0f172a !important; /* Dark icon on light active pill */
}

[data-theme="dark"] .nav-link.active .nav-icon i {
    color: #0f172a !important;
}

/* Footer Dark Mode */
[data-theme="dark"] .sidebar-footer-modern {
    background: var(--bg-tertiary);
    border-top-color: var(--border-color);
}

[data-theme="dark"] .version-info,
[data-theme="dark"] .copyright {
    color: var(--text-muted);
}

/* Scrollbar Dark Mode */
[data-theme="dark"] .sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--border-color);
}

[data-theme="dark"] .sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-right: 280px; /* RTL - Updated to match new sidebar width */
    padding: var(--spacing-xl);
    transition: margin-right 0.3s;
    width: 100%;
}

/* Header */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-xl);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

/* Cards */
.card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Grid System (Simple) */
.grid {
    display: grid;
    gap: var(--spacing-lg);
}

.grid-cols-1 { grid-template-columns: repeat(1, 1fr); }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

/* Forms */
.form-group {
    margin-bottom: var(--spacing-md);
}

.form-label {
    display: block;
    margin-bottom: var(--spacing-xs);
    font-weight: 500;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    gap: var(--spacing-sm);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--bg-primary);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
}

.table th, .table td {
    padding: var(--spacing-md);
    text-align: right; /* RTL */
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background-color: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-secondary);
}

.table tr:last-child td {
    border-bottom: none;
}

/* Utilities */
.text-success { color: var(--success-color) !important; }
.text-danger { color: var(--danger-color) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-info { color: #0ea5e9 !important; }

/* Dark Mode Overrides for Bootstrap Utilities */
[data-theme="dark"] .table-light {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .table-light th,
[data-theme="dark"] .table-light td {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .bg-light,
[data-theme="dark"] .bg-white {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .text-dark {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .border-light {
    border-color: var(--border-color) !important;
}

/* Dark Mode Forms */
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .form-check-input {
    background-color: var(--bg-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .form-check-input:checked {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

/* Dark Mode Lists */
[data-theme="dark"] .list-group-item {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

/* Dark Mode Modals */
[data-theme="dark"] .modal-content {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer {
    border-color: var(--border-color);
}

[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Dark Mode Dropdowns */
[data-theme="dark"] .dropdown-menu {
    background-color: var(--bg-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .dropdown-item {
    color: var(--text-primary);
}

[data-theme="dark"] .dropdown-item:hover {
    background-color: var(--bg-tertiary);
}

/* Dark Mode - Additional Specificity for Stubborn Elements */
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] h5,
[data-theme="dark"] h6 {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .card-header h1,
[data-theme="dark"] .card-header h2,
[data-theme="dark"] .card-header h3,
[data-theme="dark"] .card-header h4,
[data-theme="dark"] .card-header h5,
[data-theme="dark"] .card-header h6 {
    color: var(--text-primary) !important;
}

[data-theme="dark"] label,
[data-theme="dark"] .form-label {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .form-check-label {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .form-check-label strong {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .alert {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .alert-danger {
    background-color: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border-color: #dc2626;
}

[data-theme="dark"] .alert-success {
    background-color: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
    border-color: #059669;
}

[data-theme="dark"] .btn-outline-secondary {
    color: var(--text-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .btn-outline-secondary:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

[data-theme="dark"] .sticky-top {
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] span,
[data-theme="dark"] .fw-bold {
    color: inherit;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background-color: #dcfce7; color: #166534; }
.badge-danger { background-color: #fee2e2; color: #991b1b; }
.badge-warning { background-color: #fef3c7; color: #92400e; }
.badge-info { background-color: #e0f2fe; color: #075985; }
.badge-secondary { background-color: #f1f5f9; color: #475569; }

.d-md-none { display: none; }

/* Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 900;
}

/* Responsive */
@media (max-width: 768px) {
    .d-md-none { display: inline-flex; }
    
    .sidebar {
        width: 280px;
        transform: translateX(100%);
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    .main-content {
        margin-right: 0;
        padding: var(--spacing-md);
    }
    
    .grid-cols-2, .grid-cols-3, .grid-cols-4 {
        grid-template-columns: 1fr;
    }
    
    .top-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .top-header > div {
        width: 100%;
        justify-content: space-between;
    }
    
    .user-menu {
        width: 100%;
        justify-content: space-between;
    }
    
    /* Adjust user profile card for mobile */
    .user-profile-card {
        margin: 0.75rem;
        padding: 0.75rem;
    }
    
    .user-avatar {
        width: 38px;
        height: 38px;
        font-size: 1.5rem;
    }
    
    .user-name {
        font-size: 0.85rem;
    }
    
    .user-role {
        font-size: 0.7rem;
    }
    
    /* Adjust navigation for mobile */
    .nav-section-header {
        padding: 0.4rem 0.75rem;
        font-size: 0.7rem;
    }
    
    .nav-link {
        padding: 0.65rem 0.75rem;
    }
    
    .nav-link span {
        font-size: 0.9rem;
    }
}

/* ============================================
   ENHANCED MOBILE RESPONSIVE STYLES
   ============================================ */

/* Small tablets and large phones (600px - 768px) */
@media (max-width: 768px) and (min-width: 600px) {
    .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
    
    .chart-container { height: 280px; }
    .chart-container-sm { height: 220px; }
}

/* Mobile phones (< 600px) */
@media (max-width: 600px) {
    /* KPI Cards - Stack vertically on mobile */
    .grid-cols-4,
    .grid-cols-3,
    .grid-cols-2 {
        grid-template-columns: 1fr;
    }
    
    /* Reduce KPI card padding */
    .kpi-card {
        padding: 1rem;
    }
    
    .kpi-value {
        font-size: 1.35rem;
    }
    
    .kpi-icon {
        font-size: 2rem;
    }
    
    /* Chart containers - reduce height */
    .chart-container {
        height: 250px;
        padding: 0.5rem;
    }
    
    .chart-container-sm {
        height: 200px;
    }
    
    /* Cards - reduce spacing */
    .card {
        padding: var(--spacing-md);
        margin-bottom: var(--spacing-md);
    }
    
    .card-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start !important;
    }
    
    .card-header .d-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    /* Permission Grid */
    .permission-grid {
        grid-template-columns: 1fr;
    }
    
    .permission-card {
        margin-bottom: 1rem;
    }
    
    .permission-page {
        padding: 1rem;
    }
    
    /* Role tabs scroll horizontally */
    .role-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 0.5rem;
        -webkit-overflow-scrolling: touch;
    }
    
    .role-tab {
        flex-shrink: 0;
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
    
    /* Form layouts */
    .row.g-2 > [class*="col-md-"],
    .row.g-3 > [class*="col-md-"],
    .row.g-4 > [class*="col-md-"] {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    /* Buttons - larger touch targets */
    .btn {
        padding: 0.75rem 1rem;
        min-height: 44px;
    }
    
    .btn-sm {
        padding: 0.5rem 0.75rem;
        min-height: 38px;
    }
    
    /* Action buttons in tables */
    td .btn-sm {
        padding: 0.4rem 0.6rem;
        margin-bottom: 0.25rem;
    }
    
    /* Tables - allow text wrapping */
    .table {
        white-space: normal;
    }
    
    .table th,
    .table td {
        padding: var(--spacing-sm);
        font-size: 0.85rem;
    }
    
    /* Hide less important columns on mobile */
    .table .hide-mobile {
        display: none;
    }
    
    /* Alert widgets */
    .alert-widget {
        padding: 0.75rem;
    }
    
    .alert-widget-icon {
        font-size: 1.25rem;
        margin-left: 0.75rem;
    }
    
    /* Page headers */
    .d-flex.justify-content-between {
        flex-direction: column;
        gap: 1rem;
    }
    
    h2, .h2 {
        font-size: 1.35rem;
    }
    
    h4, .h4 {
        font-size: 1.1rem;
    }
    
    /* Stats cards */
    .col-md-4, .col-md-3 {
        margin-bottom: 1rem;
    }
    
    /* Save button wrapper */
    .save-btn-wrapper {
        bottom: 1rem;
    }
    
    .save-btn {
        width: 100%;
        padding: 0.875rem 2rem;
        font-size: 1rem;
    }
    
    /* Bulk actions */
    .bulk-actions {
        flex-wrap: wrap;
    }
    
    .bulk-btn {
        flex: 1;
        min-width: 45%;
        text-align: center;
    }
    
    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .page-link {
        padding: 0.5rem 0.75rem;
    }
    
    /* Modal adjustments */
    .modal-dialog {
        margin: 0.5rem;
    }
    
    /* Card header buttons group */
    .card-header > div {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-top: 0.5rem;
        width: 100%;
    }
    
    .card-header > div > .btn {
        flex: 1 1 auto;
        min-width: max-content;
        text-align: center;
    }
    
    /* Action buttons in tables - wrap nicely */
    td > .btn,
    td > a.btn {
        margin: 0.125rem;
    }
    
    /* Trend indicators */
    .trend-indicator {
        font-size: 0.75rem;
        padding: 0.2rem 0.4rem;
    }
}

/* Extra small devices (< 400px) */
@media (max-width: 400px) {
    body {
        font-size: 15px;
    }
    
    .kpi-value {
        font-size: 1.2rem;
    }
    
    .page-title {
        font-size: 1.1rem;
    }
    
    .btn {
        font-size: 0.875rem;
    }
    
    /* Stack action buttons vertically */
    td .btn-sm {
        display: block;
        width: 100%;
        margin-bottom: 0.25rem;
    }
    
    .permission-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .custom-checkbox {
        align-self: flex-end;
    }
}

/* Touch-friendly improvements */
@media (pointer: coarse) {
    /* Larger touch targets */
    .btn, 
    .nav-link, 
    .form-control, 
    .form-select,
    .custom-checkbox {
        min-height: 44px;
    }
    
    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
    }
    
    /* More spacing for tappable items */
    .nav-item {
        margin-bottom: 0.375rem;
    }
    
    .permission-item {
        padding: 1rem 0;
    }
}

/* Landscape mode on mobile */
@media (max-height: 500px) and (max-width: 900px) {
    .sidebar {
        width: 240px;
    }
    
    .sidebar-header-modern {
        padding: 0.75rem;
    }
    
    .user-profile-card {
        padding: 0.5rem;
        margin: 0.5rem;
    }
    
    .chart-container {
        height: 200px;
    }
}

/* Print Styles */
@media print {
    .sidebar, 
    .top-header, 
    .no-print,
    .btn {
        display: none !important;
    }

    .main-content {
        margin-right: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .app-container {
        display: block !important;
    }

    body {
        background-color: white !important;
        color: black !important;
    }

    .card {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin-bottom: 20px !important;
        break-inside: avoid;
    }

    .card-header {
        border-bottom: 2px solid #000 !important;
    }

    .table th {
        background-color: #f0f0f0 !important;
        color: #000 !important;
        border: 1px solid #000 !important;
    }

    .table td {
        border: 1px solid #000 !important;
    }

    /* Ensure text colors print correctly */
    .text-success { color: #166534 !important; }
    .text-danger { color: #991b1b !important; }
}

/* ============================================
   ENHANCED SIDEBAR STYLING
   ============================================ */

/* Section Separators */
.nav-section {
    position: relative;
    padding-bottom: 0.5rem;
}

.nav-section:not(:last-child)::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 1rem;
    right: 1rem;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-color), transparent);
}

/* Section Header Icons with Colors */
.nav-section-header .section-title i {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 0.9rem;
}

/* Color-coded Section Icons */
.nav-section:nth-child(2) .nav-section-header .section-title i { /* العقارات */
    background: rgba(37, 99, 235, 0.15);
    color: #2563eb;
}

.nav-section:nth-child(3) .nav-section-header .section-title i { /* الحجوزات */
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.nav-section:nth-child(4) .nav-section-header .section-title i { /* الملاك */
    background: rgba(139, 92, 246, 0.15);
    color: #8b5cf6;
}

.nav-section:nth-child(6) .nav-section-header .section-title i { /* المالية */
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.nav-section:nth-child(7) .nav-section-header .section-title i { /* التقارير */
    background: rgba(236, 72, 153, 0.15);
    color: #ec4899;
}

.nav-section:nth-child(8) .nav-section-header .section-title i { /* النظام */
    background: rgba(107, 114, 128, 0.15);
    color: #6b7280;
}

/* Smooth Hover Animation */
.nav-section-header {
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-section.collapsible .nav-section-header:hover {
    transform: translateX(-2px);
}

/* Enhanced Active State */
.nav-link.active {
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.15);
}

/* Improved Content Animation */
.nav-section-content {
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.25s ease-in-out,
                padding 0.25s ease;
    padding: 0;
}

.nav-section.collapsible.open .nav-section-content {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

/* Maintenance Item Special Styling */
.nav-section:not(.collapsible) .nav-link {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.05), rgba(245, 158, 11, 0.1));
    border: 1px solid rgba(245, 158, 11, 0.15);
}

.nav-section:not(.collapsible) .nav-link:hover {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(245, 158, 11, 0.15));
    border-color: rgba(245, 158, 11, 0.25);
}

/* Dark Mode Enhancements */
[data-theme="dark"] .nav-section:not(:last-child)::after {
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
}

[data-theme="dark"] .nav-section-header .section-title i {
    opacity: 0.9;
}

[data-theme="dark"] .nav-link.active {
    box-shadow: 0 2px 8px rgba(96, 165, 250, 0.2);
}

[data-theme="dark"] .nav-section:not(.collapsible) .nav-link {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.08), rgba(245, 158, 11, 0.12));
    border-color: rgba(245, 158, 11, 0.2);
}
