/* =====================================================================
   نظام إدارة الشكاوى — نظام التصميم (RTL)
   ===================================================================== */

:root {
  --c-primary: #12467e;
  --c-primary-700: #0e3a68;
  --c-primary-50: #eef4fb;
  --c-accent: #0ea5e9;
  --c-success: #10b981;
  --c-warning: #f59e0b;
  --c-danger: #ef4444;
  --c-purple: #8b5cf6;

  --c-bg: #f3f6fa;
  --c-surface: #ffffff;
  --c-surface-2: #f8fafc;
  --c-text: #0f172a;
  --c-muted: #64748b;
  --c-border: #e4e9f2;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 2px 10px rgba(15, 23, 42, .06);
  --shadow-lg: 0 12px 30px rgba(15, 23, 42, .10);

  --sidebar-w: 264px;
  --font: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
}

/* ------------------------------- الأساس ------------------------------- */
* { box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 15px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; }
h1, h2, h3, h4, h5, h6 { font-weight: 700; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ------------------------------ التخطيط ------------------------------ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, #133c6b 0%, #0d2a4d 100%);
  color: #e2e8f0;
  position: fixed;
  /* الملاحة على حافة inline-start — أي اليمين في صفحة RTL، وهو العرف المتّبع.
     والأهم للإخفاء: transform يعمل بإحداثيات فيزيائية ولا ينعكس مع اتجاه
     الصفحة. مع القائمة على اليمين تُخرجها translateX(100%) فعلاً خارج الشاشة؛
     حين كانت على inset-inline-end (اليسار فيزيائياً) كانت translateX(100%)
     تزحلقها فوق المحتوى بدل إخفائها، فلا تختفي على الجوال إطلاقاً. */
  inset-inline-start: 0;
  inset-inline-end: auto;
  top: 0;
  bottom: 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease;
  box-shadow: -4px 0 24px rgba(2, 20, 43, .12);
}

.sidebar__brand {
  padding: 20px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar__logo {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .12);
  display: grid; place-items: center;
  font-size: 20px; color: #fff;
  overflow: hidden; flex-shrink: 0;
}
.sidebar__logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.sidebar__title { font-size: 15px; font-weight: 700; color: #fff; line-height: 1.35; }
.sidebar__subtitle { font-size: 11.5px; color: #a8b8cc; } /* كان #94a3b8 = 4.34:1 */

.sidebar__nav { padding: 14px 10px; overflow-y: auto; flex: 1; }
.sidebar__section {
  font-size: 11px; color: #9fb3cd; letter-spacing: .4px; /* كان #7f96b3 = 3.67:1 */
  padding: 14px 12px 6px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; margin-bottom: 3px;
  border-radius: var(--radius-sm);
  color: #cbd8e8; font-size: 14.5px; font-weight: 500;
  transition: background .16s, color .16s;
}
.nav-item i { font-size: 17px; width: 20px; text-align: center; }
.nav-item:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav-item.active {
  background: rgba(255, 255, 255, .14);
  color: #fff; font-weight: 600;
  box-shadow: inset -3px 0 0 var(--c-accent); /* الحافة inline-start = اليمين في RTL */
}
.nav-item .badge { margin-inline-start: auto; font-size: 11px; }

.sidebar__footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: 12px; color: #94a3b8;
}

.main { flex: 1; margin-inline-start: var(--sidebar-w); min-width: 0; }

.topbar {
  height: 64px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  position: sticky; top: 0; z-index: 1020;
}
.topbar__title { font-size: 17px; font-weight: 700; margin: 0; }
.topbar__crumb { font-size: 12px; color: var(--c-muted); }

.content { padding: 22px; }

/* الشاشات الصغيرة */
.sidebar-toggle { display: none; }
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(100%); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .main { margin-inline-start: 0; }
  .sidebar-toggle { display: inline-flex; }
  body.sidebar-open::after {
    content: ''; position: fixed; inset: 0;
    background: rgba(15, 23, 42, .45); z-index: 1030;
  }
}

/* ------------------------------ البطاقات ------------------------------ */
.card {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--c-surface);
}
.card-header {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  padding: 14px 18px;
  font-weight: 700;
  display: flex; align-items: center; gap: 10px;
  /* بدون الالتفاف كانت أزرار «إضافة فرع/ملحق» تُرسم خارج الشاشة على الجوال،
     ولا يوجد مسار بديل لإنشائها — أي أن المدير لا يستطيع إنشاء فرع من هاتفه. */
  flex-wrap: wrap;
  border-radius: var(--radius) var(--radius) 0 0 !important;
}
/* الحقول داخل ترويسة البطاقة تتقلّص بدل أن تدفع الأزرار خارج الإطار */
.card-header .form-select,
.card-header .form-control { flex: 1 1 160px; min-width: 0; }
.card-header .card-title { margin: 0; font-size: 15.5px; font-weight: 700; }
.card-body { padding: 18px; }

/* --------------------------- بطاقات المؤشرات --------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}
.kpi {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform .16s, box-shadow .16s;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi::before {
  content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0;
  width: 4px; background: var(--kpi-color, var(--c-primary));
}
/* المساحة المحجوزة على اليسار تمنع تداخل النص مع الأيقونة */
.kpi__label { font-size: 12.5px; color: var(--c-muted); font-weight: 600; margin-bottom: 6px; padding-inline-end: 50px; min-height: 34px; }
.kpi__value { font-size: 27px; font-weight: 800; line-height: 1.1; color: var(--c-text); }
.kpi__value small { font-size: 14px; font-weight: 600; color: var(--c-muted); }
.kpi__meta { font-size: 11.5px; color: var(--c-muted); margin-top: 6px; }
.kpi__icon {
  position: absolute; inset-inline-end: 14px; top: 14px;
  width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center; font-size: 19px;
  background: color-mix(in srgb, var(--kpi-color, var(--c-primary)) 12%, white);
  color: var(--kpi-color, var(--c-primary));
}

/* ------------------------------ الجداول ------------------------------ */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
.table { margin: 0; font-size: 14px; }
.table > :not(caption) > * > * { padding: 11px 14px; }
.table thead th {
  background: var(--c-surface-2);
  color: var(--c-muted);
  font-size: 12.5px;
  font-weight: 700;
  text-transform: none;
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}
.table tbody tr { border-bottom: 1px solid #f1f5f9; }
.table tbody tr:hover { background: #f9fbfe; }
.table td { vertical-align: middle; }
.table .ticket-link {
  font-family: 'Consolas', monospace; font-weight: 700; color: var(--c-primary);
  direction: ltr; display: inline-block; white-space: nowrap;
}
.table .ticket-link:hover { text-decoration: underline; }

.table .col-customer { min-width: 150px; }
.table .col-place { min-width: 145px; }

.empty-state { padding: 46px 20px; text-align: center; color: var(--c-muted); }
.empty-state i { font-size: 42px; opacity: .35; display: block; margin-bottom: 12px; }

/* ------------------------------ الشارات ------------------------------ */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
  border: 1px solid transparent;
}
.status-open      { background: #e0f2fe; color: #0369a1; border-color: #bae6fd; }
.status-progress  { background: #fef3c7; color: #b45309; border-color: #fde68a; }
.status-closed    { background: #d1fae5; color: #047857; border-color: #a7f3d0; }

.prio-low     { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.prio-medium  { background: #e0f2fe; color: #0369a1; border-color: #bae6fd; }
.prio-high    { background: #ffedd5; color: #c2410c; border-color: #fed7aa; }
.prio-urgent  { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }

.sla-ok    { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.sla-risk  { background: #fef3c7; color: #854d0e; border-color: #fde68a; } /* كان #a16207 = 4.42:1 */
.sla-late  { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }

/* ------------------------------ النماذج ------------------------------ */
.form-label { font-size: 13.5px; font-weight: 600; color: #334155; margin-bottom: 6px; }
.form-label .req { color: var(--c-danger); }
.form-control, .form-select {
  border-radius: var(--radius-sm);
  border-color: #dbe3ee;
  padding: 9px 13px;
  font-size: 14.5px;
  background-color: #fff;
}
.form-control:focus, .form-select:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, .15);
}
.form-text { font-size: 12px; }
textarea.form-control { min-height: 110px; line-height: 1.8; }

.filter-bar {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

/* ------------------------------ الأزرار ------------------------------ */
.btn { border-radius: var(--radius-sm); font-weight: 600; font-size: 14px; padding: 8px 16px; }
.btn i { vertical-align: -1px; }
.btn-primary { background: var(--c-primary); border-color: var(--c-primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--c-primary-700); border-color: var(--c-primary-700); }
.btn-outline-primary { color: var(--c-primary); border-color: #c9d8ea; }
.btn-outline-primary:hover { background: var(--c-primary); border-color: var(--c-primary); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-icon { width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center; }

/* ---------------------------- سجل الإجراءات ---------------------------- */
.timeline { position: relative; padding-inline-start: 6px; }
.timeline::before {
  content: ''; position: absolute; inset-inline-start: 19px; top: 8px; bottom: 8px;
  width: 2px; background: linear-gradient(180deg, #dbe6f3, #eef2f7);
}
.timeline__item { position: relative; padding-inline-start: 52px; padding-bottom: 22px; }
.timeline__item:last-child { padding-bottom: 4px; }
.timeline__dot {
  position: absolute; inset-inline-start: 6px; top: 2px;
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: #fff; border: 2px solid #dbe6f3;
  color: var(--c-primary); font-size: 14px; z-index: 1;
}
.timeline__dot.is-created { border-color: #bae6fd; color: #0284c7; background: #f0f9ff; }
.timeline__dot.is-progress { border-color: #fde68a; color: #b45309; background: #fffbeb; }
.timeline__dot.is-closed  { border-color: #a7f3d0; color: #047857; background: #ecfdf5; }
.timeline__dot.is-reopen  { border-color: #fecaca; color: #b91c1c; background: #fef2f2; }
.timeline__card {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.timeline__head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; }
.timeline__type { font-weight: 700; font-size: 13.5px; color: var(--c-text); }
.timeline__time { font-size: 11.5px; color: var(--c-muted); margin-inline-start: auto; }
.timeline__note { font-size: 14px; color: #334155; line-height: 1.85; white-space: pre-wrap; margin: 0; }
.timeline__who { font-size: 12px; color: var(--c-muted); margin-top: 7px; }

/* --------------------------- تفاصيل الشكوى --------------------------- */
.detail-list { display: grid; gap: 0; }
.detail-row {
  display: grid; grid-template-columns: 150px 1fr;
  gap: 10px; padding: 10px 0;
  border-bottom: 1px dashed #eef2f7; font-size: 14px;
}
.detail-row:last-child { border-bottom: none; }
.detail-row dt { color: var(--c-muted); font-weight: 600; font-size: 13px; }
.detail-row dd { margin: 0; font-weight: 600; color: var(--c-text); }

.ticket-hero {
  background: linear-gradient(135deg, #12467e 0%, #1c5fa8 100%);
  color: #fff; border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.ticket-hero__no {
  font-family: 'Consolas', monospace; font-size: 25px; font-weight: 800;
  letter-spacing: 1px; direction: ltr; display: inline-block;
}
.ticket-hero__meta { font-size: 13px; opacity: .88; }
.ticket-hero .chip { border: none; }

.sla-meter { height: 7px; background: #e9eef5; border-radius: 999px; overflow: hidden; }
.sla-meter__fill { height: 100%; border-radius: 999px; transition: width .4s ease; }

.attachment-box {
  border: 1px dashed #cbd5e1; border-radius: var(--radius-sm);
  padding: 10px; text-align: center; background: var(--c-surface-2);
}
.attachment-box img { max-height: 240px; border-radius: 8px; object-fit: contain; }

/* ------------------------------ الرسوم ------------------------------ */
.chart-box { position: relative; height: 260px; }
.chart-box--sm { height: 210px; }

/* ------------------------------ متنوعات ------------------------------ */
.text-muted-sm { font-size: 12.5px; color: var(--c-muted); }
.divider-y { height: 1px; background: var(--c-border); margin: 14px 0; }
.avatar-circle {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--c-primary-50); color: var(--c-primary);
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, #0d2a4d 0%, #12467e 55%, #1c5fa8 100%);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 420px;
  background: #fff; border-radius: 20px;
  padding: 34px 32px; box-shadow: var(--shadow-lg);
}
.login-logo {
  width: 66px; height: 66px; border-radius: 18px; margin: 0 auto 14px;
  background: var(--c-primary-50); color: var(--c-primary);
  display: grid; place-items: center; font-size: 30px; overflow: hidden;
}
.login-logo img { width: 100%; height: 100%; object-fit: contain; }

.pagination { --bs-pagination-border-radius: 10px; margin: 0; }
.page-link { color: var(--c-primary); border-color: var(--c-border); font-size: 13.5px; }
.active > .page-link { background: var(--c-primary); border-color: var(--c-primary); }

.modal-content { border: none; border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 1px solid var(--c-border); padding: 15px 20px; }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-footer { border-top: 1px solid var(--c-border); padding: 13px 20px; }

.alert { border-radius: var(--radius-sm); border: none; font-size: 14px; font-weight: 600; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-danger { background: #fee2e2; color: #991b1b; }

/* لا تظهر عناصر الواجهة عند الطباعة */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main { margin: 0 !important; }
  .content { padding: 0 !important; }
  body { background: #fff !important; }
}
