/* Metapsy dark mode + Shiny/shinydashboard (html[data-theme="dark"]) — postMessage / ?embed_theme=dark */

/* ========== Metapsy dark mode (html[data-theme="dark"]) ========== */
html[data-theme="dark"] {
  color-scheme: dark;
  /* Align with www/css/custom.css when embedded */
  --bs-info: rgba(94, 186, 189, 1);
  --bs-primary: #0372b7;
  --bs-primary-darker: #045385;
  --bs-dark2: #c5d1d6;
  --sidebar-menu-link-border: #3d4f58;
  --bd-panel-bg: #1f2a30;
  --bd-box-bg: #243038;
  --btn-primary-text: #ffffff;
  /* Match body-copy greyish white (see `p`); brighter than --bd-muted-text */
  --bd-subtitle-text: #c5d1d6;
  --bd-muted-text: #9fb0b8;
  --code-bg: #2d383d;
  --code-color: #a5b4fc;
  --bd-disabled-bg: #3d4f58;
  --bd-disabled-border: #4d5a62;
  --bd-link-hover: #c5d1d6;
}

/* waiter preloader: ui.R uses light overlay; inline backgroundColor needs !important to override in dark */
html[data-theme="dark"] .waiter-overlay {
  background-color: #1f2a30 !important;
}

/* spin_atebits: dark dots on white (default); light dots on dark overlay */
html[data-theme="dark"] .atebits-loader:not(:required) {
  background: rgba(226, 232, 235, 0.92) !important;
  -moz-box-shadow: rgba(226, 232, 235, 0.65) -12px -12px 0 0, rgba(226, 232, 235, 0.65) 12px -12px 0 0, rgba(226, 232, 235, 0.65) -12px 0 0 0, rgba(226, 232, 235, 0.65) 12px 0 0 0, rgba(226, 232, 235, 0.65) -12px 12px 0 0, rgba(226, 232, 235, 0.65) 0 12px 0 0, rgba(226, 232, 235, 0.65) 12px 12px 0 0 !important;
  -webkit-box-shadow: rgba(226, 232, 235, 0.65) -12px -12px 0 0, rgba(226, 232, 235, 0.65) 12px -12px 0 0, rgba(226, 232, 235, 0.65) -12px 0 0 0, rgba(226, 232, 235, 0.65) 12px 0 0 0, rgba(226, 232, 235, 0.65) -12px 12px 0 0, rgba(226, 232, 235, 0.65) 0 12px 0 0, rgba(226, 232, 235, 0.65) 12px 12px 0 0 !important;
  box-shadow: rgba(226, 232, 235, 0.65) -12px -12px 0 0, rgba(226, 232, 235, 0.65) 12px -12px 0 0, rgba(226, 232, 235, 0.65) -12px 0 0 0, rgba(226, 232, 235, 0.65) 12px 0 0 0, rgba(226, 232, 235, 0.65) -12px 12px 0 0, rgba(226, 232, 235, 0.65) 0 12px 0 0, rgba(226, 232, 235, 0.65) 12px 12px 0 0 !important;
}

/* 113 Zelfmoordpreventie logo in about_start.md */
html[data-theme="dark"] img[src*="logo-zelfmoord-preventie.svg"] {
  filter: invert(1) grayscale(1);
}

html[data-theme="dark"] body {
  background-color: #1f2a30 !important;
  color: #e2e8eb;
}

html[data-theme="dark"] body.bg-dark-2,
html[data-theme="dark"] .bg-dark-2 {
  background-color: #1f2a30 !important;
}

html[data-theme="dark"] .bg-white,
html[data-theme="dark"] .bg-white-blue,
html[data-theme="dark"] main.bg-white,
html[data-theme="dark"] #main-databases,
html[data-theme="dark"] #main-body {
  background-color: #1f2a30 !important;
  color: #e2e8eb;
}

html[data-theme="dark"] .bg-light {
  background-color: #243038 !important;
  color: #e2e8eb;
}

html[data-theme="dark"] .text-dark {
  color: #e2e8eb !important;
}

html[data-theme="dark"] .text-muted,
html[data-theme="dark"] .footer-text,
html[data-theme="dark"] .small.text-muted {
  color: #9fb0b8 !important;
}

html[data-theme="dark"] .lead,
html[data-theme="dark"] .fs-5,
html[data-theme="dark"] .fs-6 {
  color: #c5d1d6 !important;
}

html[data-theme="dark"] .card,
html[data-theme="dark"] .feature-box,
html[data-theme="dark"] .people-box {
  background-color: #243038 !important;
  border-color: #3d4f58 !important;
  color: #e2e8eb;
}

html[data-theme="dark"] .border,
html[data-theme="dark"] .list-group-item {
  border-color: #3d4f58 !important;
}

html[data-theme="dark"] hr {
  border-color: #3d4f58 !important;
  opacity: 1 !important;
}

html[data-theme="dark"] .table {
  color: #e2e8eb;
  --bs-table-bg: transparent;
  --bs-table-striped-bg: rgba(255, 255, 255, 0.04);
  --bs-table-hover-bg: rgba(255, 255, 255, 0.06);
}

html[data-theme="dark"] .table > :not(caption) > * > * {
  border-bottom-color: #3d4f58;
}

html[data-theme="dark"] .modal-content {
  background-color: #243038;
  color: #e2e8eb;
  border-color: #3d4f58;
}

html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer {
  border-color: #3d4f58;
}

html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] textarea {
  background-color: #2d383d;
  border-color: #4d5a62;
  color: #e2e8eb;
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
  background-color: #2d383d;
  color: #e2e8eb;
}

html[data-theme="dark"] .input-group-text {
  background-color: #2d383d;
  border-color: #4d5a62;
  color: #c5d1d6;
}

html[data-theme="dark"] .accordion-item {
  background-color: #1f2a30;
  border-color: #3d4f58;
}

html[data-theme="dark"] .accordion-button {
  background-color: #243038;
  color: #e2e8eb;
}

html[data-theme="dark"] .accordion-button:not(.collapsed) {
  background-color: #2d383d;
  color: #e2e8eb;
}

html[data-theme="dark"] .accordion-body {
  background-color: #1f2a30;
  color: #c5d1d6;
}

html[data-theme="dark"] .dropdown-menu {
  background-color: #2d383d !important;
  border-color: #4d5a62 !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45) !important;
}

html[data-theme="dark"] .dropdown-item {
  color: #e2e8eb;
}

html[data-theme="dark"] .dropdown-item:hover,
html[data-theme="dark"] .dropdown-item:focus {
  background-color: #3d4f58;
  color: #fff;
}

/* navbarPage / tabset dropdowns: plain <li><a> (no .dropdown-item) — override Bootstrap tab hover */
html[data-theme="dark"] .dropdown-menu > li > a {
  color: #e2e8eb !important;
  background-color: transparent !important;
}

html[data-theme="dark"] .dropdown-menu > li > a:hover,
html[data-theme="dark"] .dropdown-menu > li > a:focus {
  background-color: #3d4f58 !important;
  color: #fff !important;
}

html[data-theme="dark"] .dropdown-menu > .active > a,
html[data-theme="dark"] .dropdown-menu > .active > a:hover,
html[data-theme="dark"] .dropdown-menu > li.active > a,
html[data-theme="dark"] .dropdown-menu > li.active > a:hover {
  background-color: #4a6270 !important;
  color: #fff !important;
}

html[data-theme="dark"] .dropdown-menu .divider,
html[data-theme="dark"] .dropdown-menu > li.divider {
  background-color: #4d5a62 !important;
}

html[data-theme="dark"] .list-group-item {
  background-color: #243038;
  color: #e2e8eb;
}

html[data-theme="dark"] .list-group-item-action:hover {
  background-color: #2d383d;
}

html[data-theme="dark"] .nav-tabs .nav-link {
  color: #9fb0b8;
}

html[data-theme="dark"] .nav-tabs .nav-link.active {
  background-color: #243038;
  border-color: #3d4f58 #3d4f58 #243038;
  color: #e2e8eb;
}

html[data-theme="dark"] .breadcrumb-item,
html[data-theme="dark"] .breadcrumb-item a {
  color: #9fb0b8;
}

html[data-theme="dark"] .breadcrumb-item.active {
  color: #e2e8eb;
}

html[data-theme="dark"] .cookiealert {
  background-color: #243038 !important;
  color: #e2e8eb !important;
  border-top: 1px solid #3d4f58 !important;
}

html[data-theme="dark"] .alert-secondary,
html[data-theme="dark"] .alert-light {
  background-color: #2d383d !important;
  border-color: #4d5a62 !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .link-gray,
html[data-theme="dark"] .link-muted {
  color: #9fb0b8 !important;
}

html[data-theme="dark"] .link-gray:hover,
html[data-theme="dark"] .link-muted:hover {
  color: var(--bs-info) !important;
}

html[data-theme="dark"] pre,
html[data-theme="dark"] code {
  background-color: #2d383d !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .bg-primary-light {
  background-color: rgba(3, 114, 183, 0.25) !important;
}

html[data-theme="dark"] #metapsy-theme-toggle:focus-visible {
  outline: 2px solid var(--bs-info);
  outline-offset: 2px;
}

/* ========== Shiny / shinydashboard (same Metapsy palette) ========== */

html[data-theme="dark"] .wrapper,
html[data-theme="dark"] .right-side {
  background-color: #1f2a30 !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .content-wrapper {
  background-color: #1f2a30 !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .main-sidebar,
html[data-theme="dark"] .left-side {
  background: #1f2a30 !important;
  background-image: none !important;
  border-right: none !important;
  box-shadow: none !important;
}

html[data-theme="dark"] .sidebar-collapse .main-sidebar,
html[data-theme="dark"] .sidebar-collapse .left-side {
  border-right: 0 !important;
  box-shadow: none !important;
}

html[data-theme="dark"] .sidebar-menu > li > a,
html[data-theme="dark"] .sidebar-menu > li > a > .fa {
  color: #9fb0b8 !important;
}

html[data-theme="dark"] .sidebar-menu > li.active > a,
html[data-theme="dark"] .sidebar-menu > li:hover > a {
  background: #243038 !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .main-header .logo,
html[data-theme="dark"] .main-header .navbar {
  background-color: #1f2a30 !important;
  color: #e2e8eb !important;
  box-shadow: none !important;
  border-bottom: 1px solid #3d4f58 !important;
}

html[data-theme="dark"] .main-header .logo {
  color: var(--bs-primary) !important;
}

html[data-theme="dark"] .navbar-static-top .sidebar-toggle {
  color: #e2e8eb !important;
  background-color: transparent !important;
}

html[data-theme="dark"] .box,
html[data-theme="dark"] .nav-tabs-custom > .tab-content {
  background-color: #1f2a30 !important;
  border-color: #3d4f58 !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .box-body {
  background-color: #243038 !important;
}

/* valueBox / AdminLTE .small-box.bg-blue — deep teal-blue for dark UI (was bright #0073b7) */
html[data-theme="dark"] .small-box.bg-blue,
html[data-theme="dark"] .bg-blue {
  background-color: #124458 !important;
  background-image: none !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .small-box.bg-blue .inner > h3,
html[data-theme="dark"] .small-box.bg-blue .inner > p {
  color: #e2e8eb !important;
}

html[data-theme="dark"] .small-box.bg-blue .icon-large,
html[data-theme="dark"] .small-box.bg-blue .icon-large i,
html[data-theme="dark"] .small-box.bg-blue .icon,
html[data-theme="dark"] .small-box.bg-blue .icon i {
  color: rgba(226, 232, 235, 0.2) !important;
}

html[data-theme="dark"] .box-header.with-border {
  border-bottom-color: #3d4f58 !important;
}

html[data-theme="dark"] .box-title,
html[data-theme="dark"] .nav-tabs-custom > .nav-tabs > li > a {
  color: #e2e8eb !important;
}

html[data-theme="dark"] .nav-tabs-custom > .nav-tabs > li.active > a {
  background-color: #243038 !important;
  border-color: #3d4f58 !important;
}

html[data-theme="dark"] h1 {
  color: var(--bs-info) !important;
}

html[data-theme="dark"] h2 {
  color: var(--bs-primary) !important;
}

html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] label {
  color: #e2e8eb !important;
}

/* Softer than default h4 white; matches --bd-subtitle-text / body copy tone */
html[data-theme="dark"] h4.bd-subtitle-line {
  color: var(--bd-subtitle-text) !important;
}

/* Body copy: slightly greyer than main UI white for easier reading */
html[data-theme="dark"] p {
  color: var(--bs-dark2) !important;
}

html[data-theme="dark"] a {
  color: var(--bs-primary) !important;
}

html[data-theme="dark"] a:hover {
  color: var(--bs-info) !important;
}

/* Primary buttons (often <a class="btn btn-primary">); global link color above would make text blue-on-blue */
html[data-theme="dark"] a.btn-primary,
html[data-theme="dark"] .btn-primary {
  color: #fff !important;
}

html[data-theme="dark"] a.btn-primary:hover,
html[data-theme="dark"] a.btn-primary:focus,
html[data-theme="dark"] .btn-primary:hover,
html[data-theme="dark"] .btn-primary:focus,
html[data-theme="dark"] .btn-primary:active {
  color: #fff !important;
}

html[data-theme="dark"] #ideation,
html[data-theme="dark"] #attempts,
html[data-theme="dark"] #start\.to\.data {
  background-color: var(--bs-primary) !important;
  border-color: var(--bs-primary-darker) !important;
  color: var(--btn-primary-text) !important;
}

html[data-theme="dark"] #ideation:hover,
html[data-theme="dark"] #attempts:hover,
html[data-theme="dark"] #start\.to\.data:hover {
  background-color: var(--bs-primary-darker) !important;
  color: var(--btn-primary-text) !important;
}

html[data-theme="dark"] .well,
html[data-theme="dark"] .sidebar-panel {
  background-color: #243038 !important;
  border-color: #3d4f58 !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] form.well .box-body {
  background-color: revert !important;
}

html[data-theme="dark"] select.form-control {
  background-color: #2d383d !important;
  border-color: #4d5a62 !important;
  color: #e2e8eb !important;
}

/* Selectize (Shiny selectInput/selectizeInput, multi “tag” buttons) */
html[data-theme="dark"] .selectize-input {
  background-color: #2d383d !important;
  border-color: #4d5a62 !important;
  color: #e2e8eb !important;
  box-shadow: none !important;
}

html[data-theme="dark"] .selectize-input.focus {
  border-color: var(--bs-info) !important;
  box-shadow: 0 0 0 1px rgba(94, 186, 189, 0.35) !important;
}

html[data-theme="dark"] .selectize-input input {
  color: #e2e8eb !important;
}

html[data-theme="dark"] .selectize-input input::placeholder {
  color: #9fb0b8 !important;
}

/* Tag chips: multi-select only (not single shiny-input-select / plugin-selectize-plugin-a11y) */
html[data-theme="dark"] .selectize-control.multi .selectize-input .item {
  background: #3d4f58 !important;
  color: #f0f4f6 !important;
  border: 1px solid #5c7380 !important;
  box-shadow: none !important;
}

html[data-theme="dark"] .selectize-control.multi .selectize-input .item.active {
  background: #4a6270 !important;
  border-color: #6b8494 !important;
  color: #fff !important;
}

html[data-theme="dark"] .selectize-control.multi .selectize-input .item .remove {
  color: #c5d1d6 !important;
  border-left-color: #5c7380 !important;
}

html[data-theme="dark"] .selectize-control.multi .selectize-input .item .remove:hover {
  background: rgba(0, 0, 0, 0.25) !important;
  color: #fff !important;
}

html[data-theme="dark"] .selectize-control.single .selectize-input .item,
html[data-theme="dark"] .selectize-control.single .selectize-input .item.active {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .selectize-dropdown {
  background-color: #2d383d !important;
  border-color: #4d5a62 !important;
  color: #e2e8eb !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45) !important;
}

html[data-theme="dark"] .selectize-dropdown .option {
  color: #e2e8eb !important;
}

html[data-theme="dark"] .selectize-dropdown .option.active,
html[data-theme="dark"] .selectize-dropdown .option:hover {
  background-color: #3d4f58 !important;
  color: #fff !important;
}

html[data-theme="dark"] .selectize-dropdown .create {
  color: var(--bs-info) !important;
}

html[data-theme="dark"] .selectize-control.multi.plugin-remove_button .selectize-input .item .remove {
  border-left-color: #5c7380 !important;
}

html[data-theme="dark"] .selectize-input.disabled,
html[data-theme="dark"] .selectize-input.disabled * {
  opacity: 1 !important;
}

html[data-theme="dark"] .selectize-input.disabled {
  background-color: #243038 !important;
  border-color: #3d4f58 !important;
  color: #9fb0b8 !important;
}

html[data-theme="dark"] .selectize-control.multi .selectize-input.disabled .item {
  background: #35454e !important;
  color: #9fb0b8 !important;
  border-color: #4d5a62 !important;
}

html[data-theme="dark"] .btn-default {
  background-color: #2d383d !important;
  border-color: #4d5a62 !important;
  color: #e2e8eb !important;
}

/* DataTables / DT (R) — wrapper, ScrollX, FixedColumns, Buttons extension */
html[data-theme="dark"] .dataTables_wrapper {
  color: #e2e8eb !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_scroll,
html[data-theme="dark"] .dataTables_wrapper .dataTables_scrollHead,
html[data-theme="dark"] .dataTables_wrapper .dataTables_scrollBody,
html[data-theme="dark"] .dataTables_wrapper .dataTables_scrollHeadInner {
  border-color: #3d4f58 !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable {
  background-color: #1f2a30 !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable thead th,
html[data-theme="dark"] .dataTables_wrapper table.dataTable thead td {
  background-color: #243038 !important;
  color: #e2e8eb !important;
  border: 1px solid #3d4f58 !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td,
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody th {
  border: 1px solid #3d4f58 !important;
  color: #e2e8eb !important;
}

/* Odd/even/hover: all DT tables (moderator #mreg.table & subgroup #sg.table use display/cell-border without .stripe) */
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.even > td,
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.even > th {
  background-color: #1f2a30 !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.odd > td,
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.odd > th {
  background-color: #252f36 !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr:hover > td,
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr:hover > th {
  background-color: #2d383d !important;
}

/* RowGroup (subgroup table): section header row */
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.dtrg-group th,
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.dtrg-group td {
  background-color: #2d383d !important;
  color: #e2e8eb !important;
  border: 1px solid #3d4f58 !important;
  font-weight: 600 !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.dtrg-group:hover th,
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.dtrg-group:hover td {
  background-color: #35454e !important;
}

/* Top-level RowGroup section labels: lighter band vs odd/even data rows */
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.dtrg-group.dtrg-start.dtrg-level-0 th,
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.dtrg-group.dtrg-start.dtrg-level-0 td {
  background-color: #3d4f58 !important;
  color: #f0f4f6 !important;
  border: 1px solid #5c7380 !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.dtrg-group.dtrg-start.dtrg-level-0:hover th,
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.dtrg-group.dtrg-start.dtrg-level-0:hover td {
  background-color: #4a6270 !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.even > td.dtfc-fixed-left,
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.even > th.dtfc-fixed-left {
  background-color: #1f2a30 !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.odd > td.dtfc-fixed-left,
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody tr.odd > th.dtfc-fixed-left {
  background-color: #252f36 !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable thead th.dtfc-fixed-left,
html[data-theme="dark"] .dataTables_wrapper table.dataTable thead td.dtfc-fixed-left {
  background-color: #243038 !important;
  border: 1px solid #3d4f58 !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td.dtfc-fixed-left,
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody th.dtfc-fixed-left {
  border: 1px solid #3d4f58 !important;
}

html[data-theme="dark"] .dataTables_wrapper .dtfc-right-top-blocker,
html[data-theme="dark"] .dataTables_wrapper .dtfc-left-top-blocker {
  background-color: #243038 !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_length,
html[data-theme="dark"] .dataTables_wrapper .dataTables_filter,
html[data-theme="dark"] .dataTables_wrapper .dataTables_filter label,
html[data-theme="dark"] .dataTables_wrapper .dataTables_info,
html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate {
  color: #9fb0b8 !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_filter input {
  background-color: #2d383d !important;
  border: 1px solid #4d5a62 !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_filter input::placeholder {
  color: #9fb0b8 !important;
}

html[data-theme="dark"] .dataTables_wrapper .dt-button,
html[data-theme="dark"] .dataTables_wrapper .buttons-collection {
  background-color: #2d383d !important;
  border: 1px solid #4d5a62 !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .dataTables_wrapper .dt-button:hover,
html[data-theme="dark"] .dataTables_wrapper .buttons-collection:hover {
  background-color: #3d4f58 !important;
  color: #fff !important;
}

/* Buttons “Download” submenu is often portaled to body */
html[data-theme="dark"] .dt-button-collection {
  background-color: #2d383d !important;
  border: 1px solid #4d5a62 !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45) !important;
}

html[data-theme="dark"] .dt-button-collection .dt-button {
  background-color: transparent !important;
  border: none !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .dt-button-collection .dt-button:hover {
  background-color: #3d4f58 !important;
  color: #fff !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_length select {
  background-color: #2d383d !important;
  border: 1px solid #4d5a62 !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_processing {
  background: rgba(26, 34, 38, 0.92) !important;
  color: #e2e8eb !important;
  border: 1px solid #3d4f58 !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button {
  color: #e2e8eb !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current,
html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
  background: #2d383d !important;
  border-color: #4d5a62 !important;
  color: #fff !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: #3d4f58 !important;
  border-color: #4d5a62 !important;
  color: #fff !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
  color: #6b7a82 !important;
}

/* Non-scroll DataTables fallbacks */
html[data-theme="dark"] table.dataTable thead th,
html[data-theme="dark"] table.dataTable thead td {
  background-color: #243038 !important;
  color: #e2e8eb !important;
  border: 1px solid #3d4f58 !important;
}

html[data-theme="dark"] table.dataTable tbody td {
  border: 1px solid #3d4f58 !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .modal-content {
  background-color: #243038 !important;
  color: #e2e8eb !important;
  border-color: #3d4f58 !important;
}

html[data-theme="dark"] .shiny-input-container .checkbox label,
html[data-theme="dark"] .shiny-input-container .radio label {
  color: #e2e8eb !important;
}

html[data-theme="dark"] blockquote {
  border-left-color: #3d4f58 !important;
  color: #9fb0b8 !important;
}

html[data-theme="dark"] .irs-line,
html[data-theme="dark"] .irs-grid-text,
html[data-theme="dark"] .irs-min,
html[data-theme="dark"] .irs-max,
html[data-theme="dark"] .irs-single,
html[data-theme="dark"] .irs-from,
html[data-theme="dark"] .irs-to {
  color: #ffffff !important;
}

html[data-theme="dark"] .irs-line {
  background-color: #2d383d !important;
}

/* navbarPage on meta-analysis tab: inline background-color: white */
html[data-theme="dark"] .navbar.navbar-default {
  background-color: #1f2a30 !important;
  border-color: #3d4f58 !important;
}

html[data-theme="dark"] .navbar-default .navbar-nav > li > a,
html[data-theme="dark"] .navbar-default .navbar-nav > .active > a {
  color: #e2e8eb !important;
  background-color: transparent !important;
}

html[data-theme="dark"] .navbar-default .navbar-nav > .active > a {
  background-color: #243038 !important;
}

html[data-theme="dark"] .tab-content {
  background-color: #1f2a30 !important;
}

html[data-theme="dark"] .tab-pane {
  background-color: #1f2a30 !important;
  color: #e2e8eb !important;
}

/* navbarPage (meta-analysis): inner tab strip + panes should match .box / --bd-panel-bg, not page base #1a2226 */
html[data-theme="dark"] .navbar.navbar-default ~ .tab-content {
  background-color: var(--bd-panel-bg) !important;
}

html[data-theme="dark"] .navbar.navbar-default ~ .tab-content > .tab-pane {
  background-color: var(--bd-panel-bg) !important;
  color: #e2e8eb !important;
}

html[data-theme="dark"] .navbar.navbar-default ~ .tab-content > .tab-pane h4,
html[data-theme="dark"] .navbar.navbar-default ~ .tab-content > .tab-pane h4 strong {
  color: #e2e8eb !important;
}

/* formatStyle() inline backgrounds — any DataTables instance (ids like DataTables_Table_0) */
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="lightblue"],
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="LightBlue"],
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="rgb(173, 216, 230)"],
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="rgb(173,216,230)"] {
  background-color: #2d383d !important;
  color: #e2e8eb !important;
}

/* Significance / highlight cells (formatStyle uses hex or rgb) */
/* Significant cells: same mint family as light theme #cbf7c7 / rgb(203,247,199), adapted for dark */
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="#cbf7c7"],
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="cbf7c7"],
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="rgb(203, 247, 199)"],
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="rgb(203,247,199)"] {
  background: linear-gradient(rgba(203, 247, 199, 0.28), rgba(203, 247, 199, 0.28)), #2a3d31 !important;
  color: #dcedc8 !important;
  border: 1px solid rgba(129, 199, 132, 0.55) !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="lightgray"],
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="LightGray"],
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="rgb(211, 211, 211)"],
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="rgb(211,211,211)"] {
  background-color: #2d383d !important;
  color: #e2e8eb !important;
}

/* Same overrides outside wrapper (fallback) */
html[data-theme="dark"] table.dataTable tbody td[style*="#cbf7c7"],
html[data-theme="dark"] table.dataTable tbody td[style*="cbf7c7"],
html[data-theme="dark"] table.dataTable tbody td[style*="rgb(203, 247, 199)"],
html[data-theme="dark"] table.dataTable tbody td[style*="rgb(203,247,199)"] {
  background: linear-gradient(rgba(203, 247, 199, 0.28), rgba(203, 247, 199, 0.28)), #2a3d31 !important;
  color: #dcedc8 !important;
  border: 1px solid rgba(129, 199, 132, 0.55) !important;
}

html[data-theme="dark"] table.dataTable tbody td[style*="lightgray"],
html[data-theme="dark"] table.dataTable tbody td[style*="LightGray"],
html[data-theme="dark"] table.dataTable tbody td[style*="rgb(211, 211, 211)"],
html[data-theme="dark"] table.dataTable tbody td[style*="rgb(211,211,211)"] {
  background-color: #2d383d !important;
  color: #e2e8eb !important;
}

/* Moderator table: R dark fills rgb(42,61,49) / #3a4650 */
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="rgb(42, 61, 49)"],
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="rgb(42,61,49)"],
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="#2a3d31"] {
  background-color: rgb(42, 61, 49) !important;
  color: #dcedc8 !important;
  box-shadow: inset 0 0 0 9999px rgb(42, 61, 49) !important;
}

html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="#3a4650"],
html[data-theme="dark"] .dataTables_wrapper table.dataTable tbody td[style*="58, 70, 80"] {
  background-color: #3a4650 !important;
  color: #e2e8eb !important;
  box-shadow: inset 0 0 0 9999px #3a4650 !important;
}

html[data-theme="dark"] a.shiny-download-link {
  color: var(--btn-primary-text) !important;
}

/*
 * Markdown fences: use shinydashboard tab pane ids (see ?tabItem) so we beat .content pre.
 * Inset box-shadow is a fallback when another layer strips border. ui.R also injects the
 * same rules late in dashboardBody for cascade order vs dashboardthemes.
 */
#shiny-tab-start pre,
#shiny-tab-outcome pre,
#shiny-tab-data pre,
#shiny-tab-metaanalysis pre,
#shiny-tab-about pre,
#shiny-tab-rpackage pre,
html[data-theme="dark"] #shiny-tab-start pre,
html[data-theme="dark"] #shiny-tab-outcome pre,
html[data-theme="dark"] #shiny-tab-data pre,
html[data-theme="dark"] #shiny-tab-metaanalysis pre,
html[data-theme="dark"] #shiny-tab-about pre,
html[data-theme="dark"] #shiny-tab-rpackage pre {
  border: 1px solid #3d4f58 !important;
  box-shadow: inset 0 0 0 1px #3d4f58 !important;
}
