/* ===================================================================
   binaa_erp — نظام التصميم | عربي RTL
   هوية عصرية منضبطة للإدارة المالية والمشاريع
   =================================================================== */

:root {
  /* الألوان */
  --primary:        #1e3a5f;
  --primary-dark:   #16293f;
  --primary-light:  #2d5180;
  --accent:         #0f6e56;
  --accent-light:   #e6f4ef;
  --danger:         #c0392b;
  --danger-light:   #fdeceb;
  --warning:        #b9770e;
  --warning-light:  #fdf3e2;
  --bg:             #f1f4f8;
  --surface:        #ffffff;
  --border:         #e5e9f0;
  --border-strong:  #d4dae4;
  --text:           #1c2733;
  --text-muted:     #74808f;
  --text-faint:     #9aa5b1;
  --shadow-sm:      0 1px 2px rgba(16,30,54,.06);
  --shadow:         0 2px 8px rgba(16,30,54,.08);
  --shadow-lg:      0 12px 32px rgba(16,30,54,.14);

  /* المقاييس */
  --radius:         8px;
  --radius-lg:      12px;
  --sidebar-w:      244px;
  --sidebar-collapsed: 64px;
  --topbar-h:       58px;
  --field-h:        42px;

  /* مقياس المسافات */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: 'Segoe UI', Tahoma, 'Cairo', system-ui, sans-serif;
  direction: rtl;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

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

/* ===== شاشة الدخول ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, var(--primary-light), var(--primary-dark));
  padding: var(--sp-5);
}
.login-card {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
  padding: var(--sp-8) var(--sp-6);
}
.login-logo { text-align: center; margin-bottom: var(--sp-6); }
.login-logo h1 { color: var(--primary); font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.login-logo p { color: var(--text-muted); font-size: 13px; margin-top: var(--sp-1); }

/* ===== النماذج ===== */
.form-group { margin-bottom: var(--sp-4); }
.form-group label {
  display: block;
  margin-bottom: var(--sp-2);
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
}
.form-control {
  width: 100%;
  height: var(--field-h);
  padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
textarea.form-control { height: auto; padding: var(--sp-3); min-height: 90px; resize: vertical; }
.form-control:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(45,81,128,.14);
}
.form-control::placeholder { color: var(--text-faint); }
select.form-control { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2374808f' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left var(--sp-3) center; padding-left: var(--sp-6); }

/* صف حقول شبكي */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-4);
}
.checkbox-line { display: flex; align-items: center; gap: var(--sp-2); font-size: 13px; cursor: pointer; user-select: none; }
.checkbox-line input { width: 16px; height: 16px; cursor: pointer; }
.form-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-5); padding-top: var(--sp-5); border-top: 1px solid var(--border); }

/* ===== الأزرار ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--field-h); padding: 0 var(--sp-5);
  border: 1px solid transparent; border-radius: var(--radius);
  font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s, border-color .15s, transform .05s; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #0c5a46; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a5301f; color: #fff; }
.btn-light { background: #fff; color: var(--text); border-color: var(--border-strong); }
.btn-light:hover { background: #f5f7fa; color: var(--text); }
.btn-sm { height: 32px; padding: 0 var(--sp-3); font-size: 12.5px; }
.btn-block { width: 100%; }

/* ===== التنبيهات ===== */
.alert { padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); margin-bottom: var(--sp-4);
  font-size: 13px; font-weight: 500; border: 1px solid transparent; }
.alert-error   { background: var(--danger-light);  color: var(--danger);  border-color: #f3c9c4; }
.alert-success { background: var(--accent-light);  color: var(--accent);  border-color: #bfe5d8; }
.alert-warning { background: var(--warning-light); color: var(--warning); border-color: #f3dcb0; }

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: #b9c6d6;
  flex-shrink: 0;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  transition: width .22s ease;
  z-index: 40;
}
.sidebar-brand {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 0 var(--sp-5);
  font-size: 19px; font-weight: 800; color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
  white-space: nowrap; overflow: hidden;
}
.sidebar-brand .brand-mark {
  width: 30px; height: 30px; flex-shrink: 0;
  background: var(--accent); border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 800;
}
.sidebar-menu { list-style: none; padding: var(--sp-3) 0; overflow-y: auto; overflow-x: hidden; flex: 1; }
.sidebar-menu::-webkit-scrollbar { width: 5px; }
.sidebar-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }
.sidebar-section {
  padding: var(--sp-4) var(--sp-5) var(--sp-2);
  font-size: 10.5px; color: #6f859c; font-weight: 700;
  letter-spacing: .6px; white-space: nowrap; overflow: hidden;
}
.sidebar-menu > li > a {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 10px var(--sp-5);
  color: #b9c6d6; font-size: 13.5px; font-weight: 500;
  border-right: 3px solid transparent;
  transition: background .14s, color .14s; white-space: nowrap; overflow: hidden;
}
.sidebar-menu > li > a .ico { width: 18px; flex-shrink: 0; text-align: center; font-size: 15px; opacity: .85; }
.sidebar-menu > li > a .lbl { overflow: hidden; text-overflow: ellipsis; }
.sidebar-menu > li > a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-menu > li > a.active { background: rgba(15,110,86,.22); color: #fff; border-right-color: var(--accent); }

/* السايدبار المطوي */
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .sidebar-brand span.brand-text,
.sidebar.collapsed .sidebar-menu .lbl,
.sidebar.collapsed .sidebar-section { opacity: 0; visibility: hidden; }
.sidebar.collapsed .sidebar-section { padding-top: var(--sp-2); padding-bottom: var(--sp-2); height: 1px; }
.sidebar.collapsed .sidebar-menu > li > a { justify-content: center; padding: 11px 0; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 0; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: var(--surface);
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--sp-5);
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 30;
}
.topbar-right { display: flex; align-items: center; gap: var(--sp-3); }
.topbar h2 { font-size: 16px; font-weight: 700; color: var(--text); }
.menu-btn {
  width: 38px; height: 38px; border: none; background: transparent; cursor: pointer;
  border-radius: var(--radius); color: var(--text-muted); font-size: 18px;
  display: flex; align-items: center; justify-content: center; transition: background .14s;
}
.menu-btn:hover { background: #eef1f6; color: var(--text); }
.topbar-user { display: flex; align-items: center; gap: var(--sp-3); font-size: 13px; }
.topbar-user .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary-light); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
}
.topbar-user .uname { font-weight: 600; }

.content { padding: var(--sp-6); flex: 1; max-width: 1180px; width: 100%; }

/* ===== البطاقات ===== */
.card { background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); border: 1px solid var(--border); margin-bottom: var(--sp-5); }
.card-header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
}
.card-header h3 { font-size: 15.5px; font-weight: 700; color: var(--text); }
.card-header .sub { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.card-body { padding: var(--sp-5); }
.card-narrow { max-width: 720px; }

/* بطاقات الإحصاء */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--sp-4); margin-bottom: var(--sp-6); }
.stat-card { background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); border: 1px solid var(--border);
  padding: var(--sp-5); position: relative; overflow: hidden; }
.stat-card::before { content:''; position: absolute; top: 0; right: 0; width: 4px; height: 100%; background: var(--primary); }
.stat-card .num { font-size: 26px; font-weight: 800; color: var(--text); letter-spacing: -.5px; }
.stat-card .label { color: var(--text-muted); font-size: 12.5px; margin-top: var(--sp-1); }
.stat-card.accent::before { background: var(--accent); }
.stat-card.accent .num { color: var(--accent); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.warning .num { color: var(--warning); }

/* ===== الجداول ===== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 11px var(--sp-4); text-align: right; }
table.data thead th {
  background: #f7f9fc; font-weight: 700; color: var(--text-muted);
  font-size: 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0;
}
table.data tbody td { border-bottom: 1px solid var(--border); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: #f7f9fc; }
table.data.keyval th { width: 200px; background: #f7f9fc; }

.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; line-height: 1.5; }
.badge-success { background: var(--accent-light); color: var(--accent); }
.badge-danger  { background: var(--danger-light);  color: var(--danger); }
.badge-muted   { background: #eef1f6; color: var(--text-muted); }

.actions-cell { display: flex; gap: var(--sp-1); flex-wrap: wrap; }

/* أدوات مساعدة */
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.text-muted { color: var(--text-muted); }
.mt-2 { margin-top: var(--sp-3); }
.mb-0 { margin-bottom: 0; }
.empty-state { text-align: center; padding: var(--sp-8); color: var(--text-faint); font-size: 13px; }
.pagination { display: flex; gap: var(--sp-1); flex-wrap: wrap; margin-top: var(--sp-4); }

/* مجموعات الصلاحيات */
.perm-group { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: var(--sp-3); overflow: hidden; }
.perm-group > summary, .perm-group-head {
  padding: var(--sp-3) var(--sp-4); background: #f7f9fc; font-weight: 700; font-size: 13px;
  cursor: pointer; display: flex; align-items: center; gap: var(--sp-2); border-bottom: 1px solid var(--border);
}
.perm-group-body { padding: var(--sp-4);
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--sp-2); }
.perm-item { font-size: 12.5px; display: flex; gap: var(--sp-2); align-items: flex-start; }

/* الغطاء الخلفي للجوال */
.overlay { display: none; position: fixed; inset: 0; background: rgba(16,30,54,.5); z-index: 35; }
.overlay.show { display: block; }

/* ===== التجاوب ===== */
@media (max-width: 1024px) {
  .content { padding: var(--sp-4); }
}
@media (max-width: 768px) {
  .sidebar {
    position: fixed; right: 0; top: 0; height: 100vh;
    transform: translateX(100%); transition: transform .25s ease; width: var(--sidebar-w);
  }
  .sidebar.mobile-open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar.collapsed { width: var(--sidebar-w); } /* على الجوال لا نطوي بل نخفي */
  .sidebar.collapsed .lbl, .sidebar.collapsed .sidebar-section,
  .sidebar.collapsed .sidebar-brand span.brand-text { opacity: 1; visibility: visible; }
  .sidebar.collapsed .sidebar-menu > li > a { justify-content: flex-start; padding: 10px var(--sp-5); }
  .topbar h2 { font-size: 14px; }
  .topbar-user .uname { display: none; }
  .content { padding: var(--sp-3); }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; }
}

/* ============ قواعد الطباعة ============ */
@media print {
  /* إخفاء عناصر الواجهة */
  .sidebar,
  .topbar,
  .no-print,
  .btn,
  .menu-btn,
  .topbar-user {
    display: none !important;
  }
  /* توسيع المحتوى لكامل الصفحة */
  .layout { display: block !important; }
  .main { margin: 0 !important; width: 100% !important; }
  .content { padding: 0 !important; margin: 0 !important; }
  .card {
    box-shadow: none !important;
    border: none !important;
    margin: 0 !important;
  }
  .card-header { border-bottom: 1px solid #ccc !important; padding: 0 0 10px 0 !important; }
  .card-body { padding: 0 !important; }
  /* الجداول */
  .data { font-size: 12px !important; }
  .data th { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table-wrap { overflow: visible !important; }
  /* البطاقات الإحصائية */
  .stats-grid { display: grid !important; }
  .stat-card { border: 1px solid #ccc !important; box-shadow: none !important; }
  /* تجنّب قطع الصفوف */
  tr, .stat-card { page-break-inside: avoid; }
  /* ألوان دقيقة */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  /* خلفية بيضاء */
  body, .content { background: #fff !important; }
}

/* ===== السايدبار: الأقسام القابلة للطي ===== */
.sidebar-group { list-style: none; }
.sidebar-section-toggle {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; cursor: pointer; user-select: none;
  font-size: 12px; font-weight: 700; color: #9fb3c8;
  text-transform: none; letter-spacing: .3px;
  transition: background .15s;
}
.sidebar-section-toggle:hover { background: rgba(255,255,255,.05); }
.sidebar-section-toggle .chevron { font-size: 11px; transition: transform .2s; opacity: .7; }
.sidebar-group.open .sidebar-section-toggle .chevron { transform: rotate(180deg); }
.sidebar-subitems {
  list-style: none; margin: 0; padding: 0;
  max-height: 0; overflow: hidden; transition: max-height .25s ease;
}
.sidebar-group.open .sidebar-subitems { max-height: 600px; }
.sidebar-subitems li a {
  padding-right: 26px; /* إزاحة بسيطة للبنود تحت القسم */
}

/* ===== إصلاح: أنماط البنود داخل الأقسام القابلة للطي ===== */
.sidebar-subitems li a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 26px 10px 16px;
  color: #c5d2e0; text-decoration: none;
  font-size: 13.5px; transition: background .15s, color .15s;
  border-right: 3px solid transparent;
}
.sidebar-subitems li a .ico { width: 18px; flex-shrink: 0; text-align: center; font-size: 15px; opacity: .85; }
.sidebar-subitems li a .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-subitems li a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-subitems li a.active { background: rgba(15,110,86,.22); color: #fff; border-right-color: var(--accent); }
