/* ============================================
   الأساسيات
   ============================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  background: #f5f5f5;
  color: #171717;
  direction: inherit;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ============================================
   Header
   ============================================ */
.header {
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  height: 60px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-shrink: 0;
  z-index: 100;
}

.logo {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
  flex-shrink: 0;
}

.search {
  flex: 1;
  max-width: 500px;
  position: relative;
}

.search i {
  position: absolute;
  inset-inline-end: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #a3a3a3;
  font-size: 14px;
}

.search input {
  width: 100%;
  padding-block: 9px;
  padding-inline: 12px 38px;
  border: 1px solid #d4d4d4;
  border-radius: 8px;
  background: #fafafa;
  outline: none;
  font-size: 14px;
  box-sizing: border-box;
}

.search input:focus { border-color: #171717; }

/* ============================================
   زر فتح/إغلاق Sidebar
   ============================================ */
.sidebar-toggle {
  background: none;
  border: none;
  padding: 8px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  color: #404040;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-toggle:hover { background: #f5f5f5; }
.sidebar-toggle i { font-size: 18px; line-height: 1; display: block; }

/* ============================================
   زر الإشعارات
   ============================================ */
.notif {
  position: relative;
  background: none;
  border: none;
  padding: 8px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  color: #404040;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: background 0.15s;
  overflow: visible;
}

.notif:hover { background: #f5f5f5; }
.notif > i { font-size: 18px; line-height: 1; display: block; }

.notif-count {
  position: absolute;
  top: 2px;
  inset-inline-end: 2px;
  min-width: 17px;
  height: 17px;
  padding: 2px 2px;
  background: #ef4444;
  color: white;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border: 2px solid #fff;
  box-sizing: border-box;
  z-index: 10;
  pointer-events: none;
}

.notif-count.has-count { display: flex; }

/* ============================================
   Body
   ============================================ */
.body {
  display: flex;
  flex: 1 1 auto;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
  height: 0;
}

.body.sidebar-closed .sidebar { display: none; }

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
  width: 240px;
  background: #fff;
  border-inline-start: 1px solid #e5e5e5;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  height: 100%;
}

.nav {
  flex: 1 1 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

.nav::-webkit-scrollbar { width: 4px; }
.nav::-webkit-scrollbar-thumb { background: #d4d4d4; border-radius: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #171717;
  font-size: 14px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: start;
  flex-shrink: 0;
  white-space: nowrap;
  transition: background 0.15s;
}

.nav-item i { width: 24px; text-align: center; flex-shrink: 0; }
.nav-item:hover { background: #f5f5f5; }
.nav-item.active { background: #e5e5e5; font-weight: 600; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border-top: 1px solid #e5e5e5;
  background: #fff;
  flex-shrink: 0;
}

/* ============================================
   Main
   ============================================ */
.main {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  padding-bottom: 80px;
  min-height: 0;
  min-width: 0;
  height: 100%;
  box-sizing: border-box;
}

/* ============================================
   ✅ صفحة الرأس (موحّدة لكل الصفحات)
   ============================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.page-header h2 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
}

/* ============================================
   أزرار
   ============================================ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #171717;
  color: white;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}
.btn-primary:hover { background: #404040; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #e5e5e5;
  color: #171717;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}
.btn-secondary:hover { background: #d4d4d4; }

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #dc2626;
  color: white;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
}
.btn-danger:hover { background: #b91c1c; }

/* ============================================
   البحث
   ============================================ */
.search-bar {
  position: relative;
  margin-bottom: 20px;
  max-width: 400px;
}
.search-bar i {
  position: absolute;
  inset-inline-end: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #a3a3a3;
  font-size: 14px;
}
.search-bar input {
  width: 100%;
  padding-block: 10px;
  padding-inline: 12px 36px;
  border: 1px solid #d4d4d4;
  border-radius: 8px;
  background: white;
  outline: none;
  font-size: 14px;
  box-sizing: border-box;
}

/* ============================================
   النماذج
   ============================================ */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 14px;
  color: #404040;
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d4d4d4;
  border-radius: 8px;
  background: white;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: #171717; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

/* ============================================
   التنبيهات
   ============================================ */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

/* ============================================
   الحالات الفارغة
   ============================================ */
.empty-state {
  background: white;
  padding: 48px 24px;
  border-radius: 10px;
  text-align: center;
  color: #737373;
}
.empty-state i {
  font-size: 3rem;
  color: #d4d4d4;
  margin-bottom: 12px;
}

/* ============================================
   ✅ دعم تلقائي للاتجاه
   ============================================ */
[dir="ltr"] .form-group label,
[dir="ltr"] .section-title,
[dir="ltr"] .sub-text,
[dir="ltr"] .plan-features li,
[dir="ltr"] .pending-row,
[dir="ltr"] .page-header h2,
[dir="ltr"] .empty-state p,
[dir="ltr"] .alert,
[dir="ltr"] .plan-card {
  text-align: left;
}

[dir="rtl"] .form-group label,
[dir="rtl"] .section-title,
[dir="rtl"] .sub-text,
[dir="rtl"] .plan-features li,
[dir="rtl"] .pending-row,
[dir="rtl"] .page-header h2,
[dir="rtl"] .empty-state p,
[dir="rtl"] .alert,
[dir="rtl"] .plan-card {
  text-align: right;
}

[dir="rtl"] .btn-primary i.fa-arrow-left,
[dir="rtl"] .btn-secondary i.fa-arrow-left,
[dir="rtl"] .btn-primary i.fa-arrow-right,
[dir="rtl"] .btn-secondary i.fa-arrow-right,
[dir="rtl"] .welcome-btn i.fa-arrow-left,
[dir="rtl"] .welcome-btn i.fa-arrow-right {
  transform: scaleX(-1);
}

[dir="ltr"] .password-wrapper .toggle-password {
  right: 12px;
  left: auto;
}

[dir="rtl"] .password-wrapper .toggle-password {
  left: 12px;
  right: auto;
}

[dir="ltr"] .picker-check {
  margin-left: auto;
  margin-right: 0;
}

[dir="rtl"] .picker-check {
  margin-right: auto;
  margin-left: 0;
}

/* ============================================
   ✅ الموبايل
   ============================================ */
@media (max-width: 768px) {
  .header { padding: 0 12px; gap: 10px; }
  .logo { font-size: 1.1rem; }

  .sidebar {
    width: 65px;
    min-width: 65px;
    max-width: 65px;
  }

  .nav { padding: 8px 4px; }
  .nav-item {
    padding: 12px 4px;
    justify-content: center;
    gap: 0;
    font-size: 0;
  }
  .nav-item span { display: none; }
  .nav-item i { font-size: 18px; width: auto; }

  .sidebar-footer { padding: 8px 4px; }
  .sidebar-footer .nav-item { padding: 12px 4px; justify-content: center; }
  .sidebar-footer .nav-item i { font-size: 18px; }

  .main { padding: 12px; padding-bottom: 80px; }

  .body.sidebar-hidden-mobile .sidebar { display: none; }
}

/* ============================================
   Landscape
   ============================================ */
@media (orientation: landscape) and (max-height: 500px) {
  .header { height: 45px; padding: 0 12px; gap: 10px; }
  .logo { font-size: 1rem; }
  .search input { padding-block: 6px; padding-inline: 10px 32px; font-size: 12px; }

  .sidebar { width: 200px; min-width: 200px; max-width: 200px; }
  .nav { padding: 6px 8px; gap: 2px; }
  .nav-item { padding: 6px 10px; font-size: 12px; gap: 8px; }
  .nav-item i { font-size: 14px; width: 18px; }
  .sidebar-footer { padding: 6px 8px; gap: 2px; }
  .sidebar-footer .nav-item { padding: 6px 10px; font-size: 12px; }
  .sidebar-footer .nav-item i { font-size: 14px; }
  .main { padding: 12px; padding-bottom: 40px; }
}