/* --- استيراد الخطوط الرسمية --- */
@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;800&display=swap');

:root {
  --bg: #f8fafb;
  --sidebar-bg: #ffffff;
  --card: #ffffff;
  --text: #334155;
  --muted: #94a3b8;
  --border: #f1f5f9;
  --primary: #0b6b2a;
  --hero: #166534;
  --hero2: #14532d;      /* الأخضر الرسمي */
  --primary-dark: #085220;
  --accent-light: #e6f6f1; /* المينت الفاتح */
  --shadow-sm: 0 4px 12px rgba(0,0,0,0.03);
  --shadow-md: 0 10px 30px rgba(0,0,0,0.05);
  --radius: 20px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --topbar-h: 64px;
}

/* --- التهيئة الأساسية --- */
* { box-sizing: border-box; outline: none; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; padding: 0; scroll-behavior: smooth; }

body {
  font-family: "Tajawal", sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  overflow-x: hidden;
  /* لأن الهيدر سيتم تثبيته (fixed) نترك مساحة أعلى الصفحة مساوية لارتفاعه */
  padding-top: var(--topbar-h);
  line-height: 1.6;
}

a { text-decoration: none; color: inherit; transition: var(--transition); }

.app-shell {
  display: flex;
  /* حتى لا نضيف مساحة زائدة بسبب padding-top في body */
  min-height: calc(100vh - var(--topbar-h));
  gap: 16px;
  padding: 16px;
}

/* --- الهيدر العلوي (يشبه نمط المنصات الحكومية) --- */
.topbar {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 1600;
  background: #fff;
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
}

/* --- القائمة الجانبية (Sidebar) --- */
.sidebar {
  width: 280px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  padding: 18px 14px;
  position: sticky;
  top: calc(var(--topbar-h) + 16px);
  height: calc(100vh - var(--topbar-h) - 32px);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow-y: auto;
  transition: var(--transition);
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 10px; }

/* ✅ جديد: صندوق المستخدم للجوال (يظهر داخل السايدبار) */
.userbox-mobile {
    display: none; /* مخفي في الكمبيوتر */
    align-items: center;
    gap: 12px;
    padding: 15px;
    background: var(--accent-light);
    border-radius: 18px;
    margin-bottom: 20px;
    position: relative;
}

/* زر إغلاق القائمة داخل Drawer (الجوال) */
.sidebar-close {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sidebar-close:hover { border-color: var(--primary); }

.userbox-mobile .avatar {
    width: 45px; height: 45px; background: #fff; color: var(--primary);
    border-radius: 12px; display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 18px;
}

.brand { margin-bottom: 18px; text-align: center; padding: 10px; border-bottom: 1px solid var(--border); }
.brand .title { font-weight: 800; font-size: 19px; color: var(--primary); }

.user-info .u-name { display: block; font-weight: 900; color: var(--text); font-size: 13px; }
.user-info .u-role { display: block; font-weight: 700; color: #64748b; font-size: 11px; }

.group-title {
  margin: 14px 10px 8px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
}

.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-radius: 16px;
  color: var(--text); font-weight: 500; font-size: 14px;
  margin-bottom: 6px;
}

.nav a i { width: 18px; height: 18px; }

.nav a:hover { background: #f8fafc; color: var(--primary); }

.nav a.active {
  background: var(--accent-light) !important;
  color: var(--primary) !important;
  font-weight: 800;
  position: relative;
}

.nav a.active::after {
  content: ""; position: absolute; right: 0; top: 20%;
  height: 60%; width: 4px; background: var(--primary);
  border-radius: 10px 0 0 10px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--border);
  font-weight: 800;
}

.logout-btn:hover {
  border-color: var(--primary);
  background: #f8fafc;
}

/* --- منطقة العمل والهيدر --- */
.main { flex: 1; padding: 18px 20px; min-width: 0; }

/* منطقة العنوان داخل الهيدر */
.header-brand-area { display: flex; align-items: center; gap: 12px; }
.site-name {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ✅ جديد: تصميم صندوق المستخدم للكمبيوتر */
.userbox-desktop {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 14px;
    background: #f8fafc;
    border: 1px solid #edf2f7;
    border-radius: 14px;
    transition: var(--transition);
    cursor: pointer;
}
.userbox-desktop:hover { border-color: var(--primary); background: #fff; transform: translateY(-2px); }
.user-text { text-align: left; }
.user-name { display: block; font-weight: 800; font-size: 13.5px; color: var(--text); }
.user-role { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.avatar-circle {
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--accent-light); color: var(--primary);
    display: flex; align-items: center; justify-content: center; font-weight: 800;
}

.page-title { font-size: 22px; font-weight: 800; color: var(--text); margin: 0 0 20px 0; }
/* ===== Page header (Hero) ===== */
.page-header-title{
  position: relative;
  overflow: hidden;
  border-radius: 26px;
  padding: 28px 22px;
  margin: 0 0 18px 0;
  background: linear-gradient(135deg, var(--hero), var(--hero2));
  color: #fff;
  box-shadow: var(--shadow-md);
}
.page-header-title::before{
  content: "";
  position: absolute;
  inset: -45%;
  background-image:
    radial-gradient(circle at 18% 22%, rgba(255,255,255,.16) 0 2px, transparent 3px 44px),
    radial-gradient(circle at 82% 18%, rgba(255,255,255,.12) 0 2px, transparent 3px 46px),
    radial-gradient(circle at 70% 78%, rgba(255,255,255,.10) 0 2px, transparent 3px 42px),
    repeating-linear-gradient(60deg, rgba(255,255,255,.07) 0 2px, transparent 2px 14px),
    repeating-linear-gradient(-60deg, rgba(255,255,255,.05) 0 2px, transparent 2px 14px);
  transform: rotate(-2deg);
  opacity: .9;
}
.page-header-title::after{
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 100% at 0% 0%, rgba(255,255,255,.10) 0%, rgba(255,255,255,0) 55%);
  pointer-events: none;
}
.page-header-inner{
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header-title .page-title{
  margin: 0;
  color: #fff;
  font-size: 36px;
  font-weight: 900;
  letter-spacing: -.3px;
  line-height: 1.15;
  text-shadow: 0 1px 0 rgba(0,0,0,.14);
}
@media (max-width: 900px){
  .page-header-title{ padding: 22px 16px; border-radius: 22px; }
  .page-header-title .page-title{ font-size: 30px; }
}
@media (max-width: 520px){
  .page-header-title{ padding: 18px 14px; border-radius: 20px; }
  .page-header-title .page-title{ font-size: 26px; }
}


/* إخفاء زر الجوال الافتراضي وتفعيله في التجاوب */
.mobile-toggle { display: none !important; }

/* Overlay للجوال عند فتح القائمة */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: var(--transition);
  z-index: 1900;
}

.sidebar-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

body.no-scroll { overflow: hidden; }

/* صندوق البحث */
.search { flex: 1; display: flex; gap: 12px; max-width: 500px; }
.search input {
  width: 100%; padding: 12px 20px; border: 1px solid var(--border);
  border-radius: 15px; background: #fff; font-family: inherit; transition: var(--transition);
}
.search input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--accent-light); }
.search button {
  padding: 0 25px; border: 0; border-radius: 15px;
  background: var(--primary); color: #fff; cursor: pointer; font-weight: 700; transition: var(--transition);
}
.search button:hover { background: var(--primary-dark); }

/* --- المكونات (الأزرار) --- */
.small-actions { display: flex !important; gap: 10px !important; align-items: center; }
.small-actions a, .btn {
  display: inline-flex !important; align-items: center; justify-content: center;
  padding: 10px 18px !important; border-radius: 14px !important;
  font-size: 13px !important; font-weight: 700 !important;
  white-space: nowrap !important; transition: var(--transition); border: 1px solid transparent;
}
.small-actions a.light, .btn.light { background: #fff; border: 1px solid var(--border); color: var(--text); }
.small-actions a.ok, .btn.ok { background: var(--primary); color: #fff; }
.small-actions a:hover, .btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

select {
  width: 100%; padding: 12px 18px; border: 1px solid var(--border);
  border-radius: 15px; background: #ffffff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E") no-repeat left 15px center;
  background-size: 18px; font-family: inherit; font-size: 14px;
  color: var(--text); cursor: pointer; appearance: none; -webkit-appearance: none;
  padding-left: 45px; transition: var(--transition);
}
select:focus { border-color: var(--primary); }

/* --- الإحصائيات والجداول --- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 15px; margin-bottom: 30px; }
.kpi {
  background: #fff; border: 1px solid var(--border);
  border-radius: 20px; padding: 22px; text-align: center; box-shadow: var(--shadow-sm); transition: var(--transition);
}
.kpi:hover { transform: translateY(-5px); box-shadow: var(--shadow-md); }
.kpi .value { font-size: 26px; font-weight: 800; color: var(--primary); margin-top: 8px; }

.card {
  background: #fff; border: 1px solid var(--border);
  border-radius: 25px; box-shadow: var(--shadow-sm);
  padding: 25px; margin-bottom: 25px; transition: var(--transition);
}

table { width: 100%; border-collapse: collapse; }
th { text-align: right; padding: 16px; font-size: 12px; color: var(--muted); font-weight: 800; border-bottom: 2px solid var(--border); }
td { padding: 16px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }

/* --- 📱 التجاوب للجوال (مطور بناءً على نسختك) --- */
@media (max-width: 980px) {
  :root { --topbar-h: 56px; }

  .app-shell { padding: 12px; }

  .sidebar {
    position: fixed;
    top: 0;
    right: -320px;
    height: 100vh;
    width: 300px;
    border-radius: 0;
    z-index: 2000;
    box-shadow: none;
  }
  .sidebar.open { right: 0; box-shadow: -10px 0 50px rgba(0,0,0,0.15); }

  /* تبديل عرض صناديق المستخدم */
  .userbox-desktop { display: none !important; }
  .userbox-mobile { display: flex !important; }

  .main { padding: 12px; }

  .topbar-inner { padding: 8px 12px; }
  .site-name { font-size: 0.98rem; }

  .mobile-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: #fff;
    border-radius: 10px;
    border: 1px solid var(--border);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    padding: 0;
  }

  .search { max-width: 100%; flex-basis: 100%; margin-top: 10px; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

/* ===== QSM Portal UI helpers (نسختك الأصلية بالكامل دون أي حذف) ===== */
.grid{display:grid;grid-template-columns:repeat(12,1fr);gap:18px}
.col-12{grid-column:span 12}
.col-6{grid-column:span 6}
.col-4{grid-column:span 4}
.col-3{grid-column:span 3}
@media (max-width:720px){ .col-6,.col-4,.col-3{grid-column:span 12} }

.card-title{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:14px}
.badge{display:inline-flex;align-items:center;justify-content:center;padding:6px 12px;border-radius:999px;background:#eef2ff;color:#1e3a8a;font-size:12px;font-weight:800}
.badge.ok{background:#dcfce7;color:#166534}
.badge.warn{background:#fef9c3;color:#854d0e}
.badge.info{background:#e0f2fe;color:#075985}

.alert{padding:12px 14px;border-radius:12px;margin:12px 0;font-weight:800}
.alert.ok{background:#dcfce7;color:#14532d}
.alert.danger{background:#fee2e2;color:#7f1d1d}
.muted{color:#64748b;font-weight:700}
.hint{color:#64748b;font-size:13px;margin-top:6px}

.form-grid{display:grid;grid-template-columns:repeat(12,1fr);gap:14px}
.field label{display:block;margin-bottom:6px;font-weight:900}
.field input,.field select,.field textarea{width:100%;padding:10px 12px;border:1px solid #e5e7eb;border-radius:12px;font:inherit; transition: 0.3s;}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--accent-light); }
.field textarea{resize:vertical}

.details{border:1px dashed #e5e7eb;border-radius:14px;padding:10px;background:#fafafa}
.details summary{cursor:pointer;font-weight:900}

.actions{display:flex;gap:10px;flex-wrap:wrap;justify-content:flex-end;margin-top:14px}
.actions .btn{min-height:42px}

.wizard-steps{display:flex;gap:8px;flex-wrap:wrap;margin-top:6px}
.wizard-step{padding:8px 12px;border-radius:999px;background:#f1f5f9;color:#0f172a;font-weight:900;font-size:12px; transition: 0.3s;}
.wizard-step.active{background:#111827;color:#fff}
.wizard-step.done{background:#dbeafe;color:#1e40af}

.meta-grid{display:grid;grid-template-columns:repeat(12,1fr);gap:10px}
.meta-item{grid-column:span 3;background:#f8fafc;border:1px solid #e5e7eb;border-radius:12px;padding:10px}
.meta-item .k{display:block;color:#64748b;font-size:12px;font-weight:800;margin-bottom:4px}
.meta-item .v{display:block;color:#0f172a;font-weight:900}
@media (max-width:900px){ .meta-item{grid-column:span 6} }
@media (max-width:720px){ .meta-item{grid-column:span 12} }

.thumbs{display:flex;gap:10px;flex-wrap:wrap;margin-top:10px}
.thumbs img{width:120px;height:84px;object-fit:cover;border-radius:12px;border:1px solid #e5e7eb; transition: 0.3s;}
.thumbs img:hover { transform: scale(1.05); cursor: pointer; }

.obs-list{display:flex;flex-direction:column;gap:12px}
.obs-item{border:1px solid #e5e7eb;border-radius:16px;padding:12px;background:#fff; transition: 0.3s;}
.obs-item:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.obs-head{display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap;align-items:center}
.obs-actions{display:flex;gap:8px;flex-wrap:wrap}
.obs-note{margin-top:10px;font-weight:800}

.table-wrap{overflow:auto;border:1px solid #e5e7eb;border-radius:16px}
.table{width:100%;border-collapse:collapse;min-width:720px}
.table th,.table td{padding:12px 12px;border-bottom:1px solid #e5e7eb;vertical-align:top}
.table th{background:#f8fafc;text-align:right;font-weight:900; white-space: nowrap;}

.rating{display:flex;gap:6px;flex-wrap:wrap}
.rate{display:flex;align-items:center;gap:6px}
.rate input{display:none}
.rate span{display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:10px;border:1px solid #e5e7eb;background:#fff;font-weight:900; cursor: pointer; transition: 0.2s;}
.rate input:checked + span{background:#111827;color:#fff;border-color:#111827}
.rate:hover span { background: var(--accent-light); }
