/* ===== نظام التصميم ===== */
:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e6e9f0;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;

  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eff4ff;

  --success: #15803d;
  --success-soft: #dcfce7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --info: #0e7490;
  --info-soft: #cffafe;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 6px 20px rgba(15, 23, 42, .07);

  --sidebar-w: 254px;
  --sidebar-bg: #0f172a;
}

body {
  font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: .93rem;
}

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

/* ===== هيكل الصفحة ===== */
.app-shell { display: flex; min-height: 100vh; }

/* !important ضروري: بوتستراب يجعل .offcanvas-lg شفافاً على الشاشات الكبيرة */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg) !important;
  color: #cbd5e1;
  flex-shrink: 0;
}

@media (min-width: 992px) {
  .sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; }
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.1rem 1.15rem;
  color: #fff;
  font-weight: 700;
  font-size: 1.02rem;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  line-height: 1.35;
}
.sidebar .brand img { height: 34px; width: auto; border-radius: 6px; background: #fff; padding: 3px; }
.sidebar .brand .brand-sub { display: block; font-size: .72rem; font-weight: 400; color: #94a3b8; }

.sidebar .nav-section {
  padding: 1rem 1.15rem .35rem;
  font-size: .7rem;
  letter-spacing: .04em;
  color: #64748b;
  font-weight: 600;
}

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem 1.15rem;
  color: #cbd5e1;
  border-right: 3px solid transparent;
  font-size: .9rem;
}
.sidebar .nav-link i { font-size: 1.02rem; width: 1.2rem; text-align: center; color: #94a3b8; }
.sidebar .nav-link:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.sidebar .nav-link:hover i { color: #cbd5e1; }
.sidebar .nav-link.active {
  background: rgba(37, 99, 235, .16);
  color: #fff;
  border-right-color: var(--brand);
  font-weight: 600;
}
.sidebar .nav-link.active i { color: #93c5fd; }

.sidebar-footer {
  margin-top: auto;
  padding: .9rem 1.15rem;
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: .8rem;
  color: #94a3b8;
}

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}
.topbar .today-chip {
  font-size: .82rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .2rem .7rem;
}

.content { padding: 1.15rem; flex: 1; }
@media (min-width: 992px) { .content { padding: 1.5rem 1.75rem; } }

/* ===== ترويسة الصفحة ===== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.1rem;
}
.page-header h1 { font-size: 1.3rem; margin: 0; }
.page-header .page-sub { color: var(--muted); font-size: .85rem; margin-top: .15rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.page-actions form { margin: 0; }

/* ===== البطاقات ===== */
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--surface);
}
.card-header {
  background: var(--surface);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  padding: .7rem 1rem;
  font-size: .93rem;
  border-radius: var(--radius) var(--radius) 0 0 !important;
}
.card-body { padding: 1rem; }

/* بطاقات الأرقام */
.stat-card { position: relative; overflow: hidden; }
.stat-card .card-body { display: flex; align-items: center; gap: .85rem; }
.stat-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
  background: var(--brand-soft);
  color: var(--brand);
}
.stat-icon.success { background: var(--success-soft); color: var(--success); }
.stat-icon.danger { background: var(--danger-soft); color: var(--danger); }
.stat-icon.warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.info { background: var(--info-soft); color: var(--info); }
.stat-label { color: var(--muted); font-size: .8rem; line-height: 1.3; }
.stat-value { font-size: 1.35rem; font-weight: 700; line-height: 1.25; }
.stat-value.sm { font-size: 1.12rem; }
.stat-hint { font-size: .75rem; color: var(--muted); }

/* ===== الجداول ===== */
.table { margin-bottom: 0; font-size: .88rem; }
.table > :not(caption) > * > * { padding: .6rem .65rem; }
.table thead th {
  background: var(--surface-2);
  color: var(--ink-2);
  font-weight: 600;
  font-size: .82rem;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.table td, .table th { vertical-align: middle; }
.table-hover tbody tr:hover { background: var(--brand-soft); }
.table tfoot th { background: var(--surface-2); }
.table-card { overflow: hidden; }
.table-card .table-responsive { border-radius: 0 0 var(--radius) var(--radius); }

.table-sticky { max-height: 70vh; overflow: auto; }
.table-sticky thead th { position: sticky; top: 0; z-index: 2; }

.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.empty-state { text-align: center; color: var(--muted); padding: 2.2rem 1rem; }
.empty-state i { font-size: 1.9rem; display: block; margin-bottom: .5rem; opacity: .45; }

/* ===== الشارات ===== */
.badge { font-weight: 600; font-size: .74rem; padding: .32em .6em; border-radius: 6px; }
.badge-day-work { background: var(--brand-soft); color: var(--brand-dark); }
.badge-day-paid_leave { background: var(--success-soft); color: var(--success); }
.badge-day-unpaid_leave { background: #f1f5f9; color: #475569; }
.badge-day-absent { background: var(--danger-soft); color: var(--danger); }
.badge-day-official_holiday { background: var(--warning-soft); color: var(--warning); }
.badge-soft-success { background: var(--success-soft); color: var(--success); }
.badge-soft-danger { background: var(--danger-soft); color: var(--danger); }
.badge-soft-muted { background: #f1f5f9; color: var(--muted); }

/* ===== النماذج ===== */
.form-label { font-size: .82rem; font-weight: 600; color: var(--ink-2); margin-bottom: .25rem; }
.form-control, .form-select { border-color: #dbe1ea; border-radius: var(--radius-sm); font-size: .9rem; }
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.form-text { font-size: .76rem; }
.btn { border-radius: var(--radius-sm); font-weight: 600; font-size: .87rem; }
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover, .btn-primary:focus { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-sm { font-size: .8rem; padding: .27rem .6rem; }

.filter-card { background: var(--surface); }
.filter-card .btn-group .btn { font-size: .78rem; }

/* ===== الإدخال الجماعي ===== */
#bulkEntryTable td { padding: .4rem .45rem; }
#bulkEntryTable input, #bulkEntryTable select { font-size: .84rem; }
.table-sm-input { min-width: 92px; }
tr.row-off { background: #fbfcfe; }
tr.row-off td:not(:first-child):not(:nth-child(2)) { opacity: .55; }
tr.row-locked { background: #f8fafc; }
tr.row-active { box-shadow: inset 3px 0 0 var(--brand); }
.hours-pill {
  display: inline-block;
  min-width: 44px;
  text-align: center;
  background: var(--brand-soft);
  color: var(--brand-dark);
  border-radius: 6px;
  padding: .12rem .4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.bulk-summary {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: .7rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  align-items: center;
  border-radius: 0 0 var(--radius) var(--radius);
}
.bulk-summary .item { font-size: .85rem; color: var(--muted); }
.bulk-summary .item strong { color: var(--ink); font-size: 1rem; }

/* ===== صندوق المعادلة ===== */
.formula-box {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-right: 3px solid var(--brand);
  border-radius: var(--radius-sm);
  padding: .9rem 1rem;
  font-size: .88rem;
  line-height: 2.1;
}
.formula-box hr { margin: .5rem 0; opacity: .35; }

/* ===== التنبيهات ===== */
.alert { border: 1px solid transparent; border-radius: var(--radius-sm); font-size: .88rem; }
.toast-stack {
  position: fixed;
  top: .8rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1080;
  width: min(92vw, 460px);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.toast-stack .alert { box-shadow: var(--shadow); margin: 0; }

/* ===== صفحة الدخول ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: linear-gradient(140deg, #0f172a 0%, #1e293b 55%, #1d4ed8 100%);
}
.login-card {
  width: min(100%, 400px);
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 22px 55px rgba(2, 6, 23, .32);
  padding: 2rem 1.75rem;
}
.login-logo {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--brand-soft);
  color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  margin: 0 auto .85rem;
}
.login-card img.login-logo-img { display: block; margin: 0 auto .85rem; max-height: 60px; }

/* ===== الطباعة ===== */
@media print {
  .no-print, .sidebar, .topbar, .offcanvas-backdrop { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; }
  body { background: #fff; font-size: 11pt; }
  .card { border: none; box-shadow: none; }
  .card-header { border-bottom: 1px solid #999; }
  .table thead th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a[href]:after { content: none !important; }
  .print-header { display: block !important; margin-bottom: 1rem; }
}
.print-header { display: none; }
