:root {
    --bg-color: #f8f9fa;
    --text-color: #2d3748;
    --primary-color: #4a90e2;
    --primary-gradient: linear-gradient(135deg, #1a2a6c 0%, #2c3e50 100%);
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --footer-bg: #eef2f7;
    --footer-text: #2d3748;
    --footer-link: #1a2a6c;
    --border-color: #e2e8f0;
    --header-bg: #ffffff;
    --hover-bg: #edf2f7;
    --text-muted: #718096;
    --sidebar-active-text: #ffffff;
    --sidebar-active-bg: linear-gradient(135deg, #1a2a6c 0%, #2c3e50 100%);
    --sidebar-active-shadow: 0 8px 18px rgba(26, 42, 108, 0.28);
    --input-bg: #ffffff;
    --input-border: #cfd8e3;
    --input-text: #1f2937;
    --input-placeholder: #9aa4b2;
    --input-focus: #4a90e2;
    --input-focus-glow: rgba(74, 144, 226, 0.25);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --transition: all 0.3s ease;
}

[data-theme="dark"] {
    --bg-color: #1a202c;
    --text-color: #f7fafc;
    --primary-color: #63b3ed;
    --primary-gradient: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    --sidebar-bg: #2d3748;
    --card-bg: #2d3748;
    --footer-bg: #111827;
    --footer-text: #e5e7eb;
    --footer-link: #93c5fd;
    --border-color: #4a5568;
    --header-bg: #2d3748;
    --hover-bg: #4a5568;
    --text-muted: #a0aec0;
    --sidebar-active-text: #ffffff;
    --sidebar-active-bg: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    --sidebar-active-shadow: 0 8px 20px rgba(15, 23, 42, 0.45);
    --input-bg: #1e293b;
    --input-border: #475569;
    --input-text: #f8fafc;
    --input-placeholder: #94a3b8;
    --input-focus: #63b3ed;
    --input-focus-glow: rgba(99, 179, 237, 0.35);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}

[data-theme="gold"] {
    --bg-color: #121212;
    --text-color: #f2d06b;
    --primary-color: #d4af37;
    --primary-gradient: linear-gradient(135deg, #1a1a1a 0%, #333333 100%);
    --sidebar-bg: #1a1a1a;
    --card-bg: #1e1e1e;
    --footer-bg: #1a1a1a;
    --footer-text: #f2d06b;
    --footer-link: #ffd36b;
    --border-color: #333333;
    --header-bg: #1a1a1a;
    --hover-bg: #2d2d2d;
    --text-muted: #a68a2d;
    --sidebar-active-text: #f2d06b;
    --sidebar-active-bg: linear-gradient(135deg, #1f1f1f 0%, #3a3a3a 100%);
    --sidebar-active-shadow: 0 8px 20px rgba(212, 175, 55, 0.22);
    --input-bg: #222222;
    --input-border: #5c4a1d;
    --input-text: #f2d06b;
    --input-placeholder: #a68a2d;
    --input-focus: #d4af37;
    --input-focus-glow: rgba(212, 175, 55, 0.3);
}

[data-theme="pink"] {
    --bg-color: #fff1f8;
    --text-color: #5b2146;
    --primary-color: #db2777;
    --primary-gradient: linear-gradient(135deg, #ec4899 0%, #be185d 100%);
    --sidebar-bg: #ffe4f2;
    --card-bg: #ffffff;
    --footer-bg: #ffe4f2;
    --footer-text: #5b2146;
    --footer-link: #be185d;
    --border-color: #f9a8d4;
    --header-bg: #fff1f8;
    --hover-bg: #ffd6ea;
    --text-muted: #9d4f7a;
    --sidebar-active-text: #ffffff;
    --sidebar-active-bg: linear-gradient(135deg, #ec4899 0%, #be185d 100%);
    --sidebar-active-shadow: 0 8px 20px rgba(190, 24, 93, 0.3);
    --input-bg: #fff7fb;
    --input-border: #f9a8d4;
    --input-text: #5b2146;
    --input-placeholder: #b46b93;
    --input-focus: #db2777;
    --input-focus-glow: rgba(219, 39, 119, 0.25);
}

[data-theme="emerald"] {
    --bg-color: #ecfdf5;
    --text-color: #064e3b;
    --primary-color: #059669;
    --primary-gradient: linear-gradient(135deg, #065f46 0%, #064e3b 100%);
    --sidebar-bg: #d1fae5;
    --card-bg: #ffffff;
    --footer-bg: #d1fae5;
    --footer-text: #064e3b;
    --footer-link: #047857;
    --border-color: #86efac;
    --header-bg: #ecfdf5;
    --hover-bg: #bbf7d0;
    --text-muted: #0f766e;
    --sidebar-active-text: #ffffff;
    --sidebar-active-bg: linear-gradient(135deg, #065f46 0%, #064e3b 100%);
    --sidebar-active-shadow: 0 8px 20px rgba(5, 150, 105, 0.28);
    --input-bg: #f7fffb;
    --input-border: #6ee7b7;
    --input-text: #065f46;
    --input-placeholder: #4b8b76;
    --input-focus: #059669;
    --input-focus-glow: rgba(5, 150, 105, 0.25);
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: background-color 0.3s ease, color 0.3s ease;
    direction: rtl;
    text-align: right;
}

/* Layout */
#wrapper {
    display: flex;
    width: 100%;
    align-items: stretch;
    min-height: calc(100vh - 60px);
}

#sidebar-wrapper {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    transition: var(--transition);
    z-index: 1000;
    box-shadow: var(--shadow-sm);
    --bs-list-group-active-bg: transparent;
    --bs-list-group-active-color: var(--sidebar-active-text);
    --bs-list-group-active-border-color: transparent;
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.main-content {
    flex: 1;
    padding: 20px;
    min-width: 0;
    /* To prevent flex child from overflowing */
}

#sidebar-wrapper.collapsed {
    margin-right: calc(-1 * var(--sidebar-width));
}

.sidebar-heading {
    padding: 1rem;
    font-size: 0.95rem;
    font-weight: bold;
    color: var(--primary-color);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* عناصر القائمة في الشريط الجانبي — تصميم مضغوط احترافي */
#sidebar-wrapper .list-group {
    flex: 1 1 auto;
    overflow: visible;
}

#sidebar-wrapper .list-group-item {
    background-color: transparent;
    color: var(--text-color);
    border: none;
    padding: 0.45rem 1.25rem;
    margin-bottom: 1px;
    font-weight: 500;
    font-size: 0.82rem;
    transition: var(--transition);
    display: block;
    text-decoration: none;
    white-space: nowrap;
}

#sidebar-wrapper .list-group-item i {
    width: 1.1rem;
    text-align: center;
    margin-left: 6px;
    font-size: 0.8rem;
    color: inherit !important;
}

#sidebar-wrapper .list-group-item:hover {
    background-color: var(--hover-bg);
    color: var(--primary-color);
}

#sidebar-wrapper .list-group-item.active {
    background: var(--sidebar-active-bg) !important;
    color: var(--sidebar-active-text) !important;
    border-color: transparent !important;
    box-shadow: var(--sidebar-active-shadow);
}

#sidebar-wrapper .list-group-item.active:hover,
#sidebar-wrapper .list-group-item.active:focus,
#sidebar-wrapper .list-group-item.list-group-item-action.active {
    background: var(--sidebar-active-bg) !important;
    color: var(--sidebar-active-text) !important;
    border-color: transparent !important;
}

/* Top Navbar */
.top-navbar {
    background-color: var(--header-bg);
    box-shadow: var(--shadow-sm);
    border-bottom: 1px solid var(--border-color);
    height: 60px;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.top-navbar .navbar-brand {
    color: var(--primary-color) !important;
    font-weight: bold;
    font-size: 1.5rem;
    text-decoration: none;
    display: flex;
    align-items: center;
}

.top-navbar .nav-link {
    color: var(--text-color) !important;
}

/* شارة لون خفيف (يُستخدم في الشريط والبطاقات — كان مفقوداً في site.css) */
.bg-soft-primary {
    background-color: rgba(13, 110, 253, 0.12) !important;
    color: #0d6efd !important;
}

.btn-soft-danger {
    color: #dc3545;
    background-color: rgba(220, 53, 69, 0.1);
    border: 1px solid rgba(220, 53, 69, 0.25);
}

.btn-soft-danger:hover {
    color: #fff;
    background-color: #dc3545;
    border-color: #dc3545;
}

/* قائمة المستخدم — الشريط العلوي */
.user-menu-trigger {
    max-width: min(240px, 48vw);
    white-space: nowrap;
}

.user-menu-avatar-lg {
    width: 40px;
    height: 40px;
    min-width: 40px;
    font-size: 1rem;
}

.user-menu-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 700;
    line-height: 1;
    background: linear-gradient(145deg, var(--primary-color), #2b6cb0);
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.user-menu-name {
    min-width: 0;
    max-width: 150px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-color);
}

.navbar .user-menu-trigger {
    background-color: #fff;
    border-color: var(--border-color, #dee2e6) !important;
}

[data-theme="dark"] .user-menu-trigger,
[data-theme="gold"] .user-menu-trigger,
[data-theme="pink"] .user-menu-trigger,
[data-theme="emerald"] .user-menu-trigger {
    background-color: var(--card-bg);
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .user-menu-name,
[data-theme="gold"] .user-menu-name,
[data-theme="pink"] .user-menu-name,
[data-theme="emerald"] .user-menu-name {
    color: var(--text-color);
}

/* Cards */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    margin-bottom: 20px;
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    font-weight: 600;
    color: var(--text-color);
}

.card-body {
    color: var(--text-color);
}

/* Forms */
.form-control,
.form-select,
input,
textarea,
select {
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--input-text);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    transition: var(--transition);
}

.form-control:disabled,
.form-select:disabled,
input:disabled,
textarea:disabled,
select:disabled {
    background-color: color-mix(in srgb, var(--input-bg) 85%, #808080 15%);
    color: color-mix(in srgb, var(--input-text) 65%, #808080 35%);
    border-color: color-mix(in srgb, var(--input-border) 75%, #808080 25%);
    opacity: 1;
}

.form-control:focus,
.form-select:focus,
input:focus,
textarea:focus,
select:focus {
    background-color: var(--input-bg);
    border-color: var(--input-focus);
    color: var(--input-text);
    box-shadow: 0 0 0 0.2rem var(--input-focus-glow);
    outline: 0;
}

.form-control::placeholder,
input::placeholder,
textarea::placeholder {
    color: var(--input-placeholder);
    opacity: 1;
}

input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
    -webkit-text-fill-color: var(--input-text);
    -webkit-box-shadow: 0 0 0 1000px var(--input-bg) inset;
    box-shadow: 0 0 0 1000px var(--input-bg) inset;
    transition: background-color 9999s ease-in-out 0s;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

.table {
    color: var(--text-color);
    margin-bottom: 0;
    width: 100%;
}

.table th {
    border-bottom: 2px solid var(--border-color);
    color: var(--text-muted);
    font-weight: 600;
    padding: 1rem;
    background-color: var(--bg-color);
    /* slightly separate header */
}

.table td {
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    padding: 1rem;
}

.table-hover tbody tr:hover {
    background-color: var(--hover-bg);
    color: var(--text-color);
}

/* Buttons */
.btn {
    border-radius: 8px;
    font-weight: 500;
    padding: 0.5rem 1.25rem;
    transition: var(--transition);
    cursor: pointer;
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

.btn-primary:hover {
    filter: brightness(1.1);
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

.btn-outline-primary {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background-color: transparent;
}

.btn-outline-primary:hover {
    background-color: var(--primary-color);
    color: #fff;
}

footer.site-footer {
    margin-top: 2rem;
    background: var(--footer-bg);
    color: var(--footer-text);
    border-top: 1px solid var(--border-color);
    padding: 14px 20px;
}

footer.site-footer a {
    color: var(--footer-link);
    text-decoration: none;
}

footer.site-footer a:hover {
    text-decoration: underline;
}

/* Utilities */
.text-primary {
    color: var(--primary-color) !important;
}

.text-success {
    color: #48bb78 !important;
}

.text-info {
    color: #38b2ac !important;
}

.text-warning {
    color: #ecc94b !important;
}

.text-danger {
    color: #f56565 !important;
}

.text-muted {
    color: var(--text-muted) !important;
}

/* Dashboard Cards (Border Left Variants - Adjusted for RTL so it's right border) */
.border-left-primary {
    border-right: 4px solid var(--primary-color) !important;
    border-left: none !important;
}

.border-left-success {
    border-right: 4px solid #48bb78 !important;
    border-left: none !important;
}

.border-left-info {
    border-right: 4px solid #38b2ac !important;
    border-left: none !important;
}

.border-left-warning {
    border-right: 4px solid #ecc94b !important;
    border-left: none !important;
}

/* Switcher Button */
.theme-switch {
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    transition: var(--transition);
}

.theme-switch:hover {
    background-color: var(--hover-bg);
    color: var(--primary-color);
}

/* Sidebar toggle */
.sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    margin-left: 1rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #sidebar-wrapper {
        position: fixed;
        right: 0;
        margin-right: calc(-1 * var(--sidebar-width));
        height: calc(100vh - 60px);
    }

    #sidebar-wrapper.show {
        margin-right: 0;
    }
}