/* Theme switcher (light / gray / dark) for Backpack CoreUI v2 */

body.ui-theme-light {
  --ui-bg: #ffffff;
  --ui-bg-soft: #f6f7fb;
  --ui-card: #ffffff;
  --ui-border: #e6e9ef;
  --ui-text: #212529;
  --ui-text-muted: #6b778c;
}

body.ui-theme-gray {
  --ui-bg: #f1f3f6;
  --ui-bg-soft: #e9edf2;
  --ui-card: #f7f8fa;
  --ui-border: #d7dde6;
  --ui-text: #1f2a37;
  --ui-text-muted: #5b677a;
}

body.ui-theme-dark {
  --ui-bg: #0f172a;
  --ui-bg-soft: #111c33;
  --ui-card: #111827;
  --ui-border: #24324a;
  --ui-text: #e5e7eb;
  --ui-text-muted: #9aa6b2;
}

body.ui-theme-light,
body.ui-theme-gray,
body.ui-theme-dark {
  background-color: var(--ui-bg);
  color: var(--ui-text);
}

body.ui-theme-gray .app-body,
body.ui-theme-dark .app-body {
  background-color: var(--ui-bg);
}

body.ui-theme-gray .card,
body.ui-theme-dark .card,
body.ui-theme-gray .box,
body.ui-theme-dark .box,
body.ui-theme-gray .container-fluid .card,
body.ui-theme-dark .container-fluid .card {
  background-color: var(--ui-card);
  color: var(--ui-text);
  border-color: var(--ui-border);
}

body.ui-theme-dark .table,
body.ui-theme-dark .table td,
body.ui-theme-dark .table th {
  color: var(--ui-text);
}

body.ui-theme-dark .table thead th {
  border-bottom-color: var(--ui-border);
}

body.ui-theme-dark .table td,
body.ui-theme-dark .table th,
body.ui-theme-dark .table thead th,
body.ui-theme-dark .table tbody + tbody {
  border-color: var(--ui-border);
}

/*
 * Bootstrap 5 tables: striped/hover use CSS variables. Without overriding them,
 * row backgrounds stay "light theme" while body text becomes light — unreadable rows.
 */
body.ui-theme-dark .table,
body.ui-theme-dark table.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--ui-text);
  --bs-table-border-color: var(--ui-border);
  --bs-table-striped-bg: rgba(255, 255, 255, 0.055);
  --bs-table-striped-color: var(--ui-text);
  --bs-table-active-bg: rgba(255, 255, 255, 0.1);
  --bs-table-active-color: var(--ui-text);
  --bs-table-hover-bg: rgba(255, 255, 255, 0.075);
  --bs-table-hover-color: var(--ui-text);
}

body.ui-theme-gray .table,
body.ui-theme-gray table.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--ui-text);
  --bs-table-border-color: var(--ui-border);
  --bs-table-striped-bg: rgba(15, 23, 42, 0.04);
  --bs-table-striped-color: var(--ui-text);
  --bs-table-active-bg: rgba(15, 23, 42, 0.07);
  --bs-table-active-color: var(--ui-text);
  --bs-table-hover-bg: rgba(15, 23, 42, 0.055);
  --bs-table-hover-color: var(--ui-text);
}

/* Bootstrap 4-style striped tables (no CSS variables): force dark-compatible stripes */
body.ui-theme-dark .table.table-striped tbody tr:nth-of-type(odd) td,
body.ui-theme-dark .table.table-striped tbody tr:nth-of-type(odd) th {
  background-color: rgba(255, 255, 255, 0.055) !important;
  color: var(--ui-text) !important;
}

body.ui-theme-dark .table.table-striped tbody tr:nth-of-type(even) td,
body.ui-theme-dark .table.table-striped tbody tr:nth-of-type(even) th {
  background-color: transparent !important;
  color: var(--ui-text) !important;
}

body.ui-theme-gray .table.table-striped tbody tr:nth-of-type(odd) td,
body.ui-theme-gray .table.table-striped tbody tr:nth-of-type(odd) th {
  background-color: rgba(15, 23, 42, 0.04) !important;
  color: var(--ui-text) !important;
}

body.ui-theme-dark .table.table-hover tbody tr:hover td,
body.ui-theme-dark .table.table-hover tbody tr:hover th {
  background-color: rgba(255, 255, 255, 0.075) !important;
  color: var(--ui-text) !important;
}

body.ui-theme-gray .table.table-hover tbody tr:hover td,
body.ui-theme-gray .table.table-hover tbody tr:hover th {
  background-color: rgba(15, 23, 42, 0.055) !important;
  color: var(--ui-text) !important;
}

/*
 * Backpack list: #crudTable has class "card" on <table> — Bootstrap applies --bs-card-bg (white)
 * to the table, which paints tbody cells while thead/tfoot may look correct.
 */
body.ui-theme-dark #crudTable_wrapper table.table.card,
body.ui-theme-dark #crudTable_wrapper table.card.table,
body.ui-theme-gray #crudTable_wrapper table.table.card,
body.ui-theme-gray #crudTable_wrapper table.card.table {
  --bs-card-bg: var(--ui-card);
  --bs-card-border-color: var(--ui-border);
  background-color: var(--ui-card) !important;
  color: var(--ui-text);
}

body.ui-theme-dark #crudTable_wrapper table.dataTable,
body.ui-theme-gray #crudTable_wrapper table.dataTable {
  color: var(--ui-text);
  --bs-table-bg: var(--ui-card);
  --bs-table-color: var(--ui-text);
  --bs-table-border-color: var(--ui-border);
  --bs-table-striped-bg: rgba(255, 255, 255, 0.055);
  --bs-table-striped-color: var(--ui-text);
  --bs-table-hover-bg: rgba(255, 255, 255, 0.075);
  --bs-table-hover-color: var(--ui-text);
}

body.ui-theme-gray #crudTable_wrapper table.dataTable {
  --bs-table-striped-bg: rgba(15, 23, 42, 0.06);
  --bs-table-hover-bg: rgba(15, 23, 42, 0.055);
}

body.ui-theme-dark #crudTable_wrapper table.dataTable > tbody > tr > td,
body.ui-theme-dark #crudTable_wrapper table.dataTable > tbody > tr > th,
body.ui-theme-gray #crudTable_wrapper table.dataTable > tbody > tr > td,
body.ui-theme-gray #crudTable_wrapper table.dataTable > tbody > tr > th {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  /* قاعدة: لون الخلية = لون البطاقة — لا تُترك شفافة (الشفافية تُظهر أبيض Bootstrap/DataTables) */
  background-color: var(--ui-card) !important;
  /* Bootstrap 5 striping uses inset box-shadow */
  box-shadow: none !important;
  --bs-table-accent-bg: transparent;
}

body.ui-theme-dark #crudTable_wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(odd) > td,
body.ui-theme-dark #crudTable_wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(odd) > th,
body.ui-theme-dark #crudTable_wrapper table.dataTable.table-striped > tbody > tr.odd > td,
body.ui-theme-dark #crudTable_wrapper table.dataTable.table-striped > tbody > tr.odd > th {
  background-color: rgba(255, 255, 255, 0.055) !important;
  --bs-table-accent-bg: rgba(255, 255, 255, 0.055);
}

body.ui-theme-gray #crudTable_wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(odd) > td,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(odd) > th,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-striped > tbody > tr.odd > td,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-striped > tbody > tr.odd > th {
  background-color: rgba(15, 23, 42, 0.05) !important;
  --bs-table-accent-bg: rgba(15, 23, 42, 0.05);
}

/* الصفوف الزوجية: نفس لون البطاقة صراحةً (لا transparent) */
body.ui-theme-dark #crudTable_wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(even) > td,
body.ui-theme-dark #crudTable_wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(even) > th,
body.ui-theme-dark #crudTable_wrapper table.dataTable.table-striped > tbody > tr.even > td,
body.ui-theme-dark #crudTable_wrapper table.dataTable.table-striped > tbody > tr.even > th,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(even) > td,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(even) > th,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-striped > tbody > tr.even > td,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-striped > tbody > tr.even > th {
  background-color: var(--ui-card) !important;
  --bs-table-accent-bg: transparent;
}

body.ui-theme-dark #crudTable_wrapper table.dataTable.table-hover > tbody > tr:hover > td,
body.ui-theme-dark #crudTable_wrapper table.dataTable.table-hover > tbody > tr:hover > th,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-hover > tbody > tr:hover > td,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-hover > tbody > tr:hover > th {
  background-color: rgba(255, 255, 255, 0.08) !important;
}

body.ui-theme-gray #crudTable_wrapper table.dataTable.table-hover > tbody > tr:hover > td,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-hover > tbody > tr:hover > th {
  background-color: rgba(15, 23, 42, 0.07) !important;
}

/*
 * DataTables scrollX + Bootstrap 5: التخطيط يُطبَّق على tr > * (وليس td فقط).
 * كما أنّ .dataTables_scrollBody تفرض خلفية فاتحة في ملفات CDN.
 */
body.ui-theme-dark #crudTable_wrapper .dataTables_scroll,
body.ui-theme-gray #crudTable_wrapper .dataTables_scroll {
  background-color: var(--ui-card) !important;
}

body.ui-theme-dark #crudTable_wrapper .dataTables_scrollBody,
body.ui-theme-gray #crudTable_wrapper .dataTables_scrollBody {
  background-color: var(--ui-card) !important;
}

body.ui-theme-dark #crudTable_wrapper .dataTables_scrollHead,
body.ui-theme-gray #crudTable_wrapper .dataTables_scrollHead {
  background-color: var(--ui-bg-soft) !important;
}

body.ui-theme-dark #crudTable_wrapper .dataTables_scrollBody table.dataTable > tbody > tr > *,
body.ui-theme-gray #crudTable_wrapper .dataTables_scrollBody table.dataTable > tbody > tr > * {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  background-color: var(--ui-card) !important;
  box-shadow: none !important;
}

body.ui-theme-dark #crudTable_wrapper .dataTables_scrollBody table.dataTable.table-striped > tbody > tr:nth-of-type(odd) > *,
body.ui-theme-dark #crudTable_wrapper .dataTables_scrollBody table.dataTable.table-striped > tbody > tr.odd > *,
body.ui-theme-gray #crudTable_wrapper .dataTables_scrollBody table.dataTable.table-striped > tbody > tr:nth-of-type(odd) > *,
body.ui-theme-gray #crudTable_wrapper .dataTables_scrollBody table.dataTable.table-striped > tbody > tr.odd > * {
  background-color: rgba(255, 255, 255, 0.055) !important;
}

body.ui-theme-gray #crudTable_wrapper .dataTables_scrollBody table.dataTable.table-striped > tbody > tr:nth-of-type(odd) > *,
body.ui-theme-gray #crudTable_wrapper .dataTables_scrollBody table.dataTable.table-striped > tbody > tr.odd > * {
  background-color: rgba(15, 23, 42, 0.05) !important;
}

body.ui-theme-dark #crudTable_wrapper .dataTables_scrollBody table.dataTable.table-striped > tbody > tr:nth-of-type(even) > *,
body.ui-theme-dark #crudTable_wrapper .dataTables_scrollBody table.dataTable.table-striped > tbody > tr.even > *,
body.ui-theme-gray #crudTable_wrapper .dataTables_scrollBody table.dataTable.table-striped > tbody > tr:nth-of-type(even) > *,
body.ui-theme-gray #crudTable_wrapper .dataTables_scrollBody table.dataTable.table-striped > tbody > tr.even > * {
  background-color: var(--ui-card) !important;
}

/* نفس المنطق على الجدول بدون scroll (أو داخل scroll) باستخدام tr > * */
body.ui-theme-dark #crudTable_wrapper table.dataTable > tbody > tr > *,
body.ui-theme-gray #crudTable_wrapper table.dataTable > tbody > tr > * {
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
  background-color: var(--ui-card) !important;
  box-shadow: none !important;
}

body.ui-theme-dark #crudTable_wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(odd) > *,
body.ui-theme-dark #crudTable_wrapper table.dataTable.table-striped > tbody > tr.odd > * {
  background-color: rgba(255, 255, 255, 0.055) !important;
}

body.ui-theme-gray #crudTable_wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(odd) > *,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-striped > tbody > tr.odd > * {
  background-color: rgba(15, 23, 42, 0.05) !important;
}

body.ui-theme-dark #crudTable_wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(even) > *,
body.ui-theme-dark #crudTable_wrapper table.dataTable.table-striped > tbody > tr.even > *,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(even) > *,
body.ui-theme-gray #crudTable_wrapper table.dataTable.table-striped > tbody > tr.even > * {
  background-color: var(--ui-card) !important;
}

/* DataTables footer: length selector + info text */
body.ui-theme-dark #crudTable_wrapper .dataTables_length select,
body.ui-theme-gray #crudTable_wrapper .dataTables_length select,
body.ui-theme-dark #crudTable_wrapper .dataTables_filter input,
body.ui-theme-gray #crudTable_wrapper .dataTables_filter input {
  background-color: var(--ui-bg-soft) !important;
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
}

body.ui-theme-dark #crudTable_wrapper .dataTables_info,
body.ui-theme-dark #crudTable_wrapper .dataTables_length,
body.ui-theme-gray #crudTable_wrapper .dataTables_info,
body.ui-theme-gray #crudTable_wrapper .dataTables_length {
  color: var(--ui-text-muted);
}

/* FixedHeader duplicate table (if enabled) */
body.ui-theme-dark .table thead.fixedHeader-floating th,
body.ui-theme-gray .table thead.fixedHeader-floating th,
body.ui-theme-dark table.dataTable thead.fixedHeader-floating th,
body.ui-theme-gray table.dataTable thead.fixedHeader-floating th {
  background-color: var(--ui-bg-soft) !important;
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
}

/* Theme config forces bg-light on header/sidebar — align with ui-theme-dark / gray */
body.ui-theme-dark .app-header,
body.ui-theme-dark header.app-header {
  background-color: var(--ui-card) !important;
  border-bottom: 1px solid var(--ui-border) !important;
  color: var(--ui-text);
}

body.ui-theme-gray .app-header,
body.ui-theme-gray header.app-header {
  background-color: var(--ui-card) !important;
  border-bottom: 1px solid var(--ui-border) !important;
  color: var(--ui-text);
}

body.ui-theme-dark .app-header .navbar-nav .nav-link,
body.ui-theme-dark .app-header .nav-link,
body.ui-theme-gray .app-header .navbar-nav .nav-link,
body.ui-theme-gray .app-header .nav-link {
  color: var(--ui-text);
}

body.ui-theme-dark .app-header .navbar-toggler-icon,
body.ui-theme-gray .app-header .navbar-toggler-icon {
  filter: invert(1) grayscale(100%);
}

body.ui-theme-dark .sidebar,
body.ui-theme-gray .sidebar {
  background-color: var(--ui-card) !important;
  color: var(--ui-text);
  border-color: var(--ui-border);
}

body.ui-theme-dark .sidebar .nav-link,
body.ui-theme-gray .sidebar .nav-link {
  color: var(--ui-text-muted);
}

body.ui-theme-dark .sidebar .nav-link:hover,
body.ui-theme-dark .sidebar .nav-link.active,
body.ui-theme-gray .sidebar .nav-link:hover,
body.ui-theme-gray .sidebar .nav-link.active {
  color: var(--ui-text);
  background-color: var(--ui-bg-soft);
}

body.ui-theme-dark .sidebar .nav-title,
body.ui-theme-gray .sidebar .nav-title {
  color: var(--ui-text-muted);
}

body.ui-theme-dark .sidebar .nav-dropdown-toggle,
body.ui-theme-gray .sidebar .nav-dropdown-toggle {
  color: var(--ui-text-muted);
}

body.ui-theme-dark .app-footer,
body.ui-theme-gray .app-footer {
  background-color: var(--ui-card) !important;
  color: var(--ui-text);
  border-top: 1px solid var(--ui-border);
}

body.ui-theme-dark .main,
body.ui-theme-gray .main {
  color: var(--ui-text);
}

body.ui-theme-dark .dropdown-menu,
body.ui-theme-gray .dropdown-menu {
  background-color: var(--ui-card);
  color: var(--ui-text);
  border-color: var(--ui-border);
}

body.ui-theme-dark .dropdown-item,
body.ui-theme-gray .dropdown-item {
  color: var(--ui-text);
}

body.ui-theme-dark .dropdown-item:hover,
body.ui-theme-gray .dropdown-item:hover {
  background-color: var(--ui-bg-soft);
}

body.ui-theme-dark .form-control,
body.ui-theme-gray .form-control,
body.ui-theme-dark .custom-select,
body.ui-theme-gray .custom-select {
  background-color: var(--ui-bg-soft);
  color: var(--ui-text);
  border-color: var(--ui-border);
}

body.ui-theme-dark .form-control::placeholder,
body.ui-theme-gray .form-control::placeholder {
  color: var(--ui-text-muted);
}

body.ui-theme-dark .breadcrumb,
body.ui-theme-gray .breadcrumb {
  background-color: transparent;
}

body.ui-theme-dark .breadcrumb-item,
body.ui-theme-gray .breadcrumb-item {
  color: var(--ui-text-muted);
}

body.ui-theme-dark .breadcrumb-item.active,
body.ui-theme-gray .breadcrumb-item.active {
  color: var(--ui-text);
}

/* شريط العلامة في القائمة: أيقونة التطبيق + عنوان + وصف */
.dc-backpack-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-align: start;
  max-width: min(240px, 100%);
}

.dc-backpack-brand__icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
}

.dc-backpack-brand--noicon .dc-backpack-brand__icon{
  display:none !important;
}

.dc-backpack-brand__meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  line-height: 1.28;
}

.dc-backpack-brand__title {
  font-weight: 700;
  font-size: 0.94rem;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dc-backpack-brand__title b {
  font-weight: 700;
}

/* Organization name: nicer color + subtle animation */
.dc-backpack-brand--noicon .dc-backpack-brand__title{
  font-weight: 900;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, #1e3a8a 0%, #4f46e5 55%, #0ea5e9 120%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 1px 6px rgba(0,0,0,.12));
  position: relative;
  animation: dcOrgPulse 6s ease-in-out infinite;
}

@keyframes dcOrgPulse{
  0%, 100% { filter: drop-shadow(0 1px 6px rgba(0,0,0,.12)); }
  50% { filter: drop-shadow(0 2px 10px rgba(79,70,229,.18)); }
}

/* Tiny shimmer highlight (very subtle) */
.dc-backpack-brand--noicon .dc-backpack-brand__title::after{
  content:"";
  position:absolute;
  inset: -2px -10px;
  background: linear-gradient(110deg, transparent 0%, rgba(255,255,255,.35) 45%, transparent 65%);
  transform: translateX(-120%);
  animation: dcOrgShimmer 8.5s ease-in-out infinite;
  pointer-events:none;
  mix-blend-mode: overlay;
}

@keyframes dcOrgShimmer{
  0%, 72% { transform: translateX(-120%); opacity: 0; }
  78% { opacity: .35; }
  90% { transform: translateX(120%); opacity: 0; }
  100% { transform: translateX(120%); opacity: 0; }
}

body.ui-theme-dark .dc-backpack-brand--noicon .dc-backpack-brand__title,
body.ui-theme-gray .dc-backpack-brand--noicon .dc-backpack-brand__title{
  background: linear-gradient(135deg, #ffffff 0%, #e0e7ff 45%, #7dd3fc 120%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 10px rgba(0,0,0,.35));
}

@media (prefers-reduced-motion: reduce){
  .dc-backpack-brand--noicon .dc-backpack-brand__title,
  .dc-backpack-brand--noicon .dc-backpack-brand__title::after{
    animation: none !important;
  }
}

.dc-backpack-brand__tagline {
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 1;
  color: rgba(17, 24, 39, 0.86);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.14);
  width: fit-content;
  max-width: 100%;
}

body.ui-theme-dark .dc-backpack-brand__tagline,
body.ui-theme-gray .dc-backpack-brand__tagline {
  opacity: 1;
  color: rgba(255, 255, 255, 0.86);
  background: rgba(255, 255, 255, 0.10);
  border-color: rgba(255, 255, 255, 0.16);
}

.dc-current-org-name{
  margin: 4px 0 8px;
  font-weight: 800;
  font-size: 0.95rem;
  color: rgba(17, 24, 39, 0.92);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.ui-theme-dark .dc-current-org-name,
body.ui-theme-gray .dc-current-org-name{
  color: rgba(255,255,255,.92);
}

@media (max-width: 768px){
  /* On mobile, avoid repeating/over-emphasizing org name under the logo */
  .app-header .dc-backpack-brand__tagline,
  .sidebar .dc-backpack-brand__tagline{
    display: none;
  }

  .dc-current-org-name{
    font-size: 1.0rem;
    letter-spacing: 0;
    margin: 2px 0 6px;
  }
  /* make the select less visually heavy on mobile */
  .sidebar .dc-current-org-name + select.form-control{
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 15px;
  }
}

.sidebar .navbar-brand .dc-backpack-brand,
.app-header .navbar-brand .dc-backpack-brand {
  padding: 0.15rem 0;
}

/* Mobile: make sidebar menu scrollable */
@media (max-width: 768px) {
  /*
   * Backpack/CoreUIv2 sidebar markup:
   * <div class="sidebar ..."><nav class="sidebar-nav overflow-hidden"><ul class="nav">...</ul></nav></div>
   * The `overflow-hidden` utility prevents scrolling on mobile. Override it.
   */
  body.sidebar-show .sidebar .sidebar-nav,
  body.sidebar-sm-show .sidebar .sidebar-nav,
  body.sidebar-md-show .sidebar .sidebar-nav,
  .sidebar .sidebar-nav {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    max-height: 100dvh;
    padding-bottom: 180px;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }

  /* Ensure the inner list doesn't force horizontal scroll */
  .sidebar .sidebar-nav > .nav{
    width: 100%;
  }

  /* Prevent wide items from forcing horizontal scrolling */
  .sidebar .nav-link,
  .sidebar .nav-title,
  .sidebar .nav-dropdown-toggle,
  .sidebar .nav-dropdown-items .nav-link {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/*
 * Backpack CRUD list (DataTables): center cell text; horizontal scroll when many columns.
 * responsiveTable is off in config so scrollX is used — keep scroll areas scrollable.
 */
#crudTable_wrapper .dataTables_scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#crudTable_wrapper table.dataTable > thead > tr > th,
#crudTable_wrapper table.dataTable > thead > tr > td,
#crudTable_wrapper table.dataTable > tbody > tr > th,
#crudTable_wrapper table.dataTable > tbody > tr > td,
#crudTable_wrapper table.dataTable > tfoot > tr > th,
#crudTable_wrapper table.dataTable > tfoot > tr > td {
  text-align: center !important;
  vertical-align: middle !important;
}

/* Top bar notification panel (styles also exist in topbar_right_content.blade.php) */
body.ui-theme-dark .notification-icon,
body.ui-theme-gray .notification-icon {
  color: var(--ui-text) !important;
}

body.ui-theme-dark .notification-dropdown,
body.ui-theme-gray .notification-dropdown {
  background-color: var(--ui-card) !important;
  border-color: var(--ui-border) !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35) !important;
}

body.ui-theme-dark .notification-header,
body.ui-theme-gray .notification-header {
  background-color: var(--ui-bg-soft) !important;
  border-bottom-color: var(--ui-border) !important;
  color: var(--ui-text) !important;
}

body.ui-theme-dark .notification-body,
body.ui-theme-gray .notification-body {
  background-color: var(--ui-card) !important;
}

body.ui-theme-dark .notification-item,
body.ui-theme-gray .notification-item {
  border-bottom-color: var(--ui-border) !important;
  color: var(--ui-text) !important;
}

body.ui-theme-dark .notification-item:hover,
body.ui-theme-gray .notification-item:hover {
  background-color: var(--ui-bg-soft) !important;
}

body.ui-theme-dark .notification-title,
body.ui-theme-gray .notification-title {
  color: var(--ui-text) !important;
}

body.ui-theme-dark .notification-text,
body.ui-theme-gray .notification-text {
  color: var(--ui-text-muted) !important;
}

body.ui-theme-dark .notification-time,
body.ui-theme-gray .notification-time {
  color: var(--ui-text-muted) !important;
}

body.ui-theme-dark .notification-empty,
body.ui-theme-gray .notification-empty {
  background-color: var(--ui-card) !important;
  color: var(--ui-text-muted) !important;
}

body.ui-theme-dark .notification-footer,
body.ui-theme-gray .notification-footer {
  background-color: var(--ui-card) !important;
  border-top-color: var(--ui-border) !important;
}

/* Global safety net for pages that still use light utility classes or inline white backgrounds */
body.ui-theme-dark .bg-light,
body.ui-theme-gray .bg-light,
body.ui-theme-dark .bg-white,
body.ui-theme-gray .bg-white {
  background-color: var(--ui-bg-soft) !important;
  color: var(--ui-text) !important;
}

body.ui-theme-dark .text-dark,
body.ui-theme-gray .text-dark {
  color: var(--ui-text) !important;
}

body.ui-theme-dark .card-header.bg-light,
body.ui-theme-gray .card-header.bg-light,
body.ui-theme-dark .input-group-text,
body.ui-theme-gray .input-group-text,
body.ui-theme-dark .list-group-item,
body.ui-theme-gray .list-group-item,
body.ui-theme-dark .modal-content,
body.ui-theme-gray .modal-content,
body.ui-theme-dark .custom-modal-content,
body.ui-theme-gray .custom-modal-content {
  background-color: var(--ui-card) !important;
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
}

body.ui-theme-dark .badge.bg-light,
body.ui-theme-gray .badge.bg-light {
  background-color: var(--ui-bg-soft) !important;
  color: var(--ui-text) !important;
  border: 1px solid var(--ui-border) !important;
}

body.ui-theme-dark .nav-tabs .nav-link,
body.ui-theme-gray .nav-tabs .nav-link {
  color: var(--ui-text-muted);
}

body.ui-theme-dark .nav-tabs .nav-link.active,
body.ui-theme-gray .nav-tabs .nav-link.active {
  background-color: var(--ui-card) !important;
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
}

body.ui-theme-dark .page-link,
body.ui-theme-gray .page-link {
  background-color: var(--ui-card) !important;
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
}

body.ui-theme-dark .page-item.active .page-link,
body.ui-theme-gray .page-item.active .page-link {
  background-color: var(--ui-bg-soft) !important;
}

body.ui-theme-dark .select2-container--default .select2-selection--single,
body.ui-theme-gray .select2-container--default .select2-selection--single,
body.ui-theme-dark .select2-container--default .select2-selection--multiple,
body.ui-theme-gray .select2-container--default .select2-selection--multiple,
body.ui-theme-dark .select2-dropdown,
body.ui-theme-gray .select2-dropdown {
  background-color: var(--ui-bg-soft) !important;
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
}

body.ui-theme-dark .select2-container--default .select2-results__option,
body.ui-theme-gray .select2-container--default .select2-results__option {
  color: var(--ui-text) !important;
}

body.ui-theme-dark .select2-container--default .select2-results__option--highlighted[aria-selected],
body.ui-theme-gray .select2-container--default .select2-results__option--highlighted[aria-selected] {
  background-color: var(--ui-bg-soft) !important;
  color: var(--ui-text) !important;
}

/* Override common inline style cases: background:#fff / #fefefe / #ffffff */
body.ui-theme-dark [style*="background:#fff"],
body.ui-theme-dark [style*="background: #fff"],
body.ui-theme-dark [style*="background:#fefefe"],
body.ui-theme-dark [style*="background: #fefefe"],
body.ui-theme-dark [style*="background:#ffffff"],
body.ui-theme-dark [style*="background: #ffffff"],
body.ui-theme-gray [style*="background:#fff"],
body.ui-theme-gray [style*="background: #fff"],
body.ui-theme-gray [style*="background:#fefefe"],
body.ui-theme-gray [style*="background: #fefefe"],
body.ui-theme-gray [style*="background:#ffffff"],
body.ui-theme-gray [style*="background: #ffffff"] {
  background-color: var(--ui-card) !important;
  color: var(--ui-text) !important;
  border-color: var(--ui-border) !important;
}

body.ui-theme-dark .text-muted,
body.ui-theme-gray .text-muted {
  color: var(--ui-text-muted) !important;
}

