/* Screen-only dark palette; paper exports and media retain their original colours. */
:root {
  --rd-canvas: #f8fafc; --rd-surface: #fff; --rd-surface-rgb: 255 255 255;
  --rd-raised: #f1f5f9; --rd-border: #cbd5e1; --rd-text: #0f172a;
  --rd-muted: #475569; --rd-focus: #2563eb;
}
.app-top-bar { flex-wrap: wrap; }
.rd-theme-switcher { display: inline-flex; align-items: center; gap: .5rem; max-width: 100%; flex: 0 0 auto; font-size: .875rem; color: var(--rd-text); }
.rd-theme-switcher[hidden] { display: none; }
.rd-theme-switcher select { min-height: 2.5rem; max-width: 100%; padding: .375rem .5rem; border: 1px solid var(--rd-border); border-radius: .5rem; background: var(--rd-surface); color: var(--rd-text); font: inherit; }
.rd-theme-switcher select:focus-visible { outline: 2px solid var(--rd-focus); outline-offset: 3px; }
.rd-theme-fallback { display: flex; justify-content: flex-end; padding: .75rem; grid-column: 1 / -1; }
@media screen {
  html[data-rd-theme="light"] { color-scheme: light; }
  html[data-rd-theme="dark"] {
    color-scheme: dark;
    --rd-canvas: #0f172a; --rd-surface: #1e293b; --rd-surface-rgb: 30 41 59;
    --rd-raised: #334155; --rd-border: #64748b; --rd-text: #f1f5f9;
    --rd-muted: #cbd5e1; --rd-focus: #93c5fd;
    background-color: var(--rd-canvas); color: var(--rd-text);
  }
  html[data-rd-theme="dark"] body { background-color: var(--rd-canvas); background-image: none; color: var(--rd-text); }
  html[data-rd-theme="dark"] :where(input:not([type]), input[type="text"], input[type="search"], input[type="email"], input[type="url"], input[type="tel"], input[type="password"], input[type="number"], input[type="date"], input[type="time"], input[type="datetime-local"], textarea, select) { background-color: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme="dark"] :where(input, textarea)::placeholder { color: var(--rd-muted); opacity: 1; }
  html[data-rd-theme="dark"] :where(input, select, textarea):disabled { color: var(--rd-muted); background-color: var(--rd-raised); }
  html[data-rd-theme="dark"] :where(input[type="checkbox"], input[type="radio"], input[type="range"]) { accent-color: #60a5fa; }
  html[data-rd-theme="dark"] :where(a, button, input, textarea, select, [tabindex]):focus-visible { outline: 2px solid var(--rd-focus); outline-offset: 2px; }

  /* Exact utilities: do not invert media or rewrite style attributes. */
  html[data-rd-theme="dark"] :is(.bg-white, .hover\:bg-white:hover) { background-color: rgb(var(--rd-surface-rgb) / var(--tw-bg-opacity, 1)); }
  html[data-rd-theme="dark"] :is(.bg-slate-50, .bg-gray-50, .bg-zinc-50, .bg-neutral-50, .bg-stone-50) { background-color: var(--rd-canvas); }
  html[data-rd-theme="dark"] :is(.bg-slate-100, .bg-gray-100, .bg-zinc-100, .bg-neutral-100, .bg-stone-100) { background-color: var(--rd-surface); }
  html[data-rd-theme="dark"] :is(.bg-slate-200, .bg-gray-200, .bg-zinc-200, .bg-neutral-200, .bg-stone-200, .bg-slate-300, .bg-gray-300) { background-color: var(--rd-raised); }
  html[data-rd-theme="dark"] :is(.hover\:bg-slate-50:hover, .hover\:bg-slate-100:hover, .hover\:bg-slate-200:hover, .hover\:bg-gray-50:hover, .hover\:bg-gray-100:hover, .hover\:bg-gray-200:hover) { background-color: var(--rd-raised); }
  html[data-rd-theme="dark"] :is(.text-slate-400, .text-slate-500, .text-slate-600, .text-gray-400, .text-gray-500, .text-gray-600, .text-zinc-400, .text-zinc-500, .text-zinc-600, .text-neutral-500, .text-neutral-600, .text-stone-500, .text-stone-600) { color: var(--rd-muted); }
  html[data-rd-theme="dark"] :is(.text-black, .text-slate-700, .text-slate-800, .text-slate-900, .text-slate-950, .text-gray-700, .text-gray-800, .text-gray-900, .text-gray-950, .text-zinc-700, .text-zinc-800, .text-zinc-900, .text-neutral-700, .text-neutral-800, .text-neutral-900, .text-stone-700, .text-stone-800, .text-stone-900, .hover\:text-slate-700:hover, .hover\:text-slate-900:hover, .hover\:text-gray-700:hover, .hover\:text-gray-900:hover) { color: var(--rd-text); }
  html[data-rd-theme="dark"] :is(.border-slate-100, .border-slate-200, .border-slate-300, .border-slate-400, .border-gray-100, .border-gray-200, .border-gray-300, .border-gray-400, .border-zinc-200, .border-zinc-300, .border-neutral-200, .border-neutral-300, .border-stone-200, .border-stone-300) { border-color: var(--rd-border); }
  html[data-rd-theme="dark"] :is(.divide-slate-100, .divide-slate-200, .divide-gray-100, .divide-gray-200) > :not([hidden]) ~ :not([hidden]) { border-color: var(--rd-border); }
  html[data-rd-theme="dark"] :is(.ring-slate-100, .ring-slate-200, .ring-slate-200\/70, .ring-gray-200) { --tw-ring-color: var(--rd-border); }
  html[data-rd-theme="dark"] :is(.bg-white\/50) { background-color: rgb(var(--rd-surface-rgb) / .5); }
  html[data-rd-theme="dark"] :is(.bg-white\/60) { background-color: rgb(var(--rd-surface-rgb) / .6); }
  html[data-rd-theme="dark"] .bg-white\/70 { background-color: rgb(var(--rd-surface-rgb) / .7); }
  html[data-rd-theme="dark"] .bg-white\/75 { background-color: rgb(var(--rd-surface-rgb) / .75); }
  html[data-rd-theme="dark"] :is(.bg-white\/80) { background-color: rgb(var(--rd-surface-rgb) / .8); }
  html[data-rd-theme="dark"] :is(.bg-white\/90) { background-color: rgb(var(--rd-surface-rgb) / .9); }
  html[data-rd-theme="dark"] :is(.bg-white\/95) { background-color: rgb(var(--rd-surface-rgb) / .95); }

  /* Semantic badges keep their hues; saturated actions and white text are untouched. */
  html[data-rd-theme="dark"] :is(.bg-blue-50, .bg-blue-100, .bg-blue-200, .bg-sky-50, .bg-sky-100, .hover\:bg-blue-50:hover, .hover\:bg-blue-100:hover) { background-color: #172e52; }
  html[data-rd-theme="dark"] :is(.text-blue-500, .text-blue-600, .text-blue-700, .text-blue-800, .text-blue-900, .text-sky-600, .text-sky-700, .text-sky-800, .hover\:text-blue-700:hover, .hover\:text-blue-800:hover) { color: #bfdbfe; }
  html[data-rd-theme="dark"] :is(.bg-indigo-50, .bg-indigo-100, .bg-indigo-200, .bg-violet-50, .bg-violet-100, .bg-purple-50, .bg-purple-100, .hover\:bg-indigo-50:hover, .hover\:bg-indigo-100:hover) { background-color: #27264f; }
  html[data-rd-theme="dark"] :is(.text-indigo-500, .text-indigo-600, .text-indigo-700, .text-indigo-800, .text-indigo-900, .text-violet-600, .text-violet-700, .text-purple-600, .text-purple-700, .text-purple-800) { color: #ddd6fe; }
  html[data-rd-theme="dark"] :is(.bg-green-50, .bg-green-100, .bg-green-200, .bg-emerald-50, .bg-emerald-100, .bg-emerald-200, .bg-teal-50, .bg-teal-100, .hover\:bg-green-50:hover, .hover\:bg-green-100:hover, .hover\:bg-emerald-50:hover) { background-color: #153d35; }
  html[data-rd-theme="dark"] :is(.text-green-500, .text-green-600, .text-green-700, .text-green-800, .text-green-900, .text-emerald-500, .text-emerald-600, .text-emerald-700, .text-emerald-800, .text-emerald-900, .text-teal-600, .text-teal-700) { color: #a7f3d0; }
  html[data-rd-theme="dark"] :is(.bg-yellow-50, .bg-yellow-100, .bg-yellow-200, .bg-amber-50, .bg-amber-100, .bg-amber-200, .bg-orange-50, .bg-orange-100, .hover\:bg-yellow-50:hover, .hover\:bg-amber-50:hover) { background-color: #49321b; }
  html[data-rd-theme="dark"] :is(.text-yellow-500, .text-yellow-600, .text-yellow-700, .text-yellow-800, .text-yellow-900, .text-amber-500, .text-amber-600, .text-amber-700, .text-amber-800, .text-amber-900, .text-orange-500, .text-orange-600, .text-orange-700, .text-orange-800) { color: #fde68a; }
  html[data-rd-theme="dark"] :is(.bg-red-50, .bg-red-100, .bg-red-200, .bg-rose-50, .bg-rose-100, .bg-pink-50, .bg-pink-100, .hover\:bg-red-50:hover, .hover\:bg-red-100:hover, .hover\:bg-rose-50:hover) { background-color: #4b2529; }
  html[data-rd-theme="dark"] :is(.text-red-500, .text-red-600, .text-red-700, .text-red-800, .text-red-900, .text-rose-500, .text-rose-600, .text-rose-700, .text-rose-800, .text-pink-600, .text-pink-700) { color: #fecaca; }

  /* Vendor surfaces and menus, including body-portaled dropdowns. */
  html[data-rd-theme="dark"] .dataTables_wrapper :is(.dataTables_length, .dataTables_filter, .dataTables_info, .dataTables_processing, .dataTables_paginate) { color: var(--rd-text); }
  html[data-rd-theme="dark"] table.dataTable tbody tr:not([class*="bg-"]):not([style*="background"]) { background-color: var(--rd-surface); color: var(--rd-text); }
  html[data-rd-theme="dark"] table.dataTable :is(thead, tfoot) { background-color: var(--rd-raised); color: var(--rd-text); }
  html[data-rd-theme="dark"] table.dataTable :is(th, td) { border-color: var(--rd-border); }
  html[data-rd-theme="dark"] table.dataTable:is(.stripe, .display) tbody tr.odd:not([class*="bg-"]):not([style*="background"]) { background-color: var(--rd-canvas); }
  html[data-rd-theme="dark"] table.dataTable:is(.hover, .display) tbody tr:hover:not([class*="bg-"]):not([style*="background"]) { background-color: var(--rd-raised); }
  html[data-rd-theme="dark"] .dataTables_wrapper .dataTables_processing { background: var(--rd-surface); }
  /* DataTables itself marks pagination colours important. */
  html[data-rd-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button { color: var(--rd-text) !important; }
  html[data-rd-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button:is(.current, :hover) { background: var(--rd-raised); border-color: var(--rd-border); color: var(--rd-text) !important; }
  html[data-rd-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.disabled { color: var(--rd-muted) !important; }
  html[data-rd-theme="dark"] :is(.ui-widget-content, .ui-widget-header) { background: var(--rd-surface); border-color: var(--rd-border); color: var(--rd-text); }
  html[data-rd-theme="dark"] .ui-widget-content a { color: #93c5fd; }
  html[data-rd-theme="dark"] :is(.ui-state-default, .ui-state-hover, .ui-state-focus) { background: var(--rd-raised); border-color: var(--rd-border); color: var(--rd-text); }
  html[data-rd-theme="dark"] .ui-menu .ui-state-active { background: #1d4ed8; border-color: #93c5fd; color: #fff; }
  html[data-rd-theme="dark"] .select2-container--default :is(.select2-selection--single, .select2-selection--multiple), html[data-rd-theme="dark"] .select2-dropdown { background-color: var(--rd-surface); border-color: var(--rd-border); color: var(--rd-text); }
  html[data-rd-theme="dark"] .select2-container--default :is(.select2-selection__rendered, .select2-selection__placeholder, .select2-selection__clear, .select2-selection__choice__remove) { color: var(--rd-text); }
  html[data-rd-theme="dark"] .select2-container--default .select2-selection__choice { background: var(--rd-raised); border-color: var(--rd-border); color: var(--rd-text); }
  html[data-rd-theme="dark"] .select2-container--default .select2-results__option[aria-selected="true"] { background: var(--rd-raised); }
  html[data-rd-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected] { background: #1d4ed8; color: #fff; }
}
@media print {
  html[data-rd-theme] { color-scheme: light; }
  .rd-theme-switcher, .rd-theme-fallback { display: none !important; }
}
