/* Back-office visual layer, loaded straight after main.css. Every colour is a theme variable: brand.md stays the one place colours are defined. */

:root,
[data-bs-theme="light"] {
  --sqas-surface: var(--bs-white);
  --sqas-hairline: rgba(var(--bs-secondary-rgb), .1);
  --sqas-hover: rgba(var(--bs-primary-rgb), .06);
  --sqas-band: rgba(var(--bs-secondary-rgb), .035);
  /* The same band, solid: for a table cell that stays in place while rows scroll under it. */
  --sqas-band-solid: color-mix(in srgb, var(--bs-secondary) 3.5%, var(--sqas-surface));
  --sqas-strong-text: color-mix(in srgb, var(--bs-body-color) 40%, var(--bs-emphasis-color));
  --sqas-shadow-sm: 0 1px 2px 0 rgba(var(--bs-secondary-rgb), .06), 0 1px 1px -1px rgba(var(--bs-secondary-rgb), .08);
  --sqas-shadow: 0 12px 28px -18px rgba(var(--bs-secondary-rgb), .3), 0 2px 8px -4px rgba(var(--bs-secondary-rgb), .1);
  --sqas-shadow-lg: 0 22px 45px -24px rgba(var(--bs-secondary-rgb), .4), 0 8px 18px -12px rgba(var(--bs-secondary-rgb), .16);

  --bs-border-radius: .5rem;
  --bs-border-radius-sm: .375rem;
  --bs-border-radius-lg: .75rem;
  --bs-border-radius-xl: 1rem;
}

[data-bs-theme="dark"] {
  --sqas-surface: var(--bs-body-bg);
}

/* Resting edge of a field, tick box or radio at 3:1 against its surface (WCAG 2.1, 1.4.11). */
:root,
[data-bs-theme="light"],
[data-bs-theme="dark"] {
  --sqas-control-border: color-mix(in srgb, var(--bs-body-color) 70%, var(--sqas-surface));
}

.form-control,
.form-control:focus,
.form-select {
  background-color: var(--sqas-surface);
  border-color: var(--sqas-control-border);
}

.form-check-input {
  --bs-form-check-bg: var(--sqas-surface);
  border-color: var(--sqas-control-border);
}

.dropdown-menu {
  --bs-dropdown-bg: var(--sqas-surface);
  --bs-dropdown-border-color: var(--sqas-hairline);
  --bs-dropdown-box-shadow: var(--sqas-shadow-lg);
  --bs-dropdown-link-hover-bg: var(--sqas-hover);
  box-shadow: var(--bs-dropdown-box-shadow);
}

.modal {
  --bs-modal-bg: var(--sqas-surface);
  --bs-modal-border-color: var(--sqas-hairline);
  --bs-modal-box-shadow: var(--sqas-shadow-lg);
  --bs-modal-header-border-color: var(--sqas-hairline);
  --bs-modal-footer-border-color: var(--sqas-hairline);
}

.modal-content {
  box-shadow: var(--bs-modal-box-shadow);
}

.popover {
  --bs-popover-bg: var(--sqas-surface);
  --bs-popover-border-color: var(--sqas-hairline);
  --bs-popover-header-bg: var(--sqas-band);
  --bs-popover-box-shadow: var(--sqas-shadow-lg);
  box-shadow: var(--bs-popover-box-shadow);
}

.list-group {
  --bs-list-group-bg: var(--sqas-surface);
  --bs-list-group-border-color: var(--sqas-hairline);
  --bs-list-group-action-hover-bg: var(--sqas-hover);
  --bs-list-group-action-hover-color: var(--sqas-strong-text);
  --bs-list-group-item-padding-y: .75rem;
  --bs-list-group-item-padding-x: 1.25rem;
}

.card {
  --bs-card-bg: var(--sqas-surface);
  --bs-card-border-color: var(--sqas-hairline);
  --bs-card-spacer-y: 1.25rem;
  --bs-card-spacer-x: 1.25rem;
  --bs-card-cap-padding-y: .875rem;
  --bs-card-cap-padding-x: 1.25rem;
  --bs-card-cap-bg: transparent;
  box-shadow: var(--sqas-shadow);
}

.card-header {
  border-bottom-color: var(--sqas-hairline);
}

.card-footer {
  border-top-color: var(--sqas-hairline);
}

.card-title {
  margin-bottom: 0;
  font-size: 1rem;
  font-weight: 600;
}

@media (min-width: 992px) {
  .container-fluid {
    --bs-gutter-x: 3rem;
  }
}

/* ── Page width ───────────────────────────────────────────────────────────────────────────────────────────────────────
   The page grows with the screen: a list (anything in a .table-responsive box) takes all the width there is, so a wide
   monitor shows more columns. Forms and text stop at a reading width on the left instead of stretching: the measure is the
   widest the page column used to be (1,320px page less the links bar), so they look as they did before at 1,400px and up. */
:root {
  --sqas-measure: 65.75rem;
}

/* main is a flex item beside the links bar: without this it keeps the width of its widest content, and a wide table would
   push it under the bar instead of scrolling inside its own frame. */
main {
  min-width: 0;
}

/* Everything directly in the page column stops at the measure, except a list, a block holding one, and the page header,
   whose actions stay at the right edge above the list. Inside a form that holds a list (Tailor), the form's other parts
   stop at the measure. A row the page centres (sign-in, the password page) sets its own width with its column and stays in
   the middle of the screen. */
main > :not(.table-responsive, .sqas-page-header, .row.justify-content-center):not(:has(.table-responsive)),
main > form:has(> .table-responsive) > :not(.table-responsive) {
  max-width: var(--sqas-share, var(--sqas-measure));
}

/* A block given a share of the page with a column class (col-lg-6 for a half-width form, col-lg-10 for a narrow list) keeps
   the share of the measure it had before, instead of a share of an ever wider page. */
:is(main, main > form) > :is(.col-lg-6, .col-lg-7, .col-lg-8, .col-lg-10, .col-xl-9) {
  max-width: var(--sqas-share);
}

@media (min-width: 992px) {
  .col-lg-6 { --sqas-share: calc(var(--sqas-measure) * 6 / 12); }
  .col-lg-7 { --sqas-share: calc(var(--sqas-measure) * 7 / 12); }
  .col-lg-8 { --sqas-share: calc(var(--sqas-measure) * 8 / 12); }
  .col-lg-10 { --sqas-share: calc(var(--sqas-measure) * 10 / 12); }

  /* The links bar is never wider than this, whatever the screen. */
  .sqas-side {
    width: 13.75rem;
  }
}

@media (min-width: 1200px) {
  .col-xl-9 { --sqas-share: calc(var(--sqas-measure) * 9 / 12); }
}

h1,
.h1,
h2,
.h2,
h3,
.h3 {
  font-weight: 700;
  letter-spacing: -.01em;
}

.sqas-label {
  margin-bottom: .375rem;
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
}

.btn {
  --bs-btn-font-weight: 600;
  --bs-btn-padding-x: 1rem;
}

.btn-sm {
  --bs-btn-padding-x: .75rem;
}

.btn-link {
  --bs-btn-font-weight: 400;
}

.btn-primary {
  box-shadow: var(--sqas-shadow-sm);
}

.btn:has(.bi) {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
}

.sqas-menubar .nav-underline .nav-link .bi,
.dropdown-item .bi {
  margin-right: .375rem;
}

.badge {
  --bs-badge-font-weight: 600;
  --bs-badge-padding-x: .7em;
  --bs-badge-padding-y: .4em;
}

/* ── Non-Conformance grades ───────────────────────────────────────────────────────────────────────────────────────
   The grade pill (Pages/Shared/_GradePill.cshtml) deepens with the grade: Minor yellow, Major red, Critical dark red.
   Minor and Major are Bootstrap's own text-bg-warning and text-bg-danger. Bootstrap has no fill for a darker red, so
   this class makes one: the theme's danger red let down with black, worked out from the theme's variables so it
   follows them if they change. White text on it is about 11:1. The theme's own dark danger shade
   (--bs-danger-text-emphasis) was tried first and reads as near black in a pill, not as a red. */
.text-bg-danger-emphasis {
  color: var(--bs-white);
  background-color: color-mix(in srgb, var(--bs-danger) 65%, var(--bs-black));
}

.sqas-search {
  position: relative;
}

.sqas-search > .bi {
  position: absolute;
  top: 50%;
  left: .875rem;
  transform: translateY(-50%);
  color: var(--bs-secondary-color);
  pointer-events: none;
}

.sqas-search > .form-control {
  padding-left: 2.375rem;
}

.sqas-page-header {
  margin-bottom: 1.5rem;
}

.sqas-page-header h1 {
  margin-bottom: .25rem;
}

/* One title size on every page, whatever heading class the page gave its h1 (most still write <h1 class="h3">). The [class]
   form outweighs Bootstrap's .h2 and .h3. */
main h1,
main h1[class] {
  font-size: 1.625rem;
}

/* "Skip to content": hidden until the keyboard reaches it as the first stop on the page, then shown over the top bar. */
.sqas-skip {
  position: absolute;
  top: .5rem;
  left: .5rem;
  z-index: 5;
}

/* The skip link moves focus to the page column: it needs no focus ring of its own, since nothing there is clicked. */
main[tabindex="-1"]:focus {
  outline: 0;
}

.sqas-page-header p {
  margin-bottom: 0;
  color: var(--bs-secondary-color);
}

.sqas-topbar {
  position: relative;
  z-index: 4;
  box-shadow: var(--sqas-shadow);
}

.sqas-topbar .form-control {
  border-color: transparent;
  border-radius: var(--bs-border-radius-pill);
}

.sqas-menubar {
  background-color: var(--sqas-surface);
  border-bottom: var(--bs-border-width) solid var(--sqas-hairline);
  box-shadow: var(--sqas-shadow-sm);
}

.sqas-menubar .nav-underline {
  --bs-nav-link-color: var(--bs-body-color);
  --bs-nav-link-hover-color: var(--bs-heading-color);
  --bs-nav-underline-link-active-color: var(--bs-heading-color);
  --bs-nav-underline-gap: 1rem;
}

.sqas-menubar .nav-underline .nav-link {
  padding-top: .75rem;
  padding-bottom: .75rem;
  font-weight: 500;
}

.sqas-menubar .nav-underline .nav-link.active {
  font-weight: 600;
  border-bottom-color: var(--bs-primary);
}

.sqas-menubar .nav-underline .nav-link .bi {
  color: var(--bs-secondary-color);
}

.sqas-menubar .nav-underline .nav-link.active .bi {
  color: var(--bs-primary);
}

.sqas-menu-panel {
  background-color: var(--sqas-surface);
  border-bottom: var(--bs-border-width) solid var(--sqas-hairline);
  box-shadow: var(--sqas-shadow-lg);
}

.sqas-nav {
  --bs-nav-link-color: var(--bs-body-color);
  --bs-nav-link-hover-color: var(--sqas-strong-text);
  --bs-nav-pills-link-active-bg: var(--bs-primary-bg-subtle);
  --bs-nav-pills-link-active-color: var(--bs-primary-text-emphasis);
  --bs-nav-pills-border-radius: var(--bs-border-radius);
  gap: .125rem;
}

.sqas-nav .nav-link {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4375rem .75rem;
}

.sqas-nav .nav-link:hover:not(.active) {
  background-color: var(--sqas-hover);
}

.sqas-nav .nav-link.active {
  font-weight: 600;
}

.sqas-nav .nav-link .badge {
  margin-left: auto;
}

.sqas-side {
  position: sticky;
  top: 1rem;
  align-self: flex-start;
}

/* The left links bar shows only on a wide window, and not once the user has hidden it (side-panel.js marks the page). The
   trail above the page takes its place; its Show button is there only for a bar the user hid, since a narrow window has
   no room for the bar. */
.sqas-side,
.sqas-trail [data-side-toggle] {
  display: none;
}

.sqas-trail {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: .5rem;
}

@media (min-width: 992px) {
  :root:not([data-side="hidden"]) .sqas-side {
    display: block;
  }

  :root:not([data-side="hidden"]) .sqas-trail {
    display: none;
  }

  :root[data-side="hidden"] .sqas-trail [data-side-toggle] {
    display: inline-flex;
  }
}

.sqas-side-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin: 0 0 1rem .75rem;
}

.sqas-side-title h2 {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: 0;
  font-size: 1rem;
}

.sqas-side-title [data-side-toggle] {
  color: var(--bs-secondary-color);
}

.sqas-side-title h2 .bi {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--bs-border-radius);
  background-color: var(--bs-primary-bg-subtle);
  color: var(--bs-primary-text-emphasis);
}

.sqas-side .sqas-label {
  margin: 1.25rem .75rem .375rem;
}

.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--sqas-strong-text);
  --bs-table-border-color: var(--sqas-hairline);
  --bs-table-hover-bg: var(--sqas-hover);
  --bs-table-hover-color: var(--sqas-strong-text);
  border: var(--bs-border-width) solid var(--bs-table-border-color);
  border-collapse: separate;
  border-spacing: 0;
  border-radius: var(--bs-border-radius-lg);
  background-color: var(--sqas-surface);
  overflow: hidden;
}

.table > :not(caption) > * > * {
  padding: .75rem 1rem;
  border-bottom-width: 0;
}

.table-sm > :not(caption) > * > * {
  padding: .5rem .75rem;
}

/* The divider sits on top of each row: client-table.js hides rows, so the last row in the markup is often not the last on screen. */
.table > tbody > tr > *,
.table > tfoot > tr > * {
  border-top-width: var(--bs-border-width);
}

.table > thead {
  --bs-table-bg: var(--sqas-band);
}

.table > thead > tr > * {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: bottom;
  color: var(--bs-secondary-color);
}

/* The table's frame. Every table sits in a .table-responsive box (ClientTableTagHelper writes it around a client table; other
   tables are wrapped by hand), and the box, not the table, carries the border and the rounded corners. A table wider than the
   page then scrolls sideways inside its frame instead of making the whole page scroll, and the box's own clipping keeps the
   corners round, whichever rows client-table.js has hidden. position: relative keeps a visually hidden heading, which is
   positioned absolutely, inside the box: otherwise it widens the page. isolation keeps whatever sticks inside the box
   underneath the open menu. A table outside a box keeps its own frame, above. */
.table-responsive {
  position: relative;
  isolation: isolate;
  margin-bottom: 1rem;
  border: var(--bs-border-width) solid var(--sqas-hairline);
  border-radius: var(--bs-border-radius-lg);
  background-color: var(--sqas-surface);
}

.table-responsive > .table {
  margin-bottom: 0;
  border-width: 0;
  border-radius: 0;
  overflow: visible;
}

/* A list taller than the window scrolls inside its frame, which stops a little short of the window's height, so its header
   row, its fixed columns and its sideways scroll bar all stay in view while the user reads down or across it. A list that
   fits shows no scroll bar and looks as it did. */
.table-responsive {
  max-height: calc(100vh - 2rem);
  overflow: auto;
}

/* The header row stays at the top of the frame. A cell that stays put while rows slide under it needs a solid background:
   the header band and the row hover tint are see-through. The hover tint is painted on top of it, so it still shows. */
.table-responsive > .table > thead > tr > * {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--sqas-band-solid);
}

/* A list that names its row in the first column and has the row's action in the last says so with
   data-fixed-columns="first last" on the table: those two columns stay in view while the middle ones scroll sideways
   underneath. Not on a phone, where two fixed columns would leave no room for the rest. */
@media (min-width: 768px) {
  .table-responsive > .table[data-fixed-columns~="first"] > * > tr > :first-child {
    position: sticky;
    left: 0;
  }

  .table-responsive > .table[data-fixed-columns~="last"] > * > tr > :last-child {
    position: sticky;
    right: 0;
  }

  .table-responsive > .table[data-fixed-columns~="first"] > tbody > tr > :first-child,
  .table-responsive > .table[data-fixed-columns~="last"] > tbody > tr > :last-child {
    z-index: 1;
    background-color: var(--sqas-surface);
  }

  /* The header cells over a fixed column stay above everything that scrolls, both ways. */
  .table-responsive > .table[data-fixed-columns~="first"] > thead > tr > :first-child,
  .table-responsive > .table[data-fixed-columns~="last"] > thead > tr > :last-child {
    z-index: 3;
  }
}

/* ── Form actions ─────────────────────────────────────────────────────────────────────────────────────────────────────
   The bar of Save and Cancel at the end of a form (FormActionsTagHelper). It sticks to the bottom of the window while the
   rest of the form is below it, so Save stays in reach on a long form; on a short form it simply sits under the last field.
   Its background hides the fields scrolling under it, and it stays under the open menu. */
.sqas-form-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
  padding: .75rem 0;
  border-top: var(--bs-border-width) solid var(--sqas-hairline);
  background-color: var(--bs-body-bg);
}

.card .sqas-form-actions {
  background-color: var(--sqas-surface);
}

/* A field the keyboard moves to is scrolled into view above the bar, not behind it. */
:root:has(.sqas-form-actions) {
  scroll-padding-bottom: 5rem;
}

/* A list inside such a form stops short of the bar, so the bar never covers the list's sideways scroll bar. */
form:has(> .sqas-form-actions) .table-responsive {
  max-height: calc(100vh - 6.5rem);
}

/* In a card the card is the frame: the box and the table sit flush with it. */
.card > .table-responsive {
  margin-bottom: 0;
  border-width: 0;
  border-radius: 0;
}

.card > .table,
.card > .table-responsive > .table {
  margin-bottom: 0;
  border-width: 0;
  border-radius: 0;
  box-shadow: none;
}

.card > .table > :not(caption) > * > :first-child,
.card > .table-responsive > .table > :not(caption) > * > :first-child {
  padding-left: 1.25rem;
}

.card > .table > :not(caption) > * > :last-child,
.card > .table-responsive > .table > :not(caption) > * > :last-child {
  padding-right: 1.25rem;
}

.card > .table:last-child,
.card > .table-responsive:last-child {
  border-bottom-right-radius: var(--bs-card-inner-border-radius);
  border-bottom-left-radius: var(--bs-card-inner-border-radius);
}

/* A sort heading is at least 24px high so it is easy to hit (WCAG 2.2, 2.5.8). The negative margin takes the extra height back,
   so the header row is no taller. The server-sorted heading is a link styled as a button and gets the same room. */
.table > thead button[data-sort] {
  margin: -.25rem 0;
  padding: .25rem 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  white-space: nowrap;
}

.table > thead a[data-sort] {
  --bs-btn-padding-x: 0;
  --bs-btn-padding-y: .25rem;
  margin: -.25rem 0;
}

.table > thead button[data-sort]:hover {
  color: var(--bs-heading-color);
}

.table > thead button[data-sort]:focus-visible {
  border-radius: var(--bs-border-radius-sm);
  outline: 0;
  box-shadow: 0 0 0 .125rem var(--sqas-surface), 0 0 0 .3125rem var(--bs-primary);
}

/* The sort arrow, drawn the way Bootstrap draws a dropdown arrow; client-table.js sets aria-sort on the th. */
.table > thead button[data-sort]::after {
  display: inline-block;
  margin-left: .35em;
  vertical-align: .15em;
  content: "";
  border: .3em solid transparent;
  border-top-width: 0;
  border-bottom-color: currentcolor;
  opacity: 0;
}

.table > thead button[data-sort]:hover::after,
.table > thead button[data-sort]:focus-visible::after {
  opacity: .5;
}

.table > thead [aria-sort] > button[data-sort] {
  color: var(--bs-heading-color);
}

.table > thead [aria-sort] > button[data-sort]::after {
  opacity: 1;
}

.table > thead [aria-sort="descending"] > button[data-sort]::after {
  border-top-width: .3em;
  border-top-color: currentcolor;
  border-bottom-width: 0;
}

/* ── Target sizes ─────────────────────────────────────────────────────────────────────────────────────────────────────
   Nothing that can be clicked is less than 24px high (WCAG 2.2, 2.5.8). A link in a table cell or the footer sits in smaller
   text: padding on the link, which stays in the line, makes its clickable area taller without moving the text. */
.table > tbody a:not(.btn),
.sqas-footer a {
  padding-block: .25rem;
}

/* The switch on Tailor is 24px high rather than the theme's 16px. */
.form-switch {
  min-height: 1.5rem;
  padding-left: 3.25rem;
}

.form-switch .form-check-input {
  width: 2.75rem;
  height: 1.5rem;
  margin-top: 0;
  margin-left: -3.25rem;
}

/* On a touch screen, such as an Auditor's tablet, everything that is tapped is at least 44px high (WCAG 2.2, 2.5.5). A mouse
   keeps the compact sizes above. */
@media (pointer: coarse) {
  .btn,
  .form-control,
  .form-select {
    min-height: 2.75rem;
  }

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .nav-link,
  .dropdown-item {
    display: flex;
    align-items: center;
    min-height: 2.75rem;
  }

  /* Links that stand on their own: in a table, beside Save (older forms write that row as a d-flex), the way back, the
     footer. A link inside a sentence is left alone. */
  .table > tbody a:not(.btn),
  .sqas-form-actions > a:not(.btn),
  main .d-flex > a:not(.btn),
  main a.d-inline-flex:not(.btn),
  .sqas-footer a {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
    padding-block: 0;
  }

  /* A tick box or radio grows to 24px, and its label, which also ticks it, to 44px. */
  .form-check-input {
    width: 1.5rem;
    height: 1.5rem;
  }

  .form-check {
    min-height: 2.75rem;
    padding-left: 2.25rem;
  }

  .form-check .form-check-input {
    margin-top: .625rem;
    margin-left: -2.25rem;
  }

  .form-check-label {
    display: inline-block;
    padding-block: .625rem;
  }

  .form-switch {
    padding-left: 5.25rem;
  }

  .form-switch .form-check-input {
    width: 4.5rem;
    height: 2.75rem;
    margin-top: 0;
    margin-left: -5.25rem;
  }
}

/* ── Date field ───────────────────────────────────────────────────────────────────────────────────────────────────
   The browser's own date input (type="date"): its calendar is drawn by the browser and cannot be styled, so it is asked
   to use its light colours to match the white field, and the calendar icon shows it can be clicked. */
.form-control[type="date"] {
  color-scheme: light;
}

.form-control[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
}

.sqas-empty {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--bs-secondary-color);
}

.sqas-empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: .75rem;
  border-radius: 50%;
  background-color: var(--bs-primary-bg-subtle);
  color: var(--bs-primary-text-emphasis);
  font-size: 1.375rem;
}

.sqas-empty p:last-child {
  margin-bottom: 0;
}

.sqas-footer {
  border-top: var(--bs-border-width) solid var(--sqas-hairline);
  font-size: .875rem;
}
