/**
 * Modern theme - RTL, CSS variables, light + dark mode toggle
 */
:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1a1d29;
  --muted: #5c6370;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --border: #e5e7eb;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-bg: #ffffff;
  --header-bg: #ffffff;
  --badge-active: #10b981;
  --badge-expired: #ef4444;
  --badge-pending: #f59e0b;
  --badge-disabled: #6b7280;
  --success-bg: #d1fae5;
  --success-text: #065f46;
  --error-bg: #fee2e2;
  --error-text: #991b1b;
  --alert-success: #10b981;
  --alert-error: #ef4444;
  --alert-warning: #f59e0b;
}

[data-theme="dark"] {
  --bg: #111827;
  --card: #1f2937;
  --text: #f9fafb;
  --muted: #9ca3af;
  --border: #374151;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --sidebar-bg: #1f2937;
  --header-bg: #1f2937;
  --success-bg: #064e3b;
  --success-text: #a7f3d0;
  --error-bg: #7f1d1d;
  --error-text: #fecaca;
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Tajawal', sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  direction: rtl;
  font-size: 1rem;
  line-height: 1.6;
}

/* Layout — شريط جانبي ثابت + هيدر (لا تغيير بالـ Bootstrap) */
body .hub-layout {
  display: flex !important;
  flex-direction: row !important;
  min-height: 100vh;
}

.hub-sidebar {
  width: 260px !important;
  min-width: 260px !important;
  max-width: 260px !important;
  background: var(--sidebar-bg) !important;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.06);
  border-left: 1px solid var(--border);
  display: flex !important;
  flex-direction: column !important;
  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  height: 100vh !important;
  z-index: 1030;
  border-radius: 0 0 0 var(--radius);
  transition: transform 0.2s ease;
}

.hub-sidebar-brand {
  padding: 1.25rem 1.5rem;
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.hub-sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
  display: flex !important;
  flex-direction: column !important;
}

.hub-sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.25rem;
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  font-weight: 500;
}

.hub-sidebar-nav a:hover {
  background: var(--bg);
  color: var(--text);
}

.hub-sidebar-nav a.active {
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
}

.hub-sidebar-nav a i {
  font-size: 1.25rem;
  width: 1.5rem;
  text-align: center;
}

.hub-main {
  flex: 1;
  margin-right: 260px !important;
  margin-left: 0 !important;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.hub-header {
  background: var(--header-bg);
  padding: 0.75rem 1.5rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.hub-header-search {
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}

.hub-header-search input {
  width: 100%;
  padding: 0.5rem 1rem 0.5rem 2.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9375rem;
}

.hub-header-search input::placeholder {
  color: var(--muted);
}

.hub-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.hub-user-menu {
  position: relative;
}

.hub-user-menu .btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9375rem;
  cursor: pointer;
}

.hub-user-menu .dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.25rem;
  min-width: 180px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 0.25rem;
  display: none;
  z-index: 1050;
}

.hub-user-menu.open .dropdown-menu {
  display: block;
}

.hub-user-menu .dropdown-menu a {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.9375rem;
}

.hub-user-menu .dropdown-menu a:hover {
  background: var(--bg);
}

.hub-content {
  flex: 1;
  padding: 1.5rem;
}

/* Cards */
.hub-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.hub-card-title {
  margin: 0 0 1rem;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
}

/* KPI cards */
.hub-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.hub-kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  border: 1px solid var(--border);
}

.hub-kpi-card .label {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.hub-kpi-card .value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
}

/* Tables */
.hub-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

.hub-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.hub-table th {
  background: var(--bg);
  padding: 0.75rem 1rem;
  text-align: right;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

.hub-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.hub-table tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .hub-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.03);
}

.hub-table tbody tr:hover {
  background: rgba(99, 102, 241, 0.06);
}

.hub-table td a:not(.btn):not(.hub-btn) {
  color: var(--primary);
  text-decoration: none;
}

.hub-table td a:not(.btn):not(.hub-btn):hover {
  text-decoration: underline;
}

/* أزرار داخل الجدول — النص بلون واضح (أبيض على الأساسي) */
.hub-table td .hub-btn-primary {
  color: #fff !important;
}

/* Badges */
.hub-badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
}

.hub-badge-active { background: #d1fae5; color: #065f46; }
[data-theme="dark"] .hub-badge-active { background: #064e3b; color: #a7f3d0; }

.hub-badge-expired { background: #fee2e2; color: #991b1b; }
[data-theme="dark"] .hub-badge-expired { background: #7f1d1d; color: #fecaca; }

.hub-badge-pending { background: #fef3c7; color: #92400e; }
[data-theme="dark"] .hub-badge-pending { background: #78350f; color: #fde68a; }

.hub-badge-disabled { background: #e5e7eb; color: #4b5563; }
[data-theme="dark"] .hub-badge-disabled { background: #374151; color: #9ca3af; }

.hub-badge-paused { background: #e0e7ff; color: #3730a3; }
[data-theme="dark"] .hub-badge-paused { background: #312e81; color: #c7d2fe; }

/* Chips */
.hub-chip {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8125rem;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}

/* Forms */
.hub-form-group {
  margin-bottom: 1.25rem;
}

.hub-form-group label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 500;
  color: var(--text);
  font-size: 0.9375rem;
}

.hub-form-group .help {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.hub-form-group input,
.hub-form-group select,
.hub-form-group textarea {
  width: 100%;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9375rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.hub-form-group input:focus,
.hub-form-group select:focus,
.hub-form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.hub-content .form-control {
  border-radius: 12px;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  font-family: 'Tajawal', sans-serif;
}
.hub-content .form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.hub-form-group input.error,
.hub-form-group select.error,
.hub-form-group textarea.error {
  border-color: var(--alert-error);
}

.hub-form-group .error-msg {
  font-size: 0.8125rem;
  color: var(--alert-error);
  margin-top: 0.25rem;
}

.hub-form-section {
  margin-bottom: 2rem;
}

.hub-form-section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* توثيق API — كروت وكود منسق */
.hub-docs-block {
  margin-bottom: 1.5rem;
}

.hub-code-block {
  display: block;
  padding: 1rem 1.25rem;
  margin: 0.5rem 0 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: 'ui-monospace', 'SFMono-Regular', 'Menlo', monospace;
  font-size: 0.875rem;
  color: var(--text);
  overflow-x: auto;
  line-height: 1.5;
}

.hub-docs-desc {
  font-size: 0.9375rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

.hub-docs-inline {
  padding: 0.2rem 0.45rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--text);
  font-family: 'ui-monospace', 'SFMono-Regular', 'Menlo', monospace;
}

/* Buttons */
.hub-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.hub-btn-primary {
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.hub-btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.hub-btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.hub-btn-secondary:hover {
  background: var(--border);
}

.hub-btn-danger {
  background: var(--alert-error);
  color: #fff;
}

.hub-btn-danger:hover {
  background: #dc2626;
}

.hub-btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.875rem;
}

/* Alerts (toast-like) */
.hub-alert {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  border: 1px solid transparent;
}

.hub-alert-success {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: rgba(16, 185, 129, 0.3);
}

.hub-alert-error {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: rgba(239, 68, 68, 0.3);
}

.hub-alert-warning {
  background: #fef3c7;
  color: #92400e;
  border-color: rgba(245, 158, 11, 0.3);
}

[data-theme="dark"] .hub-alert-warning {
  background: #78350f;
  color: #fde68a;
}

/* Empty state */
.hub-empty {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--muted);
}

.hub-empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.hub-empty-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.hub-empty-desc {
  font-size: 0.9375rem;
  margin-bottom: 1rem;
}

/* Dark mode toggle */
.hub-theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
}

/* Mobile sidebar */
.hub-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1025;
}

@media (max-width: 991px) {
  .hub-sidebar {
    transform: translateX(100%);
  }

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

  .hub-main {
    margin-right: 0;
  }

  .hub-sidebar-overlay.open {
    display: block;
  }
}

/* Page title */
.hub-page-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0 0 1rem;
  color: var(--text);
}

/* Wizard steps */
.hub-wizard-steps {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.hub-wizard-step {
  flex: 1;
  min-width: 100px;
  padding: 0.75rem 1rem;
  text-align: center;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid var(--border);
}

.hub-wizard-step.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.hub-wizard-step.done {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: var(--badge-active);
}
