/* Arabic text styling */
[dir="rtl"] input, [dir="rtl"] textarea, [dir="rtl"] select,
.name-ar, .description-ar, [name$="_ar"] {
    font-family: 'Cairo', 'Inter', sans-serif;
}

/* AI-filled field highlight animation */
@keyframes aiHighlight {
    0% { box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.5); }
    100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}
.ai-filled {
    animation: aiHighlight 1.5s ease;
}

/* Dark Mode (Phase 22) */
body.dark-mode {
    --bs-body-bg: #0f172a;
    --bs-body-color: #e2e8f0;
    --bs-border-color: #334155;
    background-color: #0f172a !important;
    color: #e2e8f0;
}
body.dark-mode .card,
body.dark-mode .modal-content,
body.dark-mode .dropdown-menu {
    background-color: #1e293b !important;
    border-color: #334155 !important;
    color: #e2e8f0 !important;
}
body.dark-mode .card-header,
body.dark-mode .card-footer,
body.dark-mode .table-light,
body.dark-mode thead.table-light tr,
body.dark-mode .table-light th {
    background-color: #273548 !important;
    color: #e2e8f0 !important;
    border-color: #334155 !important;
}
body.dark-mode .table {
    color: #e2e8f0;
    border-color: #334155;
}
body.dark-mode .table tbody tr:hover td {
    background-color: #1e293b;
}
body.dark-mode .form-control,
body.dark-mode .form-select,
body.dark-mode .input-group-text {
    background-color: #1e293b !important;
    border-color: #475569 !important;
    color: #e2e8f0 !important;
}
body.dark-mode .sidebar {
    background: #0f172a !important;
    border-color: #334155 !important;
}
body.dark-mode .sidebar .nav-link,
body.dark-mode .sidebar .nav-text {
    color: #cbd5e1 !important;
}
body.dark-mode .sidebar .nav-item.active .nav-link,
body.dark-mode .sidebar .nav-link:hover {
    background: #1e3a5f !important;
}
body.dark-mode .alert-info { background-color: #1e3a5f; border-color: #3b82f6; color: #93c5fd; }
body.dark-mode .alert-success { background-color: #14532d; border-color: #16a34a; color: #86efac; }
body.dark-mode .alert-warning { background-color: #451a03; border-color: #d97706; color: #fde68a; }
body.dark-mode .alert-danger { background-color: #450a0a; border-color: #dc2626; color: #fca5a5; }
body.dark-mode .text-muted { color: #94a3b8 !important; }
body.dark-mode a { color: #60a5fa; }
body.dark-mode a:hover { color: #93c5fd; }
body.dark-mode #darkModeIcon::before { content: "\f185"; } /* fa-sun */

/* Accessibility: Skip link */
.visually-hidden-focusable {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.visually-hidden-focusable:focus {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 9999;
    width: auto;
    height: auto;
    padding: 0.75rem 1.5rem;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    background: #1e293b;
    color: #ffffff;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    text-decoration: none;
}

/* Professional Sidebar Layout */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 0;
    background: #f8fafc;
}

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Professional Sidebar */
.sidebar {
    width: 280px;
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: white;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 1000;
    overflow-y: auto;
    transition: all 0.3s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
}

.sidebar.collapsed {
    width: 80px;
}

/* Logo Section */
.sidebar-logo {
    padding: 2rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sidebar-logo .logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-logo .logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    white-space: nowrap;
    transition: opacity 0.3s ease;
}

.sidebar.collapsed .logo-text {
    opacity: 0;
}

/* User Profile Section */
.sidebar-user {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-avatar {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.user-details {
    flex: 1;
    transition: opacity 0.3s ease;
}

.sidebar.collapsed .user-details {
    opacity: 0;
}

.user-name {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

.user-role {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
}

/* Navigation Menu */
.sidebar-nav {
    padding: 0.75rem 0 1rem;
}

.nav-section {
    margin-bottom: 1rem;
    padding-top: 0.25rem;
}

.nav-section-title {
    padding: 0.45rem 1rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    transition: opacity 0.3s ease;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(90deg, rgba(148, 163, 184, 0.12), rgba(148, 163, 184, 0));
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.nav-section-title:hover {
    color: rgba(255, 255, 255, 0.8);
}

.nav-section-title::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.9);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
    margin-right: 0.5rem;
}

.nav-section-title i {
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

.nav-section.collapsed .nav-section-title i {
    transform: rotate(-90deg);
}

.sidebar.collapsed .nav-section-title {
    opacity: 0;
}

.nav-section-items {
    transition: all 0.3s ease;
    overflow: hidden;
}

.nav-section.collapsed .nav-section-items {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}

.nav-item {
    margin: 0.2rem 0.75rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.85rem;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    border-radius: 12px;
    transition: all 0.3s ease;
    font-size: 0.85rem;
    font-weight: 500;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    transform: translateX(4px);
}

.nav-link.active {
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.nav-icon {
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    font-family: "Font Awesome 6 Free", "Font Awesome 6 Brands", "FontAwesome" !important;
    font-weight: 900 !important;
    font-style: normal !important;
    display: inline-block !important;
}

.nav-text {
    transition: opacity 0.3s ease;
}

.sidebar.collapsed .nav-text {
    opacity: 0;
}

.nav-badge {
    background: #ef4444;
    color: white;
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    border-radius: 10px;
    margin-left: auto;
    transition: opacity 0.3s ease;
}

.sidebar.collapsed .nav-badge {
    opacity: 0;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: 280px;
    transition: margin-left 0.3s ease;
    min-height: 100vh;
}

.main-content.expanded {
    margin-left: 80px;
}

/* Page Content */
.page-content {
    padding: 2rem;
    padding-top: 90px; /* Account for professional navbar height */
    min-height: calc(100vh - 70px);
    transition: padding-top 0.3s ease;
}

/* Mobile Responsiveness */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .main-content.expanded {
        margin-left: 0;
    }

    .page-content {
        padding: 1rem;
        padding-top: 80px; /* Adjusted for mobile navbar */
    }
}

/* Mobile Overlay */
.mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
}

.mobile-overlay.active {
    display: block;
}

/* RTL Support for Arabic */
[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
}

[dir="rtl"] .main-content {
    margin-left: 0;
    margin-right: 280px;
}

[dir="rtl"] .sidebar.collapsed + .main-content {
    margin-right: 80px;
}

[dir="rtl"] .sidebar-nav .nav-item {
    text-align: right;
}

[dir="rtl"] .sidebar-nav .nav-link {
    padding-left: 2rem;
    padding-right: 1.5rem;
}

[dir="rtl"] .sidebar-nav .nav-link .nav-icon {
    margin-left: 0.75rem;
    margin-right: 0;
}

[dir="rtl"] .breadcrumb-nav {
    flex-direction: row-reverse;
}

[dir="rtl"] .breadcrumb-separator {
    transform: scaleX(-1);
}

/* RTL Mobile Support */
@media (max-width: 1024px) {
    [dir="rtl"] .sidebar {
        transform: translateX(100%);
    }

    [dir="rtl"] .sidebar.mobile-open {
        transform: translateX(0);
    }

    [dir="rtl"] .main-content {
        margin-right: 0;
    }
}
