:root {
  --blue-900: #0b3d78;
  --blue-800: #0f4c95;
  --blue-700: #1565c0;
  --blue-100: #e8f1fb;
  --orange-500: #f5a623;
  --orange-600: #e8940c;
  --gray-50: #f7f9fc;
  --gray-100: #eef1f6;
  --gray-200: #dfe4ec;
  --gray-500: #6b7688;
  --gray-700: #3a4252;
  --gray-900: #1c212b;
  --red-600: #d84343;
  --green-600: #1f9d55;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(15, 40, 80, 0.08);
  --shadow-lg: 0 10px 35px rgba(15, 40, 80, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  direction: rtl;
}

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

img { max-width: 100%; display: block; }

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- Header ---------- */
.site-header {
  background: linear-gradient(120deg, var(--blue-900), var(--blue-700));
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
.site-header .header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  gap: 16px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.brand-text h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 700;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: rgba(255,255,255,0.75);
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform .12s ease, box-shadow .12s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--orange-500); color: #17222f; }
.btn-primary:hover { background: var(--orange-600); }
.btn-outline {
  background: rgba(255,255,255,0.08);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
}
.btn-outline:hover { background: rgba(255,255,255,0.18); }
.btn-ghost {
  background: transparent;
  color: var(--blue-800);
  border: 1px solid var(--gray-200);
}
.btn-ghost:hover { background: var(--gray-100); }
.btn-danger { background: var(--red-600); color: #fff; }
.btn-danger:hover { background: #c23434; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(160deg, var(--blue-800), var(--blue-900) 70%);
  color: #fff;
  padding: 42px 0 40px;
}
.hero h2 {
  font-size: 26px;
  margin: 0 0 10px;
}
.hero p {
  color: rgba(255,255,255,0.8);
  max-width: 640px;
  line-height: 1.9;
  margin: 0 0 26px;
  font-size: 15px;
}
.search-bar {
  background: #fff;
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  gap: 10px;
  box-shadow: var(--shadow-lg);
  flex-wrap: wrap;
}
.search-bar input[type="text"] {
  flex: 1 1 220px;
  border: none;
  outline: none;
  padding: 10px 14px;
  font-size: 14.5px;
  font-family: inherit;
  border-radius: 8px;
  background: var(--gray-50);
}
.search-bar select {
  border: none;
  outline: none;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--gray-50);
  font-family: inherit;
  font-size: 14px;
  color: var(--gray-700);
}

/* ---------- Section title row ---------- */
.muted { color: var(--gray-500); font-size: 13.5px; }

/* ---------- Course grid ---------- */
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 26px 0 16px;
}
.section-title h3 { font-size: 19px; margin: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
  transition: opacity .15s ease;
}
.grid.is-loading { opacity: 0.5; }

.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid transparent;
  transition: box-shadow .15s ease, border-color .15s ease, transform .15s ease;
}
.card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--blue-100);
  transform: translateY(-2px);
}
.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--blue-100);
  color: var(--blue-800);
  white-space: nowrap;
}
.badge-code {
  background: var(--gray-100);
  color: var(--gray-700);
  font-family: monospace;
  font-size: 12px;
}
.card h4 {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  min-height: 24px;
}
.card .meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--gray-500);
}
.card .meta span { display: flex; align-items: center; gap: 4px; }
.card-actions {
  margin-top: auto;
  display: flex;
  gap: 8px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-500);
}
.empty-state .icon { font-size: 40px; margin-bottom: 10px; }


/* ---------- Footer ---------- */
.site-footer {
  margin-top: 60px;
  padding: 26px 0;
  text-align: center;
  color: var(--gray-500);
  font-size: 13px;
  border-top: 1px solid var(--gray-200);
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 25, 40, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 30px 16px;
  overflow-y: auto;
  z-index: 200;
}
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  padding: 26px;
  box-shadow: var(--shadow-lg);
  animation: pop .15s ease;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  gap: 10px;
}
.modal-head h3 { margin: 0 0 4px; font-size: 18px; }
.close-btn {
  border: none;
  background: var(--gray-100);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
}
.modal-body { max-height: 70vh; overflow-y: auto; padding-inline-end: 4px; }

.content-block { line-height: 2; font-size: 14px; color: var(--gray-700); }
.content-block ul { padding-inline-start: 20px; margin: 8px 0; }
.content-block li { margin-bottom: 6px; }

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
}
.field label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-700);
  margin-bottom: 6px;
}
.field label .req { color: var(--red-600); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 9px;
  font-family: inherit;
  font-size: 14px;
  background: var(--gray-50);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--blue-700);
  background: #fff;
}
.field textarea { resize: vertical; min-height: 70px; }

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  margin-bottom: 14px;
}
.alert-error { background: #fdeaea; color: var(--red-600); }
.alert-success { background: #e8f8ee; color: var(--green-600); }

.success-panel { text-align: center; padding: 20px 6px; }
.success-panel .icon {
  font-size: 44px;
  margin-bottom: 10px;
}

/* ---------- Admin ---------- */
.admin-shell { min-height: 100vh; display: flex; }
.admin-sidebar {
  width: 236px;
  background: var(--blue-900);
  color: #fff;
  padding: 20px 14px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.admin-sidebar .brand-text h1 { font-size: 14.5px; }
.admin-sidebar .brand-text p { font-size: 11px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}
.nav-item:hover { background: rgba(255,255,255,0.08); }
.nav-item.active { background: var(--orange-500); color: #17222f; }
.admin-main {
  flex: 1;
  padding: 26px 30px 60px;
  min-width: 0;
}
.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.admin-topbar h2 { margin: 0; font-size: 21px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.stat-card .num { font-size: 26px; font-weight: 800; color: var(--blue-900); }
.stat-card .label { font-size: 13px; color: var(--gray-500); margin-top: 4px; }

.panel {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.panel h4 { margin: 0 0 16px; font-size: 15.5px; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.bar-row .bar-label { width: 190px; flex-shrink: 0; color: var(--gray-700); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; background: var(--gray-100); border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill { background: linear-gradient(90deg, var(--blue-700), var(--orange-500)); height: 100%; border-radius: 999px; }
.bar-row .bar-value { width: 34px; text-align: left; color: var(--gray-500); }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th, table.data-table td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--gray-100);
}
table.data-table th { color: var(--gray-500); font-size: 12.5px; font-weight: 700; }
table.data-table tr:hover td { background: var(--gray-50); }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }

.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-left: 6px;
}
.status-dot.on { background: var(--green-600); }
.status-dot.off { background: var(--gray-500); }

.chip-tabs { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
.chip-tab {
  padding: 8px 16px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--gray-200);
  color: var(--gray-700);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}
.chip-tab.active { background: var(--blue-800); color: #fff; border-color: var(--blue-800); }
.reg-count-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  color: var(--blue-800);
}

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--blue-900), var(--blue-700));
  padding: 20px;
}
.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.auth-card .brand { justify-content: center; margin-bottom: 18px; }
.auth-card .brand-icon { background: var(--blue-100); color: var(--blue-800); }
.auth-card .brand-text h1 { color: var(--gray-900); }
.auth-card .brand-text p { color: var(--gray-500); }
.auth-card h2 { text-align: center; font-size: 18px; margin: 0 0 4px; }
.auth-card .sub { text-align: center; color: var(--gray-500); font-size: 13px; margin-bottom: 22px; }

.pagination-info { font-size: 13px; color: var(--gray-500); }

.spinner {
  width: 20px; height: 20px;
  border: 3px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
.spinner.dark { border-color: var(--gray-200); border-top-color: var(--blue-800); }
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ---------- Branding / version badge ---------- */
.brand-logo-img {
  height: 40px;
  width: auto;
  display: block;
  border-radius: 6px;
}
.auth-card .brand-logo-img { height: 56px; margin-bottom: 4px; }
.admin-sidebar .brand-logo-img { height: 34px; }

.version-badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--orange-500);
  color: #17222f;
  vertical-align: middle;
  margin-inline-start: 6px;
  letter-spacing: 0.3px;
}
.brand-text .app-title-row {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.footer-version {
  color: var(--gray-500);
  font-size: 12px;
  margin-top: 4px;
}
.sidebar-version {
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  margin-top: 6px;
}

/* ---------- PWA install button ---------- */
.pwa-install-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.1);
  color: #fff;
  padding: 9px 14px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}
.pwa-install-btn:hover { background: rgba(255,255,255,0.2); }
.pwa-install-btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- Admin toast notifications ---------- */
.admin-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--gray-900);
  color: #fff;
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 400;
  max-width: 90vw;
  text-align: center;
}
.admin-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal-tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--gray-100); }
.modal-tab {
  padding: 9px 14px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--gray-500);
  border-bottom: 2px solid transparent;
}
.modal-tab.active { color: var(--blue-800); border-color: var(--blue-800); }

@media (max-width: 820px) {
  .admin-shell { flex-direction: column; }
  .admin-sidebar { width: 100%; height: auto; position: static; display: flex; flex-wrap: wrap; gap: 4px; }
  .admin-sidebar .brand { width: 100%; margin-bottom: 6px; }
  .admin-main { padding: 20px 16px 50px; }
}
