/* 
 * Enterprise Admin Dashboard - Production Ready CSS
 * Refactored for: Responsiveness, Depth, Hierarchy, and Robust Theme Support
 */

:root {
    /* --- Design Tokens: Light Mode (Default) --- */
    --font-primary: 'Inter', 'Cairo', system-ui, sans-serif;

    /* Backgrounds */
    --bg-app: #f1f4f9;
    --bg-panel: #ffffff;
    --bg-element: #f8fafc;
    --bg-hover: #f1f5f9;

    /* Glass Effect (Light) */
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.4);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);

    /* Text */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    /* Borders & Depth */
    --border-color: #e2e8f0;
    --border-focus: #4f46e5;

    /* Shadows (Premium Depth System) */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.03);
    --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.1);

    /* Brand Colors - Sophisticated Navy/Blue Palette */
    --primary: #1e40af;
    /* Blue 800 */
    --primary-hover: #1e3a8a;
    /* Blue 900 */
    --primary-light: #eff6ff;
    /* Blue 50 */
    --accent: #f59e0b;

    --success: #10b981;
    --success-bg: #f0fdf4;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --info: #3b82f6;
    --info-bg: #eff6ff;

    /* Layout Dimensions */
    --sidebar-w: 260px;
    --sidebar-w-collapsed: 80px;
    --header-h: 74px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius: var(--radius-md);

    /* Z-Layers */
    --z-sidebar: 1000;
    --z-header: 900;
    --z-overlay: 1100;
    --z-dropdown: 950;
}

[data-theme="dark"] {
    /* --- Design Tokens: Dark Mode --- */
    --bg-app: #0b0f19;
    --bg-panel: #161c2d;
    --bg-element: #1d253b;
    --bg-hover: #212c47;

    /* Glass Effect (Dark) */
    --glass-bg: rgba(22, 28, 45, 0.7);
    --glass-border: rgba(255, 255, 255, 0.05);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --border-color: #212c47;

    /* Shadows for Dark Mode - Inner glow + deeper shadow */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 12px -1px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.7);

    --primary-light: rgba(30, 64, 175, 0.15);
    --success-bg: rgba(16, 185, 129, 0.1);
    --warning-bg: rgba(245, 158, 11, 0.1);
    --danger-bg: rgba(239, 68, 68, 0.1);
    --info-bg: rgba(59, 130, 246, 0.1);
}

/* --- Base --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

/* Icon Base */
.lucide {
    display: inline-block;
    vertical-align: middle;
    line-height: 1;
    width: 1em;
    height: 1em;
    font-size: 1.2em;
    /* Default scale */
}

body {
    font-family: var(--font-primary);
    background-color: var(--bg-app);
    color: var(--text-secondary);
    /* Text secondary by default for better hierarchy */
    font-size: 0.95rem;
    line-height: 1.6;
    direction: rtl;
    text-align: right;
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a {
    text-decoration: none;
    color: inherit;
    transition: 0.2s ease;
}

ul {
    list-style: none;
}

img {
    max-width: 100%;
    display: block;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary);
    font-weight: 700;
    margin-bottom: 0.5em;
    line-height: 1.25;
}

/* --- Typography System --- */
h1 {
    font-size: 1.875rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

p {
    margin-bottom: 1rem;
}

.text-muted {
    color: var(--text-muted) !important;
}

.font-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.text-sm {
    font-size: 0.875rem;
}

.text-xs {
    font-size: 0.75rem;
}

.font-bold {
    font-weight: 700;
}

.font-medium {
    font-weight: 500;
}

/* --- Sidebar (Navigation) --- */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-panel);
    border-left: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: var(--z-sidebar);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.02);
}

/* Sidebar is now always visible */
@media (max-width: 1024px) {
    /* Optionally adjust sidebar width for tablet/mobile if needed */
    /* .sidebar { width: 200px; } */
}

.sidebar-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
}

.logo-brand {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-section-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    margin: 24px 12px 12px;
    letter-spacing: 0.8px;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    margin-bottom: 6px;
    color: var(--text-secondary);
    border-radius: var(--radius);
    font-weight: 500;
    position: relative;
    overflow: hidden;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-link i {
    font-size: 1.25rem;
    margin-left: 12px;
    color: var(--text-muted);
    transition: 0.2s;
}

.nav-link:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.nav-link:hover i {
    color: var(--primary);
}

.nav-link.active {
    background-color: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.nav-link.active i {
    color: var(--primary);
}

/* --- Mobile Overlay (Removed since sidebar is persistent) --- */
.sidebar-overlay {
    display: none !important;
}

/* --- Main Layout --- */
.main-wrapper {
    flex: 1;
    margin-right: var(--sidebar-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.sidebar.collapsed+.main-wrapper {
    margin-right: var(--sidebar-w-collapsed);
}

@media (max-width: 1024px) {
    .main-wrapper {
        margin-right: var(--sidebar-w) !important;
    }
}

/* --- Header --- */
.top-header {
    height: var(--header-h);
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    backdrop-filter: blur(10px);
    /* Glassmorphism hint */
}

@media (max-width: 768px) {
    .top-header {
        padding: 0 16px;
    }
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.toggle-btn {
    display: none !important;
}

.toggle-btn:hover {
    background: var(--bg-hover);
    color: var(--primary);
}

.page-title {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* --- Content Area --- */
.page-content {
    flex: 1;
    padding: 32px;
}

@media (max-width: 768px) {
    .page-content {
        padding: 20px;
    }
}

/* --- Components --- */

/* 1. Cards */
.card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* For header borders */
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--text-primary);
    background: var(--bg-panel);
}

.card-body {
    padding: 24px;
    flex: 1;
}

.card-body.p-0 {
    padding: 0;
}

/* 2. Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-family: var(--font-primary);
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    line-height: 1.25;
}

.btn:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 8px -1px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
    background-color: var(--bg-panel);
    color: var(--text-primary);
    border-color: var(--border-color);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-danger {
    background-color: var(--danger-bg);
    color: var(--danger);
    border-color: transparent;
}

.btn-danger:hover:not(:disabled) {
    background-color: var(--danger);
    color: white;
}

.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background-color: #059669;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.85rem;
    border-radius: 8px;
}

.w-full {
    width: 100%;
}

/* 3. Inputs */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 0.95rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background-color: var(--bg-panel);
    color: var(--text-primary);
    transition: 0.2s;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* 4. Tables */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    border-radius: 0 0 var(--radius) var(--radius);
}

.table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
}

.table th {
    background-color: var(--bg-element);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 16px 24px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.table td {
    padding: 16px 24px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.table tbody tr:hover {
    background-color: var(--bg-hover);
}

/* 5. Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.metric-card {
    background: var(--bg-panel);
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: transform 0.2s;
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.metric-title {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.metric-value {
    font-size: 2.25rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 8px;
}

.metric-trend {
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.trend-up {
    color: var(--success);
}

.trend-down {
    color: var(--danger);
}

/* 6. Badges */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-neutral {
    background: var(--bg-element);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

/* --- Footer --- */
.app-footer {
    padding: 24px 32px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-panel);
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: auto;
}

/* Utilities */
.d-flex {
    display: flex;
    align-items: center;
}

.flex-col {
    flex-direction: column;
}

.justify-between {
    justify-content: space-between;
}

.justify-center {
    justify-content: center;
}

.items-center {
    align-items: center;
}

.gap-sm {
    gap: 8px;
}

.gap-md {
    gap: 16px;
}

.gap-lg {
    gap: 24px;
}

.mb-4 {
    margin-bottom: 24px;
}

.p-4 {
    padding: 24px;
}

.text-center {
    text-align: center;
}

.grid-cols {
    display: grid;
    gap: 24px;
}

@media (max-width: 1024px) {
    .grid-cols {
        grid-template-columns: 1fr !important;
    }
}

/* Avatar */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Alert/Flash Messages */
.alert {
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border-color: rgba(16, 185, 129, 0.2);
}

.alert-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.2);
}

/* Glassmorphism Class */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

/* Animation Utils */
@keyframes float {
    0% {
        transform: translate(0, 0) scale(1);
    }

    33% {
        transform: translate(30px, -50px) scale(1.1);
    }

    66% {
        transform: translate(-20px, 20px) scale(0.9);
    }

    100% {
        transform: translate(0, 0) scale(1);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(30px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes rotateIn {
    from {
        transform: rotate(-5deg) scale(0.9);
        opacity: 0;
    }

    to {
        transform: rotate(0) scale(1);
        opacity: 1;
    }
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

.animate-fade {
    animation: fadeIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.animate-slide {
    animation: slideInRight 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.animate-scale {
    animation: scaleIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Cascade Animation Helper */
.cascade>* {
    opacity: 0;
}

.cascade>*:nth-child(1) {
    animation: fadeIn 0.5s ease forwards 0.1s;
}

.cascade>*:nth-child(2) {
    animation: fadeIn 0.5s ease forwards 0.2s;
}

.cascade>*:nth-child(3) {
    animation: fadeIn 0.5s ease forwards 0.3s;
}

.cascade>*:nth-child(4) {
    animation: fadeIn 0.5s ease forwards 0.4s;
}

.cascade>*:nth-child(5) {
    animation: fadeIn 0.5s ease forwards 0.5s;
}

.no-scroll {
    overflow: hidden !important;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}