/* ==========================================================================
   Vella Admin Portal — purple professional theme (Bootstrap 5 overlay, RTL)
   Brand: #7851a9
   ========================================================================== */
:root {
  --brand:        #7851a9;
  --brand-2:      #9d7bc4;
  --brand-dark:   #5f3f87;
  --brand-soft:   #efe9f6;
  --brand-softer: #f7f4fb;
  --ink:          #1f1b2d;
  --muted:        #6b6580;
  --line:         #e7e3ef;
  --bg:           #f5f3f9;
  --sidebar-bg:   #221a36;
  --sidebar-2:    #2d2348;
  --sidebar-ink:  #cfc7e0;
  --sidebar-mut:  #8b81a6;

  --bs-primary: #7851a9;
  --bs-primary-rgb: 120,81,169;
  --bs-link-color: #7851a9;
  --bs-link-hover-color: #5f3f87;
}

* { -webkit-font-smoothing: antialiased; }
body {
  font-family: 'Cairo','Tajawal',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

/* ---------- Layout shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-2));
  color: var(--sidebar-ink);
  position: fixed; inset-block: 0; inset-inline-start: 0;
  display: flex; flex-direction: column;
  z-index: 1040;
  transition: transform .25s ease;
}
.content {
  flex: 1; min-width: 0;
  margin-inline-start: 260px;
  display: flex; flex-direction: column;
}
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(100%); }       /* RTL: off-canvas to the right */
  html[dir="ltr"] .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .content { margin-inline-start: 0; }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1035; }
}

/* ---------- Sidebar brand ---------- */
.sidebar__brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 22px; color: #fff; text-decoration: none;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar__brand .mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  display: grid; place-items: center; font-weight: 800; font-size: 18px; color: #fff;
  box-shadow: 0 4px 12px rgba(120,81,169,.5);
}
.sidebar__brand .t { font-weight: 800; font-size: 1.05rem; line-height: 1.1; }
.sidebar__brand .s { font-size: .7rem; color: var(--sidebar-mut); }

/* ---------- Sidebar nav ---------- */
.sidebar__nav { flex: 1; overflow-y: auto; padding: 12px 12px 24px; }
.sidebar__nav::-webkit-scrollbar { width: 6px; }
.sidebar__nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 4px; }
.nav-section {
  font-size: .68rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--sidebar-mut); padding: 16px 14px 6px; font-weight: 700;
}
.nav-link-a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 14px; border-radius: 9px;
  color: var(--sidebar-ink); text-decoration: none;
  font-weight: 600; font-size: .9rem;
  transition: background .15s ease, color .15s ease;
  margin-bottom: 2px;
}
.nav-link-a i { font-size: 1.05rem; width: 20px; text-align: center; }
.nav-link-a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link-a.active {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff; box-shadow: 0 6px 16px rgba(120,81,169,.4);
}
.nav-link-a .count {
  margin-inline-start: auto; background: rgba(255,255,255,.14);
  font-size: .7rem; padding: 1px 8px; border-radius: 999px; font-weight: 700;
}

/* ---------- Topbar ---------- */
.topbar {
  height: 64px; background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px;
  padding: 0 22px; position: sticky; top: 0; z-index: 1020;
}
.topbar .page-title { font-weight: 800; font-size: 1.1rem; margin: 0; }
.topbar .burger { font-size: 1.4rem; color: var(--ink); background: none; border: 0; display: none; }
@media (max-width: 991.98px) { .topbar .burger { display: inline-flex; } }

.topbar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 6px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: #fff;
}
.topbar-user:hover { background: var(--brand-softer); }
.topbar-user .nm { font-weight: 700; font-size: .85rem; line-height: 1.1; }
.topbar-user .rl { font-size: .7rem; color: var(--muted); }

/* ---------- Page wrap ---------- */
.page { padding: 24px; flex: 1; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.page-head h1 { font-size: 1.4rem; font-weight: 800; margin: 0; }
.page-head .sub { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.breadcrumb-mini { font-size: .78rem; color: var(--muted); }
.breadcrumb-mini a { color: var(--brand); text-decoration: none; }

/* ---------- Cards ---------- */
.card {
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 1px 3px rgba(31,27,45,.04);
}
.card-header {
  background: #fff; border-bottom: 1px solid var(--line);
  font-weight: 700; padding: 14px 18px; border-radius: 14px 14px 0 0 !important;
}

/* ---------- Stat cards ---------- */
.stat-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 18px 20px; height: 100%; position: relative; overflow: hidden;
  transition: transform .2s ease, box-shadow .2s ease;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(31,27,45,.08); }
.stat-card .ic {
  width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.4rem; margin-bottom: 12px;
  background: var(--brand-soft); color: var(--brand);
}
.stat-card .val { font-size: 1.9rem; font-weight: 800; line-height: 1; }
.stat-card .lbl { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.stat-card .trend { font-size: .75rem; font-weight: 700; }

/* ---------- Tables ---------- */
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.table { margin: 0; }
.table thead th {
  background: var(--brand-softer); color: var(--muted);
  font-size: .72rem; letter-spacing: .04em; text-transform: uppercase;
  font-weight: 700; border-bottom: 1px solid var(--line); white-space: nowrap;
  padding: 12px 14px;
}
.table tbody td { padding: 11px 14px; vertical-align: middle; border-color: var(--line); }
.table tbody tr:hover { background: var(--brand-softer); }
.table-toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: #fff;
}
.table-toolbar .form-control, .table-toolbar .form-select { max-width: 220px; }

/* ---------- Avatars ---------- */
.avatar-sm, .avatar-fallback {
  width: 34px; height: 34px; border-radius: 9px; object-fit: cover; flex-shrink: 0;
}
.avatar-fallback {
  display: inline-grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
  font-weight: 800; text-transform: uppercase;
}
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); }
.cell-user { display: flex; align-items: center; gap: 10px; }
.cell-user .nm { font-weight: 700; line-height: 1.15; }
.cell-user .sm { font-size: .76rem; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.btn-brand:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-soft { background: var(--brand-soft); color: var(--brand); border: 0; font-weight: 700; }
.btn-soft:hover { background: var(--brand); color: #fff; }
.btn-icon { width: 32px; height: 32px; padding: 0; display: inline-grid; place-items: center; border-radius: 8px; }
.text-brand { color: var(--brand) !important; }
.bg-brand-soft { background: var(--brand-soft) !important; }

/* ---------- Forms ---------- */
.form-label { font-weight: 700; font-size: .82rem; margin-bottom: 5px; }
.form-control, .form-select { border-color: var(--line); border-radius: 9px; padding: 9px 12px; }
.form-control:focus, .form-select:focus {
  border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(120,81,169,.14);
}
.form-section { border: 1px solid var(--line); border-radius: 12px; padding: 18px; background: #fff; margin-bottom: 18px; }
.form-section > h6 { font-weight: 800; color: var(--brand-dark); margin-bottom: 14px; }
.input-help { font-size: .75rem; color: var(--muted); margin-top: 3px; }

/* image preview */
.img-preview { width: 90px; height: 90px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); background: var(--brand-softer); }

/* ---------- Permission matrix ---------- */
.perm-matrix .module-row { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; overflow: hidden; }
.perm-matrix .module-head {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--brand-softer); padding: 12px 16px; font-weight: 800;
}
.perm-matrix .perm-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 16px; }
.perm-chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer;
  font-size: .82rem; font-weight: 600; user-select: none;
}
.perm-chip input { accent-color: var(--brand); }
.perm-chip.on { background: var(--brand-soft); border-color: var(--brand-2); color: var(--brand-dark); }

/* ---------- Misc ---------- */
.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state .ic { font-size: 3rem; color: var(--line); }
.flash-wrap { position: fixed; top: 76px; inset-inline-end: 24px; z-index: 1080; max-width: 360px; }
.login-card { max-width: 410px; width: 100%; }
.chip { display:inline-block; padding:2px 9px; border-radius:999px; font-size:.74rem; font-weight:700; background:var(--brand-soft); color:var(--brand-dark); }
.kpi-spark { height: 40px; }
hr { border-color: var(--line); opacity: 1; }
.text-muted { color: var(--muted) !important; }
