:root {
  --brand-primary:  #1e3a5f;
  --brand-dark:     #142944;
  --brand-accent:   #f0a500;
  --brand-accent2:  #e8f4fd;
  --sidebar-width:  260px;
  --topbar-height:  60px;
  --text-muted-ar:  #6c757d;
  --card-shadow:    0 2px 16px rgba(30,58,95,.10);
  --transition:    .2s ease;
}
* { box-sizing: border-box; }
body {
  background: #f0f4f9;
  font-family: 'Segoe UI', Tahoma, 'Arabic UI', Arial, sans-serif;
  font-size: .9rem;
  color: #2c3e50;
  min-height: 100vh;
}
a { text-decoration: none; }

.topbar {
  height: var(--topbar-height);
  background: var(--brand-primary);
  position: fixed; top:0; right:0; left:0; z-index: 1030;
  display: flex; align-items: center;
  padding: 0 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.topbar .brand-logo { color: var(--brand-accent); font-size: 1.5rem; margin-left: .6rem; }
.topbar .brand-name { color: #fff; font-weight: 700; font-size: 1rem; line-height: 1.2; display: none; }
@media(min-width:576px){ .topbar .brand-name { display: block; } }
.topbar .topbar-right { margin-right: auto; display: flex; align-items: center; gap:.75rem; }
.topbar .user-pill {
  background: rgba(255,255,255,.12); border-radius: 50px;
  padding: .3rem .8rem; color: #fff; font-size: .82rem;
}
.topbar .user-pill .role-badge {
  background: var(--brand-accent); color: #1a1a1a;
  font-size: .7rem; padding: .15rem .45rem;
  border-radius: 50px; font-weight: 600; margin-right: .3rem;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--brand-primary);
  position: fixed; top: var(--topbar-height); right: 0; bottom: 0;
  overflow-y: auto; z-index: 1020;
  transition: transform .3s ease; padding-bottom: 2rem;
}
.sidebar.collapsed { transform: translateX(100%); }
.sidebar-section-title {
  color: rgba(255,255,255,.45); font-size: .7rem; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase;
  padding: 1rem 1.2rem .4rem;
}
.sidebar .nav-link {
  color: rgba(255,255,255,.75);
  padding: .6rem 1.2rem; border-radius: 8px;
  margin: .1rem .6rem;
  display: flex; align-items: center; gap: .6rem;
  font-size: .88rem; transition: var(--transition);
}
.sidebar .nav-link i { font-size: 1.1rem; flex-shrink: 0; }
.sidebar .nav-link:hover,
.sidebar .nav-link.active { background: rgba(255,255,255,.12); color: #fff; }
.sidebar .nav-link.active { background: var(--brand-accent); color: var(--brand-dark) !important; font-weight: 600; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1015; }
.sidebar-overlay.show { display: block; }

.main-content {
  margin-top: var(--topbar-height);
  padding: 1.5rem;
  transition: margin-right .3s;
}
@media(min-width:992px){
  .main-content { margin-right: var(--sidebar-width); }
  .sidebar { transform: none !important; }
}

.card { border: none; border-radius: 12px; box-shadow: var(--card-shadow); }
.card-header { border-radius: 12px 12px 0 0 !important; font-weight: 600; }
.card.border-0.shadow-sm .card-header { padding: .75rem 1.25rem; }

.stat-card {
  border-radius: 14px; padding: 1.2rem 1.4rem;
  display: flex; align-items: center; gap: 1rem;
  box-shadow: var(--card-shadow); border: none; transition: transform var(--transition);
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card .stat-icon {
  width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; flex-shrink: 0;
}
.stat-card .stat-value { font-size: 1.35rem; font-weight: 700; line-height: 1; }
.stat-card .stat-label { font-size: .78rem; color: var(--text-muted-ar); margin-top: .2rem; }

.table-hover tbody tr:hover { background: var(--brand-accent2); }
.table th { font-weight: 600; white-space: nowrap; font-size: .82rem; }
.table td { vertical-align: middle; font-size: .85rem; }

.badge-pending  { background:#ffc107; color:#212529; }
.badge-paid     { background:#198754; color:#fff; }
.badge-overdue  { background:#dc3545; color:#fff; }
.badge-partial  { background:#0d6efd; color:#fff; }

.receipt-hr { border-color: #ddd; border-style: dashed; }
.receipt-table th { width:50%; text-align:right; color:#666; font-weight:500; }
.receipt-table td { text-align:right; }

@media print {
  .topbar, .sidebar, .sidebar-overlay, .no-print { display:none !important; }
  .main-content { margin:0 !important; padding:0 !important; }
  body { background:#fff; }
}

.login-page {
  background: linear-gradient(135deg, #f0f4f9 0%, #dce6f0 100%);
}
.login-card { border: none; border-radius: 16px; box-shadow: 0 8px 40px rgba(30,58,95,.15); overflow: hidden; }
.login-header { background: linear-gradient(135deg, var(--brand-primary), #2d5986); color: #fff; padding: 2rem; text-align: center; }
.login-header .logo-icon { font-size: 3.5rem; color: var(--brand-accent); }
.btn-login { background: var(--brand-primary); border: none; color: #fff; font-weight: 600; letter-spacing: .5px; transition: background var(--transition); }
.btn-login:hover { background: #2d5986; color: #fff; }
.form-control:focus { border-color: var(--brand-primary); box-shadow: 0 0 0 .2rem rgba(30,58,95,.2); }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; flex-wrap: wrap; gap: .5rem; }
.page-header h4 { margin: 0; font-weight: 700; }

.toast-container { position: fixed; top: 1rem; left: 1rem; z-index: 9999; }

.form-section-title { font-size: .85rem; font-weight: 600; color: var(--brand-primary); border-bottom: 2px solid var(--brand-accent); padding-bottom: .3rem; margin-bottom: 1rem; }

.search-form .form-control { border-radius: 8px 0 0 8px; }
.search-form .btn { border-radius: 0 8px 8px 0; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted-ar); }
.empty-state i { font-size: 3rem; display: block; margin-bottom: 1rem; }

.installment-calc { background: #f7f9fc; border: 2px solid var(--brand-primary); border-radius: 12px; padding: 1rem; }
.installment-calc td { padding: .35rem .5rem; }
.installment-calc hr { border-color: var(--brand-primary); opacity: .2; }

.settings-group { margin-bottom: 1.5rem; }
.settings-group .group-title { font-weight: 600; color: var(--brand-primary); margin-bottom: .75rem; }

.sticky-top-custom { position: sticky; top: 80px; }

.btn-primary, .btn-success { transition: all .2s ease; }
.btn-primary:hover, .btn-success:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.15); }

.form-label { font-size: .85rem; margin-bottom: .25rem; }
.form-label .text-muted.fw-normal { font-size: .8rem; }

#items-table td, #items-table th { white-space: nowrap; }
#items-table tbody tr:last-child td { border-bottom: none; }
#items-table tfoot td { border-bottom: none; font-size: .95rem; }
#items-table .table-light td { background: #f8f9fa; }

#schedule-table td:first-child,
#schedule-table th:first-child { width: 40px; text-align: center; }
#schedule-table td:last-child { text-align: center; }

@media (max-width: 576px) {
  .page-header .btn { width: 100%; }
  #sel-qty { margin-bottom: .5rem; }
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeSlideIn .3s ease; }

@media (max-width: 576px) {
  .main-content { padding: .75rem; }
  .stat-card { padding: .8rem 1rem; }
  .stat-card .stat-value { font-size: 1.1rem; }
  .page-header h4 { font-size: 1.1rem; }
  .table-responsive { font-size: .8rem; }
}

/* ── Select2 RTL overrides for Bootstrap 5 ───────────────────── */
.select2-container--default .select2-selection--single {
  height: calc(2.25rem + 2px);
  border: 1px solid #dee2e6;
  border-radius: 6px;
  padding: .25rem .5rem;
  font-size: .9rem;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 1.8;
  padding: 0;
  color: #2c3e50;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 2.15rem;
  left: 4px;
  right: auto;
}
.select2-container--default .select2-selection--single .select2-selection__placeholder {
  color: #6c757d;
}
.select2-container--default .select2-search--dropdown .select2-search__field {
  border-radius: 6px;
  border: 1px solid #dee2e6;
  padding: .375rem .5rem;
  font-size: .85rem;
}
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
  background: var(--brand-primary);
}
.select2-container--default .select2-results__option {
  padding: .4rem .6rem;
  font-size: .85rem;
}
.select2-dropdown {
  border: 1px solid #dee2e6;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.1);
}
.select2-container--open .select2-dropdown--above {
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}
.select2-container--open .select2-dropdown--below {
  border-top: none;
  border-radius: 0 0 8px 8px;
}
.select2-container--default .select2-selection--single .select2-selection__clear {
  left: 1.2rem;
  right: auto;
  font-size: 1.1rem;
}
.select2-container--default.select2-container--focus .select2-selection--single {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 .2rem rgba(30,58,95,.2);
}
