:root {
  --primary: #F97316;
  --primary-hover: #EA580C;
  --primary-soft: rgba(249, 115, 22, 0.12);
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --text: #0F172A;
  --text-muted: #64748B;
  --border: #E2E8F0;
  --success: #16A34A;
  --danger: #DC2626;
  --info: #2563EB;
  --purple: #7C3AED;
  --sidebar-width: 248px;
  --header-height: 72px;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --sidebar-bg: #FFFFFF;
  --chart-fill: rgba(249, 115, 22, 0.18);
}

[data-theme="dark"] {
  --bg: #0B1220;
  --surface: #111827;
  --surface-2: #1E293B;
  --text: #F8FAFC;
  --text-muted: #94A3B8;
  --border: #334155;
  --sidebar-bg: #0F172A;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --primary-soft: rgba(249, 115, 22, 0.2);
  --chart-fill: rgba(249, 115, 22, 0.25);
}

* { box-sizing: border-box; }

html {
  height: 100%;
  direction: rtl;
  text-align: right;
}

html, body {
  height: 100%;
}

body.admin-body {
  margin: 0;
  font-family: "Cairo", sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  text-align: right;
  unicode-bidi: embed;
}

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

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

.admin-sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border);
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0; /* دائماً على يمين الشاشة */
  left: auto !important;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease;
  will-change: transform;
}

.admin-sidebar .brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1.25rem .75rem;
  font-weight: 800;
  font-size: 1.25rem;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 1.05rem;
  letter-spacing: .02em;
}

.brand-text small {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  flex-shrink: 0;
}

.sidebar-section-label {
  padding: .35rem 1.35rem .5rem;
  font-size: .75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.sidebar-nav {
  padding: .15rem .85rem .5rem;
  overflow-y: auto;
  flex: 1;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .8rem 1rem;
  border-radius: 12px;
  color: var(--text-muted);
  margin-bottom: .25rem;
  font-weight: 600;
}

.sidebar-nav .nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar-nav .nav-link.active {
  background: var(--primary);
  color: #fff;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: .75rem;
}

.sidebar-footer .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.admin-main {
  flex: 1;
  width: 100%;
  margin-right: var(--sidebar-width); /* مساحة الشريط على اليمين */
  margin-left: 0;
  min-width: 0;
}

.admin-header {
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1030;
}

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

.search-box {
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: .55rem 1rem;
  min-width: 220px;
  color: var(--text);
  direction: rtl;
  text-align: right;
}

.search-box:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  display: inline-grid;
  place-items: center;
}

.icon-btn:hover { color: var(--primary); }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding-block: .4rem;
  padding-inline: .4rem .85rem;
  font-weight: 700;
}

.user-chip .dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: grid;
  place-items: center;
}

.admin-content {
  padding: 1.5rem;
}

.page-title {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
  height: 100%;
}

.stat-card .stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: .85rem;
}

.stat-card .stat-value {
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.2;
}

.stat-card .stat-label {
  color: var(--text-muted);
  font-size: .9rem;
  margin-top: .2rem;
}

.stat-change {
  font-size: .85rem;
  font-weight: 700;
  margin-top: .55rem;
}

.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  height: 100%;
}

.panel-header {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.panel-body { padding: 1.2rem; }

.period-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-weight: 700;
  padding: .35rem .7rem;
  border-radius: 999px;
}

.period-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.btn-primary, .btn-knooz {
  --bs-btn-bg: var(--primary);
  --bs-btn-border-color: var(--primary);
  --bs-btn-hover-bg: var(--primary-hover);
  --bs-btn-hover-border-color: var(--primary-hover);
  --bs-btn-active-bg: var(--primary-hover);
  --bs-btn-active-border-color: var(--primary-hover);
  background: var(--primary);
  border-color: var(--primary);
}

.btn-outline-knooz {
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline-knooz:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.table-admin {
  --bs-table-bg: transparent;
  --bs-table-color: var(--text);
  --bs-table-border-color: var(--border);
  margin-bottom: 0;
  text-align: right;
}

.table-admin thead th {
  color: var(--text-muted);
  font-weight: 700;
  font-size: .85rem;
  white-space: nowrap;
  text-align: right;
}

.table-admin tbody td {
  vertical-align: middle;
  white-space: nowrap;
  text-align: right;
}

.table-admin .col-actions {
  text-align: left; /* نهاية الصف بصرياً في RTL */
  white-space: nowrap;
}

.table-admin .col-actions .btn + .btn {
  margin-inline-start: .35rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: .25rem .65rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
}

.status-badge.success { background: rgba(22,163,74,.12); color: var(--success); }
.status-badge.danger { background: rgba(220,38,38,.12); color: var(--danger); }
.status-badge.warning { background: rgba(249,115,22,.12); color: var(--primary); }
.status-badge.info { background: rgba(37,99,235,.12); color: var(--info); }
.status-badge.muted { background: var(--surface-2); color: var(--text-muted); }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 2.5rem;
  margin-bottom: .75rem;
  display: block;
}

.form-control, .form-select {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  text-align: right;
  direction: rtl;
}

.form-control::placeholder {
  color: var(--text-muted);
  text-align: right;
  direction: rtl;
  opacity: 1;
}

.form-control:focus, .form-select:focus {
  background: var(--surface);
  color: var(--text);
  border-color: var(--primary);
  box-shadow: 0 0 0 .2rem var(--primary-soft);
}

.form-label {
  font-weight: 700;
  display: block;
  text-align: right;
}

/* حقول الأرقام/البريد/الأكواد تُعرض LTR داخل واجهة RTL */
.dir-ltr,
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="url"],
input[type="datetime-local"],
input[type="date"],
input[type="time"],
input[type="password"],
code,
.mono-ltr {
  direction: ltr !important;
  text-align: left !important;
  unicode-bidi: isolate;
}

.form-check {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding-inline-start: 0;
  text-align: right;
  direction: rtl;
}

.form-check .form-check-input {
  float: none;
  margin: 0;
  flex-shrink: 0;
}

.form-check .form-check-label {
  margin: 0;
}

.dropdown-menu {
  text-align: right;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  text-align: right;
}

.dropdown-item i {
  order: 0;
}

.breadcrumb {
  direction: rtl;
  margin-bottom: 0;
}

.pagination {
  direction: rtl;
  justify-content: center;
  margin-bottom: 0;
}

.alert {
  text-align: right;
}

.alert ul {
  padding-inline-start: 1.25rem;
  margin: 0;
}

.btn i {
  margin-inline-end: .35rem;
}

.btn i:last-child:first-child {
  margin-inline-end: 0;
}

.list-group-item {
  text-align: right;
}

.modal-header,
.modal-body,
.modal-footer {
  text-align: right;
}

.filters-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.ops-item {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .85rem 0;
  border-bottom: 1px solid var(--border);
  direction: rtl;
  text-align: right;
}

.ops-item:last-child { border-bottom: 0; }

.ops-meta {
  text-align: left;
  flex-shrink: 0;
}

.ops-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  color: var(--primary);
}

.guest-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at top left, rgba(249,115,22,.18), transparent 35%),
    radial-gradient(circle at bottom right, rgba(37,99,235,.12), transparent 30%),
    var(--bg);
  padding: 1.5rem;
  direction: rtl;
  text-align: right;
}

.guest-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 2rem;
  direction: rtl;
  text-align: right;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  z-index: 1035;
  cursor: pointer;
}

.sidebar-overlay.show {
  display: block;
}

body.sidebar-open {
  overflow: hidden;
}

@media (max-width: 991.98px) {
  /* مخفية خارج الحافة اليمنى؛ .open تُظهرها */
  .admin-sidebar {
    right: 0 !important;
    left: auto !important;
    transform: translateX(105%);
    pointer-events: none;
    box-shadow: none;
  }

  .admin-sidebar.open {
    transform: translateX(0);
    pointer-events: auto;
    box-shadow: -8px 0 24px rgba(15, 23, 42, 0.18);
  }

  .admin-main {
    margin-right: 0;
    margin-left: 0;
  }

  .search-box { min-width: 140px; }

  .admin-header {
    padding-inline: 1rem;
  }

  .admin-content {
    padding: 1rem;
  }
}
