/* ==========================================================================
   Bootstrap theme
   Everything that restyles Bootstrap: the --bs-* mapping onto tokens.css,
   the base and heading styles over Bootstrap's reboot, component variable
   overrides, focus styles, and the TomSelect skin. The staff UI checker
   exempts this sheet; shell.css may restyle Bootstrap inside the shell's
   own elements only.
   ========================================================================== */

/* Loaded after Bootstrap, so this :root mapping also beats Bootstrap's own
   [data-bs-theme=dark] values: it holds in both themes. */
:root {
  --bs-primary: var(--color-primary);
  --bs-primary-rgb: 249, 115, 22;
  /* Link text is the 700 step (5.2:1 on white): the 500 brand is 2.8:1 as
     text. --text-brand flips to the 400 step in dark mode. Feeds .nav-link
     and .btn-link; plain <a> reads Bootstrap's own --bs-link-color-rgb. */
  --bs-link-color: var(--text-brand);
  /* Hover keeps the colour; feedback is Bootstrap's own underline or fill.
     A near-black hover would match the nav-underline active tab. */
  --bs-link-hover-color: var(--text-brand);
  --bs-body-bg: var(--bg-secondary);
  --bs-body-color: var(--text-primary);
  --bs-secondary-color: var(--text-secondary);
  --bs-border-color: var(--border-color);
  --bs-focus-ring-color: var(--color-brand-glow);
  --bs-btn-focus-shadow-rgb: 249, 115, 22;
  /* -700 in light, as the old status pill (-600 on the pale fill is under
     4.5:1); -400 on the dark, translucent fill. */
  --bs-primary-text-emphasis: var(--text-brand);
  --bs-primary-bg-subtle: var(--color-brand-light);
  --bs-primary-border-subtle: var(--color-brand-ring);
  /* Bootstrap's *-subtle / *-emphasis pairs read the status palette, so
     `badge bg-success-subtle text-success-emphasis` (the {% status_badge %}
     tag) is the pastel status chip. */
  --bs-success-bg-subtle: var(--color-status-success-bg);
  --bs-success-text-emphasis: var(--color-status-success-text);
  --bs-warning-bg-subtle: var(--color-status-warning-bg);
  --bs-warning-text-emphasis: var(--color-status-warning-text);
  --bs-danger-bg-subtle: var(--color-status-danger-bg);
  --bs-danger-text-emphasis: var(--color-status-danger-text);
  --bs-info-bg-subtle: var(--color-status-info-bg);
  --bs-info-text-emphasis: var(--color-status-info-text);
  --bs-secondary-bg-subtle: var(--color-status-neutral-bg);
  --bs-secondary-text-emphasis: var(--color-status-neutral-text);
  /* One corner radius: stock cards, buttons, inputs and the custom cards
     all round to 12px. Pills and badges keep their own. */
  --bs-border-radius: var(--radius-md);
  --bs-border-radius-sm: var(--radius-md);
  --bs-border-radius-lg: var(--radius-md);
  --bs-border-radius-xl: var(--radius-md);
  --bs-border-radius-xxl: var(--radius-md);
  --bs-border-radius-2xl: var(--radius-md);
}

/* Dark mode needs only the variables the :root block leaves to Bootstrap. */
[data-bs-theme="dark"] {
  --bs-emphasis-color: var(--text-primary);
  --bs-tertiary-color: var(--text-tertiary);
  --bs-tertiary-bg: var(--bg-secondary);
  --bs-secondary-bg: var(--bg-tertiary);
  /* .text-body and .bg-body-tertiary read these -rgb twins, which Bootstrap
     leaves at its own dark greys. Light keeps Bootstrap's values: there they
     equal the .text-dark and .bg-light they replaced. */
  --bs-body-color-rgb: 248, 250, 252; /* --text-primary */
  --bs-tertiary-bg-rgb: 27, 38, 53;   /* --bg-tertiary */
}

/* Bootstrap keeps .table-light and .btn-outline-dark fixed in both themes,
   so in dark mode they read as a white band and dark on dark. Their
   component variables follow the theme here; light mode is untouched. */
[data-bs-theme="dark"] .table-light {
  --bs-table-color: var(--text-primary);
  --bs-table-bg: var(--bg-tertiary);
  --bs-table-border-color: var(--border-color);
}

[data-bs-theme="dark"] .btn-outline-dark {
  --bs-btn-color: var(--text-primary);
  --bs-btn-border-color: var(--border-color-dark);
  --bs-btn-hover-color: var(--bg-primary);
  --bs-btn-hover-bg: var(--text-primary);
  --bs-btn-hover-border-color: var(--text-primary);
  --bs-btn-active-color: var(--bg-primary);
  --bs-btn-active-bg: var(--text-primary);
  --bs-btn-active-border-color: var(--text-primary);
}

/* ==========================================================================
   Base Styles and Reset
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  line-height: var(--line-height-normal);
  -webkit-text-size-adjust: 100%;
  -moz-tab-size: 4;
  tab-size: 4;
}

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Typography System
   ========================================================================== */

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--space-4) 0;
  font-weight: var(--font-weight-black);
  line-height: var(--line-height-tight);
  color: var(--text-primary);
}

h1 {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-black);
}

h2 {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-black);
}

h3 {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-black);
}

h4 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-black);
}

/* Two roles below the page title, chosen by picking the Bootstrap heading:
   h5 / .card-title is a section title, h6 / .form-label is an eyebrow (the
   uppercase grey label over a field or a sub-block). Page-local section-title
   classes are replaced by these, never added. */
h5, .h5, .card-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--text-primary);
  margin-bottom: var(--space-3);
}

h6, .h6, .form-label {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

p {
  margin: 0 0 var(--space-4) 0;
  color: var(--text-secondary);
  font-weight: var(--font-weight-regular);
}

/* ==========================================================================
   Component Library
   ========================================================================== */

/* Bootstrap components are themed through their own custom properties. The
   display / hover / focus / disabled machinery stays Bootstrap's. */

/* Brand orange is the one action colour; Bootstrap's blue never shows.
   Its text is --color-on-brand: dark, because white on orange fails AA.
   Hover and active stay on the 600 step, the darkest that keeps dark text
   above 4.5:1. */
.btn-primary {
  --bs-btn-color: var(--color-on-brand);
  --bs-btn-bg: var(--color-brand);
  --bs-btn-border-color: var(--color-brand);
  --bs-btn-hover-color: var(--color-on-brand);
  --bs-btn-hover-bg: var(--color-primary-dark);
  --bs-btn-hover-border-color: var(--color-primary-dark);
  --bs-btn-active-color: var(--color-on-brand);
  --bs-btn-active-bg: var(--color-primary-dark);
  --bs-btn-active-border-color: var(--color-primary-dark);
  --bs-btn-disabled-color: var(--color-on-brand);
  --bs-btn-disabled-bg: var(--color-brand);
  --bs-btn-disabled-border-color: var(--color-brand);
  --bs-btn-focus-shadow-rgb: 249, 115, 22;
}

.btn-outline-primary {
  --bs-btn-color: var(--color-primary-dark);
  --bs-btn-border-color: var(--color-brand);
  --bs-btn-hover-color: var(--color-on-brand);
  --bs-btn-hover-bg: var(--color-brand);
  --bs-btn-hover-border-color: var(--color-brand);
  --bs-btn-active-color: var(--color-on-brand);
  --bs-btn-active-bg: var(--color-primary-dark);
  --bs-btn-active-border-color: var(--color-primary-dark);
  --bs-btn-disabled-color: var(--color-primary-dark);
  --bs-btn-disabled-border-color: var(--color-brand);
  --bs-btn-focus-shadow-rgb: 249, 115, 22;
}

/* The other components that paint their active item with --bs-primary
   take the same dark text. */
.nav-pills { --bs-nav-pills-link-active-color: var(--color-on-brand); }
.pagination { --bs-pagination-active-color: var(--color-on-brand); }
.dropdown-menu { --bs-dropdown-link-active-color: var(--color-on-brand); }
.list-group { --bs-list-group-active-color: var(--color-on-brand); }

/* The row-action button in every list. Quiet at rest so it reads as
   "available", not "do this"; the border only darkens under the pointer. */
.btn-outline-secondary {
  --bs-btn-color: var(--text-secondary);
  --bs-btn-border-color: var(--border-color-light);
  --bs-btn-hover-color: var(--text-primary);
  --bs-btn-hover-bg: var(--bg-tertiary);
  --bs-btn-hover-border-color: var(--border-color-dark);
  --bs-btn-active-color: var(--text-primary);
  --bs-btn-active-bg: var(--bg-tertiary);
  --bs-btn-active-border-color: var(--border-color-dark);
  --bs-btn-disabled-color: var(--text-tertiary);
  --bs-btn-disabled-border-color: var(--border-color-light);
}

/* A card inside a card is content, not a second surface: no border, no fill.
   Coloured status surfaces inside a card use the bg-*-subtle / border-*
   utilities instead of card chrome. */
.card .card {
  --bs-card-border-color: transparent;
  --bs-card-bg: transparent;
}

/* Tables: body cells read as secondary and the row's subject carries the one
   fw-semibold (never the address). Headers are eyebrows, the same role as h6. */
.table {
  --bs-table-color: var(--text-secondary);
}

.table thead th {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

/* The badge is the one status chip; pair it with bg-*-subtle text-*-emphasis
   for the pastel variant (the subtle pairs mapped above). */
.badge {
  --bs-badge-padding-x: var(--space-2);
  --bs-badge-padding-y: var(--space-1);
  --bs-badge-font-size: var(--font-size-xs);
  --bs-badge-font-weight: var(--font-weight-semibold);
  --bs-badge-border-radius: var(--radius-full);
}

/* ==========================================================================
   TomSelect
   ========================================================================== */

/* TomSelect - Bootstrap-aligned defaults */
.ts-wrapper {
  width: 100%;
  position: relative;
}

.ts-wrapper .ts-control {
  position: relative;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  min-height: calc(1.5em + 0.75rem + 2px);
  padding: 0.375rem 2rem 0.375rem 0.75rem;
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  box-shadow: none;
}

/* If the source select had .form-select, neutralize Bootstrap select skin on TomSelect wrapper. */
.ts-wrapper.form-select {
  border: 0;
  padding: 0;
  background-image: none;
  box-shadow: none;
  min-height: 0;
}

/* Standard chevron for TomSelect controls (click passes through to control). */
.ts-wrapper .ts-control::after {
  content: "";
  position: absolute;
  right: 0.7rem;
  top: 50%;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-60%) rotate(45deg);
  color: var(--text-secondary);
  opacity: 0.9;
  z-index: 2;
  pointer-events: none;
  transition: transform var(--transition-fast);
}

.ts-wrapper.dropdown-active .ts-control::after {
  transform: translateY(-35%) rotate(225deg);
}

.ts-wrapper .ts-control input {
  color: inherit !important;
}

.ts-wrapper .ts-control > .item {
  border-radius: var(--bs-border-radius-sm);
  background: var(--bs-tertiary-bg);
  color: var(--bs-body-color);
  border: 1px solid var(--bs-border-color);
  padding: 0.2rem 0.5rem;
  margin-right: 0.25rem;
}

.ts-wrapper.multi .ts-control > .item {
  margin-bottom: 0.2rem;
}

.ts-wrapper.focus .ts-control {
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
}

.ts-wrapper .ts-dropdown {
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  box-shadow: var(--shadow-md);
}

.ts-wrapper .ts-dropdown .option {
  padding: 0.4rem 0.75rem;
}

.ts-wrapper .ts-dropdown .active {
  background: var(--bs-tertiary-bg);
  color: var(--bs-body-color);
}

/* Hide a pillbox's native multi-select until static/js/pillbox.js enhances
   it. TomSelect adds `tomselected` once initialised; until then the raw
   <select multiple> would flash as a tall list box. The reserved height keeps
   the row from shifting when the widget mounts. */
select[data-pillbox]:not(.tomselected) {
  visibility: hidden;
  height: calc(2.25rem + 2px);
  overflow: hidden;
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* M21: Improved focus styles for keyboard navigation — WCAG 2.1 AA */
*:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(249, 115, 22, 0.2);
}

/* Remove focus ring on mouse click (non-keyboard) */
*:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

/* ==========================================================================
   Form controls and dropdowns
   ========================================================================== */

/* Bootstrap checkboxes/switches default to Bootstrap blue; theme to brand. */
.form-check-input:checked {
  background-color: var(--color-brand);
  border-color: var(--color-brand);
}

.form-check-input:focus {
  border-color: var(--color-brand-ring);
  box-shadow: 0 0 0 3px var(--color-brand-glow);
}

.form-switch .form-check-input:focus:not(:checked) {
  /* Bootstrap's focused thumb SVG is hardcoded blue; repaint it in the ring tone */
  --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23FED7AA'/%3e%3c/svg%3e");
}

/* Vertically align Bootstrap switches with their labels across forms and toolbars. */
.form-check.form-switch {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-left: 0;
}

.form-check.form-switch .form-check-input {
  margin-left: 0;
  margin-top: 0;
  flex-shrink: 0;
}

.form-text {
  font-size: var(--font-size-meta);
}

/* Nav dropdown group labels are no longer <h6> (de-headed so page outlines start
   at the <h1>, not at three navbar headings). They previously took the global
   h6 weight; pin it here so the visual is unchanged. */
.dropdown-header {
  font-weight: var(--font-weight-black);
}
