/* ============================================================
   Scarab WhatsApp API — Admin Dashboard
   ============================================================ */

:root {
  color-scheme: light;
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-2: #f6faf8;
  --surface-3: #edf3f0;
  --text: #0e1f1a;
  --muted: #61756c;
  --border: rgba(14, 31, 26, 0.09);
  --border-strong: rgba(14, 31, 26, 0.16);

  /* اللوحة اللونية */
  --teal: #0d9488;
  --teal-light: #2dd4bf;
  --emerald: #10b981;
  --cyan: #06b6d4;
  --blue: #2563eb;
  --blue-light: #60a5fa;
  --indigo: #4f46e5;
  --violet: #7c3aed;
  --violet-light: #a78bfa;
  --amber: #f59e0b;
  --amber-light: #fbbf24;
  --orange: #ea580c;
  --rose: #e11d48;
  --rose-light: #fb7185;
  --green: #16a34a;
  --green-light: #4ade80;

  --accent: #0aa37f;
  --accent-strong: #067a5f;
  --accent-soft: rgba(10, 163, 127, 0.12);
  --accent-contrast: #ffffff;

  --danger: #d92d20;
  --danger-soft: rgba(217, 45, 32, 0.1);
  --warning: #b54708;
  --warning-soft: rgba(247, 144, 9, 0.14);
  --info: #175cd3;
  --info-soft: rgba(23, 92, 211, 0.1);

  --sidebar-bg: #0b1f1a;
  --sidebar-bg-2: #103128;
  --sidebar-text: #c9ded7;
  --sidebar-muted: #7d978e;
  --sidebar-active: rgba(10, 163, 127, 0.18);

  --shadow-sm: 0 1px 2px rgba(14, 31, 26, 0.05), 0 1px 6px rgba(14, 31, 26, 0.04);
  --shadow-md: 0 8px 28px rgba(14, 31, 26, 0.09);
  --shadow-lg: 0 24px 70px rgba(8, 35, 30, 0.18);

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --font-body: "Tajawal", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: "Cairo", "Tajawal", system-ui, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a1411;
  --surface: #101d18;
  --surface-2: #15241e;
  --surface-3: #1a2c25;
  --text: #e7f0ec;
  --muted: #8aa198;
  --border: rgba(231, 240, 236, 0.08);
  --border-strong: rgba(231, 240, 236, 0.16);

  --teal: #2dd4bf;
  --teal-light: #5eead4;
  --blue: #60a5fa;
  --blue-light: #93c5fd;
  --violet: #a78bfa;
  --violet-light: #c4b5fd;
  --amber: #fbbf24;
  --amber-light: #fcd34d;
  --orange: #fb923c;
  --rose: #fb7185;
  --rose-light: #fda4af;
  --green: #4ade80;
  --green-light: #86efac;

  --accent: #17c79c;
  --accent-strong: #0fa982;
  --accent-soft: rgba(23, 199, 156, 0.14);
  --accent-contrast: #04130f;

  --danger: #f97066;
  --danger-soft: rgba(249, 112, 102, 0.13);
  --warning: #fdb022;
  --warning-soft: rgba(253, 176, 34, 0.13);
  --info: #84adff;
  --info-soft: rgba(132, 173, 255, 0.12);

  --sidebar-bg: #081511;
  --sidebar-bg-2: #0d231c;
  --sidebar-text: #c9ded7;
  --sidebar-muted: #71887f;
  --sidebar-active: rgba(23, 199, 156, 0.16);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

h1, h2, h3, p { margin: 0; }

h1, h2, h3 {
  font-family: var(--font-head);
}

button {
  font-family: inherit;
  cursor: pointer;
}

code {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84em;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
}

/* ============================================================
   الأزرار
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 0.92rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease, filter 0.18s ease;
  white-space: nowrap;
}

.btn svg { width: 17px; height: 17px; flex: none; }

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--emerald), #0891b2);
  color: #fff;
  box-shadow: 0 6px 18px rgba(13, 148, 136, 0.35);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow: 0 8px 24px rgba(13, 148, 136, 0.45);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--accent-soft);
}

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

.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-icon {
  padding: 9px;
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--muted);
}

.btn-icon:hover { color: var(--accent-strong); border-color: var(--accent); }

.btn-block { width: 100%; }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
  border-radius: 8px;
}

.btn .spin {
  animation: rotate 0.9s linear infinite;
}

@keyframes rotate {
  to { transform: rotate(360deg); }
}

/* ============================================================
   حقول الإدخال
   ============================================================ */

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field > span {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--muted);
}

.field-input {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--surface-2);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.field-input svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
  flex: none;
}

.field-input input {
  flex: 1;
  min-width: 0;
  padding: 12px 0;
  font: inherit;
  font-size: 0.95rem;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
}

.field-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.field-input:focus-within svg { color: var(--accent); }

.field-grow { flex: 1; min-width: 240px; }

/* ============================================================
   شاشة تسجيل الدخول
   ============================================================ */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
}

.auth-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: var(--bg);
}

.auth-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--border-strong) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.55), transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.55), transparent 75%);
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.45;
  animation: blob-float 14s ease-in-out infinite alternate;
}

.blob-1 {
  width: 480px;
  height: 480px;
  top: -120px;
  inset-inline-end: -100px;
  background: radial-gradient(circle, var(--teal-light), transparent 70%);
}

.blob-2 {
  width: 420px;
  height: 420px;
  bottom: -140px;
  inset-inline-start: -90px;
  background: radial-gradient(circle, var(--violet-light), transparent 70%);
  animation-delay: -5s;
}

.blob-3 {
  width: 300px;
  height: 300px;
  top: 40%;
  inset-inline-start: 55%;
  background: radial-gradient(circle, var(--amber-light), transparent 70%);
  opacity: 0.28;
  animation-delay: -9s;
}

@keyframes blob-float {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(-40px, 36px) scale(1.12); }
}

.auth-card {
  width: min(100%, 1020px);
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(380px, 1.05fr);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(22px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.auth-form-side {
  padding: 54px 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 16px;
  padding: 6px;
  margin-bottom: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 10px 26px rgba(13, 148, 136, 0.22);
}

.auth-eyebrow {
  font-family: var(--font-head);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 6px;
  background: linear-gradient(90deg, var(--teal), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.auth-form-side h1 {
  font-size: 1.9rem;
  font-weight: 800;
}

.auth-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.94rem;
}

.auth-form {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-form .btn {
  margin-top: 6px;
  padding: 13px 18px;
  font-size: 1rem;
}

.auth-message {
  margin-top: 20px;
  font-size: 0.86rem;
  color: var(--muted);
  padding: 11px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.auth-message.message-error {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: transparent;
}

.auth-brand-side {
  position: relative;
  padding: 54px 48px;
  display: flex;
  align-items: flex-end;
  color: #eafff7;
  background:
    radial-gradient(circle at 88% 8%, rgba(139, 92, 246, 0.5), transparent 46%),
    radial-gradient(circle at 8% 92%, rgba(6, 182, 212, 0.42), transparent 48%),
    radial-gradient(circle at 60% 45%, rgba(251, 191, 36, 0.14), transparent 40%),
    linear-gradient(160deg, #04211a 0%, #07493a 52%, #1e1b4b 135%);
  overflow: hidden;
}

.auth-brand-side::before {
  content: "";
  position: absolute;
  inset: -60% -30% auto auto;
  width: 480px;
  height: 480px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.1);
}

.auth-brand-side::after {
  content: "";
  position: absolute;
  inset: -52% -22% auto auto;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  border: 1.5px dashed rgba(255, 255, 255, 0.14);
}

.auth-brand-glow {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.13) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: linear-gradient(200deg, rgba(0, 0, 0, 0.8), transparent 60%);
  -webkit-mask-image: linear-gradient(200deg, rgba(0, 0, 0, 0.8), transparent 60%);
}

.auth-brand-content {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-brand-content h2 {
  font-size: 1.65rem;
  font-weight: 800;
  line-height: 1.45;
}

.auth-brand-content > p {
  color: rgba(234, 255, 247, 0.78);
  font-size: 0.95rem;
  line-height: 1.8;
}

.auth-features {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-features li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(6px);
  transition: background 0.18s ease, transform 0.18s ease;
}

.auth-features li:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(-4px);
}

.feature-icon {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
}

.feature-icon svg { width: 21px; height: 21px; }

.auth-features li:nth-child(1) .feature-icon {
  background: linear-gradient(135deg, #34d399, #0d9488);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.auth-features li:nth-child(2) .feature-icon {
  background: linear-gradient(135deg, #a78bfa, #6d28d9);
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.4);
}

.auth-features li:nth-child(3) .feature-icon {
  background: linear-gradient(135deg, #fbbf24, #ea580c);
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.4);
}

.auth-features strong {
  display: block;
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 700;
}

.auth-features small {
  color: rgba(234, 255, 247, 0.65);
  font-size: 0.8rem;
}

/* ============================================================
   هيكل اللوحة
   ============================================================ */

.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- الشريط الجانبي ---------- */

.sidebar {
  flex: none;
  width: 264px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  color: var(--sidebar-text);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px 24px;
}

.sidebar-brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px;
}

.sidebar-brand strong {
  display: block;
  font-family: var(--font-head);
  font-size: 1.05rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.02em;
}

.sidebar-brand small {
  color: var(--sidebar-muted);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  font-size: 0.93rem;
  font-weight: 500;
  color: var(--sidebar-muted);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  text-align: start;
  transition: background 0.16s ease, color 0.16s ease;
}

.nav-item svg { width: 19px; height: 19px; flex: none; }

.nav-item:hover {
  color: var(--sidebar-text);
  background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
  color: #fff;
  font-weight: 700;
  background: var(--sidebar-active);
  position: relative;
}

.nav-item.active svg { color: var(--accent); }

.nav-item.active::before {
  content: "";
  position: absolute;
  inset-inline-start: -16px;
  top: 50%;
  translate: 0 -50%;
  width: 4px;
  height: 60%;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--teal-light), var(--accent));
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
}

.user-avatar {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #34d399, #0891b2);
  color: #fff;
}

.user-avatar svg { width: 19px; height: 19px; }

.sidebar-user strong {
  display: block;
  font-size: 0.9rem;
  color: #fff;
}

.sidebar-user small {
  color: var(--sidebar-muted);
  font-size: 0.76rem;
}

.nav-logout:hover {
  color: #ffb4ab;
  background: rgba(217, 45, 32, 0.14);
}

/* ---------- المنطقة الرئيسية ---------- */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 32px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar-titles h1 {
  font-size: 1.35rem;
  font-weight: 800;
}

.topbar-titles p {
  margin-top: 3px;
  font-size: 0.84rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.last-updated {
  font-size: 0.78rem;
  color: var(--muted);
}

.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

.content {
  padding: 28px 32px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.content > section {
  display: flex;
  flex-direction: column;
  gap: 24px;
  animation: panel-in 0.28s ease;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ============================================================
   بطاقات الإحصائيات
   ============================================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 16px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  flex: none;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
}

.stat-icon svg { width: 22px; height: 22px; }

.stat-icon-teal {
  background: linear-gradient(135deg, #34d399, #0d9488);
  box-shadow: 0 7px 16px rgba(13, 148, 136, 0.32);
}

.stat-icon-blue {
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  box-shadow: 0 7px 16px rgba(37, 99, 235, 0.32);
}

.stat-icon-green {
  background: linear-gradient(135deg, #4ade80, #16a34a);
  box-shadow: 0 7px 16px rgba(22, 163, 74, 0.32);
}

.stat-icon-amber {
  background: linear-gradient(135deg, #fbbf24, #ea580c);
  box-shadow: 0 7px 16px rgba(234, 88, 12, 0.32);
}

.stat-icon-violet {
  background: linear-gradient(135deg, #a78bfa, #6d28d9);
  box-shadow: 0 7px 16px rgba(109, 40, 217, 0.32);
}

.stat-icon-rose {
  background: linear-gradient(135deg, #fb7185, #be123c);
  box-shadow: 0 7px 16px rgba(190, 18, 60, 0.32);
}

.stat-body { min-width: 0; }

.stat-body span {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.stat-body strong {
  display: block;
  margin-top: 2px;
  font-family: var(--font-head);
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.2;
}

.stat-body small {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
  color: var(--muted);
}

.stat-card-accent {
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  background: linear-gradient(150deg, var(--accent-soft), var(--surface) 55%);
}

/* ============================================================
   البطاقات العامة
   ============================================================ */

.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.card-head h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.card-head p {
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--muted);
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.card-wide { grid-column: 1 / -1; }

/* ============================================================
   الرسوم البيانية
   ============================================================ */

.bar-chart {
  --bar-1: var(--teal-light);
  --bar-2: var(--teal);
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 220px;
  padding: 30px 0 6px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  border-bottom: 1.5px solid var(--border-strong);
  background-image:
    linear-gradient(to top, transparent calc(25% - 1px), var(--border) 25%, transparent calc(25% + 1px)),
    linear-gradient(to top, transparent calc(50% - 1px), var(--border) 50%, transparent calc(50% + 1px)),
    linear-gradient(to top, transparent calc(75% - 1px), var(--border) 75%, transparent calc(75% + 1px));
}

.bar-chart-compact { height: 170px; }

.chart-teal   { --bar-1: #2dd4bf; --bar-2: #0d9488; }
.chart-violet { --bar-1: #a78bfa; --bar-2: #6d28d9; }
.chart-amber  { --bar-1: #fbbf24; --bar-2: #ea580c; }

[data-theme="dark"] .chart-teal   { --bar-2: #14b8a6; }
[data-theme="dark"] .chart-violet { --bar-2: #8b5cf6; }
[data-theme="dark"] .chart-amber  { --bar-2: #f97316; }

.bar-chart::-webkit-scrollbar { height: 6px; }

.bar-chart::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
}

.bar-chart::-webkit-scrollbar-track { background: transparent; }

.bar-item {
  position: relative;
  flex: 1 0 26px;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.bar-item strong {
  position: absolute;
  bottom: calc(100% - 26px);
  font-size: 0.7rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--bar-1), var(--bar-2));
  border-radius: 7px;
  padding: 3px 8px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  transform: translateY(4px);
  box-shadow: var(--shadow-md);
  z-index: 2;
}

.bar-item:hover strong {
  opacity: 1;
  transform: none;
}

.bar-fill {
  width: 100%;
  max-width: 36px;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, var(--bar-1), var(--bar-2));
  opacity: 0.85;
  transition: opacity 0.15s ease, transform 0.15s ease;
  transform-origin: bottom;
  min-height: 4px;
  animation: bar-grow 0.5s ease backwards;
}

@keyframes bar-grow {
  from { transform: scaleY(0); }
}

.bar-item:hover .bar-fill {
  opacity: 1;
  transform: scaleY(1.02);
}

.bar-item small {
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
}

.chart-empty {
  width: 100%;
  align-self: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.86rem;
  padding: 28px 0;
}

/* ---------- قوائم الترتيب ---------- */

.rank-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.rank-item {
  --rank-1: var(--teal-light);
  --rank-2: var(--teal);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rank-item:nth-child(6n+1) { --rank-1: #2dd4bf; --rank-2: #0d9488; }
.rank-item:nth-child(6n+2) { --rank-1: #60a5fa; --rank-2: #2563eb; }
.rank-item:nth-child(6n+3) { --rank-1: #a78bfa; --rank-2: #6d28d9; }
.rank-item:nth-child(6n+4) { --rank-1: #fbbf24; --rank-2: #ea580c; }
.rank-item:nth-child(6n+5) { --rank-1: #fb7185; --rank-2: #be123c; }
.rank-item:nth-child(6n+6) { --rank-1: #22d3ee; --rank-2: #0e7490; }

[data-theme="dark"] .rank-item:nth-child(6n+1) { --rank-2: #14b8a6; }
[data-theme="dark"] .rank-item:nth-child(6n+2) { --rank-2: #3b82f6; }
[data-theme="dark"] .rank-item:nth-child(6n+3) { --rank-2: #8b5cf6; }
[data-theme="dark"] .rank-item:nth-child(6n+4) { --rank-2: #f97316; }
[data-theme="dark"] .rank-item:nth-child(6n+5) { --rank-2: #f43f5e; }
[data-theme="dark"] .rank-item:nth-child(6n+6) { --rank-2: #06b6d4; }

.rank-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
}

.rank-head span {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-head strong {
  font-family: var(--font-head);
  font-weight: 800;
  color: var(--rank-2);
}

[data-theme="dark"] .rank-head strong { color: var(--rank-1); }

.rank-track {
  height: 9px;
  border-radius: 99px;
  background: var(--surface-3);
  overflow: hidden;
}

.rank-track span {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--rank-1), var(--rank-2));
  animation: rank-grow 0.6s ease backwards;
  transform-origin: right;
}

@keyframes rank-grow {
  from { transform: scaleX(0); }
}

.rank-item small {
  font-size: 0.72rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
  text-align: end;
}

/* ============================================================
   النماذج داخل البطاقات
   ============================================================ */

.inline-form {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.token-reveal {
  border: 1.5px dashed color-mix(in srgb, var(--warning) 55%, transparent);
  background: var(--warning-soft);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.token-reveal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--warning);
}

.token-reveal-title svg { width: 18px; height: 18px; flex: none; }

.token-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.token-row code {
  flex: 1;
  min-width: 220px;
  padding: 10px 12px;
  font-size: 0.82rem;
  word-break: break-all;
  background: var(--surface);
  border-radius: 8px;
}

/* ============================================================
   الجداول
   ============================================================ */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.89rem;
  min-width: 640px;
}

.data-table th {
  text-align: start;
  padding: 12px 16px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr {
  transition: background 0.13s ease;
}

.data-table tbody tr:hover {
  background: var(--surface-2);
}

.cell-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  white-space: nowrap;
}

/* ---------- شارات الحالة ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px;
  border-radius: 99px;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.badge-connected {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

[data-theme="dark"] .badge-connected { color: var(--accent); }

.badge-connected::before {
  box-shadow: 0 0 0 0 currentColor;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 45%, transparent); }
  70% { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.badge-waiting {
  color: var(--warning);
  background: var(--warning-soft);
}

.badge-error {
  color: var(--danger);
  background: var(--danger-soft);
}

.badge-muted {
  color: var(--muted);
  background: var(--surface-3);
}

/* ---------- الحالات الفارغة ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 38px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-state svg {
  width: 42px;
  height: 42px;
  opacity: 0.45;
}

/* ============================================================
   نافذة QR المنبثقة
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 16, 13, 0.55);
  backdrop-filter: blur(6px);
  animation: fade-in 0.18s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: min(100%, 440px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: modal-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.94) translateY(10px); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.modal-head h2 {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-head p {
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.7;
}

.qr-wrap {
  display: grid;
  place-items: center;
  padding: 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-height: 280px;
}

.qr-placeholder {
  width: 240px;
  height: 240px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1.5px dashed var(--border-strong);
  color: var(--muted);
}

.qr-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: rotate 0.8s linear infinite;
}

.qr-image {
  width: 240px;
  height: 240px;
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 8px;
}

.qr-status {
  font-size: 0.86rem;
  color: var(--muted);
  text-align: center;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

/* ============================================================
   الإشعارات (Toasts)
   ============================================================ */

.toasts {
  position: fixed;
  bottom: 22px;
  inset-inline-start: 22px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(92vw, 380px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 16px;
  font-size: 0.88rem;
  font-weight: 500;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  animation: toast-in 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

.toast::before {
  content: "";
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.toast-success { border-inline-start: 3px solid var(--accent); }
.toast-success::before { background: var(--accent); }
.toast-error { border-inline-start: 3px solid var(--danger); color: var(--danger); }
.toast-error::before { background: var(--danger); }

.toast.toast-out {
  animation: toast-out 0.25s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(10px); }
}

/* ============================================================
   التجاوب
   ============================================================ */

@media (max-width: 1100px) {
  .analytics-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 920px) {
  .app { flex-direction: column; }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
  }

  .sidebar-brand { padding: 0; }
  .sidebar-brand div { display: none; }

  .sidebar-nav {
    flex: 1;
    flex-direction: row;
    justify-content: center;
    gap: 6px;
  }

  .nav-item { width: auto; padding: 9px 13px; }
  .nav-item.active::before { display: none; }
  .nav-item span { display: none; }
  .nav-item svg { width: 21px; height: 21px; }

  .sidebar-foot {
    margin: 0;
    padding: 0;
    border: none;
    flex-direction: row;
  }

  .sidebar-user { display: none; }

  .topbar { padding: 14px 18px; flex-wrap: wrap; }
  .content { padding: 18px 16px 40px; }
  .last-updated { display: none; }

  .auth-card { grid-template-columns: 1fr; }
  .auth-brand-side { display: none; }
  .auth-form-side { padding: 38px 28px; }
}

@media (max-width: 560px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  .stat-card { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px; }
  .stat-body strong { font-size: 1.3rem; }

  .bar-chart { gap: 4px; }
  .bar-item { flex-basis: 30px; }
  .bar-item small { font-size: 0.56rem; }

  .topbar-actions .btn span { display: none; }

  .inline-form { flex-direction: column; align-items: stretch; }
  .field-grow { min-width: 0; }
}
