/* =========================================================================
   GENESIS DESIGN SYSTEM v2  (spec: .agents/team/ux-developer/UX_DESIGN_SYSTEM.md)

   v2 is global: _Layout, _AuthLayout and the standalone pages put class="ds2"
   on <body>, so every rule below applies app-wide (modals and the backdrop
   included). Every rule is still scoped under .ds2. Loaded after site.css;
   where site.css or Bootstrap use !important, the matching rule here does too.
   Light and dark: the tokens switch on [data-theme="dark"] (set on <html>).

   COMPONENT INDEX (use these before writing page CSS)
   Layout
     .page-header        Title row: .page-heading (h1 + one muted line) and .page-actions (buttons)
     .surface            Bordered white section (24px padding). .surface-flush = no padding
     .surface-head       Header row inside a surface: h2 left, actions right, rule below
     .surface-body       Padded body when the surface also has a .surface-head or a table
     .toolbar            Row of buttons/controls that wraps. .toolbar-divided adds a top rule
     .toolbar-spacer     Pushes the following toolbar items to the right
     .filter-bar         Filters row: .filter-field (label + control), .filter-actions (buttons)
     .tabs               Underline tabs (also applied to Bootstrap .nav-tabs). Active: .active / aria-selected
     .prose              Caps prose at ~75 characters
   Figures and data
     .figures            Summary row in one bordered surface: .figure > .figure-label + .figure-value (+ .figure-note)
     .kv                 Key/value list: <dl class="kv"><div><dt/><dd/></div></dl>
     .table-wrap         Table container: horizontal scroll, rule border, radius. .table-wrap-tall = 70vh + sticky
     .num                Numeric cell or figure: right-aligned, tabular digits, no wrap
     .col-sticky         Sticky first column inside .table-wrap (put on th/td)
     .row-total          Totals row inside tbody (tfoot rows get this automatically)
     .table-stack        Phones: table becomes one block per row; labels from td[data-label]
                         (.stack-title = the row heading cell, .stack-hide = hidden on phones).
                         Example of the nth-child variant (no data-label): .ds2-stack on Run Payrun
     .empty-state        Centered "nothing here" block: .empty-state-title, text, optional actions
   Status and tags
     .status             Status word with an 8px dot. .status-ok / -warn / -bad / -info (default muted)
     .tag                Calm 4px-radius tag (category labels). .tag-ok / -warn / -bad / -info
     .badge              Bootstrap badges are restyled as .tag automatically (bg-* picks the colour)
     .text-ink / .text-ok / .text-warn / .text-bad   Token text colours
   Calendar
     .cal-wrap           Horizontal-scroll wrapper for a month grid
     .cal-grid           7-column grid; .cal-head = weekday header cell; .cal-cell = day cell
     .cal-day            Day number inside a cell. Cell modifiers: .is-today .is-outside .is-weekend
                         .is-holiday .is-ok .is-warn .is-bad (3px left status bar). button/a.cal-cell = clickable
   Shell and auth (used by the layouts; pages rarely need them)
     .sidebar / .topbar / .user-menu-toggle / .avatar / .impersonation-banner
     .auth-page (body) .auth-shell(-wide) .auth-brand .auth-card .auth-lead .auth-foot
   Pilot helpers kept for Run Payrun (prefer the names above for new work)
     .ds2-page-header .ds2-page-heading .ds2-page-actions .ds2-toolbar .ds2-figures .ds2-figure
     .ds2-figure-label .ds2-figure-value .ds2-kv .ds2-status(.is-ok/.is-warn/.is-bad) .ds2-status-list
     .ds2-card-ok .ds2-card-bad .ds2-alert-title .ds2-small .ds2-prose .ds2-count .ds2-code .ds2-name
     .ds2-key .ds2-text-bad .ds2-required .ds2-field-date .ds2-check-panel .ds2-rows-blocking .ds2-empty
     .ds2-cell-notes .ds2-stack

   Neutralised app-wide (no need to remove from markup, but do not add new uses):
     text-uppercase, letter-spacing, shadow / shadow-sm / shadow-lg, rounded-3/4/5, rounded-pill,
     bg-gradient and inline gradients, hover lifts, fw-bold (600), fs-7/fs-8/text-xs (13px floor),
     Bootstrap colour utilities (primary/info = blue, success/warning/danger = status tokens),
     coloured card/modal headers (white with ink title), btn-success/-info/-warning/-light/-dark.

   Contents
     1. Tokens (light + dark) and Bootstrap colour mapping
     2. Base: page, type, headings, links, focus, helpers
     3. Neutralise Bootstrap / v1 noise
     4. Layout components: page header, surface, cards, toolbar, filter bar, empty state
     5. Figures, key/value list, status, tags and badges
     6. Buttons
     7. Data tables
     8. Alerts
     9. Forms
    10. Modals
    11. Navigation: tabs, pills, list group, pagination, breadcrumb, dropdown, accordion,
        progress, toast, tooltip, popover, offcanvas
    12. Calendar
    13. App shell: sidebar, top bar, user menu, impersonation banner
    14. Auth pages (Login, Logout, notice acknowledgement)
    15. Phones and small screens
    16. Reduced motion
   ========================================================================= */

/* 1. Tokens ------------------------------------------------------------- */
.ds2 {
  --ink: #0F2A4A;
  --text: #26374D;
  --muted: #5B6B80;
  --blue: #1D5FD1;
  --blue-hover: #174DAA;
  --on-blue: #FFFFFF;
  --blue-tint: #EAF1FB;
  --row-hover: rgba(234, 241, 251, 0.5);
  --surface: #FFFFFF;
  --page: #F6F8FB;
  --rule: #D9E0EA;
  --ok: #1F8A4C;
  --warn: #B26B00;
  --bad: #C2362F;
  --ok-tint: rgba(31, 138, 76, 0.08);
  --warn-tint: rgba(178, 107, 0, 0.08);
  --bad-tint: rgba(194, 54, 47, 0.08);
  --info-tint: rgba(29, 95, 209, 0.08);
  --neutral-tint: rgba(15, 42, 74, 0.05);
  --on-solid: #FFFFFF; /* text on a solid status fill */

  --font: 'IBM Plex Sans', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 6px;
  --shadow-float: 0 8px 24px rgba(15, 42, 74, 0.12);
  --motion-fast: 120ms;
  --motion-open: 200ms;

  /* Bootstrap 5.1 colour utilities (bg-*, text-*, border-*, bg-opacity-*) read these */
  --bs-primary: #1D5FD1;
  --bs-primary-rgb: 29, 95, 209;
  --bs-info-rgb: 29, 95, 209;
  --bs-success-rgb: 31, 138, 76;
  --bs-warning-rgb: 178, 107, 0;
  --bs-danger-rgb: 194, 54, 47;
  --bs-secondary-rgb: 91, 107, 128;
  --bs-dark-rgb: 15, 42, 74;
  --bs-light-rgb: 246, 248, 251;
  --bs-body-rgb: 38, 55, 77;
  --bs-gradient: none;
}

[data-theme="dark"] .ds2 {
  --ink: #E6EDF7;
  --text: #C9D4E3;
  --muted: #8FA0B5;
  --blue: #5B8FE8;
  --blue-hover: #7AA6EE;
  --on-blue: #0A131E; /* white on #5B8FE8 is below AA; dark text keeps primary buttons readable */
  --blue-tint: #17263B;
  --row-hover: rgba(23, 38, 59, 0.5);
  --surface: #0F1A28;
  --page: #0A131E;
  --rule: #24364D;
  --ok: #4CC07F;
  --warn: #E0A043;
  --bad: #EF6A63;
  --ok-tint: rgba(76, 192, 127, 0.08);
  --warn-tint: rgba(224, 160, 67, 0.08);
  --bad-tint: rgba(239, 106, 99, 0.08);
  --info-tint: rgba(91, 143, 232, 0.1);
  --neutral-tint: rgba(230, 237, 247, 0.06);
  --on-solid: #0A131E;
  --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.45);

  --bs-primary: #5B8FE8;
  --bs-primary-rgb: 91, 143, 232;
  --bs-info-rgb: 91, 143, 232;
  --bs-success-rgb: 76, 192, 127;
  --bs-warning-rgb: 224, 160, 67;
  --bs-danger-rgb: 239, 106, 99;
  --bs-secondary-rgb: 143, 160, 181;
  --bs-body-rgb: 201, 212, 227;
}

/* 2. Base --------------------------------------------------------------- */
.ds2 {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
}

body.ds2 {
  background-color: var(--page);
  color: var(--text);
}

.ds2 :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6) {
  font-family: var(--font);
  font-weight: 600;
  color: var(--ink);
  letter-spacing: normal;
  text-transform: none;
  margin-top: 0;
}

.ds2 :is(h1, .h1) { font-size: 24px; line-height: 1.25; }
.ds2 :is(h2, .h2) { font-size: 18px; line-height: 1.35; margin-bottom: 0; }
.ds2 :is(h3, .h3) { font-size: 15px; line-height: 1.4; margin-bottom: 0; }
.ds2 :is(h4, .h4, h5, .h5) { font-size: 15px; line-height: 1.4; }
.ds2 :is(h6, .h6) { font-size: 14px; line-height: 1.4; }

.ds2 :is(.display-1, .display-2, .display-3, .display-4, .display-5, .display-6) {
  font-size: 24px;
  line-height: 1.25;
  font-weight: 600;
  color: var(--ink);
}

.ds2 .lead { font-size: 16px; font-weight: 400; color: var(--text); }

.ds2 :is(small, .small) { font-size: 13px; }

.ds2 p { max-width: none; }

.ds2 hr {
  color: var(--rule);
  background-color: var(--rule);
  opacity: 1;
}

.ds2 code {
  color: var(--ink);
  background-color: var(--neutral-tint);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 13px;
  word-break: break-all;
}

/* Links: low specificity (0,1,1) so component rules (dropdown items, tabs, nav) win */
.ds2 a:where(:not(.btn)) {
  color: var(--blue);
  transition: color var(--motion-fast) ease;
}

.ds2 a:where(:not(.btn)):where(:hover) { color: var(--blue-hover); }

.ds2 a:focus-visible,
.ds2 button:focus-visible,
.ds2 [role="button"]:focus-visible,
.ds2 [tabindex]:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  box-shadow: none;
}

.ds2 .text-muted { color: var(--muted) !important; }
.ds2 .text-primary { color: var(--blue) !important; }
.ds2 .text-body { color: var(--text) !important; }
.ds2 .text-ink { color: var(--ink) !important; }
.ds2 .text-ok { color: var(--ok) !important; }
.ds2 .text-warn { color: var(--warn) !important; }
.ds2 .text-bad { color: var(--bad) !important; }

.ds2 :is(.ds2-small, .text-small) { font-size: 13px; line-height: 1.4; }
.ds2 :is(.ds2-prose, .prose) { max-width: 75ch; }
.ds2 .ds2-count { color: var(--muted); font-weight: 400; }
.ds2 .ds2-code { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ds2 .ds2-name { color: var(--ink); white-space: nowrap; }
.ds2 .ds2-key { color: var(--ink); font-weight: 600; }
.ds2 .ds2-text-bad { color: var(--bad); }
.ds2 .ds2-required { color: var(--bad); }

.ds2 .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 3. Neutralise Bootstrap / v1 noise ----------------------------------- */
/* Sentence case, no tracking */
.ds2 .text-uppercase {
  text-transform: none !important;
  letter-spacing: normal !important;
}

.ds2 :is(.tracking-wide, .tracking-wider, .tracking-widest, .tracking-tight, .ls-1, .ls-2),
.ds2 [style*="letter-spacing"] { letter-spacing: normal !important; }

.ds2 [style*="text-transform"] { text-transform: none !important; }

.ds2 :is(th, label, .form-label, .badge, .btn, .nav-link, .dropdown-header, .card-header, .modal-title) {
  letter-spacing: normal;
}

/* One family: catch inline font-family left on legacy markup */
.ds2 [style*="font-family"]:not(.fa):not(.fas):not(.far):not(.fab) { font-family: var(--font) !important; }

/* Weight: 600 is the heaviest face loaded */
.ds2 :is(.fw-bold, .fw-bolder, strong, b) { font-weight: 600 !important; }

/* Size floor: nothing below 13px */
.ds2 :is(.fs-7, .fs-8, .text-xs, .x-small) { font-size: 13px !important; }

/* Shadows: only floating elements keep one */
.ds2 :is(.shadow, .shadow-sm, .shadow-lg, .shadow-md, .shadow-none):not(.dropdown-menu):not(.modal-content):not(.toast):not(.popover):not(.offcanvas) {
  box-shadow: none !important;
}

.ds2 :is(.dropdown-menu, .modal-content, .toast, .popover):is(.shadow, .shadow-sm, .shadow-lg) {
  box-shadow: var(--shadow-float) !important;
}

/* Radii: 6px for containers and controls, 4px for tags */
.ds2 :is(.rounded-3, .rounded-4, .rounded-5, .rounded-pill):not(.badge):not(.tag) { border-radius: var(--radius) !important; }

/* Gradients */
.ds2 .bg-gradient { background-image: none !important; }

.ds2 [style*="gradient"] {
  background: var(--surface) !important;
  color: var(--ink) !important;
}

.ds2 [style*="gradient"] :is(.text-white, .text-light, .text-white-50, h1, h2, h3, h4, h5, h6),
.ds2 [style*="gradient"].text-white { color: var(--ink) !important; }

/* Hover lifts and scale */
.ds2 :is(.card, .btn, .stat-card, .glass-card, .hover-lift, .hover-scale, .transition-hover, .list-group-item):hover {
  transform: none !important;
}

.ds2 .card:hover { box-shadow: none !important; }

/* Coloured card / modal headers and footers become white with an ink title */
.ds2 :is(.card-header, .modal-header, .card-footer, .modal-footer)[class*="bg-"] {
  background-color: var(--surface) !important;
  background-image: none !important;
  color: var(--ink) !important;
}

.ds2 :is(.card-header, .modal-header) :is(.text-white, .text-light, .text-dark),
.ds2 :is(.card-header, .modal-header):is(.text-white, .text-light, .text-dark) { color: var(--ink) !important; }

.ds2 :is(.card-header, .modal-header) .text-white-50 { color: var(--muted) !important; }

.ds2 .btn-close.btn-close-white { filter: none; }
[data-theme="dark"] .ds2 .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* Solid status fills: readable text in both themes */
.ds2 :is(.bg-primary, .bg-success, .bg-danger, .bg-warning, .bg-info, .bg-secondary):not([class*="bg-opacity"]):not(.badge):is(.text-white, .text-dark) {
  color: var(--on-solid) !important;
}

/* 4. Layout components ------------------------------------------------- */
/* Page header: h1 + one muted line, actions right (wrap under the title on phones) */
.ds2 :is(.ds2-page-header, .page-header) {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 24px;
}

.ds2 :is(.ds2-page-heading, .page-heading) { flex: 1 1 320px; min-width: 0; }
.ds2 :is(.ds2-page-heading, .page-heading) h1 { margin: 0; }

.ds2 :is(.ds2-page-heading, .page-heading) p {
  margin: 4px 0 0;
  color: var(--muted);
  max-width: 75ch;
}

.ds2 :is(.ds2-page-actions, .page-actions, .ds2-toolbar, .toolbar) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.ds2 :is(.ds2-toolbar, .toolbar-divided) {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}

.ds2 .toolbar-spacer { flex: 1 1 auto; }

/* Surface: the plain bordered section */
.ds2 .surface {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

.ds2 .surface:last-child { margin-bottom: 0; }
.ds2 .surface-flush { padding: 0; }

.ds2 .surface-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--rule);
}

.ds2 .surface > .surface-head:first-child { margin: -24px -24px 24px; }
.ds2 .surface-flush > .surface-head:first-child { margin: 0; }
.ds2 .surface-head h2 { margin: 0; }
.ds2 .surface-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.ds2 .surface-body { padding: 24px; }

/* A table directly inside a flush surface: the surface draws the border */
.ds2 .surface-flush > .table-wrap { border: 0; border-radius: 0 0 var(--radius) var(--radius); }

/* Bootstrap cards = surfaces */
.ds2 .card {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: none;
  transition: none;
  transform: none;
}

.ds2 .card.border-0:not(.border-start):not(.border-top) { border: 1px solid var(--rule) !important; }

/* Left accent cards (border-start border-4 border-*): rule on the other three sides */
.ds2 .card.border-start {
  border-top: 1px solid var(--rule) !important;
  border-right: 1px solid var(--rule) !important;
  border-bottom: 1px solid var(--rule) !important;
}

.ds2 .card-header {
  background-color: var(--surface);
  border-bottom: 1px solid var(--rule);
  padding: 16px 24px;
  font-weight: 400;
  color: var(--ink);
}

.ds2 .card-header:first-child {
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
}

.ds2 .card-header :is(h1, h2, h3, h4, h5, h6, .card-title) { font-size: 18px; line-height: 1.35; margin-bottom: 0; }

.ds2 .card-body { padding: 24px; }
.ds2 .card-title { color: var(--ink); font-weight: 600; }
.ds2 .card-subtitle { color: var(--muted); }

.ds2 .card-footer {
  background-color: var(--surface);
  border-top: 1px solid var(--rule);
  padding: 12px 24px;
}

.ds2 .card-footer:last-child {
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
}

.ds2 .ds2-card-bad { border-left: 4px solid var(--bad); }
.ds2 .ds2-card-ok { border-left: 4px solid var(--ok); }

/* Filter bar: labels above controls, aligned on the bottom edge */
.ds2 .filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background-color: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.ds2 .filter-bar.filter-bar-plain { padding: 0; border: 0; background: none; }

.ds2 .filter-bar .filter-field {
  flex: 1 1 180px;
  max-width: 280px;
  min-width: 0;
}

.ds2 .filter-bar .filter-field-wide { flex-basis: 280px; max-width: 420px; }
.ds2 .filter-bar .form-label { margin-bottom: 4px; }

.ds2 .filter-bar .filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

/* Empty state */
.ds2 .empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}

.ds2 .empty-state > i,
.ds2 .empty-state .empty-state-icon {
  display: block;
  font-size: 24px;
  color: var(--muted);
  margin-bottom: 8px;
}

.ds2 .empty-state-title {
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.ds2 .empty-state p { max-width: 60ch; margin: 0 auto; }

.ds2 .empty-state :is(.toolbar, .page-actions) { justify-content: center; margin-top: 16px; }

/* 5. Figures, key/value list, status, tags ------------------------------ */
.ds2 :is(.ds2-figures, .figures) {
  display: flex;
  background-color: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.ds2 :is(.ds2-figure, .figures > .figure) {
  display: block;
  flex: 1 1 0;
  min-width: 0;
  padding: 12px 16px;
  margin: 0;
}

.ds2 :is(.ds2-figure + .ds2-figure, .figures > .figure + .figure) { border-left: 1px solid var(--rule); }

.ds2 :is(.ds2-figure-label, .figure-label) {
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.ds2 :is(.ds2-figure-value, .figure-value) {
  font-size: 24px;
  line-height: 1.25;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.ds2 .figure-note {
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
  margin-top: 2px;
}

.ds2 :is(.ds2-kv, .kv) {
  margin: 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.ds2 :is(.ds2-kv, .kv) > div {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px 16px;
  padding: 8px 12px;
}

.ds2 :is(.ds2-kv, .kv) > div + div { border-top: 1px solid var(--rule); }

.ds2 :is(.ds2-kv, .kv) dt {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}

.ds2 :is(.ds2-kv, .kv) dd {
  margin: 0;
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Status: a word in its status colour with an 8px dot */
.ds2 :is(.ds2-status, .status) {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 600;
  color: var(--muted);
}

.ds2 :is(.ds2-status, .status)::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
}

.ds2 :is(.ds2-status.is-ok, .status-ok) { color: var(--ok); }
.ds2 :is(.ds2-status.is-warn, .status-warn) { color: var(--warn); }
.ds2 :is(.ds2-status.is-bad, .status-bad) { color: var(--bad); }
.ds2 .status-info { color: var(--blue); }

.ds2 .ds2-status-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
}

/* Tags and Bootstrap badges: calm 4px tags, 8% tint + status text */
.ds2 :is(.tag, .badge) {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  position: static;
  padding: 2px 6px;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  white-space: nowrap;
  vertical-align: middle;
  border-radius: 4px !important;
  background-color: var(--neutral-tint);
  color: var(--text);
}

.ds2 .badge:empty { display: none; }

.ds2 .tag-info,
.ds2 .badge:is(.bg-primary, .bg-info, .bg-primary-subtle, .bg-info-subtle, .badge-soft-primary, .badge-soft-info, .bg-info-soft, .badge-segment-day) {
  background-color: var(--info-tint) !important;
  color: var(--blue) !important;
  border-color: transparent !important;
}

.ds2 .tag-ok,
.ds2 .badge:is(.bg-success, .bg-success-subtle, .badge-soft-success, .bg-success-soft) {
  background-color: var(--ok-tint) !important;
  color: var(--ok) !important;
  border-color: transparent !important;
}

.ds2 .tag-warn,
.ds2 .badge:is(.bg-warning, .bg-warning-subtle, .badge-soft-warning, .bg-warning-soft) {
  background-color: var(--warn-tint) !important;
  color: var(--warn) !important;
  border-color: transparent !important;
}

.ds2 .tag-bad,
.ds2 .badge:is(.bg-danger, .bg-danger-subtle, .badge-soft-danger, .bg-danger-soft) {
  background-color: var(--bad-tint) !important;
  color: var(--bad) !important;
  border-color: transparent !important;
}

.ds2 .badge:is(.bg-secondary, .bg-light, .bg-dark, .bg-white, .bg-secondary-subtle, .bg-light-subtle, .badge-soft-secondary, .bg-purple, .bg-purple-subtle, .badge-segment-night, .period-locked-badge) {
  background-color: var(--neutral-tint) !important;
  border-color: transparent !important;
}

.ds2 .badge:is(.bg-secondary, .bg-dark, .bg-purple):is(.text-white, .text-light) { color: var(--text) !important; }

/* A badge inside a button (counts) sits on the button colour */
.ds2 .btn .badge { background-color: var(--neutral-tint) !important; color: inherit !important; }

/* 6. Buttons ------------------------------------------------------------ */
.ds2 .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 16px;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.2;
  text-align: center;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background-image: none;
  box-shadow: none;
  transform: none;
  transition: color var(--motion-fast) ease, background-color var(--motion-fast) ease, border-color var(--motion-fast) ease;
}

.ds2 .btn:is(:hover, :focus, :active) {
  box-shadow: none;
  transform: none;
}

.ds2 .btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.ds2 .btn:disabled,
.ds2 .btn.disabled { opacity: 0.55; }

.ds2 .btn-sm {
  min-height: 32px;
  padding: 4px 12px;
  font-size: 14px;
  gap: 6px;
}

.ds2 .btn-xs {
  min-height: 28px;
  padding: 2px 8px;
  font-size: 13px;
  gap: 4px;
}

.ds2 .btn-lg {
  min-height: 44px;
  padding: 8px 20px;
  font-size: 16px;
}

/* Primary: solid blue. btn-success is an action too, so it is blue (green only describes status) */
.ds2 .btn-primary,
.ds2 .btn-primary:disabled,
.ds2 .btn-success,
.ds2 .btn-success:disabled {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--on-blue);
}

.ds2 :is(.btn-primary, .btn-success):is(:hover, :active, :focus-visible) {
  background: var(--blue-hover);
  border-color: var(--blue-hover);
  color: var(--on-blue);
}

/* Secondary: surface, rule border, ink text */
.ds2 .btn-secondary,
.ds2 .btn-outline-secondary,
.ds2 .btn-outline-primary,
.ds2 .btn-outline-success,
.ds2 .btn-outline-info,
.ds2 .btn-outline-warning,
.ds2 .btn-outline-dark,
.ds2 .btn-outline-light,
.ds2 .btn-outline-danger,
.ds2 .btn-light,
.ds2 .btn-info,
.ds2 .btn-warning,
.ds2 .btn-dark,
.ds2 .btn-secondary:disabled {
  background: var(--surface);
  border-color: var(--rule);
  color: var(--ink);
}

.ds2 .btn-outline-danger { color: var(--bad); }

.ds2 :is(.btn-secondary, .btn-outline-secondary, .btn-outline-primary, .btn-outline-success, .btn-outline-info,
         .btn-outline-warning, .btn-outline-dark, .btn-outline-light, .btn-light, .btn-info, .btn-warning, .btn-dark):is(:hover, :active) {
  background: var(--blue-tint);
  border-color: var(--rule);
  color: var(--ink);
}

.ds2 .btn-outline-danger:is(:hover, :active) {
  background: var(--bad-tint);
  border-color: var(--rule);
  color: var(--bad);
}

/* Danger: solid red only for destructive confirmations */
.ds2 .btn-danger,
.ds2 .btn-danger:disabled {
  background: var(--bad);
  border-color: var(--bad);
  color: #FFFFFF;
}

.ds2 .btn-danger:is(:hover, :active) {
  background: var(--bad);
  border-color: var(--bad);
  color: #FFFFFF;
  filter: brightness(0.92);
}

[data-theme="dark"] .ds2 .btn-danger,
[data-theme="dark"] .ds2 .btn-danger:is(:hover, :active, :disabled) { color: var(--on-solid); }

/* Link button: text only */
.ds2 .btn-link {
  background: transparent;
  border-color: transparent;
  color: var(--blue);
  padding-left: 8px;
  padding-right: 8px;
  text-decoration: none;
}

.ds2 .btn-link:is(:hover, :active) {
  color: var(--blue-hover);
  text-decoration: underline;
  background: transparent;
}

/* Toggle / pressed state (btn-check, .active) */
.ds2 .btn-check:checked + .btn,
.ds2 .btn-check:active + .btn,
.ds2 .btn.active:not(.btn-primary):not(.btn-success):not(.btn-danger) {
  background: var(--blue-tint);
  border-color: var(--blue);
  color: var(--ink);
}

.ds2 .btn-check:focus-visible + .btn {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  box-shadow: none;
}

/* Icon-only: 32px square. Give it aria-label and title. */
.ds2 .btn-icon {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  gap: 0;
  background: transparent;
  border-color: transparent;
  color: var(--ink);
}

.ds2 .btn-icon:is(:hover, :active) {
  background: var(--blue-tint);
  color: var(--ink);
}

.ds2 .btn-icon.btn-secondary { background: var(--surface); border-color: var(--rule); }

.ds2 .btn-close:focus { box-shadow: none; }

.ds2 .btn-close:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* 7. Data tables -------------------------------------------------------- */
/* .table-wrap is the table container. .table-responsive also scrolls (site.css) but has no border. */
.ds2 .table-wrap {
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background-color: var(--surface);
  -webkit-overflow-scrolling: touch;
}

/* Tall tables scroll vertically inside the wrapper so the sticky header and totals stay in view. */
.ds2 .table-wrap-tall { max-height: 70vh; }

.ds2 .table {
  --bs-table-bg: var(--surface);
  --bs-table-accent-bg: transparent;
  --bs-table-striped-bg: transparent;
  --bs-table-striped-color: var(--text);
  --bs-table-hover-bg: var(--row-hover);
  --bs-table-hover-color: var(--text);
  --bs-table-active-bg: var(--row-hover);
  --bs-table-active-color: var(--text);
  color: var(--text);
  border-color: var(--rule);
  font-size: 14px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  border-collapse: separate;
  border-spacing: 0;
  margin-bottom: 0;
}

.ds2 .table > :not(caption) > * > * {
  padding: 8px 12px;
  border-bottom: 1px solid var(--rule);
  color: inherit;
}

.ds2 .table-sm > :not(caption) > * > * { padding: 4px 8px; }

/* Bootstrap 5.1 draws a 2px currentColor rule between table sections */
.ds2 .table > :not(:first-child) { border-top: 0; }

.ds2 .table th,
.ds2 .table td {
  text-transform: none;
  letter-spacing: normal;
}

.ds2 .table > thead > tr > th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--blue-tint);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
  font-weight: 600;
  white-space: nowrap;
  vertical-align: bottom;
}

.ds2 .table > thead > tr > th[role="button"],
.ds2 .table > thead > tr > th.sortable { cursor: pointer; transition: color var(--motion-fast) ease; }
.ds2 .table > thead > tr > th:is([role="button"], .sortable):hover { color: var(--blue); }

.ds2 .table > tfoot > tr > * {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background-color: var(--surface);
  border-top: 2px solid var(--ink);
  color: var(--ink);
  font-weight: 600;
}

/* Totals row inside tbody */
.ds2 .table tr.row-total > * {
  border-top: 2px solid var(--ink);
  color: var(--ink);
  font-weight: 600;
}

/* The wrapper already draws the outer border */
.ds2 .table-wrap > .table > :last-child > tr:last-child > * { border-bottom: 0; }

/* Sticky first column (code) on tall/wide tables */
.ds2 .table-wrap-tall > .table > * > tr > :first-child,
.ds2 .table-wrap .table .col-sticky {
  position: sticky;
  left: 0;
  z-index: 1;
  background-color: var(--surface);
  border-right: 1px solid var(--rule);
}

.ds2 .table-wrap .table > thead .col-sticky { background-color: var(--blue-tint); }

.ds2 .table-wrap-tall > .table > thead > tr > :first-child,
.ds2 .table-wrap-tall > .table > tfoot > tr > :first-child,
.ds2 .table-wrap .table > :is(thead, tfoot) .col-sticky { z-index: 3; }

/* Bordered tables: single 1px grid with separate borders */
.ds2 .table-bordered > :not(caption) > * > * {
  border-width: 0 1px 1px 0;
  border-style: solid;
  border-color: var(--rule);
}

.ds2 .table-bordered > :not(caption) > * > :first-child { border-left-width: 1px; }
.ds2 .table-bordered > :first-child > tr:first-child > * { border-top-width: 1px; }
.ds2 .table-wrap > .table-bordered > :not(caption) > * > :first-child { border-left-width: 0; }
.ds2 .table-wrap > .table-bordered > :not(caption) > * > :last-child { border-right-width: 0; }
.ds2 .table-wrap > .table-bordered > :first-child > tr:first-child > * { border-top-width: 0; }

/* Contextual rows / header variants mapped to tokens (no black or pastel bars) */
.ds2 .table-light { --bs-table-bg: var(--page); color: var(--text); border-color: var(--rule); }
.ds2 .table-dark { --bs-table-bg: var(--blue-tint); --bs-table-striped-bg: transparent; color: var(--ink); border-color: var(--rule); }
.ds2 :is(.table-primary, .table-info) { --bs-table-bg: var(--info-tint); color: var(--text); border-color: var(--rule); }
.ds2 .table-success { --bs-table-bg: var(--ok-tint); color: var(--text); border-color: var(--rule); }
.ds2 .table-warning { --bs-table-bg: var(--warn-tint); color: var(--text); border-color: var(--rule); }
.ds2 .table-danger { --bs-table-bg: var(--bad-tint); color: var(--text); border-color: var(--rule); }
.ds2 .table-secondary { --bs-table-bg: var(--neutral-tint); color: var(--text); border-color: var(--rule); }
.ds2 .table-active { --bs-table-accent-bg: var(--blue-tint); color: var(--ink); }

/* Rows that block an action (e.g. skipped in a payment file) */
.ds2 .ds2-rows-blocking > tr > * { --bs-table-accent-bg: var(--bad-tint); }

.ds2 .table td:is(.ds2-empty, .empty-state) {
  text-align: center;
  padding: 48px 16px;
}

.ds2 .ds2-cell-notes { max-width: 200px; }

/* 8. Alerts ------------------------------------------------------------- */
.ds2 .alert,
.ds2 .alert[class*="alert-"] {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--alert-accent, var(--blue));
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 15px;
  box-shadow: none;
}

/* Legacy markup: border-0 / bg-* on alerts */
.ds2 .alert.border-0 {
  border: 1px solid var(--rule) !important;
  border-left: 4px solid var(--alert-accent, var(--blue)) !important;
}

.ds2 .alert[class*="bg-"] { background-color: var(--surface) !important; }

.ds2 .alert.alert-danger { --alert-accent: var(--bad); }
.ds2 .alert.alert-warning { --alert-accent: var(--warn); }
.ds2 .alert.alert-success { --alert-accent: var(--ok); }
.ds2 .alert.alert-info,
.ds2 .alert.alert-primary { --alert-accent: var(--blue); }
.ds2 .alert:is(.alert-secondary, .alert-light, .alert-dark) { --alert-accent: var(--muted); }

.ds2 .alert :is(.ds2-alert-title, .alert-title, .alert-heading) {
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}

.ds2 .alert :is(h3, h4, h5, h6) { color: var(--ink); }

.ds2 .alert .alert-link {
  color: var(--blue);
  font-weight: 600;
  text-decoration: underline;
}

/* No large icons in alerts */
.ds2 .alert :is(.fa-2x, .fa-3x, .fa-4x, .fa-5x) { font-size: 1.1em; }

.ds2 .alert-dismissible { padding-right: 48px; }
.ds2 .alert-dismissible .btn-close { padding: 14px 16px; }

/* 9. Forms -------------------------------------------------------------- */
.ds2 .form-label {
  font-size: 13px;
  line-height: 1.4;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}

.ds2 .form-control,
.ds2 .form-select {
  min-height: 36px;
  padding: 6px 12px;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink) !important;
  background-color: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: none;
  transition: border-color var(--motion-fast) ease;
}

.ds2 .form-select {
  padding-right: 36px;
  background-position: right 12px center;
}

.ds2 :is(.form-control-sm, .form-select-sm) {
  min-height: 32px;
  padding-top: 4px;
  padding-bottom: 4px;
  font-size: 14px;
}

.ds2 .form-control-sm { padding-left: 8px; padding-right: 8px; }

.ds2 :is(.form-control-lg, .form-select-lg) { min-height: 44px; font-size: 16px; }

.ds2 textarea.form-control { min-height: 72px; }

.ds2 .form-control::placeholder { color: var(--muted); opacity: 1; }

.ds2 .form-control:focus,
.ds2 .form-select:focus {
  border-color: var(--blue);
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  box-shadow: none;
}

.ds2 .form-control:disabled,
.ds2 .form-select:disabled { opacity: 0.6; }

.ds2 .form-control[readonly] { background-color: var(--page); }

.ds2 .form-control-plaintext { color: var(--ink); }

.ds2 :is(.form-control, .form-select).is-invalid { border-color: var(--bad); }
.ds2 :is(.form-control, .form-select).is-invalid:focus { outline-color: var(--bad); }
.ds2 :is(.form-control, .form-select).is-valid { border-color: var(--ok); }

.ds2 .invalid-feedback,
.ds2 .field-validation-error {
  font-size: 13px;
  line-height: 1.4;
  color: var(--bad);
}

.ds2 .valid-feedback { font-size: 13px; color: var(--ok); }

.ds2 .input-group-text {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 14px;
  color: var(--muted);
  background-color: var(--page);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.ds2 .ds2-field-date { max-width: 240px; }

.ds2 .form-text {
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted) !important;
  margin-top: 4px;
}

.ds2 .form-check-label { color: var(--text); }

.ds2 .form-check-input {
  border-color: var(--rule);
  background-color: var(--surface);
}

.ds2 .form-check-input:checked {
  background-color: var(--blue);
  border-color: var(--blue);
}

.ds2 .form-check-input:focus {
  box-shadow: none;
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.ds2 .form-switch .form-check-input { width: 2.25em; }

.ds2 .form-range::-webkit-slider-thumb { background-color: var(--blue); }
.ds2 .form-range::-moz-range-thumb { background-color: var(--blue); }

.ds2 .ds2-check-panel {
  padding: 12px 12px 12px 36px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

/* 10. Modals ------------------------------------------------------------ */
.ds2 .modal.fade { transition: opacity var(--motion-open) ease-out; }

.ds2 .modal.fade .modal-dialog {
  transform: none;
  transition: none;
}

.ds2 .modal-backdrop { background-color: #0F2A4A; }
[data-theme="dark"] .ds2 .modal-backdrop { background-color: #000000; }

.ds2 .modal-content {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-float);
}

.ds2 .modal-content.border-0 { border: 1px solid var(--rule) !important; }

.ds2 .modal-header {
  background-color: var(--surface);
  border-bottom: 1px solid var(--rule);
  padding: 16px 24px;
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
}

.ds2 .modal-header.border-0 { border-bottom: 1px solid var(--rule) !important; }

.ds2 .modal-title {
  font-size: 18px;
  line-height: 1.35;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}

.ds2 .modal-body {
  padding: 24px;
  color: var(--text);
}

.ds2 .modal-footer {
  background-color: var(--surface);
  border-top: 1px solid var(--rule);
  padding: 12px 24px;
  gap: 8px;
  justify-content: flex-end;
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
}

.ds2 .modal-footer > * { margin: 0; }

/* 11. Navigation and other Bootstrap components ------------------------- */
/* Tabs: underline style. Bootstrap .nav-tabs and the plain .tabs class look the same. */
.ds2 :is(.nav-tabs, .tabs) {
  display: flex;
  flex-wrap: wrap;
  gap: 0 4px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 16px;
}

.ds2 .tabs { list-style: none; padding: 0; }

.ds2 :is(.nav-tabs .nav-link, .tabs > a, .tabs > button, .tabs .nav-link) {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: -1px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  transition: color var(--motion-fast) ease, border-color var(--motion-fast) ease;
}

.ds2 :is(.nav-tabs .nav-link, .tabs > a, .tabs > button, .tabs .nav-link):hover {
  color: var(--ink);
  border-bottom-color: var(--rule);
  background: transparent;
}

.ds2 :is(.nav-tabs .nav-link.active, .nav-tabs .nav-item.show .nav-link, .tabs > .active, .tabs .nav-link.active, .tabs [aria-selected="true"]) {
  color: var(--ink);
  background: transparent;
  border-bottom-color: var(--blue);
}

.ds2 .nav-tabs .nav-link.disabled { color: var(--muted); opacity: 0.6; }

/* Pills: quiet segmented choice; active = blue tint */
.ds2 .nav-pills { gap: 4px; }

.ds2 .nav-pills .nav-link {
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
}

.ds2 .nav-pills .nav-link:hover { background-color: var(--row-hover); color: var(--ink); }

.ds2 .nav-pills .nav-link.active,
.ds2 .nav-pills .show > .nav-link {
  background-color: var(--blue-tint);
  border-color: var(--rule);
  color: var(--ink);
}

/* List group */
.ds2 .list-group { border-radius: var(--radius); }

.ds2 .list-group-item {
  background-color: var(--surface);
  border-color: var(--rule);
  color: var(--text);
  padding: 8px 12px;
}

.ds2 .list-group-item-action { color: var(--ink); }

.ds2 .list-group-item-action:is(:hover, :focus) {
  background-color: var(--row-hover);
  color: var(--ink);
}

.ds2 .list-group-item.active {
  background-color: var(--blue-tint);
  border-color: var(--rule);
  color: var(--ink);
  box-shadow: inset 3px 0 0 var(--blue);
}

.ds2 :is(.list-group-item-primary, .list-group-item-info) { background-color: var(--info-tint); color: var(--text); }
.ds2 .list-group-item-success { background-color: var(--ok-tint); color: var(--text); }
.ds2 .list-group-item-warning { background-color: var(--warn-tint); color: var(--text); }
.ds2 .list-group-item-danger { background-color: var(--bad-tint); color: var(--text); }

/* Pagination */
.ds2 .pagination { gap: 4px; flex-wrap: wrap; }

.ds2 .pagination .page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  margin-left: 0;
  padding: 0 10px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background-color: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: none;
}

.ds2 .pagination .page-link:hover { background-color: var(--blue-tint); color: var(--ink); }

.ds2 .pagination .page-item.active .page-link {
  background-color: var(--blue);
  border-color: var(--blue);
  color: var(--on-blue);
}

.ds2 .pagination .page-item.disabled .page-link {
  color: var(--muted);
  background-color: var(--surface);
  opacity: 0.6;
}

/* Breadcrumb (only for pages nested more than one level) */
.ds2 .breadcrumb {
  font-size: 13px;
  margin-bottom: 8px;
  padding: 0;
  background: none;
}

.ds2 .breadcrumb-item,
.ds2 .breadcrumb-item.active,
.ds2 .breadcrumb-item + .breadcrumb-item::before { color: var(--muted); }

/* Dropdowns (floating: the one place a shadow is allowed) */
.ds2 .dropdown-menu {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-float);
  padding: 4px;
  font-size: 14px;
  min-width: 180px;
}

.ds2 .dropdown-item {
  padding: 6px 12px;
  border-radius: 4px;
  color: var(--ink);
  font-weight: 400;
}

.ds2 .dropdown-item:is(:hover, :focus) {
  background-color: var(--blue-tint);
  color: var(--ink);
}

.ds2 .dropdown-item:is(.active, :active) {
  background-color: var(--blue-tint);
  color: var(--blue);
  font-weight: 600;
}

.ds2 .dropdown-item:is(.disabled, :disabled) { color: var(--muted); opacity: 0.7; }

.ds2 .dropdown-header {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 12px;
  text-transform: none;
}

.ds2 .dropdown-divider { border-top-color: var(--rule); margin: 4px 0; }

/* Accordion */
.ds2 .accordion-item {
  background-color: var(--surface);
  border-color: var(--rule);
  color: var(--text);
}

.ds2 .accordion-item:first-of-type,
.ds2 .accordion-item:first-of-type .accordion-button { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.ds2 .accordion-item:last-of-type { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }

.ds2 .accordion-button {
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  background-color: var(--surface);
  box-shadow: none;
}

.ds2 .accordion-button:not(.collapsed) {
  color: var(--ink);
  background-color: var(--blue-tint);
  box-shadow: inset 0 -1px 0 var(--rule);
}

.ds2 .accordion-button:focus {
  box-shadow: none;
  outline: 2px solid var(--blue);
  outline-offset: -2px;
  z-index: 3;
}

.ds2 .accordion-body { padding: 16px; }

/* Progress: thin bar, no stripes */
.ds2 .progress {
  height: 8px;
  background-color: var(--blue-tint);
  border-radius: 4px !important;
  box-shadow: none;
  font-size: 12px;
}

.ds2 .progress-bar {
  background-color: var(--blue);
  color: var(--on-blue);
}

.ds2 .progress-bar-striped { background-image: none !important; }
.ds2 .progress-bar-animated { animation: none !important; }

/* Toasts, tooltips, popovers, offcanvas */
.ds2 .toast {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-float);
}

.ds2 .toast-header {
  background-color: var(--surface);
  color: var(--ink);
  border-bottom: 1px solid var(--rule);
}

.ds2 .tooltip-inner {
  background-color: var(--ink);
  color: var(--surface);
  font-size: 13px;
  border-radius: 4px;
}

.ds2 :is(.bs-tooltip-top, .bs-tooltip-auto[data-popper-placement^="top"]) .tooltip-arrow::before { border-top-color: var(--ink); }
.ds2 :is(.bs-tooltip-bottom, .bs-tooltip-auto[data-popper-placement^="bottom"]) .tooltip-arrow::before { border-bottom-color: var(--ink); }
.ds2 :is(.bs-tooltip-start, .bs-tooltip-auto[data-popper-placement^="left"]) .tooltip-arrow::before { border-left-color: var(--ink); }
.ds2 :is(.bs-tooltip-end, .bs-tooltip-auto[data-popper-placement^="right"]) .tooltip-arrow::before { border-right-color: var(--ink); }

.ds2 .popover {
  background-color: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-float);
  font-family: var(--font);
}

.ds2 .popover-header { background-color: var(--surface); color: var(--ink); border-bottom-color: var(--rule); }
.ds2 .popover-body { color: var(--text); }

.ds2 .offcanvas {
  background-color: var(--surface);
  color: var(--text);
  border-color: var(--rule);
}

/* 12. Calendar ---------------------------------------------------------- */
.ds2 .cal-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.ds2 .cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(96px, 1fr));
  border-top: 1px solid var(--rule);
  border-left: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  background-color: var(--surface);
}

.ds2 :is(.cal-head, .cal-cell) {
  border-right: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.ds2 .cal-head {
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink);
  background-color: var(--blue-tint);
  text-align: center;
}

.ds2 .cal-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  min-height: 96px;
  padding: 8px;
  font: inherit;
  font-size: 13px;
  text-align: left;
  color: var(--text);
  background-color: var(--surface);
  border-top: 0;
  border-left: 0;
  border-radius: 0;
}

.ds2 :is(button.cal-cell, a.cal-cell) {
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--motion-fast) ease;
}

.ds2 :is(button.cal-cell, a.cal-cell):hover { background-color: var(--row-hover); color: var(--text); }
.ds2 :is(button.cal-cell, a.cal-cell):focus-visible { outline-offset: -2px; }

.ds2 .cal-day {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.ds2 .cal-cell.is-today .cal-day {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 4px;
  border-radius: 4px;
  background-color: var(--blue);
  color: var(--on-blue);
  align-self: flex-start;
}

.ds2 .cal-cell.is-weekend { background-color: var(--page); }
.ds2 .cal-cell.is-outside { background-color: var(--page); color: var(--muted); }
.ds2 .cal-cell.is-outside .cal-day { color: var(--muted); font-weight: 400; }
.ds2 .cal-cell.is-holiday { box-shadow: inset 3px 0 0 var(--ink); }
.ds2 .cal-cell.is-ok { box-shadow: inset 3px 0 0 var(--ok); }
.ds2 .cal-cell.is-warn { box-shadow: inset 3px 0 0 var(--warn); }
.ds2 .cal-cell.is-bad { box-shadow: inset 3px 0 0 var(--bad); }

/* 13. App shell --------------------------------------------------------- */
.ds2 .sidebar {
  background-color: var(--surface);
  border-right: 1px solid var(--rule);
  box-shadow: none;
  font-family: var(--font);
}

.ds2 .sidebar.show { box-shadow: var(--shadow-float); }

.ds2 .sidebar-header {
  height: 56px;
  flex: none;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--rule);
}

.ds2 .sidebar-brand {
  color: var(--ink);
  font-size: 18px;
  font-weight: 600;
  text-decoration: none;
}

.ds2 .sidebar-brand:hover { color: var(--ink); }
.ds2 .sidebar-brand i { color: var(--blue); }

.ds2 .sidebar-content { padding: 12px 8px 12px 0; }

.ds2 .sidebar-nav > .nav { gap: 2px !important; }

.ds2 .sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: 36px;
  padding: 6px 12px 6px 16px;
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
  font-weight: 600;
  color: var(--ink);
  background-color: transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--motion-fast) ease, color var(--motion-fast) ease;
}

.ds2 .sidebar-nav .nav-link > span { display: inline-flex; align-items: center; min-width: 0; }

.ds2 .sidebar-nav .nav-link i:not(.arrow-icon) {
  flex: none;
  width: 18px;
  margin-right: 10px !important;
  text-align: center;
  color: var(--muted);
}

.ds2 .sidebar-nav .arrow-icon { margin-left: auto; font-size: 11px; color: var(--muted); }

.ds2 .sidebar-nav .nav-link:hover { background-color: var(--row-hover); color: var(--ink); }

.ds2 .sidebar-nav .nav-link.active {
  background-color: var(--blue-tint);
  color: var(--ink);
  box-shadow: inset 3px 0 0 var(--blue);
}

.ds2 .sidebar-nav .nav-link.active i:not(.arrow-icon) { color: var(--blue); }

.ds2 .sidebar .submenu-list {
  margin: 2px 0 6px;
  padding: 0;
}

.ds2 .sidebar .submenu-list .nav-link {
  min-height: 32px;
  padding: 6px 12px 6px 44px;
  font-weight: 400;
  color: var(--text);
}

.ds2 .sidebar .submenu-list .nav-link.active { color: var(--ink); font-weight: 600; }

.ds2 .sidebar-footer {
  flex: none;
  padding: 8px 8px 12px;
}

.ds2 .sidebar-action {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 6px 8px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  transition: background-color var(--motion-fast) ease;
}

.ds2 .sidebar-action:hover { background-color: var(--row-hover); color: var(--ink); }
.ds2 .sidebar-action i { width: 18px; text-align: center; color: var(--muted); }

.ds2 .sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 0 0 8px;
  border-top: 1px solid var(--rule);
}

.ds2 .sidebar-user-email {
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Avatar: initials or icon in a 32px circle */
.ds2 .avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  background-color: var(--blue-tint);
}

/* Top bar */
.ds2 .topbar {
  height: 56px;
  gap: 8px;
  padding: 0 16px;
  background-color: var(--surface);
  border-bottom: 1px solid var(--rule);
  box-shadow: none;
}

.ds2 .topbar .btn-icon,
.ds2 .sidebar .btn-icon {
  width: 36px;
  height: 36px;
  min-height: 36px;
  color: var(--ink);
}

.ds2 .topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

.ds2 .topbar-brand i { color: var(--blue); }

.ds2 .topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.ds2 .user-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  border-radius: var(--radius);
  transition: background-color var(--motion-fast) ease;
}

.ds2 .user-menu-toggle:hover { background-color: var(--row-hover); color: var(--ink); }
.ds2 .user-menu-toggle::after { color: var(--muted); }

.ds2 .user-menu-email {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ds2 .user-menu .dropdown-header strong {
  display: block;
  color: var(--ink);
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* Bootstrap navbar (used by _AuthLayout): flat surface, readable links in both themes */
.ds2 .navbar {
  background-color: var(--surface) !important;
  border-bottom: 1px solid var(--rule);
}

.ds2 .navbar .nav-link { color: var(--text); font-size: 14px; }
.ds2 .navbar .nav-link:is(:hover, :focus, .active) { color: var(--blue); }

/* Content gutter: 24px desktop, 16px phone */
.ds2 .content-body { padding: 24px; }

/* Impersonation banner (warn accent on a quiet surface) */
.ds2 .impersonation-banner {
  background-color: var(--warn-tint);
  color: var(--ink);
  border-bottom: 1px solid var(--rule);
  border-left: 4px solid var(--warn);
}

.ds2 .impersonation-banner i { color: var(--warn); }

/* 14. Auth pages -------------------------------------------------------- */
body.ds2.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 32px 16px;
  background-color: var(--page);
}

.ds2 .auth-shell { width: 100%; max-width: 400px; }
.ds2 .auth-shell-wide { max-width: 840px; }

.ds2 .auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
  font-size: 20px;
  line-height: 1.2;
  font-weight: 600;
  color: var(--ink);
}

.ds2 .auth-brand i { color: var(--blue); }

.ds2 .auth-card {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 32px;
}

.ds2 .auth-card h1 { margin-bottom: 4px; }

.ds2 .auth-lead {
  margin: 0 0 24px;
  color: var(--muted);
}

.ds2 .auth-foot {
  margin-top: 16px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
  text-align: center;
}

.ds2 .auth-divider {
  margin: 24px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}

/* 15. Phones and small screens ----------------------------------------- */
@media (max-width: 991.98px) {
  .ds2 .user-menu-email { max-width: 160px; }
}

@media (max-width: 767.98px) {
  .ds2 .content-body { padding: 16px; }

  .ds2 .card-header { padding: 12px 16px; }
  .ds2 .card-body { padding: 16px; }
  .ds2 .card-footer { padding: 12px 16px; }
  .ds2 .surface { padding: 16px; }
  .ds2 .surface > .surface-head:first-child { margin: -16px -16px 16px; }
  .ds2 .surface-head { padding: 12px 16px; }
  .ds2 .surface-body { padding: 16px; }
  .ds2 .auth-card { padding: 24px 16px; }

  /* Tabs scroll sideways instead of wrapping */
  .ds2 :is(.nav-tabs, .tabs) {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  /* Filter fields stack */
  .ds2 .filter-bar .filter-field,
  .ds2 .filter-bar .filter-field-wide { flex: 1 1 100%; max-width: none; }
  .ds2 .filter-bar .filter-actions { margin-left: 0; width: 100%; }

  /* Calendar: narrower day columns */
  .ds2 .cal-grid { grid-template-columns: repeat(7, minmax(44px, 1fr)); }
  .ds2 .cal-cell { min-height: 56px; padding: 4px; }
  .ds2 .cal-head { padding: 6px 2px; }

  /* .table-stack: one block per row, labels from td[data-label] */
  .ds2 .table-stack,
  .ds2 .table-stack > tbody,
  .ds2 .table-stack > tfoot,
  .ds2 .table-stack > tbody > tr,
  .ds2 .table-stack > tfoot > tr { display: block; }

  .ds2 .table-stack > thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .ds2 .table-stack > tbody > tr,
  .ds2 .table-stack > tfoot > tr {
    padding: 12px 16px;
    border-bottom: 1px solid var(--rule);
  }

  .ds2 .table-stack > tbody > tr:last-child { border-bottom: 0; }
  .ds2 .table-stack > tfoot > tr { border-top: 2px solid var(--ink); }

  /* Each cell: label floated left, value right-aligned (works with several inline children) */
  .ds2 .table-stack > tbody > tr > *,
  .ds2 .table-stack > tfoot > tr > * {
    display: flow-root;
    position: static;
    padding: 4px 0;
    border: 0;
    text-align: right;
    white-space: normal;
    background-color: transparent;
  }

  .ds2 .table-stack > tbody > tr > [data-label]::before,
  .ds2 .table-stack > tfoot > tr > [data-label]::before {
    content: attr(data-label);
    float: left;
    max-width: 50%;
    margin-right: 12px;
    font-size: 13px;
    line-height: 1.6;
    font-weight: 400;
    color: var(--muted);
    text-align: left;
  }

  .ds2 .table-stack > tbody > tr > .stack-title {
    display: block;
    padding-bottom: 6px;
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    text-align: left;
  }

  .ds2 .table-stack > tbody > tr > .stack-title::before { content: none; }
  .ds2 .table-stack .stack-hide { display: none !important; }
  .ds2 .table-stack > tbody > tr > td[colspan] { display: block; text-align: center; }
  .ds2 .table-stack > tbody > tr:hover > * { --bs-table-accent-bg: transparent; }
  .ds2 .table-wrap > .table-stack .col-sticky { position: static; border-right: 0; }

  /* Stacked payrun table (.ds2-stack, nth-child labels): one block per employee.
     Row 1: name + code. Row 2: base salary / deductions / nett pay. Then the remaining figures, smaller.
     Labels come from CSS (the rows are built in JS without per-cell labels), so keep these in
     step with the column order in Payrun.cshtml. Column sorting is desktop-only. */
  .ds2 .table-wrap-tall { max-height: none; }

  .ds2 .ds2-stack,
  .ds2 .ds2-stack > tbody,
  .ds2 .ds2-stack > tfoot { display: block; }

  .ds2 .ds2-stack > thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .ds2 .ds2-stack > tbody > tr,
  .ds2 .ds2-stack > tfoot > tr {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--rule);
  }

  .ds2 .ds2-stack > tbody > tr:last-child { border-bottom: 0; }

  .ds2 .ds2-stack > tbody > tr > *,
  .ds2 .ds2-stack > tfoot > tr > * {
    display: block;
    position: static;
    padding: 0;
    border: 0;
    text-align: left;
    white-space: normal;
    background-color: transparent;
    min-width: 0;
  }

  .ds2 .ds2-stack > tbody > tr:hover > * { --bs-table-accent-bg: transparent; }

  .ds2 .ds2-stack .num {
    text-align: left;
    white-space: normal;
  }

  /* Detail figures: three per row */
  .ds2 .ds2-stack > tbody > tr > td,
  .ds2 .ds2-stack > tfoot > tr > th { grid-column: span 2; }

  /* Release the desktop sticky first column inside the stacked blocks */
  .ds2 .table-wrap-tall > .table.ds2-stack > * > tr > :first-child {
    position: static;
    border-right: 0;
  }

  /* Labels */
  .ds2 .ds2-stack > tbody > tr > td:nth-child(n+3)::before,
  .ds2 .ds2-stack > tfoot > tr > th:nth-child(n+2)::before {
    display: block;
    font-size: 13px;
    line-height: 1.4;
    font-weight: 400;
    color: var(--muted);
  }

  .ds2 .ds2-stack > tbody > tr > td:nth-child(3)::before,  .ds2 .ds2-stack > tfoot > tr > th:nth-child(2)::before  { content: "Base salary"; }
  .ds2 .ds2-stack > tbody > tr > td:nth-child(4)::before,  .ds2 .ds2-stack > tfoot > tr > th:nth-child(3)::before  { content: "OT hours"; }
  .ds2 .ds2-stack > tbody > tr > td:nth-child(5)::before,  .ds2 .ds2-stack > tfoot > tr > th:nth-child(4)::before  { content: "DT hours"; }
  .ds2 .ds2-stack > tbody > tr > td:nth-child(6)::before,  .ds2 .ds2-stack > tfoot > tr > th:nth-child(5)::before  { content: "OT pay"; }
  .ds2 .ds2-stack > tbody > tr > td:nth-child(7)::before,  .ds2 .ds2-stack > tfoot > tr > th:nth-child(6)::before  { content: "Pension"; }
  .ds2 .ds2-stack > tbody > tr > td:nth-child(8)::before,  .ds2 .ds2-stack > tfoot > tr > th:nth-child(7)::before  { content: "Medical aid"; }
  .ds2 .ds2-stack > tbody > tr > td:nth-child(9)::before,  .ds2 .ds2-stack > tfoot > tr > th:nth-child(8)::before  { content: "SSC ded."; }
  .ds2 .ds2-stack > tbody > tr > td:nth-child(10)::before, .ds2 .ds2-stack > tfoot > tr > th:nth-child(9)::before  { content: "PAYE tax"; }
  .ds2 .ds2-stack > tbody > tr > td:nth-child(11)::before, .ds2 .ds2-stack > tfoot > tr > th:nth-child(10)::before { content: "Debt ded."; }
  .ds2 .ds2-stack > tbody > tr > td:nth-child(12)::before, .ds2 .ds2-stack > tfoot > tr > th:nth-child(11)::before { content: "Deductions"; }
  .ds2 .ds2-stack > tbody > tr > td:nth-child(13)::before, .ds2 .ds2-stack > tfoot > tr > th:nth-child(12)::before { content: "Nett pay"; }

  /* Row 1: name, then code on the right */
  .ds2 .ds2-stack > tbody > tr > td:nth-child(2) {
    grid-row: 1;
    grid-column: 1 / 5;
    color: var(--ink);
    font-size: 15px;
    font-weight: 600;
  }

  .ds2 .ds2-stack > tbody > tr > td:nth-child(1) {
    grid-row: 1;
    grid-column: 5 / 7;
    text-align: right;
    color: var(--muted);
    font-weight: 400;
  }

  /* Rows 2-3: the figures that matter (base salary, deductions, then nett pay on its own line) */
  .ds2 .ds2-stack > tbody > tr > td:nth-child(3),
  .ds2 .ds2-stack > tfoot > tr > th:nth-child(2) { grid-row: 2; grid-column: 1 / 4; }

  .ds2 .ds2-stack > tbody > tr > td:nth-child(12),
  .ds2 .ds2-stack > tfoot > tr > th:nth-child(11) { grid-row: 2; grid-column: 4 / 7; }

  .ds2 .ds2-stack > tbody > tr > td:nth-child(13),
  .ds2 .ds2-stack > tfoot > tr > th:nth-child(12) { grid-row: 3; grid-column: 1 / 7; }

  .ds2 .ds2-stack > tbody > tr > td:is(:nth-child(3), :nth-child(12), :nth-child(13)) {
    color: var(--ink);
    font-size: 15px;
    font-weight: 600;
  }

  /* Details: the remaining figures flow underneath, smaller */
  .ds2 .ds2-stack > tbody > tr > td:nth-child(n+4):nth-child(-n+11) {
    font-size: 13px;
    color: var(--text);
  }

  .ds2 .ds2-stack > tbody > tr > td:nth-child(4) { border-top: 1px solid var(--rule); padding-top: 8px; }
  .ds2 .ds2-stack > tbody > tr > td:nth-child(5),
  .ds2 .ds2-stack > tbody > tr > td:nth-child(6) { border-top: 1px solid var(--rule); padding-top: 8px; }

  /* Empty-state row spans the block */
  .ds2 .ds2-stack > tbody > tr > td[colspan] {
    grid-row: auto;
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text);
    font-weight: 400;
  }

  /* Totals block */
  .ds2 .ds2-stack > tfoot > tr {
    border-top: 2px solid var(--ink);
    border-bottom: 0;
    background-color: var(--surface);
  }

  .ds2 .ds2-stack > tfoot > tr > th:first-child { grid-column: 1 / -1; }

  .ds2 .ds2-stack > tfoot > tr > th:nth-child(n+3):nth-child(-n+10) {
    font-size: 13px;
  }

  /* Summary figures stack */
  .ds2 :is(.ds2-figures, .figures) { flex-direction: column; }

  .ds2 :is(.ds2-figure + .ds2-figure, .figures > .figure + .figure) {
    border-left: 0;
    border-top: 1px solid var(--rule);
  }
}

@media (max-width: 575.98px) {
  .ds2 :is(.ds2-page-actions, .page-actions, .ds2-toolbar) { width: 100%; }

  .ds2 :is(.ds2-page-actions, .page-actions, .ds2-toolbar) > .btn,
  .ds2 .card-body > .row .btn { width: 100%; }

  .ds2 .ds2-field-date { max-width: none; }

  .ds2 .modal-fullscreen-sm-down .modal-content {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .ds2 .modal-fullscreen-sm-down .modal-header,
  .ds2 .modal-fullscreen-sm-down .modal-footer {
    border-radius: 0;
    padding: 12px 16px;
  }

  .ds2 .modal-body { padding: 16px; }
  .ds2 .modal-header { padding: 12px 16px; }
  .ds2 .modal-footer { padding: 12px 16px; }
}

/* 16. Reduced motion ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .ds2 *:not(.spinner-border):not(.spinner-grow),
  .ds2 *::before,
  .ds2 *::after,
  .ds2 .modal.fade {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
