:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --accent: #06b6d4;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #111827;
  --hover: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --border: #334155;
  --radius: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .28);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: linear-gradient(135deg, #0f172a 0%, #172033 50%, #111827 100%);
  color: var(--text);
  font-family: "Tajawal", "Segoe UI", Tahoma, sans-serif;
  direction: rtl;
}

/* ===== SIDEBAR ===== */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(6px);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}

.sidebar-nav-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 260px;
  height: 100vh;
  background: linear-gradient(180deg, #1e1b4b 0%, #312e81 50%, #1e1b4b 100%);
  z-index: 999;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
  border-left: 1px solid rgba(99, 102, 241, 0.15);
}

.sidebar-nav-panel.active {
  transform: translateX(0);
}

.sb-brand {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sb-brand-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--primary), #06b6d4);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

.sb-brand-text {
  color: white;
  font-size: 18px;
  font-weight: 800;
}

.sb-brand-sub {
  color: rgba(255, 255, 255, 0.45);
  font-size: 11px;
  font-weight: 500;
}

.sb-close {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.sb-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.sb-menu {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.sb-menu::-webkit-scrollbar {
  width: 4px;
}

.sb-menu::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.sb-section-title {
  color: rgba(255, 255, 255, 0.3);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 0 12px 8px;
}

.sb-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin: 2px 0;
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.sb-item::before {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: linear-gradient(180deg, var(--primary), #06b6d4);
  border-radius: 2px;
  transition: height 0.25s ease;
}

.sb-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: white;
}

.sb-item:hover::before {
  height: 60%;
}

.sb-item.active {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.2), rgba(99, 102, 241, 0.05));
  color: white;
  font-weight: 700;
}

.sb-item.active::before {
  height: 80%;
}

.sb-item .sb-icon {
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s;
}

.sb-item:hover .sb-icon {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.05);
}

.sb-item.active .sb-icon {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.sb-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sb-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sb-user-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), #06b6d4);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
}

.sb-user-name {
  color: white;
  font-size: 13px;
  font-weight: 600;
}

.sb-user-role {
  color: rgba(255, 255, 255, 0.4);
  font-size: 11px;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  box-shadow: 0 6px 24px rgba(79, 70, 229, .32);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .16);
  font-weight: 800;
}

.brand-title {
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
}

.brand-subtitle {
  font-size: 11px;
  color: rgba(255, 255, 255, .72);
  margin-top: 1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.layout {
  max-width: 1440px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 72px;
  background: rgba(30, 41, 59, .92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.nav-section {
  padding: 12px;
  border-bottom: 1px solid rgba(148, 163, 184, .12);
}

.nav-section:last-child {
  border-bottom: 0;
}

.nav-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  margin: 0 8px 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 700;
  margin: 2px 0;
}

.nav-link:hover {
  background: rgba(255, 255, 255, .06);
  color: white;
}

.nav-link.active {
  background: linear-gradient(90deg, rgba(99, 102, 241, .28), rgba(6, 182, 212, .08));
  color: white;
}

.nav-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .08);
  font-size: 13px;
}

.main {
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
}

.page-kicker {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.card {
  background: rgba(30, 41, 59, .94);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

.card-body {
  padding: 14px;
}

.stat-card {
  padding: 16px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
  margin-top: 6px;
}

.stat-note {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.input,
.select,
.textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 11px;
  outline: none;
}

.textarea {
  min-height: 92px;
  resize: vertical;
  direction: ltr;
  text-align: left;
  font-family: Consolas, monospace;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .16);
}

.search {
  min-width: 260px;
  max-width: 420px;
}

.btn {
  border: 0;
  border-radius: var(--radius);
  color: white;
  background: rgba(255, 255, 255, .12);
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
}

.btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, .18);
}

.btn-primary {
  background: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-success {
  background: var(--success);
}

.btn-warning {
  background: var(--warning);
  color: #111827;
}

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

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-sm {
  padding: 6px 9px;
  min-height: 30px;
  font-size: 12px;
}

.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.tab {
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, .72);
  color: var(--muted);
  border-radius: var(--radius);
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 800;
}

.tab.active {
  color: white;
  border-color: var(--primary);
  background: rgba(99, 102, 241, .24);
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.data-table th,
.data-table td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-size: 13px;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  background: rgba(15, 23, 42, .55);
  font-size: 12px;
  white-space: nowrap;
}

.data-table tr:hover td {
  background: rgba(51, 65, 85, .52);
}

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

.empty {
  color: var(--muted);
  text-align: center;
  padding: 28px;
}

.cell-strong {
  font-weight: 800;
}

.muted {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 9px;
  background: rgba(148, 163, 184, .16);
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  background: rgba(34, 197, 94, .18);
  color: #86efac;
}

.badge.warn {
  background: rgba(245, 158, 11, .18);
  color: #fcd34d;
}

.badge.bad {
  background: rgba(239, 68, 68, .18);
  color: #fca5a5;
}

.badge.info {
  background: rgba(6, 182, 212, .18);
  color: #67e8f9;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, .72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.active {
  display: flex;
}

.modal {
  width: min(760px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal-header,
.modal-footer {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-footer {
  border-top: 1px solid var(--border);
  border-bottom: 0;
  justify-content: flex-start;
}

.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

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

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

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field.full {
  grid-column: 1 / -1;
}

.check-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding-top: 24px;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.toast-stack {
  position: fixed;
  top: 70px;
  left: 16px;
  z-index: 200;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
}

.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 700;
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--danger);
}

.drawer-toggle {
  display: none;
}

.mobile-sidebar-backdrop {
  display: none;
}

@media (max-width:960px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 280px;
    z-index: 90;
    transform: translateX(105%);
    transition: transform .25s ease;
    border-radius: 0;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(0, 0, 0, .45);
  }

  .mobile-sidebar-backdrop.open {
    display: block;
  }

  .drawer-toggle {
    display: inline-flex;
  }

  .grid-2,
  .grid-3,
  .grid-4,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .search {
    min-width: 0;
    max-width: none;
  }
}

@media (max-width:560px) {
  .brand-subtitle {
    display: none;
  }

  .header-inner {
    align-items: flex-start;
  }

  .page-head {
    flex-direction: column;
  }

  .data-table {
    min-width: 680px;
  }
}