/* ===================================================
   main.css — نظام التصميم الأساسي (أبيض نظيف - RTL)
   =================================================== */

/* ——— المتغيرات ——— */
:root {
  --clr-bg:         #f7f8fa;
  --clr-surface:    #ffffff;
  --clr-border:     #e4e7ec;
  --clr-border-md:  #c9d0db;

  --clr-primary:    #1c64f2;
  --clr-primary-dk: #1a56db;
  --clr-primary-lt: #ebf0ff;

  --clr-text-1:     #111827;
  --clr-text-2:     #4b5563;
  --clr-text-3:     #9ca3af;

  /* حالات الطلبات */
  --clr-pending:    #f59e0b;
  --clr-pending-lt: #fffbeb;
  --clr-active:     #3b82f6;
  --clr-active-lt:  #eff6ff;
  --clr-done:       #10b981;
  --clr-done-lt:    #ecfdf5;
  --clr-cancelled:  #ef4444;
  --clr-cancelled-lt: #fef2f2;

  /* عداد التأخير */
  --clr-delay-1:    #10b981;   /* 1-3 أيام */
  --clr-delay-2:    #f59e0b;   /* 4-7 أيام */
  --clr-delay-3:    #f97316;   /* 8-14 يوم */
  --clr-delay-4:    #ef4444;   /* +14 يوم  */

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  20px;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,.08);
  --shadow-lg:  0 8px 24px rgba(0,0,0,.10);

  --font-main: "Segoe UI", "Noto Kufi Arabic", Tahoma, Arial, sans-serif;

  --transition: 0.18s ease;
  --sidebar-w: 240px;
  --header-h:  60px;
}

/* ——— إعادة الضبط ——— */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  direction: rtl;
  font-family: var(--font-main);
  font-size: 15px;
  color: var(--clr-text-1);
  background: var(--clr-bg);
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; }

a { color: var(--clr-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button { cursor: pointer; font-family: inherit; }

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

/* ——— التخطيط الرئيسي ——— */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
}

/* ——— الشريط العلوي ——— */
.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.app-header .logo {
  font-size: 1rem;
  font-weight: 700;
  color: var(--clr-primary);
  white-space: nowrap;
}

.app-header .user-info {
  margin-right: auto;         /* يدفعه لليسار في RTL */
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-header .user-name {
  font-size: .875rem;
  color: var(--clr-text-2);
}

/* ——— الشريط الجانبي ——— */
.app-sidebar {
  background: var(--clr-surface);
  border-left: 1px solid var(--clr-border);
  padding: 16px 0;
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
}

.nav-section {
  padding: 6px 0;
}

.nav-section-title {
  font-size: .72rem;
  font-weight: 600;
  color: var(--clr-text-3);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 8px 18px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  font-size: .9rem;
  color: var(--clr-text-2);
  border-radius: var(--radius-sm);
  margin: 2px 8px;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  width: calc(100% - 16px);
  text-align: right;
}

.nav-item:hover,
.nav-item.active {
  background: var(--clr-primary-lt);
  color: var(--clr-primary);
}

.nav-item .nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ——— منطقة المحتوى ——— */
.app-main {
  padding: 24px;
  overflow-y: auto;
  min-width: 0;
}

/* ——— البطاقات ——— */
.card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--clr-text-1);
}

/* ——— شبكة الإحصاءات ——— */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: .8rem;
  color: var(--clr-text-3);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--clr-text-1);
  line-height: 1;
}

.stat-sub {
  font-size: .78rem;
  color: var(--clr-text-3);
}

/* ——— الجداول ——— */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--clr-border);
}

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

th {
  background: var(--clr-bg);
  color: var(--clr-text-2);
  font-weight: 600;
  text-align: right;
  padding: 10px 14px;
  border-bottom: 1px solid var(--clr-border);
  white-space: nowrap;
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--clr-border);
  color: var(--clr-text-1);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: #fafafa; }

/* ——— الشارات (Badges) ——— */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-pending    { background: var(--clr-pending-lt);   color: #92400e; }
.badge-active     { background: var(--clr-active-lt);    color: #1e40af; }
.badge-scheduled  { background: #dbeafe;                 color: #1e40af; }
.badge-done       { background: var(--clr-done-lt);      color: #065f46; }
.badge-cancelled  { background: var(--clr-cancelled-lt); color: #991b1b; }
.badge-frozen     { background: #f3f4f6;                 color: #6b7280; }

/* ——— عداد التأخير ——— */
.delay-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
}

.delay-1 { background: #d1fae5; color: #065f46; }
.delay-2 { background: #fef3c7; color: #92400e; }
.delay-3 { background: #ffedd5; color: #9a3412; }
.delay-4 { background: #fee2e2; color: #991b1b; }

/* ——— الأزرار ——— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  font-size: .875rem;
  font-weight: 500;
  border: none;
  transition: background var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--clr-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--clr-primary-dk); box-shadow: var(--shadow-sm); }

.btn-outline {
  background: transparent;
  color: var(--clr-primary);
  border: 1px solid var(--clr-primary);
}
.btn-outline:hover { background: var(--clr-primary-lt); }

.btn-ghost {
  background: transparent;
  color: var(--clr-text-2);
}
.btn-ghost:hover { background: var(--clr-bg); }

.btn-danger {
  background: var(--clr-cancelled);
  color: #fff;
}
.btn-danger:hover { background: #dc2626; }

.btn-sm { padding: 5px 12px; font-size: .8rem; }

/* ——— النماذج ——— */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: .875rem;
  font-weight: 500;
  color: var(--clr-text-1);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--clr-border-md);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: .9rem;
  color: var(--clr-text-1);
  background: var(--clr-surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  text-align: right;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px rgba(28,100,242,.12);
}

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

/* ——— المودال ——— */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: var(--clr-surface);
  border-radius: var(--radius-xl);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--clr-text-1);
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ——— الإشعارات ——— */
.toast {
  position: fixed;
  bottom: 24px;
  left: 24px;
  background: var(--clr-text-1);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: .875rem;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  animation: slideUp .25s ease;
}

@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ——— الحالة الفارغة ——— */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 24px;
  color: var(--clr-text-3);
  text-align: center;
}

.empty-icon {
  font-size: 2.5rem;
  opacity: .5;
}

/* ——— تكيّف الجوال ——— */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr auto;
  }

  .app-sidebar {
    order: 3;
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--clr-border);
    display: flex;
    padding: 4px 8px;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 4px;
    z-index: 90;
    background: var(--clr-surface);
  }

  .nav-section { display: contents; }
  .nav-section-title { display: none; }

  .nav-item {
    flex-direction: column;
    gap: 3px;
    padding: 6px 10px;
    font-size: .72rem;
    min-width: 60px;
    margin: 0;
    border-radius: var(--radius-sm);
  }

  .app-main {
    padding: 16px;
    padding-bottom: 80px;  /* مسافة للشريط السفلي */
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
