:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --primary-dark: #1e3a8a;
  --secondary: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --sidebar-width: 272px;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(15, 23, 42, .06);
}

[data-theme="dark"] {
  --primary: #3b82f6;
  --bg: #0f172a;
  --card: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, 'Noto Sans Arabic', sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .3s, color .3s;
  font-variant-numeric: lining-nums tabular-nums;
}

input, select, textarea, .data-table, .kpi-value, .dash-metric-value, .dash-kpi-value {
  font-variant-numeric: lining-nums tabular-nums;
}

[dir="rtl"] body { font-family: 'Noto Sans Arabic', 'Segoe UI', sans-serif; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(165deg, var(--primary-dark) 0%, var(--primary) 45%, #2563eb 100%);
  color: #fff;
  padding: 1.25rem 1rem;
  box-shadow: 4px 0 32px rgba(30, 64, 175, .15);
  position: fixed;
  top: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform .3s;
}
[dir="rtl"] .sidebar { left: auto; right: 0; }
[dir="ltr"] .sidebar { left: 0; }

.brand-logo { font-weight: 700; font-size: 1.1rem; margin-bottom: .25rem; }
.brand-tagline { font-size: .75rem; opacity: .85; margin-bottom: 1.5rem; }

.nav-link {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem 1rem; color: rgba(255,255,255,.85);
  text-decoration: none; border-radius: .5rem;
  margin-bottom: .25rem; transition: all .2s;
}
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.15); color: #fff; }

.main-content {
  flex: 1;
  margin-inline-start: var(--sidebar-width);
  padding: clamp(.75rem, 2vw, 1.5rem);
  min-width: 0;
  animation: fadeIn .4s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  transition: transform .2s, box-shadow .2s;
}
.card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.08); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { text-align: center; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: .85rem; color: var(--text-muted); }

.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .5rem 1rem; border-radius: .5rem; border: none;
  cursor: pointer; font-size: .9rem; transition: all .2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .75rem; text-align: start; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-muted); font-size: .85rem; }

.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e40af 0%, #06b6d4 100%);
}
.login-card {
  background: var(--card); padding: 2.5rem; border-radius: 1.25rem;
  width: 100%; max-width: 420px; box-shadow: 0 25px 50px rgba(0,0,0,.2);
  animation: fadeIn .5s ease;
}
.form-control {
  width: 100%; padding: .75rem 1rem; border: 1px solid var(--border);
  border-radius: .5rem; margin-bottom: 1rem; background: var(--bg); color: var(--text);
}

.badge { padding: .25rem .5rem; border-radius: 999px; font-size: .75rem; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }

.developer-footer {
  margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border);
  font-size: .8rem; color: var(--text-muted); text-align: center;
}

.toast-container { position: fixed; top: 1rem; inset-inline-end: 1rem; z-index: 9999; }
.toast {
  background: var(--card); border: 1px solid var(--border);
  padding: 1rem 1.25rem; border-radius: .5rem; margin-bottom: .5rem;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  animation: slideIn .3s ease;
}
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }

.mobile-toggle { display: none; }
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: none; }
  .main-content { margin-inline-start: 0; padding: .75rem; }
  .mobile-toggle { display: inline-flex; }
  .topbar { margin-bottom: 1rem; }
  .page-title { font-size: 1.1rem; }
  .card { padding: 1rem; border-radius: .85rem; }
  th, td { padding: .55rem .45rem; font-size: .82rem; }
}

.shimmer {
  background: linear-gradient(90deg, var(--border) 25%, transparent 50%, var(--border) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite;
  height: 1rem; border-radius: .25rem; margin-bottom: .5rem;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ——— Admin UI enhancements ——— */
.sidebar-brand { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.brand-icon { font-size: 1.75rem; line-height: 1; }
.sidebar-user {
  display: flex; align-items: center; gap: .75rem;
  background: rgba(255,255,255,.1); border-radius: .75rem;
  padding: .75rem; margin-bottom: 1rem;
}
.user-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,.25); display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.user-meta strong { display: block; font-size: .9rem; }
.user-meta small { opacity: .8; font-size: .75rem; }
.sidebar-nav { display: flex; flex-direction: column; gap: .15rem; }
.nav-icon { width: 1.25rem; text-align: center; }
.sidebar-footer { margin-top: auto; padding-top: 1rem; font-size: .7rem; opacity: .75; }

.topbar-start { display: flex; align-items: center; gap: .75rem; }
.page-title { margin: 0; font-size: 1.35rem; font-weight: 700; }
.topbar-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.btn-sm { padding: .4rem .75rem; font-size: .8rem; }
.btn-icon { padding: .45rem .65rem; }

.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.alert { padding: 1rem; border-radius: .75rem; margin: .5rem 0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
[data-theme="dark"] .alert-danger { background: #450a0a; color: #fecaca; border-color: #7f1d1d; }
.empty-state { text-align: center; padding: 2rem; color: var(--text-muted); }
.page-toolbar { margin-bottom: 1rem; }
.page-toolbar h3 { margin: 0 0 .35rem; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.kpi-card {
  display: flex; align-items: center; gap: 1rem;
  padding: 1.1rem 1.25rem !important;
}
.kpi-icon { font-size: 2rem; line-height: 1; opacity: .9; }
.kpi-value { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.kpi-label { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }
.tone-primary .kpi-value { color: var(--primary); }
.tone-danger .kpi-value { color: var(--danger); }
.tone-success .kpi-value { color: var(--success); }
.tone-orange .kpi-value { color: var(--warning); }
.tone-cyan .kpi-value { color: var(--secondary); }
.tone-green .kpi-value { color: var(--success); }
.tone-purple .kpi-value { color: #8b5cf6; }

.dashboard-wrap { display: flex; flex-direction: column; gap: 1.25rem; }
.dash-welcome {
  display: flex; justify-content: space-between; align-items: flex-start;
  flex-wrap: wrap; gap: 1rem;
  background: linear-gradient(135deg, rgba(30,64,175,.08) 0%, rgba(6,182,212,.08) 100%);
}
.dash-eyebrow { margin: 0; font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.dash-title { margin: .25rem 0; font-size: 1.5rem; }
.dash-welcome-stats { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.pill {
  padding: .35rem .85rem; border-radius: 999px; font-size: .8rem;
  background: var(--bg); border: 1px solid var(--border);
}
.pill-primary { background: rgba(30,64,175,.12); color: var(--primary); border-color: transparent; }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
.chart-card h3 { margin: 0 0 1rem; font-size: 1rem; }
.dash-panels {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
.card-wide { grid-column: 1 / -1; }
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem;
}
.card-head h3 { margin: 0; font-size: 1rem; }
.link-sm { font-size: .85rem; color: var(--primary); text-decoration: none; }
.link-sm:hover { text-decoration: underline; }

.data-table th { background: var(--bg); position: sticky; top: 0; }
.data-table tbody tr:hover { background: rgba(30,64,175,.04); }

.loading-block { padding: 1.5rem; text-align: center; color: var(--text-muted); }
.shimmer.short { width: 60%; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.setting-item label {
  display: block; font-size: .75rem; color: var(--text-muted); margin-bottom: .25rem;
}
.setting-value {
  font-weight: 600; padding: .5rem 0; word-break: break-word;
}

.about-card h2 { margin-top: 0; color: var(--primary); }
.about-list { line-height: 1.8; padding-inline-start: 1.25rem; }

.toast-error { border-color: var(--danger); }
.toast-info { border-color: var(--primary); }

@media (max-width: 1100px) {
  .chart-grid, .dash-panels { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
