/* Dark-mode values for main views. Light mode uses each declaration's fallback.
   Shared tokens follow the application's theme; semantic colors match Plan Operativo. */
.dark {
  color-scheme: dark;
  --main-surface: #050c17;
  --main-surface-muted: #111827;
  --main-text: var(--color-text-primary, #f3f4f6);
  --main-text-muted: var(--color-text-secondary, #d1d5db);
  --main-text-subtle: var(--color-text-tertiary, #9ca3af);
  --main-border: var(--color-border-tertiary, #374151);
  --main-info-bg: var(--color-background-info, #1e3a5f);
  --main-info-text: var(--color-text-info, #93c5fd);
  --main-info-border: #1e3a5f;
  --main-success-bg: #064e3b;
  --main-success-text: #34d399;
  --main-success-border: #065f46;
  --main-warning-bg: var(--color-background-warning, #451a03);
  --main-warning-text: var(--color-text-warning, #fcd34d);
  --main-warning-border: #78350f;
  --main-danger-bg: var(--color-background-danger, #450a0a);
  --main-danger-text: var(--color-text-danger, #fca5a5);
  --main-danger-border: #7f1d1d;
  --main-purple-bg: #2e1065;
  --main-purple-text: #d8b4fe;
  --main-purple-border: #6b21a8;
}

/* ApexCharts uses inline SVG styles; keep all chart lettering white in dark mode. */
.dark .apexcharts-canvas text,
.dark .apexcharts-canvas .apexcharts-datalabel {
  fill: #ffffff !important;
}

.dark .apexcharts-canvas .apexcharts-legend-text,
.dark .apexcharts-tooltip,
.dark .apexcharts-tooltip-title {
  color: #ffffff !important;
}

.dark .apexcharts-tooltip,
.dark .apexcharts-tooltip-title {
  background: #111827 !important;
}

/* Shared Select2 contrast. Keep module sizing and selection behaviour intact.
   The state selectors outrank the legacy option rules loaded by each module. */
.dark .select2-container--default .select2-selection--single,
.dark .select2-container--default .select2-selection--multiple,
.dark .select2-container--default .select2-dropdown {
  background-color: var(--color-background-secondary) !important;
  border-color: var(--color-border-secondary) !important;
  color: var(--main-text) !important;
}

.dark .select2-container--default .select2-selection--single .select2-selection__rendered,
.dark .select2-container--default .select2-results__option,
.dark .select2-container--default .select2-search__field {
  color: var(--main-text) !important;
}

.dark .select2-container--default .select2-search--dropdown .select2-search__field {
  background-color: var(--color-background-secondary) !important;
  border-color: var(--color-border-secondary) !important;
}

.dark .select2-container--default .select2-selection__placeholder,
.dark .select2-container--default .select2-search__field::placeholder,
.dark .select2-container--default .select2-results__message,
.dark .select2-container--default .select2-results__option--disabled {
  color: var(--main-text-muted) !important;
}

.dark .select2-container--default
  .select2-results__option.select2-results__option--selectable.select2-results__option--selected,
.dark .select2-container--default
  .select2-results__option.select2-results__option--highlighted.select2-results__option--selectable.select2-results__option--selected {
  background-color: var(--main-surface-muted) !important;
  color: var(--main-text) !important;
}

.dark .select2-container--default
  .select2-results__option.select2-results__option--highlighted:not(.select2-results__option--selected) {
  background-color: #1d4ed8 !important;
  color: #ffffff !important;
}

.dark .select2-container--default .select2-selection--multiple .select2-selection__choice {
  background-color: #1d4ed8 !important;
  color: #ffffff !important;
}

/* The label must inherit its chip colour, rather than the field's text colour. */
.select2-container--default .select2-selection--multiple
  .select2-selection__choice .select2-selection__choice__display {
  color: inherit !important;
}

.dark .select2-container--default .select2-selection--multiple .select2-selection__choice__remove,
.dark .select2-container--default .select2-selection .select2-selection__clear {
  color: #ffffff !important;
}

.dark .select2-container--default .select2-selection--single .select2-selection__arrow b {
  border-color: var(--main-text-muted) transparent transparent transparent !important;
}

/* Native selects, including those outside the form-select component. Use only
   background-color so each control retains its existing arrow and dimensions. */
.dark select,
.dark select option,
.dark select optgroup {
  color-scheme: dark;
  background-color: var(--color-background-secondary, #1f2937) !important;
  color: var(--main-text) !important;
}

.dark select:disabled,
.dark select option:disabled,
.dark select optgroup:disabled {
  color: var(--main-text-muted) !important;
}

/* Custom searchable dropdowns: selection and hover follow the current theme,
   including a theme change while the dropdown is open. */
.theme-dropdown-option {
  background-color: transparent;
  color: var(--main-text, #374151);
}

.theme-dropdown-option:hover {
  background-color: var(--main-info-bg, #eff6ff);
  color: var(--main-info-text, #1e40af);
}

.theme-dropdown-option[aria-selected="true"] {
  background-color: var(--main-info-bg, #dbeafe);
  color: var(--main-info-text, #1e40af);
  font-weight: 600;
}

.dark .theme-dropdown-option:hover,
.dark .theme-dropdown-option:focus-visible {
  background-color: #1d4ed8;
  color: #ffffff;
}

.theme-dropdown-search {
  background-color: var(--main-surface, #ffffff);
  color: var(--main-text, #374151);
}

.theme-dropdown-search::placeholder {
  color: var(--main-text-muted, #6b7280);
}

/* Leaflet controls also appear in standalone windows without module overrides. */
.dark .leaflet-control-zoom a,
.dark .leaflet-control-fullscreen a,
.dark .leaflet-control-fullscreen-btn-inside,
.dark .leaflet-control-attribution,
.dark .leaflet-popup-content-wrapper,
.dark .leaflet-popup-tip,
.dark .leaflet-tooltip {
  background-color: var(--main-surface) !important;
  color: var(--main-text) !important;
  border-color: var(--main-border) !important;
}

.dark .leaflet-control-zoom a:hover,
.dark .leaflet-control-fullscreen a:hover,
.dark .leaflet-control-fullscreen-btn-inside:hover {
  background-color: var(--main-surface-muted) !important;
}

.dark .leaflet-control-attribution a {
  color: var(--main-info-text);
}

.dark .leaflet-control-fullscreen-btn-inside,
.dark .leaflet-control-zoom-fullscreen,
.dark .leaflet-control-fullscreen a {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath d='M1 1h4V3H3v2H1zm8 0h4v4h-2V3h-2zM1 9h2v2h2v2H1zm10 2h-2v2h4V9h-2z' fill='%23f3f4f6'/%3E%3C/svg%3E") !important;
  background-size: 14px 14px !important;
  background-position: center !important;
}
