/* Color fallbacks in vega-theme.css preserve the existing light palette.
   These semantic tokens also cover report-specific cards and modal content. */
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] {
  color-scheme: dark;
  --body-bg: #0b1424;
  --card-bg: #152238;
  --topnav-bg: #111d30;
  --border: #30435f;
  /* Form control edges must reach 3:1 against the card surface; decorative borders stay quieter. */
  --input-border: #5f7799;
  --text: #e2e8f0;
  --text-muted: #a8b9d0;
  --text-light: #94a9c4;
  --primary-light: #203c61;
  --surface: #152238;
  --surface-soft: #1a2b43;
  --surface-hover: #243b59;
  --line: #30435f;
  --ink: #e2e8f0;
  --ink-muted: #a8b9d0;
  --ink-accent: #93c5fd;
  /* --ink-accent and --tone-success-text are text colors; solid fills that carry white text use these. */
  --accent-fill: #2563eb;
  --accent-fill-dark: #1d4ed8;
  --success-fill: #047857;
  --tone-success-text: #6ee7b7;
  --tone-success-bg: #123c36;
  --tone-warning-text: #fcd34d;
  --tone-warning-bg: #3d3020;
  --report-warning-accent: #d9a184;
  --report-pending-bg: #18283e;
  --tone-danger-text: #fda4af;
  --tone-danger-bg: #422533;
  --tone-purple-text: #c4b5fd;
  --tone-purple-bg: #302a49;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .18);
  --shadow: 0 2px 6px rgba(0, 0, 0, .24);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .3);
  --shadow-button: 0 2px 6px rgba(0, 0, 0, .2);
  --shadow-button-hover: 0 6px 16px rgba(0, 0, 0, .3);
}

.btn.btn-theme-toggle {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  padding: 0;
  justify-content: center;
  color: var(--text);
  border-color: var(--border);
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
  font-size: 16px;
}
.btn.btn-theme-toggle:hover { background: var(--body-bg); }
.btn.btn-theme-toggle:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 3px;
}
.modern-login-page #m_login { background: var(--body-bg) !important; }
.modern-login-page .modern-login-card {
  background: var(--card-bg) !important;
  border: 1px solid var(--border) !important;
}
.modern-login-page .modern-login-card h2,
.modern-login-page .modern-login-card label,
.modern-login-page .modern-login-card .form-control { color: var(--text) !important; }
.modern-login-page .modern-login-card input.form-control {
  background: var(--body-bg) !important;
  border-color: var(--input-border) !important;
}
.modern-login-page .modern-login-card input.form-control::placeholder {
  color: var(--text-muted) !important;
  opacity: 1;
}

/* The sidebar and the page are nearly the same navy at this depth, so the edge needs a line to stay readable. */
html[data-theme="dark"] .col-md-3.left_col { border-right: 1px solid var(--border); }

/* White gloss belongs to the light theme; colored action buttons keep their fills. */
html[data-theme="dark"] .btn {
  --btn-highlight: rgba(255, 255, 255, .05);
  --btn-glow: rgba(96, 165, 250, .08);
}
html[data-theme="dark"] .btn-user,
html[data-theme="dark"] .btn-logout,
html[data-theme="dark"] #UserLogout {
  background-image: none;
  background-color: var(--surface-soft);
  border-color: var(--border);
  box-shadow: var(--shadow-button);
}
html[data-theme="dark"] #UserLogout,
html[data-theme="dark"] .btn-logout { color: var(--tone-danger-text); }
html[data-theme="dark"] #btnChangePassword { color: var(--text); }
html[data-theme="dark"] .text-danger,
html[data-theme="dark"] .cell-negative,
html[data-theme="dark"] .has-error .help-block { color: var(--tone-danger-text); }
html[data-theme="dark"] .text-success { color: var(--tone-success-text); }
html[data-theme="dark"] .text-warning { color: var(--tone-warning-text); }
html[data-theme="dark"] .text-info { color: var(--ink-accent); }
/* Bootstrap paints nested tables (row detail panels) white. */
html[data-theme="dark"] .table .table { background-color: var(--surface); }
html[data-theme="dark"] .text-muted { color: var(--text-muted); }
html[data-theme="dark"] .sefim-home { --sefim-green: #047857; --sefim-red: #b91c1c; }
html[data-theme="dark"] .form-control::placeholder { color: var(--text-muted); opacity: 1; }
html[data-theme="dark"] input[type="checkbox"],
html[data-theme="dark"] input[type="radio"] { accent-color: #60a5fa; }
html[data-theme="dark"] .vdp { --vdp-accent: #3b82f6; box-shadow: 0 16px 36px rgba(0, 0, 0, .5), 0 4px 10px rgba(0, 0, 0, .3); }

/* Third-party controls can attach directly to body, outside the report shell. vega-dark.css loads after
   every plugin stylesheet and the html[data-theme] prefix outranks their selectors, so no !important is needed
   here; the few places that still use it are marked with the reason. */
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .dt-button-collection,
html[data-theme="dark"] .select2-drop,
html[data-theme="dark"] .select2-dropdown,
html[data-theme="dark"] .ms-drop {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}
html[data-theme="dark"] .select2-search input,
html[data-theme="dark"] .select2-search__field,
html[data-theme="dark"] .select2-choice,
html[data-theme="dark"] .select2-choices,
html[data-theme="dark"] .ms-choice {
  color: var(--text);
  background: var(--surface);
  border-color: var(--input-border);
}
html[data-theme="dark"] .dropdown-menu > li > a { color: var(--text); }
html[data-theme="dark"] .dropdown-menu > li > a:hover,
html[data-theme="dark"] .dropdown-menu > li > a:focus,
html[data-theme="dark"] .select2-results .select2-highlighted {
  background: var(--surface-hover);
  color: var(--text);
}
/* Select2 4 highlighted/selected options and chips are themed in vega-theme.css (with !important), through
   --accent-fill and --primary-light, so they follow this theme's tokens without a rule here. */
html[data-theme="dark"] .dataTables_wrapper,
html[data-theme="dark"] .dataTables_info,
html[data-theme="dark"] .dataTables_length,
html[data-theme="dark"] .dataTables_filter,
html[data-theme="dark"] .dataTables_processing { color: var(--text-muted); }
html[data-theme="dark"] .dataTables_filter input,
html[data-theme="dark"] .dataTables_length select {
  color: var(--text);
  background-color: var(--surface-soft);
  border-color: var(--input-border);
}
html[data-theme="dark"] table.dataTable tbody tr { background-color: var(--surface); }
html[data-theme="dark"] table.dataTable.display tbody tr > .sorting_1,
html[data-theme="dark"] table.dataTable.order-column tbody tr > .sorting_1 {
  background-color: var(--surface-soft);
}
/* jquery.dataTables.css declares the pager button text color with !important (#333, white on hover,
   #666 when disabled), so the text colors here have to match it; backgrounds and borders do not. */
html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button { color: var(--text) !important; }
html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current,
html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--surface-hover);
  color: var(--text) !important;
  border-color: var(--border);
}
html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
  color: var(--text-muted) !important;
  background: transparent;
}

html[data-theme="dark"] .datepicker,
html[data-theme="dark"] .daterangepicker,
html[data-theme="dark"] .daterangepicker .calendar-table,
html[data-theme="dark"] .daterangepicker .calendar,
html[data-theme="dark"] .daterangepicker .ranges {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}
html[data-theme="dark"] .datepicker table tr td.day:hover,
html[data-theme="dark"] .datepicker table tr td span:hover,
html[data-theme="dark"] .datepicker thead tr:first-child th:hover,
html[data-theme="dark"] .daterangepicker td.available:hover,
html[data-theme="dark"] .daterangepicker th.available:hover,
html[data-theme="dark"] .daterangepicker .ranges li:hover {
  color: var(--text);
  background: var(--surface-hover);
}
html[data-theme="dark"] .daterangepicker td.in-range,
html[data-theme="dark"] .daterangepicker td.off {
  color: var(--text-muted);
  background: var(--surface-soft);
}
html[data-theme="dark"] .daterangepicker td.active,
html[data-theme="dark"] .daterangepicker .ranges li.active {
  color: #fff;
  background: var(--primary);
}
html[data-theme="dark"] .daterangepicker .drp-buttons { border-color: var(--border); }
html[data-theme="dark"] .daterangepicker .calendar-table .next span,
html[data-theme="dark"] .daterangepicker .calendar-table .prev span { border-color: var(--text); }
html[data-theme="dark"] .datepicker .disabled,
html[data-theme="dark"] .datepicker .old,
html[data-theme="dark"] .datepicker .new { color: var(--text-muted); }

/* Inline legacy report colors and platform headings need a dark contrast variant. */
html[data-theme="dark"] .report-table > thead > tr > th.platform-col {
  color: var(--text-muted);
  color: color-mix(in srgb, var(--platform-ink, #60738b) 45%, white);
}
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .swal2-popup,
html[data-theme="dark"] .swal2-content,
html[data-theme="dark"] .swal2-html-container { color: var(--text); }
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .swal2-popup { background-color: var(--surface); }
html[data-theme="dark"] .modal-backdrop { background: #000; }
html[data-theme="dark"] ::-webkit-scrollbar-track { background: var(--body-bg); }
html[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #405573; }

@media (max-width: 767px) {
  .topnav-actions .btn.btn-theme-toggle { flex: 0 0 34px; width: 34px; height: 34px; min-width: 34px; }
}
/* Theme switch cross-fade (View Transitions API); other browsers swap instantly. */
::view-transition-old(root),
::view-transition-new(root) { animation-duration: .2s; }
@media (prefers-reduced-motion: reduce) {
  .btn.btn-theme-toggle { transition: none; }
}
/* Printed reports keep a white paper background even when the screen is dark. */
@media print {
  html[data-theme] {
    color-scheme: light;
    --body-bg: #fff;
    --card-bg: #fff;
    --border: #c6d6ea;
    --text: #14253b;
    --text-muted: #4c607a;
    --surface: #fff;
    --surface-soft: #f8fafc;
    --surface-hover: #edf3fb;
    --line: #c6d6ea;
    --ink: #14253b;
    --ink-muted: #4c607a;
    --ink-accent: #0d4d9a;
    --tone-success-text: #047857;
    --tone-success-bg: #ecfdf5;
    --tone-warning-text: #92400e;
    --tone-warning-bg: #fffbeb;
    --report-warning-accent: #986344;
    --report-pending-bg: #f3f7fc;
    --tone-danger-text: #991b1b;
    --tone-danger-bg: #fef2f2;
    --tone-purple-text: #6d28d9;
    --tone-purple-bg: #f5f3ff;
  }
  body { background-color: #fff !important; color: #14253b !important; }
  html[data-theme] .modern-login-page #m_login { background: #fff !important; }
  [data-theme-toggle] { display: none !important; }
}
