:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --primary: #dc2626;
    --primary-hover: #b91c1c;
    --primary-light: #fef2f2;
    --success: #22c55e;
    --success-light: #f0fdf4;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --error: #ef4444;
    --error-light: #fef2f2;
    --info: #3b82f6;
    --info-light: #eff6ff;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --primary-light: rgba(220, 38, 38, 0.15);
    --success-light: rgba(34, 197, 94, 0.15);
    --warning-light: rgba(245, 158, 11, 0.15);
    --error-light: rgba(239, 68, 68, 0.15);
    --info-light: rgba(59, 130, 246, 0.15);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Tajawal', 'Inter', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

body[dir="ltr"] { font-family: 'Inter', 'Tajawal', sans-serif; }

/* Login Page */
.login-page { min-height: 100vh; display: flex; }

.login-sidebar {
    flex: 1;
    background: linear-gradient(135deg, var(--primary) 0%, #991b1b 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    position: relative;
    overflow: hidden;
}

.login-sidebar::before {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
    top: -100px;
    right: -100px;
}

.login-branding { text-align: center; color: white; position: relative; z-index: 1; }
.login-branding img { height: 120px; margin-bottom: 30px; filter: brightness(0) invert(1); }
.login-branding h1 { font-size: 48px; font-weight: 800; margin-bottom: 15px; }
.login-branding p { font-size: 20px; opacity: 0.9; }

.login-features { margin-top: 50px; display: flex; flex-direction: column; gap: 20px; }
.login-feature { display: flex; align-items: center; gap: 15px; color: white; opacity: 0.9; }
.login-feature i { width: 24px; height: 24px; }

.login-main { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 60px; max-width: 600px; }
.login-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 50px; }
.theme-lang-controls { display: flex; gap: 10px; }

.control-btn {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    color: var(--text-secondary);
}

.control-btn:hover { background: var(--bg-tertiary); color: var(--primary); }
.control-btn i { width: 20px; height: 20px; }

.login-form-container h2 { font-size: 32px; font-weight: 700; margin-bottom: 10px; }
.login-form-container > p { color: var(--text-secondary); margin-bottom: 40px; }

.form-group { margin-bottom: 24px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 500; color: var(--text-primary); }

.input-wrapper { position: relative; }
.input-wrapper i { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 20px; height: 20px; }
[dir="ltr"] .input-wrapper i { right: auto; left: 16px; }

.form-group input, .form-group select {
    width: 100%;
    padding: 16px 50px 16px 16px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
    transition: all 0.3s;
}

[dir="ltr"] .form-group input, [dir="ltr"] .form-group select { padding: 16px 16px 16px 50px; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-light); }
.form-group select { cursor: pointer; appearance: none; }

.remember-forgot { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; }
.checkbox-wrapper { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.checkbox-wrapper input { width: 20px; height: 20px; accent-color: var(--primary); }

.btn {
    width: 100%;
    padding: 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }

.error-alert {
    background: var(--error-light);
    border: 1px solid var(--error);
    color: var(--error);
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 24px;
    display: none;
    align-items: center;
    gap: 10px;
}

.login-footer { margin-top: 40px; text-align: center; color: var(--text-muted); font-size: 14px; }
.login-footer a { color: var(--primary); text-decoration: none; }

/* Dashboard */
.dashboard { display: none; min-height: 100vh; }

.sidebar {
    position: fixed;
    right: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

[dir="ltr"] .sidebar { right: auto; left: 0; border-left: none; border-right: 1px solid var(--border-color); }

.sidebar-header { padding: 24px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.sidebar-logo { display: flex; align-items: center; gap: 12px; }
.sidebar-close { 
    display: none; 
    width: 36px; 
    height: 36px; 
    border: none; 
    background: var(--bg-tertiary); 
    border-radius: 8px; 
    align-items: center; 
    justify-content: center; 
    cursor: pointer; 
    color: var(--text-secondary);
}
.sidebar-close:hover { background: var(--error-light); color: var(--error); }
.sidebar-close i { width: 20px; height: 20px; }
.sidebar-logo img { height: 40px; }
.sidebar-logo span { font-size: 24px; font-weight: 800; color: var(--primary); }

.sidebar-nav { flex: 1; padding: 20px 16px; overflow-y: auto; }
.nav-section { margin-bottom: 24px; }
.nav-section-title { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; padding: 0 12px; margin-bottom: 10px; }
.nav-menu { list-style: none; }
.nav-item { margin-bottom: 4px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.2s;
    cursor: pointer;
    font-weight: 500;
}

.nav-link:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.nav-link.active { background: var(--primary-light); color: var(--primary); }
.nav-link i { width: 20px; height: 20px; }

.nav-badge { margin-right: auto; background: var(--primary); color: white; font-size: 11px; padding: 2px 8px; border-radius: 10px; }
[dir="ltr"] .nav-badge { margin-right: 0; margin-left: auto; }

.sidebar-footer { padding: 20px; border-top: 1px solid var(--border-color); }
.user-card { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--bg-tertiary); border-radius: 12px; }
.user-avatar { width: 44px; height: 44px; background: linear-gradient(135deg, var(--primary), var(--primary-hover)); border-radius: 12px; display: flex; align-items: center; justify-content: center; color: white; font-weight: 700; font-size: 18px; }
.user-info { flex: 1; }
.user-name { font-weight: 600; font-size: 14px; }
.user-role { font-size: 12px; color: var(--text-muted); }

.main-content { margin-right: 280px; min-height: 100vh; }
[dir="ltr"] .main-content { margin-right: 0; margin-left: 280px; }

.topbar {
    height: 70px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-right { display: flex; align-items: center; gap: 12px; }
.page-title { font-size: 24px; font-weight: 700; }
.menu-toggle { 
    display: none; 
    width: 42px; 
    height: 42px; 
    border: 1px solid var(--border-color); 
    background: var(--bg-secondary); 
    border-radius: 10px; 
    align-items: center; 
    justify-content: center; 
    cursor: pointer; 
    color: var(--text-secondary);
}
.menu-toggle:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.menu-toggle i { width: 20px; height: 20px; }
.topbar-left { display: flex; align-items: center; gap: 12px; }

.search-box { position: relative; }
.search-box input { width: 300px; padding: 10px 16px 10px 44px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 10px; color: var(--text-primary); font-family: inherit; }
.search-box i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 18px; height: 18px; }
[dir="rtl"] .search-box i { left: auto; right: 14px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
    width: 42px;
    height: 42px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
    position: relative;
}

.icon-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.icon-btn i { width: 20px; height: 20px; }
.notification-dot { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; background: var(--error); border-radius: 50%; }

.content-area { padding: 30px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; margin-bottom: 30px; }
.stat-card { background: var(--bg-secondary); border-radius: 16px; padding: 24px; border: 1px solid var(--border-color); transition: all 0.3s; }
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.stat-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.stat-icon { width: 52px; height: 52px; border-radius: 14px; display: flex; align-items: center; justify-content: center; }
.stat-icon i { width: 24px; height: 24px; }
.stat-icon.red { background: var(--error-light); color: var(--error); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.yellow { background: var(--warning-light); color: var(--warning); }
.stat-icon.blue { background: var(--info-light); color: var(--info); }
.stat-trend { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 500; }
.stat-trend.up { color: var(--success); }
.stat-value { font-size: 36px; font-weight: 700; margin-bottom: 4px; }
.stat-label { color: var(--text-secondary); font-size: 14px; }

/* Cards & Tables */
.card { background: var(--bg-secondary); border-radius: 16px; border: 1px solid var(--border-color); overflow: hidden; margin-bottom: 24px; }
.card-header { padding: 20px 24px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.card-title { font-size: 18px; font-weight: 600; }
.card-body { padding: 24px; }

.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 16px 20px; text-align: right; }
[dir="ltr"] th, [dir="ltr"] td { text-align: left; }
th { background: var(--bg-tertiary); color: var(--text-secondary); font-weight: 600; font-size: 13px; text-transform: uppercase; }
td { border-bottom: 1px solid var(--border-color); font-size: 14px; }
tr:hover td { background: var(--bg-tertiary); }

.badge { display: inline-flex; padding: 6px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.success { background: var(--success-light); color: var(--success); }
.badge.warning { background: var(--warning-light); color: var(--warning); }
.badge.error { background: var(--error-light); color: var(--error); }
.badge.info { background: var(--info-light); color: var(--info); }

.section { display: none; }
.section.active { display: block; }

/* ANPR */
.anpr-container { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.anpr-form-card, .anpr-result-card { background: var(--bg-secondary); border-radius: 16px; padding: 24px; border: 1px solid var(--border-color); }
.anpr-result-card { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 300px; }
.anpr-result-icon { width: 80px; height: 80px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-bottom: 20px; }
.anpr-result-icon i { width: 40px; height: 40px; }
.anpr-result-icon.granted { background: var(--success-light); color: var(--success); }
.anpr-result-icon.denied { background: var(--error-light); color: var(--error); }
.anpr-result-icon.waiting { background: var(--bg-tertiary); color: var(--text-muted); }
.anpr-result-title { font-size: 24px; font-weight: 700; margin-bottom: 10px; }
.anpr-result-message { color: var(--text-secondary); text-align: center; }

/* API Docs */
.api-endpoint { background: var(--bg-tertiary); border-radius: 12px; padding: 16px 20px; margin-bottom: 12px; display: flex; align-items: center; gap: 16px; }
.api-method { padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 700; min-width: 70px; text-align: center; }
.api-method.get { background: var(--success-light); color: var(--success); }
.api-method.post { background: var(--info-light); color: var(--info); }
.api-method.put { background: var(--warning-light); color: var(--warning); }
.api-method.delete { background: var(--error-light); color: var(--error); }
.api-path { font-family: 'Courier New', monospace; font-size: 14px; flex: 1; }
.api-desc { color: var(--text-secondary); font-size: 13px; }

.code-block { background: #1e1e1e; color: #d4d4d4; border-radius: 12px; padding: 20px; font-family: 'Courier New', monospace; font-size: 13px; overflow-x: auto; margin-top: 16px; white-space: pre; }
.code-block .string { color: #ce9178; }
.code-block .key { color: #9cdcfe; }
.code-block .number { color: #b5cea8; }

.tabs { display: flex; gap: 8px; margin-bottom: 24px; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.tab-btn { padding: 10px 20px; background: none; border: none; color: var(--text-secondary); font-family: inherit; font-size: 14px; font-weight: 500; cursor: pointer; border-radius: 8px; }
.tab-btn:hover { background: var(--bg-tertiary); }
.tab-btn.active { background: var(--primary-light); color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

.spinner { width: 20px; height: 20px; border: 2px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: white; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Action Buttons */
.action-btns { display: flex; gap: 6px; justify-content: center; }
.action-btn { width: 32px; height: 32px; border: none; border-radius: 6px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s; }
.action-btn i { width: 16px; height: 16px; }
.action-btn.view { background: var(--primary-light); color: var(--primary); }
.action-btn.view:hover { background: var(--primary); color: white; }
.action-btn.edit { background: #FEF3C7; color: #D97706; }
.action-btn.edit:hover { background: #F59E0B; color: white; }
.action-btn.delete { background: var(--error-light); color: var(--error); }
.action-btn.delete:hover { background: var(--error); color: white; }
.action-btn.approve { background: var(--success-light); color: var(--success); }
.action-btn.approve:hover { background: var(--success); color: white; }

/* Small Button */
.btn-sm { width: auto; padding: 8px 16px; font-size: 13px; }

/* SAR Currency Icon */
.sar-icon { width: 16px; height: 16px; vertical-align: middle; margin-right: 2px; display: inline-block; }
[dir="rtl"] .sar-icon { margin-right: 0; margin-left: 2px; }

@media (max-width: 1024px) {
    .sidebar { 
        transform: translateX(100%); 
        position: fixed;
        z-index: 1000;
        transition: transform 0.3s ease;
    }
    [dir="ltr"] .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-right: 0 !important; margin-left: 0 !important; }
    .anpr-container { grid-template-columns: 1fr; }
    .menu-toggle { display: flex !important; }
    .sidebar-close { display: flex !important; }
    
    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        transition: opacity 0.3s ease;
    }
    .sidebar-overlay.active { display: block; }
}

@media (max-width: 768px) {
    .login-sidebar { display: none; }
    .login-main { max-width: 100%; padding: 30px; }
    .search-box { display: none; }
}
