/* =====================================================================
   نظام شؤون الموظفين — نظام التصميم
   فاتح/داكن عبر متغيرات CSS، RTL افتراضي مع دعم LTR للإنجليزية
   ===================================================================== */

/* الوضع الداكن (لوحة تحليلات كحلية متوهجة) هو الافتراضي الآن في كل النظام */
:root,
:root[data-theme="dark"] {
  --bg: #0a1128;
  --bg-2: #0d1b3e;
  --surface: #101c40;
  --surface-2: #0d1836;
  --border: #22335f;
  --text: #eaf0ff;
  --text-muted: #9fb0d9;
  --text-soft: #6f81ab;

  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-fg: #ffffff;
  --primary-soft: #14265a;

  --navy: #060b1c;
  --navy-2: #0d1b3e;

  --success: #22c55e;
  --success-soft: #0f2a1e;
  --warning: #f59e0b;
  --warning-soft: #2c2109;
  --danger: #ef4444;
  --danger-soft: #2c1414;
  --info: #60a5fa;
  --info-soft: #10203a;

  --radius-sm: 10px;
  --radius: 18px;
  --radius-lg: 26px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 28px rgba(2, 8, 30, .55);
  --shadow-lg: 0 12px 40px rgba(2, 8, 30, .65);

  --sidebar-bg: #0a1330;
  --sidebar-active-bg: linear-gradient(135deg, #3b82f6, #2563eb);
  --sidebar-active-fg: #ffffff;

  --glow-1: rgba(59, 130, 246, .35);
  --glow-2: rgba(96, 165, 250, .18);
}

:root[data-theme="light"] {
  --bg: #eef2f1;
  --bg-2: #eef2f1;
  --surface: #ffffff;
  --surface-2: #f5f8f7;
  --border: #e6ebe9;
  --text: #16221f;
  --text-muted: #71827c;
  --text-soft: #9aa8a3;

  --primary: #22b57a;
  --primary-dark: #169c67;
  --primary-fg: #ffffff;
  --primary-soft: #dcf6e9;

  --navy: #0f2a2b;
  --navy-2: #163f3e;

  --success: #22b57a;
  --success-soft: #dcf6e9;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #2563eb;
  --info-soft: #eff6ff;

  --shadow: 0 1px 2px rgba(16, 24, 40, .03), 0 6px 20px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 34px rgba(16, 24, 40, .10);

  --sidebar-bg: #ffffff;
  --sidebar-active-bg: var(--primary);
  --sidebar-active-fg: #ffffff;

  --glow-1: transparent;
  --glow-2: transparent;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Arabic', 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}

body { transition: background-color .2s ease, color .2s ease; position: relative; }

/* شبكة متوهجة خفيفة في خلفية الوضع الداكن — تُلغى تلقائيًا في الوضع الفاتح عبر --glow-* */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 8% 12%, var(--glow-1) 0%, transparent 32%),
    radial-gradient(circle at 92% 8%, var(--glow-2) 0%, transparent 28%),
    radial-gradient(circle at 85% 78%, var(--glow-1) 0%, transparent 30%),
    radial-gradient(circle at 15% 85%, var(--glow-2) 0%, transparent 26%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
  background-color: var(--bg);
}
.app-shell, .auth-shell { position: relative; z-index: 1; }

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; }

::selection { background: var(--primary-soft); color: var(--primary-dark); }

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

.sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-inline-end: 1px solid var(--border);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 22px;
}
.sidebar-brand .logo-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--navy-2));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 15px;
}
.sidebar-brand .logo-img { height: 38px; width: auto; max-width: 42px; object-fit: contain; flex-shrink: 0; }
.sidebar-brand .brand-text { font-size: 15px; font-weight: 800; line-height: 1.3; }
.sidebar-brand .brand-text small { display:block; font-weight: 500; font-size: 11px; color: var(--text-muted); }

.nav-group { margin-bottom: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 2px;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-fg); }
.nav-link .nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

/* حجم افتراضي لكل أيقونات SVG أينما استُخدمت (وليس فقط داخل .nav-link) */
svg.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

/* مجموعة قائمة جانبية قابلة للطي (details/summary) */
.nav-group { margin-bottom: 2px; }
.nav-group-summary { cursor: pointer; list-style: none; position: relative; }
.nav-group-summary::-webkit-details-marker { display: none; }
.nav-group-summary::after {
  content: '';
  width: 7px; height: 7px;
  border-inline-end: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  margin-inline-start: auto;
  opacity: .6;
  transition: transform .15s ease;
}
.nav-group[open] > .nav-group-summary::after { transform: rotate(-135deg); }
.nav-group-children { padding-inline-start: 30px; display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.nav-group-children .nav-link { font-size: 13px; padding: 8px 12px; }

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

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  width: 320px;
  color: var(--text-soft);
}
.search-box input { border: none; background: transparent; outline: none; color: var(--text); flex: 1; font-family: inherit; }

.topbar-actions { display: flex; align-items: center; gap: 14px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { color: var(--primary-dark); }

.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.page {
  padding: 26px 28px 50px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title { font-size: 22px; font-weight: 800; }
.page-breadcrumb { color: var(--text-soft); font-size: 12.5px; margin-bottom: 4px; }
.page-breadcrumb a { color: var(--text-soft); text-decoration: none; }
.page-breadcrumb a:hover { color: var(--primary-dark); text-decoration: underline; }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 13.5px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: .15s ease;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: 12.5px; border-radius: 8px; }

/* ---------- البطاقات ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 15px; font-weight: 800; }

.grid { display: grid; gap: 16px; }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1200px) { .grid-5, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) { .grid-5, .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stat-card .stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-card .stat-icon {
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
}
.stat-card .stat-value { font-size: 26px; font-weight: 800; }
.stat-card .stat-label { color: var(--text-muted); font-size: 12.5px; font-weight: 600; }
.stat-badge { font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 999px; }
.stat-badge.up { background: var(--success-soft); color: var(--success); }
.stat-badge.down { background: var(--danger-soft); color: var(--danger); }

.tint-primary { background: var(--primary-soft); color: var(--primary-dark); }
.tint-info { background: var(--info-soft); color: var(--info); }
.tint-warning { background: var(--warning-soft); color: var(--warning); }
.tint-danger { background: var(--danger-soft); color: var(--danger); }
.tint-success { background: var(--success-soft); color: var(--success); }

/* ---------- الدونات + الأسطورة (مثل بطاقات "Track your team" في التصميم المرجعي) ---------- */
.donut-wrap { position: relative; width: 180px; height: 180px; flex-shrink: 0; }
.donut-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
.donut-center-value { font-size: 24px; font-weight: 800; color: var(--text); }
.donut-center-label { font-size: 11.5px; color: var(--text-muted); font-weight: 600; }

.legend-list { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 160px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.legend-label { color: var(--text-muted); font-weight: 600; }
.legend-value { font-weight: 800; margin-inline-start: auto; }

.alert-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
}
.alert-icon {
  width: 30px; height: 30px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.alert-icon .nav-icon { width: 15px; height: 15px; }

/* بطاقة مميزة بتدرج أزرق متوهج (مثل بطاقات لوحة التحليلات المرجعية) */
.card-dark {
  background: linear-gradient(160deg, #1d4ed8, #0b1e52);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: 0 10px 34px rgba(37, 99, 235, .35);
  border: 1px solid rgba(96, 165, 250, .35);
}
.card-dark .muted { color: rgba(255,255,255,.7); }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: start;
  padding: 13px 16px;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-2); }
.hidden-row { display: none; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 800;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.active, .badge.valid, .badge.approved, .badge.paid { background: var(--success-soft); color: var(--success); }
.badge.on_leave, .badge.pending, .badge.expiring_soon, .badge.under_review { background: var(--warning-soft); color: var(--warning); }
.badge.suspended, .badge.rejected, .badge.expired { background: var(--danger-soft); color: var(--danger); }
.badge.terminated, .badge.closed, .badge.draft { background: var(--surface-2); color: var(--text-muted); }

/* ---------- النماذج ---------- */
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px 20px; }
@media (max-width: 900px) { .form-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field.col-2 { grid-column: span 2; }
.field.col-3 { grid-column: span 3; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--text-muted); }
.field .hint { font-size: 11px; color: var(--text-soft); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=tel], input[type=time], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; min-height: 90px; }

/* عناصر التاريخ/الوقت الأصلية للمتصفح تُعرض بترتيب معكوس داخل سياق RTL؛
   نجبرها على LTR داخليًا مع محاذاة النص لليمين لتبدو طبيعية */
input[type=date], input[type=time], input[type=datetime-local], input[type=month] {
  direction: ltr;
  text-align: right;
}

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab-btn {
  padding: 12px 16px; font-weight: 700; font-size: 13px;
  color: var(--text-muted); border-bottom: 2px solid transparent;
  white-space: nowrap; cursor: pointer; background: none; border-top: none; border-inline: none; font-family: inherit;
}
.tab-btn.active { color: var(--primary-dark); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- تسجيل الدخول ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 24px; }
.auth-logo .logo-mark { width: 52px; height: 52px; border-radius: 14px; background: linear-gradient(135deg, var(--primary), var(--navy-2)); display:flex;align-items:center;justify-content:center; color:#fff; font-weight:800; font-size: 20px;}
.auth-logo .logo-img-lg { height: 72px; width: auto; max-width: 220px; object-fit: contain; }

/* ---------- عناصر عامة ---------- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-soft); }
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 600; font-size: 13.5px; }
.flash.success { background: var(--success-soft); color: var(--success); }
.flash.error { background: var(--danger-soft); color: var(--danger); }
.flash.warning { background: var(--warning-soft); color: var(--warning); }

.filters-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; align-items: center; }
.filters-bar select, .filters-bar input { width: auto; min-width: 140px; }

.employee-cell { display: flex; align-items: center; gap: 10px; }
.employee-cell .sub { color: var(--text-soft); font-size: 12px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
