/* Screen palettes only: print/PDF keeps the original colours through var() fallbacks. */
@media screen {
  :root, :root[data-ui-theme="blue"] {
    --ui-page: #e8eef3;
    --ui-surface: #f3f6f9;
    --ui-input: #f8fafc;
    --ui-heading: #dee7ef;
    --ui-nav: #e4ecf3;
    --ui-row: #eaf0f5;
    --ui-border: #c8d3df;
    --ui-control: #73849a;
    --ui-muted: #53647a;
    --ui-placeholder: #64748b;
    --ui-active: #d2e2f3;
  }
  :root[data-ui-theme="sage"] {
    --ui-page: #e8efeb; --ui-surface: #f2f6f3; --ui-input: #f8faf8;
    --ui-heading: #dfe9e3; --ui-nav: #e3ece6; --ui-row: #eaf0ec;
    --ui-border: #c4d1c8; --ui-control: #6f8578; --ui-muted: #506258;
    --ui-placeholder: #62736a; --ui-active: #d8e7dd;
  }
  :root[data-ui-theme="neutral"] {
    --ui-page: #eceeef; --ui-surface: #f5f6f7; --ui-input: #fafafb;
    --ui-heading: #e2e5e8; --ui-nav: #e7eaed; --ui-row: #edf0f2;
    --ui-border: #cbd0d6; --ui-control: #78828e; --ui-muted: #586474;
    --ui-placeholder: #697582; --ui-active: #dce4ee;
  }
  :root[data-ui-theme="sand"] {
    --ui-page: #efece6; --ui-surface: #f7f5f0; --ui-input: #fbfaf7;
    --ui-heading: #e8e2d7; --ui-nav: #eae5dc; --ui-row: #f0ede6;
    --ui-border: #d3cbbd; --ui-control: #897d6b; --ui-muted: #655f54;
    --ui-placeholder: #756d60; --ui-active: #e4ded0;
  }
  :root[data-ui-theme="lavender"] {
    --ui-page: #eeebf3; --ui-surface: #f6f4f9; --ui-input: #faf9fc;
    --ui-heading: #e4deed; --ui-nav: #e9e3f0; --ui-row: #f0ecf5;
    --ui-border: #d1c8dd; --ui-control: #877995; --ui-muted: #645a73;
    --ui-placeholder: #756a83; --ui-active: #e0d8ec;
  }
  :root[data-ui-theme] {
    --ui-text: #0f172a;
    --ui-link: #1d4ed8;
    --ui-grand-total: #dcf0df;
    --ui-radius: 10px;
    --ui-shadow: 0 3px 12px rgba(15, 23, 42, .035);
    /* High-specificity aliases prevent module :root declarations resetting the palette. */
    --nl-bg: var(--ui-page) !important;
    --nl-card: var(--ui-surface) !important;
    --nl-surface: var(--ui-surface) !important;
    --nl-surface-2: var(--ui-heading) !important;
    --nl-border: var(--ui-border) !important;
    --nl-muted: var(--ui-muted) !important;
    --nl-text: var(--ui-text) !important;
    --nl-text-2: var(--ui-muted) !important;
    --nl-text-3: var(--ui-muted) !important;
    --nl-brand: #2563eb !important;
    --nl-brand-2: var(--ui-link) !important;
    --nl-success: #15803d !important;
    --nl-radius: var(--ui-radius) !important;
    --nl-radius-sm: 8px !important;
    --nl-shadow: var(--ui-shadow) !important;
    --nl-shadow-sm: var(--ui-shadow) !important;
  }
  html[data-ui-theme] body { color: var(--ui-text); }
  html[data-ui-theme] .nl-app,
  html[data-ui-theme] .nl-app #wrapper_all { background: var(--ui-page); }
  html[data-ui-theme] .form-control,
  html[data-ui-theme] .nl-cselect-btn,
  html[data-ui-theme] .nl-date-trigger,
  html[data-ui-theme] .select2-container--default .select2-selection {
    background-color: var(--ui-input);
    border-color: var(--ui-control);
    color: var(--ui-text);
  }
  html[data-ui-theme] input::placeholder,
  html[data-ui-theme] textarea::placeholder { color: var(--ui-placeholder); opacity: 1; }
  html[data-ui-theme] .help-block,
  html[data-ui-theme] .text-muted,
  html[data-ui-theme] .nl-help,
  html[data-ui-theme] .nl-subtitle { color: var(--ui-muted); }
  html[data-ui-theme] .modal-content,
  html[data-ui-theme] .swal2-popup,
  html[data-ui-theme] .dropdown-menu,
  html[data-ui-theme] .ui-datepicker,
  html[data-ui-theme] .ui-dialog { background: var(--ui-surface); color: var(--ui-text); border-color: var(--ui-border); }
  html[data-ui-theme] .modal-header,
  html[data-ui-theme] .modal-footer { background: var(--ui-heading); border-color: var(--ui-border); }
  /* Shared modal colours: legacy dark headers must not leave white titles on the light theme. */
  html[data-ui-theme] .modal .modal-header,
  html[data-ui-theme] .modal .modal-title,
  html[data-ui-theme] .modal .modal-header :is(h1, h2, h3, h4, h5, h6) {
    color: var(--ui-text) !important;
  }
  html[data-ui-theme] .modal .modal-title :is(span, i) { color: inherit !important; }
  html[data-ui-theme] .modal .modal-header .close,
  html[data-ui-theme] .modal .modal-header .close :is(span, i) {
    color: var(--ui-muted) !important; text-shadow: none; opacity: 1;
  }
  html[data-ui-theme] .btn-default { background: var(--ui-input); color: var(--ui-muted); border-color: var(--ui-control); text-shadow: none; }
  html[data-ui-theme] .btn-success { background: #15803d; border-color: #15803d; color: #fff; }
  html[data-ui-theme] .nl-app a:not(.btn):not(.nl-cselect-item):not(.nl-export-menu-item) { color: var(--ui-link); }
  /* Active pagination must win over the shared blue link colour, including focus/hover. */
  html[data-ui-theme] .pagination > .active > :is(a, span),
  html[data-ui-theme] .pagination > .active > :is(a, span):is(:hover, :focus),
  html[data-ui-theme] .nl-page-number.active {
    color: #fff !important; background: #2563eb !important; border-color: #2563eb !important;
  }
  html[data-ui-theme] .pagination > li:not(.active):not(.disabled) > :is(a, span):is(:hover, :focus) {
    color: var(--ui-link) !important; background: var(--ui-active) !important;
  }

  /* Appearance chooser: a single header action, previews, and immediate selection. */
  .ui-appearance-toggle {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    background: var(--ui-input); color: var(--ui-muted); border: 1px solid var(--ui-control);
    border-radius: 8px; padding: 8px; width: 36px; min-height: 36px; flex: 0 0 auto; cursor: pointer;
    font-family: inherit; font-size: 12px; font-weight: 600; line-height: 1.2; white-space: nowrap; box-shadow: none;
  }
  .ui-appearance-toggle svg { width: 18px; height: 18px; flex: 0 0 auto; }
  .ui-appearance-menu-label, .ui-theme-menu-item { display: none; }
  @media (max-width: 768px) {
    .ui-theme-menu-item { display: block; }
    html[data-ui-theme] .nl-app #top_header .ui-theme-menu-item .ui-appearance-toggle {
      display: flex; width: 100%; min-height: 40px; margin: 0; padding: 10px 12px;
      border: 0; border-radius: 11px; background: transparent; box-shadow: none;
      justify-content: flex-start; gap: 10px; color: var(--ui-text); font-size: 12px;
    }
    html[data-ui-theme] .nl-app #top_header .ui-theme-menu-item .ui-appearance-toggle:hover { background: var(--ui-active); }
    html[data-ui-theme] .nl-app #top_header .ui-theme-menu-item .ui-appearance-toggle i { font-size: 18px; line-height: 1; }
    .ui-theme-menu-item .ui-appearance-toggle > .ui-appearance-menu-label { display: inline; }
  }
  .ui-appearance-toggle:hover { color: var(--ui-link); background: var(--ui-heading); }
  html[data-ui-theme] .nl-app #top_header .ui-appearance-shortcut {
    width: 44px; height: 44px; padding: 0; border: 0;
    background: transparent; color: #2563eb; border-radius: 12px;
  }
  html[data-ui-theme] .nl-app #top_header .ui-appearance-shortcut:hover { background: var(--ui-active); color: var(--ui-link); }
  .ui-appearance-toggle:focus-visible, .ui-theme-option:focus-visible,
  .ui-theme-close:focus-visible, .ui-theme-reset:focus-visible { outline: 2px solid #2563eb; outline-offset: 3px; }
  .ui-appearance-toggle.ui-appearance-floating { position: fixed; right: 16px; top: 16px; z-index: 1250; box-shadow: var(--ui-shadow); }
  html[data-ui-theme] .nl-landing-nav-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
  .ui-theme-dialog {
    width: min(460px, calc(100vw - 28px)); max-height: calc(100dvh - 32px);
    padding: 0; border: 1px solid var(--ui-border); border-radius: 14px;
    background: var(--ui-surface); color: var(--ui-text); box-shadow: 0 20px 70px #0f172a40;
    overflow: auto; font: 14px/1.5 Inter, "Segoe UI", Arial, sans-serif;
  }
  .ui-theme-dialog::backdrop { background: #0f172a66; }
  .ui-theme-dialog:not([open]) { display: none; }
  .ui-theme-head { padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--ui-border); background: var(--ui-heading); }
  .ui-theme-head h2 { font-size: 17px; line-height: 1.3; margin: 0; font-weight: 650; }
  .ui-theme-close { border: 0; background: transparent; color: var(--ui-muted); cursor: pointer; font: 24px/1 sans-serif; padding: 4px 8px; }
  .ui-theme-intro { color: var(--ui-muted); margin: 0; padding: 14px 20px 10px; font-size: 12px; }
  .ui-theme-options { padding: 0 20px 16px; display: grid; gap: 8px; }
  .ui-theme-option { border: 1px solid var(--ui-border); background: var(--ui-input); color: var(--ui-text); border-radius: 9px; padding: 11px 12px; display: flex; align-items: center; gap: 12px; text-align: left; cursor: pointer; width: 100%; font: inherit; }
  .ui-theme-option[aria-checked="true"] { border-color: #2563eb; box-shadow: 0 0 0 1px #2563eb; }
  .ui-theme-swatches { display: flex; overflow: hidden; border: 1px solid #64748b66; border-radius: 6px; flex: 0 0 auto; }
  .ui-theme-swatches i { display: block; width: 19px; height: 28px; }
  .ui-theme-name { flex: 1; font-weight: 600; font-size: 13px; }
  .ui-theme-name small { display: block; font-size: 11px; color: var(--ui-muted); font-weight: 400; }
  .ui-theme-check { color: #15803d; font-size: 19px; font-weight: 700; opacity: 0; }
  .ui-theme-option[aria-checked="true"] .ui-theme-check { opacity: 1; }
  .ui-theme-footer { padding: 12px 20px; border-top: 1px solid var(--ui-border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .ui-theme-status { font-size: 11px; color: var(--ui-muted); }
  .ui-theme-reset { cursor: pointer; padding: 7px 10px; font-family: inherit; font-size: 12px; font-weight: 600; line-height: 1.3; border-radius: 7px; border: 1px solid var(--ui-control); background: var(--ui-input); color: var(--ui-muted); }
  @media (max-width: 767px) {
    .ui-appearance-toggle { padding: 7px; min-width: 34px; }
    .ui-appearance-toggle > span { display: none; }
  }
}
@media print { .ui-appearance-toggle, .ui-theme-dialog { display: none !important; } }
