/* ═══════════════════════════════════════════════
   MAIN CSS — Design System & Global Styles
   ═══════════════════════════════════════════════ */

/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=Cairo:wght@400;600;700&display=swap');

/* ── CSS Custom Properties ── */
:root {
  /* ── Royal Gold & Black Theme ── */

  /* Backgrounds */
  --bg-primary: #020202;
  /* Deepest Black */
  --bg-secondary: #0a0a0a;
  /* Rich Black */
  --bg-card: #111111;
  /* Dark Charcoal */
  --bg-card-hover: #161616;
  --bg-glass: rgba(10, 10, 10, 0.85);
  --bg-glass-border: rgba(212, 175, 55, 0.15);
  /* Gold tint */
  --bg-overlay: rgba(0, 0, 0, 0.9);
  --bg-navbar-scrolled: rgba(2, 2, 2, 0.95);

  /* Text */
  --text-primary: #ffffff;
  --text-secondary: #cccccc;
  --text-muted: #888888;

  /* Accents (Gold) */
  --accent-primary: #D4AF37;
  /* Metallic Gold */
  --accent-secondary: #F1D06E;
  /* Light Gold */

  /* Gradients */
  --accent-gradient: linear-gradient(135deg, #D4AF37 0%, #F1D06E 50%, #B49026 100%);
  --accent-gradient-btn: linear-gradient(135deg, #D4AF37 0%, #B49026 100%);
  --accent-glow: rgba(212, 175, 55, 0.25);

  /* Functional Colors */
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;

  /* Borders */
  --border-color: rgba(212, 175, 55, 0.15);
  /* Subtle Gold Border */
  --border-light: rgba(255, 255, 255, 0.08);

  /* Typography */
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-arabic: 'Cairo', sans-serif;

  /* Spacing */
  --section-padding: 100px 0;
  --container-width: 1200px;
  --card-radius: 16px;
  --btn-radius: 10px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 30px rgba(108, 99, 255, 0.15);

  /* Transitions */
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-glass: rgba(255, 255, 255, 0.85);
  --bg-glass-border: rgba(108, 99, 255, 0.2);
  --bg-overlay: rgba(255, 255, 255, 0.8);
  --bg-navbar-scrolled: rgba(255, 255, 255, 0.95);

  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --border-color: rgba(0, 0, 0, 0.1);
  --border-light: rgba(0, 0, 0, 0.05);
  --shadow-glow: 0 0 30px rgba(108, 99, 255, 0.25);
}

/* ── Reset & Base ── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-primary);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Rule 2/4: Arabic body automatically uses Cairo, no Nunjucks conditional needed */
[dir="rtl"] body,
[dir="rtl"] {
  font-family: var(--font-arabic);
}

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: var(--transition-fast);
}

a:hover {
  color: var(--accent-secondary);
}

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

/* ── Container ── */
.container {
  width: 100%;
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 0 24px;
}

/* ── Typography ── */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
}

h1 {
  font-size: clamp(2.2rem, 5vw, 3.5rem);
}

h2 {
  font-size: clamp(1.8rem, 3.5vw, 2.5rem);
}

h3 {
  font-size: clamp(1.2rem, 2vw, 1.5rem);
}

h4 {
  font-size: 1.125rem;
}

p {
  color: var(--text-secondary);
  line-height: 1.7;
}

.text-gradient {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.section-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent-primary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 12px;
}

.section-label::before {
  content: '';
  width: 30px;
  height: 2px;
  background: var(--accent-gradient-btn);
  border-radius: 2px;
}

.section-title {
  margin-bottom: 20px;
}

.section-desc {
  max-width: 600px;
  color: var(--text-muted);
  font-size: 1.05rem;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: var(--btn-radius);
  font-family: var(--font-primary);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-gradient-btn);
  color: #fff;
  box-shadow: 0 4px 15px rgba(108, 99, 255, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(108, 99, 255, 0.4);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--accent-primary);
  border: 1.5px solid var(--accent-primary);
}

.btn-outline:hover {
  background: rgba(108, 99, 255, 0.1);
  transform: translateY(-2px);
  color: var(--accent-primary);
}

.btn-ghost {
  background: var(--bg-glass);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
}

.btn-ghost:hover {
  background: var(--bg-card);
  border-color: var(--accent-primary);
}

.btn-sm {
  padding: 8px 18px;
  font-size: 0.85rem;
}

.btn-lg {
  padding: 16px 36px;
  font-size: 1.05rem;
}

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 24px;
  transition: var(--transition);
}

.card:hover {
  border-color: rgba(108, 99, 255, 0.3);
  box-shadow: var(--shadow-glow);
  transform: translateY(-4px);
}

.glass-card {
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--bg-glass-border);
  border-radius: var(--card-radius);
  padding: 24px;
  transition: var(--transition);
}

/* ── Form Elements ── */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border-color);
  border-radius: var(--btn-radius);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 0.95rem;
  transition: var(--transition-fast);
  outline: none;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.15);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-textarea {
  resize: vertical;
  min-height: 120px;
}

/* ── Badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.badge-info {
  background: rgba(59, 130, 246, 0.15);
  color: var(--info);
}

.badge-primary {
  background: rgba(108, 99, 255, 0.15);
  color: var(--accent-primary);
}

/* ── Table ── */
.table-container {
  overflow-x: auto;
  border-radius: var(--card-radius);
  border: 1px solid var(--border-color);
}

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

.data-table th {
  background: var(--bg-card);
  padding: 14px 16px;
  /* Logical property: auto-flips to end in RTL */
  text-align: start;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 14px 16px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
}

.data-table tr:hover td {
  background: var(--bg-card);
}

/* ── Toast Notification ── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 14px 20px;
  border-radius: var(--btn-radius);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 300px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease-out;
  backdrop-filter: blur(20px);
}

.toast-success {
  border-left: 3px solid var(--success);
}

.toast-error {
  border-left: 3px solid var(--danger);
}

.toast-warning {
  border-left: 3px solid var(--warning);
}

.toast-info {
  border-left: 3px solid var(--info);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }

  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 30px;
}

.pagination button {
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
  font-size: 0.85rem;
}

.pagination button:hover,
.pagination button.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Loading Spinner ── */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

/* ── Animations ── */
.fade-in {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.fade-in.visible {
  opacity: 1;
  transform: translateY(0);
}

.fade-in-left {
  opacity: 0;
  transform: translateX(-30px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.fade-in-left.visible {
  opacity: 1;
  transform: translateX(0);
}

.fade-in-right {
  opacity: 0;
  transform: translateX(30px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.fade-in-right.visible {
  opacity: 1;
  transform: translateX(0);
}

.scale-in {
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.scale-in.visible {
  opacity: 1;
  transform: scale(1);
}

/* ── Utility ── */
.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.justify-center {
  justify-content: center;
}

.gap-1 {
  gap: 8px;
}

.gap-2 {
  gap: 16px;
}

.gap-3 {
  gap: 24px;
}

.gap-4 {
  gap: 32px;
}

.text-center {
  text-align: center;
}

.w-full {
  width: 100%;
}

.mt-1 {
  margin-top: 8px;
}

.mt-2 {
  margin-top: 16px;
}

.mt-3 {
  margin-top: 24px;
}

.mb-1 {
  margin-bottom: 8px;
}

.mb-2 {
  margin-bottom: 16px;
}

.mb-3 {
  margin-bottom: 24px;
}

.hidden {
  display: none !important;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-card);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

/* ── Language Toggle (Global) ── */
.lang-toggle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--border-color);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  padding: 0;
  background: none;
  vertical-align: middle;
  text-decoration: none;
}

.lang-toggle:hover {
  transform: translateY(-2px);
  border-color: var(--accent-primary);
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.25);
}

.lang-toggle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Empty State / Loading State ── */
.empty-state-wrapper {
  grid-column: 1 / -1;
  width: 100%;
  /* For flex fallback */
  display: flex !important;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  min-height: 200px;
  /* Safer than 15vw which might distort */
  padding: 3rem;
  color: var(--text-muted);
  font-size: 1.1rem;
  background: var(--bg-card);
  /* Add slight background to anchor it */
  border-radius: var(--card-radius);
  border: 1px dashed var(--border-color);
  /* Give it boundaries */
  margin: 2rem 0;
  /* Add margin to prevent bleeding into headers */
}

.empty-state-wrapper i.fa-spinner {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  color: var(--accent-primary);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  :root {
    --section-padding: 60px 0;
  }

  .container {
    padding: 0 16px;
  }
}

/* ══════════════════════════════════════════════
   RTL LOGICAL PROPERTY UTILITIES
   Rule 2: These allow icon/layout elements to
   flip automatically when dir="rtl" is active.
   ══════════════════════════════════════════════ */

/* Back-arrow icon: points left in LTR, right in RTL */
.back-arrow-icon {
  display: inline-block;
  transition: transform 0.2s ease;
}

[dir="rtl"] .back-arrow-icon {
  transform: scaleX(-1);
}

/* Toast container: anchors to inline-end (right in LTR, left in RTL) */
.toast-container {
  inset-inline-end: 20px;
  inset-block-start: 20px;
  left: auto;
  /* override the physical left if set elsewhere */
  right: auto;
}