:root {
  --theme-gradient: radial-gradient(circle at 12% 5%, rgba(59, 130, 176, .32), transparent 30%), linear-gradient(120deg, #102b4e 0%, #173c64 54%, #176b78 100%);
  --theme-photo-gradient: radial-gradient(circle at 12% 5%, rgba(59, 130, 176, .32), transparent 30%), linear-gradient(120deg, rgba(16, 43, 78, .88) 0%, rgba(23, 60, 100, .88) 54%, rgba(23, 107, 120, .88) 100%);
  --theme-shadow: 0 14px 34px rgba(20, 54, 88, .18);
  --action-save: #19d64b;
  --action-cancel: #ffc107;
  --action-search: #0d6efd;
}

/* Shared brand colors for the sidebar, top bar and table headings. */
#dw-s1.bmd-layout-drawer,
.animated #dw-s1.bmd-layout-drawer,
.modern-sidebar-drawer,
.bmd-layout-header {
  background-color: #102b4e !important;
  background-image: var(--theme-photo-gradient), var(--site-theme-image, none) !important;
  background-position: center, center;
  background-size: cover, cover;
  background-repeat: no-repeat;
  box-shadow: var(--theme-shadow) !important;
  color: #fff !important;
}

.bmd-layout-header .navbar.container {
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
}

.bmd-layout-header .navbar,
.bmd-layout-header .btn:not(.dropdown-item),
.bmd-layout-header .navbar .nav-link,
.theme-mode-toggle {
  color: #fff !important;
}

.bmd-layout-header .navbar-toggler-icon {
  filter: brightness(0) invert(1);
}

/* Keep the top bar in the content area so it does not cover the sidebar logo.
   Place install/theme controls beside the language selector. */
.bmd-layout-header .navbar.container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.bmd-layout-header .navbar-nav {
  display: contents !important;
}

.bmd-layout-header .navbar-toggler {
  order: 1;
  flex: 0 0 auto;
}

.bmd-layout-header .navbar-nav > li:nth-child(4) {
  order: 2;
  flex: 0 1 auto;
}

.bmd-layout-header .navbar-nav > li:nth-child(1) {
  order: 3;
  flex: 0 0 auto;
}

.bmd-layout-header .navbar-nav > li:nth-child(2) {
  order: 4;
  flex: 0 0 auto;
}

.bmd-layout-header > .navbar.container > .dropdown.base {
  order: 5;
  flex: 0 0 auto;
  margin: 0 !important;
}

@media (min-width: 1200px) {
  .bmd-layout-container.bmd-drawer-in > .bmd-layout-header {
    box-sizing: border-box;
    width: calc(100% - 240px) !important;
    max-width: calc(100% - 240px) !important;
  }

  body.rtl .bmd-layout-container.bmd-drawer-in > .bmd-layout-header {
    margin-right: 240px !important;
    margin-left: 0 !important;
  }

  body.ltr .bmd-layout-container.bmd-drawer-in > .bmd-layout-header {
    margin-left: 240px !important;
    margin-right: 0 !important;
  }

  .bmd-layout-container.bmd-drawer-out > .bmd-layout-header {
    width: 100% !important;
    max-width: 100% !important;
    margin-inline: 0 !important;
  }
}

.theme-mode-toggle {
  min-height: 38px;
  padding: .4rem .7rem !important;
  border: 1px solid rgba(255, 255, 255, .42) !important;
  background: rgba(255, 255, 255, .12) !important;
  white-space: nowrap;
}

.theme-mode-toggle:hover,
.theme-mode-toggle:focus {
  background: rgba(255, 255, 255, .22) !important;
}

table thead {
  background-color: #173c64 !important;
  background-image: var(--theme-photo-gradient), var(--site-theme-image, none) !important;
  background-position: center, center;
  background-size: cover, cover;
  background-repeat: no-repeat;
}

.table thead th,
.table > thead > tr > th,
table thead th,
table.dataTable thead th,
table.dataTable thead td,
.dataTables_wrapper table thead th {
  background-color: transparent !important;
  color: #fff !important;
  border-color: rgba(255, 255, 255, .22) !important;
  box-shadow: var(--theme-shadow);
}

.card.shade,
.card.flat,
.jumbotron.shade,
.breadcrumb-header.shade,
.table-responsive {
  box-shadow: var(--theme-shadow) !important;
}

/* Keep action colors consistent across forms, including dynamically added modals. */
form button[type="submit"]:not(.btn-danger):not(.btn-cancel):not(.cancel-btn):not(.btn-search):not(.btn-action-search):not(.btn-action-cancel),
form input[type="submit"]:not(.btn-danger):not(.btn-cancel):not(.cancel-btn):not(.btn-search):not(.btn-action-search):not(.btn-action-cancel),
.btn-save,
.save-btn,
.btn-submit,
button.btn-action-save,
a.btn-action-save {
  background: var(--action-save) !important;
  border-color: var(--action-save) !important;
  color: #fff !important;
}

.btn-action-search,
.btn-search,
form button[type="submit"].btn-action-search,
form input[type="submit"].btn-action-search,
form a.btn-action-search,
button:has(.fa-search),
button:has(.fa-magnifying-glass),
button:has(.fa-filter),
a.btn:has(.fa-search),
a.btn:has(.fa-magnifying-glass),
a.btn:has(.fa-filter) {
  background: var(--action-search) !important;
  border-color: var(--action-search) !important;
  color: #fff !important;
}

.btn-action-cancel,
.btn-cancel,
.cancel-btn,
.btn-secondary:not(.btn-action-save),
form button[type="submit"].btn-action-cancel,
form input[type="submit"].btn-action-cancel,
button[data-dismiss="modal"],
button[data-bs-dismiss="modal"] {
  background: var(--action-cancel) !important;
  border-color: var(--action-cancel) !important;
  color: #243247 !important;
}

/* The saved dark mode applies to every shared page and its common controls. */
body.dark {
  --bg-body: #111a25;
  --bg-surface: #1d2937;
  --text-main: #e8eef6;
  --theme-text: #e8eef6;
  --text-muted: #b8c4d2;
  --border-color: #35465a;
  background: var(--bg-body) !important;
  color: var(--text-main) !important;
}

body.dark .bmd-layout-content,
body.dark .container-fluid,
body.dark .container {
  color: var(--text-main);
}

body.dark .card,
body.dark .card.shade,
body.dark .card.flat,
body.dark .box-card,
body.dark .jumbotron,
body.dark .jumbotron.shade,
body.dark .breadcrumb-header.shade,
body.dark .modal-content,
body.dark .dropdown-menu,
body.dark .table-responsive,
body.dark .dataTables_wrapper {
  background-color: var(--bg-surface) !important;
  color: var(--text-main) !important;
  border-color: var(--border-color) !important;
}

body.dark .form-control,
body.dark select,
body.dark textarea,
body.dark input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
body.dark .select2-container--default .select2-selection--single,
body.dark .select2-container--default .select2-selection--multiple {
  background-color: #172230 !important;
  color: var(--text-main) !important;
  border-color: var(--border-color) !important;
}

body.dark .table,
body.dark table,
body.dark .table td,
body.dark .table th,
body.dark table td,
body.dark table th,
body.dark label,
body.dark .form-text,
body.dark .text-muted,
body.dark .dropdown-item {
  color: var(--text-main) !important;
}

body.dark .table tbody tr,
body.dark table tbody tr {
  background-color: #1d2937 !important;
}

body.dark .table-striped tbody tr:nth-of-type(odd) {
  background-color: #243345 !important;
}

body.dark .dropdown-item:hover,
body.dark .table-hover tbody tr:hover,
body.dark tbody tr:hover {
  background-color: #30445b !important;
}

@media (max-width: 575.98px) {
  .theme-mode-toggle {
    padding: .4rem .55rem !important;
  }

  .theme-mode-toggle .theme-mode-label {
    display: none;
  }
}

/* Consistent table sizing, alignment and DataTables toolbar layout. */
.table-responsive,
.dataTables_wrapper,
.dataTables_scroll {
  max-width: 100%;
}

.table-responsive,
.dataTables_scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.dataTables_wrapper {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 10px 14px;
  width: 100%;
  padding: 8px 0;
}

.dataTables_wrapper > .dataTables_length {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  margin: 0 !important;
  float: none !important;
}

.dataTables_wrapper > .dt-buttons {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 !important;
  float: none !important;
}

.dataTables_wrapper > .dataTables_filter {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  margin: 0 !important;
  float: none !important;
}

.dataTables_wrapper > table.dataTable,
.dataTables_wrapper > .dataTables_scroll,
.dataTables_wrapper > .dataTables_info,
.dataTables_wrapper > .dataTables_paginate {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
}

.dataTables_wrapper > table.dataTable {
  grid-row: 2;
}

.dataTables_wrapper > .dataTables_scroll {
  grid-row: 2;
}

.dataTables_wrapper > .dataTables_info {
  grid-row: 3;
  margin: 0 !important;
}

.dataTables_wrapper > .dataTables_paginate {
  grid-row: 4;
  justify-self: end;
  margin: 0 !important;
}

table.dataTable {
  width: max-content !important;
  min-width: 100% !important;
  table-layout: auto !important;
  margin: 0 !important;
}

table.dataTable th,
table.dataTable td {
  vertical-align: middle !important;
  text-align: center;
  line-height: 1.4;
}

table.dataTable thead th {
  white-space: nowrap;
  padding: .65rem .75rem !important;
}

table.dataTable tbody td {
  padding: .55rem .7rem !important;
}

table.dataTable td.table-actions {
  display: table-cell !important;
  white-space: nowrap;
  min-width: 112px;
}

/* Bootstrap's .d-flex on a td changes its display type and misaligns columns. */
table td.d-flex {
  display: table-cell !important;
  vertical-align: middle !important;
  white-space: nowrap;
}

table.dataTable td.table-actions .btn {
  margin: 2px;
}

.dataTables_wrapper .dataTables_filter input {
  box-sizing: border-box;
  width: min(260px, 100%);
  min-width: 0;
}

@media (max-width: 767.98px) {
  .dataTables_wrapper {
    grid-template-columns: minmax(0, 1fr);
    gap: 9px;
  }

  .dataTables_wrapper > .dataTables_length,
  .dataTables_wrapper > .dt-buttons,
  .dataTables_wrapper > .dataTables_filter,
  .dataTables_wrapper > table.dataTable,
  .dataTables_wrapper > .dataTables_scroll,
  .dataTables_wrapper > .dataTables_info,
  .dataTables_wrapper > .dataTables_paginate {
    grid-column: 1;
    width: 100%;
    justify-self: stretch;
  }

  .dataTables_wrapper > .dataTables_length,
  .dataTables_wrapper > .dt-buttons,
  .dataTables_wrapper > .dataTables_filter {
    grid-row: auto;
  }

  .dataTables_wrapper > .dt-buttons,
  .dataTables_wrapper > .dataTables_paginate {
    justify-content: center;
  }

  .dataTables_wrapper .dataTables_filter input {
    width: 100%;
    margin: 4px 0 0 !important;
  }
}

/* DataTables used to paint every body cell white. In dark mode, reset cells,
   stripes and hover states as well as the table row backgrounds. */
body.dark table.dataTable > tbody > tr > *,
body.dark .dataTables_wrapper table.dataTable > tbody > tr > * {
  background-color: #1d2937 !important;
  color: #e8eef6 !important;
  border-color: #35465a !important;
}

body.dark table.dataTable > tbody > tr:nth-of-type(even) > *,
body.dark .dataTables_wrapper table.dataTable > tbody > tr:nth-of-type(even) > * {
  background-color: #243345 !important;
}

body.dark table.dataTable > tbody > tr:hover > *,
body.dark .dataTables_wrapper table.dataTable > tbody > tr:hover > * {
  background-color: #30445b !important;
}

body.dark table.dataTable td.dataTables_empty {
  background-color: #1d2937 !important;
  color: #b8c4d2 !important;
}

body.dark .dataTables_wrapper .dataTables_filter input,
body.dark .dataTables_wrapper .dataTables_length select {
  background-color: #172230 !important;
  color: #e8eef6 !important;
  border-color: #506176 !important;
}

body.dark .dataTables_wrapper .dataTables_filter label,
body.dark .dataTables_wrapper .dataTables_length label,
body.dark .dataTables_wrapper .dataTables_info {
  color: #e8eef6 !important;
}

body.dark .dataTables_wrapper .dataTables_paginate .paginate_button,
body.dark .dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
  background: #243345 !important;
  color: #e8eef6 !important;
  border-color: #506176 !important;
}

body.dark .dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: #2b6cb0 !important;
  color: #fff !important;
}
