/* 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;
  /* 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;
  --bd-box-bg: #243038;
  --btn-primary-text: #ffffff;
}

/* 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: muted dots on dark overlay (avoid bright white ring) */
html[data-theme="dark"] .atebits-loader:not(:required) {
  background: rgba(159, 176, 184, 0.38) !important;
  -moz-box-shadow: rgba(159, 176, 184, 0.32) -12px -12px 0 0, rgba(159, 176, 184, 0.32) 12px -12px 0 0, rgba(159, 176, 184, 0.32) -12px 0 0 0, rgba(159, 176, 184, 0.32) 12px 0 0 0, rgba(159, 176, 184, 0.32) -12px 12px 0 0, rgba(159, 176, 184, 0.32) 0 12px 0 0, rgba(159, 176, 184, 0.32) 12px 12px 0 0 !important;
  -webkit-box-shadow: rgba(159, 176, 184, 0.32) -12px -12px 0 0, rgba(159, 176, 184, 0.32) 12px -12px 0 0, rgba(159, 176, 184, 0.32) -12px 0 0 0, rgba(159, 176, 184, 0.32) 12px 0 0 0, rgba(159, 176, 184, 0.32) -12px 12px 0 0, rgba(159, 176, 184, 0.32) 0 12px 0 0, rgba(159, 176, 184, 0.32) 12px 12px 0 0 !important;
  box-shadow: rgba(159, 176, 184, 0.32) -12px -12px 0 0, rgba(159, 176, 184, 0.32) 12px -12px 0 0, rgba(159, 176, 184, 0.32) -12px 0 0 0, rgba(159, 176, 184, 0.32) 12px 0 0 0, rgba(159, 176, 184, 0.32) -12px 12px 0 0, rgba(159, 176, 184, 0.32) 0 12px 0 0, rgba(159, 176, 184, 0.32) 12px 12px 0 0 !important;
}

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;
}

/* Inline code in prose: match body text (fenced blocks keep syntax colours) */
html[data-theme="dark"] .mp-about-prose :not(pre) > code,
html[data-theme="dark"] .mp-rpackage-prose :not(pre) > code {
  color: inherit;
  background: transparent;
  padding: 0;
}

html[data-theme="dark"] .mp-about-prose p a,
html[data-theme="dark"] .mp-about-prose ul:not(.mp-doclist) a {
  color: #8ec8e8;
}

html[data-theme="dark"] .mp-about-prose p a:hover,
html[data-theme="dark"] .mp-about-prose p a:focus,
html[data-theme="dark"] .mp-about-prose ul:not(.mp-doclist) a:hover,
html[data-theme="dark"] .mp-about-prose ul:not(.mp-doclist) a:focus {
  color: #b8dff5;
}

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;
  color: var(--bs-dark2);
}

/* 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"] .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;
}

/* 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;
}

/* R-side dark moderator p-cells (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)"] {
  background-color: rgb(42, 61, 49) !important;
  color: #dcedc8 !important;
  border: 1px solid rgba(129, 199, 132, 0.45) !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*="3a4650"] {
  background-color: #3a4650 !important;
  color: #e2e8eb !important;
  box-shadow: inset 0 0 0 9999px #3a4650 !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;
}

html[data-theme="dark"] table.dataTable tbody td[style*="rgb(42, 61, 49)"],
html[data-theme="dark"] table.dataTable tbody td[style*="rgb(42,61,49)"] {
  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"] table.dataTable tbody td[style*="#3a4650"] {
  background-color: #3a4650 !important;
  color: #e2e8eb !important;
  box-shadow: inset 0 0 0 9999px #3a4650 !important;
}

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

html[data-theme="dark"] .mp-plot-dl .mp-btn:hover,
html[data-theme="dark"] .mp-plot-dl .mp-btn:focus,
html[data-theme="dark"] .mp-plot-dl .mp-btn:focus-visible {
  color: var(--mp-ink-soft) !important;
  text-decoration: none !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.
 */
#mp-panel-start pre,
#mp-panel-data pre,
#mp-panel-metaanalysis pre,
#mp-panel-about pre,
html[data-theme="dark"] #mp-panel-start pre,
html[data-theme="dark"] #mp-panel-data pre,
html[data-theme="dark"] #mp-panel-metaanalysis pre,
html[data-theme="dark"] #mp-panel-about pre {
  border: 1px solid #3d4f58 !important;
  box-shadow: inset 0 0 0 1px #3d4f58 !important;
}

html[data-theme="dark"] #mp-panel-rpackage .mp-code-wrap {
  background: #2d383d;
  border-color: #3d4f58;
  box-shadow: inset 0 0 0 1px #3d4f58;
}

html[data-theme="dark"] #mp-panel-rpackage .mp-code-wrap--output {
  background: transparent;
  background-color: transparent;
  border-color: transparent;
  box-shadow: none;
}

html[data-theme="dark"] #mp-panel-rpackage .mp-code-wrap--prose {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

html[data-theme="dark"] #mp-panel-rpackage .mp-code-wrap--output pre,
html[data-theme="dark"] #mp-panel-rpackage .mp-code-wrap--output code {
  color: #9fb0b8;
  background: transparent !important;
  background-color: transparent !important;
}

html[data-theme="dark"] #mp-panel-rpackage .mp-code-wrap--prose pre,
html[data-theme="dark"] #mp-panel-rpackage .mp-code-wrap--prose code {
  color: #c5d1d6;
}

html[data-theme="dark"] #mp-panel-rpackage .mp-code-wrap pre {
  border: none !important;
  box-shadow: none !important;
}

html[data-theme="dark"] #mp-panel-rpackage .mp-code-wrap code[class*="language-"] {
  color: #c5d1d6;
}

html[data-theme="dark"] .mp-rpackage-prose .token.comment,
html[data-theme="dark"] .mp-rpackage-prose .token.prolog,
html[data-theme="dark"] .mp-rpackage-prose .token.doctype,
html[data-theme="dark"] .mp-rpackage-prose .token.cdata {
  color: #8a9aa3;
}

html[data-theme="dark"] .mp-rpackage-prose .token.keyword {
  color: #5ebaed;
}

html[data-theme="dark"] .mp-rpackage-prose .token.string,
html[data-theme="dark"] .mp-rpackage-prose .token.function {
  color: #7eb8d8;
}

/* Prism default theme adds hsla(0,0%,100%,.5) on operators — clashes on dark blocks */
html[data-theme="dark"] .mp-rpackage-prose .token.operator,
html[data-theme="dark"] .mp-rpackage-prose .token.entity,
html[data-theme="dark"] .mp-rpackage-prose .token.url {
  background: transparent !important;
}

html[data-theme="dark"] .mp-rpackage-prose .token.operator {
  color: #9fb0b8;
}

html[data-theme="dark"] #mp-panel-rpackage .mp-code-wrap .mp-code-copy {
  background: #243038;
  border-color: #3d4f58;
  color: #c5d1d6;
}

/* ========== mp-* layout (custom UI) — dark mode ========== */
html[data-theme="dark"] {
  --mp-bg: #1f2a30;
  --mp-surface: #243038;
  --mp-surface-alt: #2d383d;
  --mp-line: #3d4f58;
  --mp-line-soft: #35454e;
  --mp-ink: #e2e8eb;
  --mp-ink-soft: #c5d1d6;
  --mp-muted: #9fb0b8;
  --mp-slate: #e2e8eb;
  --mp-teal-soft: rgba(94, 186, 189, .12);
  --mp-hero-panel: #323f48;
  --code-bg: #2d383d;
  --code-color: #a5b4fc;
}

/* Verdict pills (funnel asymmetry / evidential value) — the light pastel
   backgrounds glare on the dark cards, so use translucent tints with
   light-toned text instead. */
html[data-theme="dark"] .mp-verdict.is-yes {
  background: rgba(63, 185, 80, .15);
  color: #6fdd8b;
  border-color: rgba(63, 185, 80, .38);
}
html[data-theme="dark"] .mp-verdict.is-warn {
  background: rgba(210, 153, 34, .16);
  color: #e3b341;
  border-color: rgba(210, 153, 34, .40);
}
html[data-theme="dark"] .mp-verdict.is-off {
  background: rgba(255, 255, 255, .04);
  color: var(--mp-muted);
  border-color: var(--mp-line);
}

html[data-theme="dark"] .mp-hero-main {
  background: linear-gradient(150deg, #243038 0%, #1f2a30 100%) !important;
  border-color: #3d4f58 !important;
  color: #e2e8eb;
}

html[data-theme="dark"] .mp-hero-aside {
  background: rgba(255, 255, 255, .05);
}

html[data-theme="dark"] #start\.to\.data,
html[data-theme="dark"] #data\.to\.metaanalysis,
html[data-theme="dark"] #report {
  background: var(--mp-primary) !important;
  border-color: var(--mp-primary) !important;
  color: #fff !important;
}

html[data-theme="dark"] #start\.to\.data:hover,
html[data-theme="dark"] #start\.to\.data:focus,
html[data-theme="dark"] #start\.to\.data:focus-visible,
html[data-theme="dark"] #data\.to\.metaanalysis:hover,
html[data-theme="dark"] #data\.to\.metaanalysis:focus,
html[data-theme="dark"] #data\.to\.metaanalysis:focus-visible,
html[data-theme="dark"] #report:hover,
html[data-theme="dark"] #report:focus,
html[data-theme="dark"] #report:focus-visible {
  background: var(--mp-primary-dark) !important;
  border-color: var(--mp-primary-dark) !important;
  color: #fff !important;
}

html[data-theme="dark"] .mp-pagehead .mp-eyebrow {
  color: var(--mp-muted) !important;
}

/* Dim the (bright) pagehead illustrations so they sit calmly on the dark bg */
html[data-theme="dark"] .mp-pagehead-art {
  filter: brightness(0.68) contrast(1.05) saturate(0.92)
          drop-shadow(0 8px 20px rgba(0, 0, 0, 0.5));
}

html[data-theme="dark"] .mp-doclist li a {
  border-left-color: #5c7380;
  background: var(--mp-surface-alt);
  color: var(--mp-ink-soft);
}

html[data-theme="dark"] .mp-doclist li a::before {
  color: #8a9aa3;
}

html[data-theme="dark"] .mp-doclist li a:hover {
  background: #35454e;
  border-color: #5c7380;
  border-left-color: #8a9aa3;
  color: var(--mp-ink);
  text-decoration: none;
}

html[data-theme="dark"] .mp-stat {
  background: linear-gradient(150deg, #124458 0%, #1a5a7a 100%) !important;
}

html[data-theme="dark"] .mp-card,
html[data-theme="dark"] .mp-filter-panel,
html[data-theme="dark"] .mp-hero-main {
  background-color: var(--mp-surface) !important;
  border-color: var(--mp-line) !important;
  color: var(--mp-ink);
}

html[data-theme="dark"] .mp-hero-sub,
html[data-theme="dark"] .mp-pagehead p,
html[data-theme="dark"] .mp-info-card p {
  color: var(--mp-ink-soft) !important;
}

/* On the dark glow panel, the primary-blue heading is too low-contrast. */
html[data-theme="dark"] .mp-hero-content h1 {
  color: #ffffff !important;
}

html[data-theme="dark"] .mp-results .nav-tabs {
  background: var(--mp-surface) !important;
  border-color: var(--mp-line) !important;
}

html[data-theme="dark"] .mp-results .nav-tabs > li > a {
  color: var(--mp-muted) !important;
  border-right-color: var(--mp-line) !important;
}

html[data-theme="dark"] .mp-results .nav-tabs > li > a:hover {
  background: var(--mp-surface-alt) !important;
  color: var(--mp-primary) !important;
}

html[data-theme="dark"] .mp-results .nav-tabs > li.active > a,
html[data-theme="dark"] .mp-results .nav-tabs > li.active > a:hover {
  background: var(--mp-primary) !important;
  color: #fff !important;
}

html[data-theme="dark"] .mp-note {
  background: rgba(94, 186, 189, .1) !important;
  border-color: rgba(94, 186, 189, .28) !important;
  color: var(--mp-ink-soft) !important;
}

html[data-theme="dark"] .mp-btn-ghost {
  background: var(--mp-surface-alt) !important;
  border-color: var(--mp-line) !important;
  color: var(--mp-ink) !important;
}

html[data-theme="dark"] .mp-metric-value,
html[data-theme="dark"] .mp-metric-value #TE,
html[data-theme="dark"] .mp-metric-value #I2,
html[data-theme="dark"] .mp-metric-value #TE\.out,
html[data-theme="dark"] .mp-metric-value #I2\.out {
  color: var(--mp-primary) !important;
}

html[data-theme="dark"] .mp-metric-value #TE .mp-metric-muted,
html[data-theme="dark"] .mp-metric-value #I2 .mp-metric-muted,
html[data-theme="dark"] .mp-metric-value #TE\.out .mp-metric-muted,
html[data-theme="dark"] .mp-metric-value #I2\.out .mp-metric-muted {
  color: var(--mp-muted) !important;
}

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

html[data-theme="dark"] .mp-topbar {
  background: #1f2a30 !important;
  border-bottom-color: #3d4f58 !important;
}

html[data-theme="dark"] .mp-step {
  color: #9fb0b8 !important;
}
html[data-theme="dark"] .mp-step.is-active {
  color: #e2e8eb !important;
}
html[data-theme="dark"] .mp-step-num {
  background: #243038 !important;
  border-color: #3d4f58 !important;
  color: #9fb0b8 !important;
}
html[data-theme="dark"] .mp-step.is-active .mp-step-num {
  background: var(--mp-primary) !important;
  border-color: var(--mp-primary) !important;
  color: #fff !important;
}
html[data-theme="dark"] .mp-step-line { background: #3d4f58 !important; }

html[data-theme="dark"] .mp-icon-link {
  background: #243038 !important;
  border-color: #3d4f58 !important;
  color: #9fb0b8 !important;
}
html[data-theme="dark"] .mp-icon-link:hover,
html[data-theme="dark"] .mp-icon-link.is-active {
  color: #e2e8eb !important;
}

html[data-theme="dark"] .mp-results-nav {
  border-bottom-color: #3d4f58 !important;
}

html[data-theme="dark"] .mp-results-nav-toggle {
  background: #243038;
  border-color: #3d4f58;
  color: #e2e8eb;
}

html[data-theme="dark"] .mp-results-nav-toggle:hover,
html[data-theme="dark"] .mp-results-nav-toggle:focus-visible {
  background: #35454e;
  border-color: #5c7380;
}

html[data-theme="dark"] .mp-results-nav-list {
  background: #243038;
  border-color: #3d4f58;
}

html[data-theme="dark"] .mp-results-nav .mp-results-tab {
  border-bottom-color: #35454e;
}

html[data-theme="dark"] .mp-results-tab {
  color: #9fb0b8 !important;
  background: transparent !important;
  border-bottom-color: transparent !important;
}

html[data-theme="dark"] .mp-results-tab:hover {
  color: var(--mp-ink-soft) !important;
  background: var(--mp-surface-alt) !important;
  border-bottom-color: var(--mp-ink-soft) !important;
}

html[data-theme="dark"] .mp-results-tab.is-active {
  background: transparent !important;
  color: var(--mp-ink) !important;
  border-bottom-color: var(--mp-ink-soft) !important;
}

html[data-theme="dark"] .mp-settings-toggle {
  background: var(--mp-surface) !important;
  border-color: var(--mp-line) !important;
  color: var(--mp-ink-soft) !important;
}

html[data-theme="dark"] .mp-settings-toggle:hover,
html[data-theme="dark"] .mp-settings-toggle:focus-visible,
html[data-theme="dark"] .mp-settings-toggle[aria-expanded="true"] {
  background: var(--mp-teal-soft) !important;
  border-color: var(--mp-teal) !important;
  color: var(--mp-ink-soft) !important;
}

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

html[data-theme="dark"] .mp-filter[open] > .mp-filter-title {
  color: var(--mp-ink) !important;
  background: var(--mp-surface-alt) !important;
  border-left-color: var(--mp-muted) !important;
}

html[data-theme="dark"] .mp-filter[open] > .mp-filter-title::before {
  color: var(--mp-ink-soft) !important;
}

/* Shiny withProgress toast + bootstrap progress track */
html[data-theme="dark"] .shiny-notification {
  background-color: var(--mp-surface) !important;
  border-color: #35454e !important;
  color: var(--mp-ink) !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32) !important;
}

html[data-theme="dark"] .shiny-notification:has(.shiny-progress-notification) {
  background-color: var(--mp-surface) !important;
  border-color: #35454e !important;
}

html[data-theme="dark"] .shiny-progress-notification .progress-message {
  color: var(--mp-ink) !important;
}

html[data-theme="dark"] .shiny-progress-notification .progress-detail {
  color: var(--mp-muted) !important;
}

html[data-theme="dark"] .progress {
  background-color: #35454e !important;
  border: none !important;
  box-shadow: none !important;
}

html[data-theme="dark"] .progress-bar {
  background-color: var(--mp-teal) !important;
}
