:root {
    --primary: #01205f;
    --primary-light: #0d3a8c;
    --primary-glow: rgba(1, 32, 95, 0.25);
    --bg: #f7f6fe;
    --bg-mesh: radial-gradient(ellipse 80% 50% at 20% -10%, rgba(1, 32, 95, 0.06), transparent),
               radial-gradient(ellipse 60% 40% at 90% 100%, rgba(59, 130, 246, 0.05), transparent),
               #f7f6fe;
    --surface: rgba(255, 255, 255, 0.72);
    --surface-solid: #ffffff;
    --surface-elevated: #ffffff;
    --border: rgba(1, 32, 95, 0.08);
    --border-subtle: rgba(1, 32, 95, 0.05);
    --text: #1f2937;
    --text-muted: #6b7280;
    --heading: #01205f;
    --chart-grid: rgba(1, 32, 95, 0.06);
    --shadow-sm: 0 1px 2px rgba(1, 32, 95, 0.04), 0 4px 16px rgba(1, 32, 95, 0.06);
    --shadow-md: 0 4px 24px rgba(1, 32, 95, 0.08);
    --shadow-lift: 0 12px 32px rgba(1, 32, 95, 0.12);
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --sidebar-w: 280px;
    --header-h: 72px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --toggle-bg: #f7f6fe;
    --input-bg: #f7f6fe;
}

[data-theme="dark"] {
    --primary: #5b8def;
    --primary-light: #7cacf8;
    --primary-glow: rgba(91, 141, 239, 0.35);
    --bg: #0b0f17;
    --bg-mesh: radial-gradient(ellipse 90% 60% at 100% -20%, rgba(59, 130, 246, 0.12), transparent),
               radial-gradient(ellipse 70% 50% at 0% 100%, rgba(1, 32, 95, 0.18), transparent),
               linear-gradient(180deg, #0b0f17 0%, #0d1320 50%, #0b0f17 100%);
    --surface: rgba(22, 28, 42, 0.75);
    --surface-solid: #161c2a;
    --surface-elevated: #1c2438;
    --border: rgba(148, 163, 184, 0.12);
    --border-subtle: rgba(148, 163, 184, 0.06);
    --text: #e8ecf4;
    --text-muted: #94a3b8;
    --heading: #f1f5f9;
    --chart-grid: rgba(148, 163, 184, 0.08);
    --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 4px 24px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 0 0 1px rgba(255, 255, 255, 0.05), 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-lift: 0 0 0 1px rgba(91, 141, 239, 0.15), 0 16px 40px rgba(0, 0, 0, 0.55);
    --toggle-bg: rgba(22, 28, 42, 0.9);
    --input-bg: rgba(11, 15, 23, 0.8);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body.admin-body {
    font-family: 'IBM Plex Sans Arabic', 'Cairo', system-ui, sans-serif;
    background: var(--bg-mesh);
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Theme-aware utilities */
.theme-heading { color: var(--heading); }
.theme-text { color: var(--text); }
.theme-muted { color: var(--text-muted); }
.theme-surface {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    color: var(--text);
}
.theme-surface:hover {
    border-color: rgba(91, 141, 239, 0.25);
    box-shadow: var(--shadow-md);
}

.theme-link {
    color: var(--primary);
}

[data-theme="dark"] .theme-link {
    color: #7cacf8;
}

[data-theme="dark"] .entity-icon-badge {
    box-shadow: 0 4px 16px rgba(91, 141, 239, 0.25);
}

.distribution-legend li {
    padding: 6px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.distribution-legend li:last-child {
    border-bottom: none;
}

.page-enter {
    animation: fadeUp 0.45s ease-out forwards;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.glass {
    background: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
}

[data-theme="dark"] .glass {
    background: rgba(22, 28, 42, 0.72);
    border-color: var(--border);
    box-shadow: var(--shadow-sm);
}

.glass-sidebar {
    background: linear-gradient(165deg, rgba(1, 32, 95, 0.92) 0%, rgba(1, 32, 95, 0.78) 50%, rgba(13, 58, 140, 0.85) 100%);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: -8px 0 32px rgba(1, 32, 95, 0.15);
}

[data-theme="dark"] .glass-sidebar {
    background: linear-gradient(180deg, #0f1729 0%, #0c1220 40%, #0a0f17 100%);
    border-left-color: rgba(91, 141, 239, 0.15);
    box-shadow: -4px 0 40px rgba(0, 0, 0, 0.5), inset 1px 0 0 rgba(255, 255, 255, 0.04);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius);
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
    position: relative;
}

.nav-item:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(-2px);
}

[data-theme="dark"] .nav-item:hover {
    background: rgba(91, 141, 239, 0.12);
}

.nav-item.active {
    color: #fff;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0.04) 100%);
    box-shadow: 0 0 24px rgba(91, 141, 239, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .nav-item.active {
    background: linear-gradient(90deg, rgba(91, 141, 239, 0.22) 0%, rgba(91, 141, 239, 0.06) 100%);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: linear-gradient(180deg, #7cacf8, #e0eaff);
    border-radius: 4px 0 0 4px;
    box-shadow: 0 0 14px rgba(124, 172, 248, 0.7);
}

.kpi-card,
.chart-card,
.data-table-card,
.entity-chart-card {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

[data-theme="dark"] .kpi-card,
[data-theme="dark"] .chart-card,
[data-theme="dark"] .data-table-card,
[data-theme="dark"] .entity-chart-card {
    background: linear-gradient(145deg, var(--surface-elevated) 0%, var(--surface-solid) 100%);
    border-color: var(--border);
}

[data-theme="dark"] .kpi-card::before,
[data-theme="dark"] .entity-chart-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(91, 141, 239, 0.4), transparent);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.kpi-card {
    padding: 24px;
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), #3b82f6, #60a5fa);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

[data-theme="dark"] .kpi-card::before {
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(91, 141, 239, 0.5), transparent);
}

.kpi-card:hover,
.entity-chart-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lift);
}

.chart-card {
    border-radius: var(--radius-xl);
    padding: 24px;
}

.entity-chart-card {
    padding: 20px;
    display: block;
    text-decoration: none;
    color: inherit;
    position: relative;
}

.search-input {
    background: var(--input-bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9999px;
    padding: 10px 44px 10px 16px;
    font-size: 0.875rem;
    width: 100%;
    max-width: 280px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.search-input.max-w-none {
    max-width: none;
    border-radius: var(--radius);
}

[data-theme="dark"] .admin-body input:not([type="color"]),
[data-theme="dark"] .admin-body select,
[data-theme="dark"] .admin-body textarea {
    background: var(--input-bg);
    color: var(--text);
    border-color: var(--border);
}

[data-theme="dark"] .admin-body input:focus,
[data-theme="dark"] .admin-body select:focus,
[data-theme="dark"] .admin-body textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.data-row {
    transition: background var(--transition);
    cursor: pointer;
}

.data-row:hover {
    background: rgba(1, 32, 95, 0.04);
}

[data-theme="dark"] .data-row:hover {
    background: rgba(91, 141, 239, 0.06);
}

.btn-primary {
    background: linear-gradient(135deg, #01205f 0%, #0d3a8c 100%);
    color: #fff;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 4px 14px var(--primary-glow);
}

[data-theme="dark"] .btn-primary {
    background: linear-gradient(135deg, #3b6fd4 0%, #5b8def 100%);
    box-shadow: 0 4px 20px rgba(91, 141, 239, 0.35);
}

.btn-primary:hover {
    transform: translateY(-1px);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-gray { background: #f3f4f6; color: #4b5563; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-primary { background: rgba(1, 32, 95, 0.1); color: var(--primary); }

[data-theme="dark"] .badge-success { background: rgba(52, 211, 153, 0.15); color: #6ee7b7; }
[data-theme="dark"] .badge-gray { background: rgba(148, 163, 184, 0.15); color: #cbd5e1; }
[data-theme="dark"] .badge-primary {
    background: rgba(91, 141, 239, 0.15);
    color: #93b4f8;
}

.period-toggle {
    background: var(--toggle-bg);
    border: 1px solid var(--border);
}

.period-toggle button {
    color: var(--text-muted);
}

.period-toggle button.active {
    background: linear-gradient(135deg, #01205f, #0d3a8c);
    color: #fff;
    box-shadow: 0 2px 12px var(--primary-glow);
}

[data-theme="dark"] .period-toggle button.active {
    background: linear-gradient(135deg, #3b6fd4, #5b8def);
    color: #fff;
}

.header-icon-btn {
    padding: 0.625rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-solid);
    color: var(--text-muted);
    transition: all var(--transition);
}

.header-icon-btn:hover {
    border-color: rgba(91, 141, 239, 0.3);
    color: var(--heading);
    box-shadow: var(--shadow-sm);
}

.header-profile-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem 0.375rem 0.375rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-solid);
    transition: all var(--transition);
}

.header-profile-btn:hover {
    box-shadow: var(--shadow-md);
    border-color: rgba(91, 141, 239, 0.25);
}

.header-profile-name {
    color: var(--text);
}

.dropdown-menu {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
}

.drawer-overlay {
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
}

.drawer-panel {
    background: var(--surface-solid);
    border-color: var(--border);
    box-shadow: var(--shadow-lift);
}

.bulk-bar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
}

.alert-success {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
}

[data-theme="dark"] .alert-success {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(52, 211, 153, 0.25);
    color: #6ee7b7;
}

.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

[data-theme="dark"] .alert-error {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(248, 113, 113, 0.25);
    color: #fca5a5;
}

.entity-mini-chart .apexcharts-canvas { margin: 0 auto; }

[data-theme="dark"] .apexcharts-text,
[data-theme="dark"] .apexcharts-title-text {
    fill: var(--text-muted) !important;
}

[data-theme="dark"] .apexcharts-legend-text {
    color: var(--text-muted) !important;
}

[data-theme="dark"] .apexcharts-tooltip.apexcharts-theme-dark {
    background: #1c2438 !important;
    border: 1px solid var(--border) !important;
    box-shadow: var(--shadow-md);
}

/* نصوص داخل الشرائح/الأعمدة الملوّنة */
.apexcharts-datalabel,
.apexcharts-datalabel-label,
.apexcharts-datalabel-value,
.apexcharts-pie-label,
.apexcharts-donut-label {
    fill: #ffffff !important;
}

.apexcharts-datalabel text,
.apexcharts-pie-label text {
    fill: #ffffff !important;
    font-weight: 700 !important;
}

@media (max-width: 768px) {
    .desktop-table { display: none; }
    .mobile-cards { display: block; }
}

@media (min-width: 769px) {
    .desktop-table { display: block; }
    .mobile-cards { display: none; }
}

.admin-sidebar::-webkit-scrollbar { width: 4px; }
.admin-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}
