/*
  ClubLedger brand, loaded after Bootstrap on every page. It only overrides Bootstrap's CSS
  variables, so pages keep using plain Bootstrap classes (btn-primary, link colours, forms).
  Teal is the accent; green, amber and red stay free for status badges. Colours pass WCAG AA.
*/
:root {
  --bs-primary: #0f5f66;
  --bs-primary-rgb: 15, 95, 102;
  --bs-link-color: #0f5f66;
  --bs-link-color-rgb: 15, 95, 102;
  --bs-link-hover-color: #0b4d53;
  --bs-link-hover-color-rgb: 11, 77, 83;
  --bs-body-color: #1f2a2a;
  --bs-body-color-rgb: 31, 42, 42;
  --bs-secondary-color: #566363;
  --bs-border-color: #dde4e4;
  --bs-danger: #b42318;
  --bs-danger-rgb: 180, 35, 24;
  --bs-font-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --cl-page-bg: #f6f8f8;
  --cl-card-bg: #fff;
  --cl-input-border: #7e8c8c;
  --cl-warning-text: #8a4b00;
}

/* Dark mode follows the system setting (static/js/theme.js sets data-bs-theme). */
[data-bs-theme="dark"] {
  --bs-primary: #5cc8d0;
  --bs-primary-rgb: 92, 200, 208;
  --bs-link-color: #5cc8d0;
  --bs-link-color-rgb: 92, 200, 208;
  --bs-link-hover-color: #8fdde3;
  --bs-link-hover-color-rgb: 143, 221, 227;
  --bs-body-color: #e8eeee;
  --bs-body-color-rgb: 232, 238, 238;
  --bs-body-bg: #0e1717;
  --bs-body-bg-rgb: 14, 23, 23;
  --bs-secondary-color: #9fb0b0;
  --bs-border-color: #2a3a3a;
  --cl-page-bg: #0e1717;
  --cl-card-bg: #162222;
  --cl-input-border: #7c9090;
  --cl-warning-text: #f2b766;
}

/* Bootstrap compiles .btn-primary with its own variables, so they are set here too. */
.btn-primary {
  --bs-btn-bg: #0f5f66;
  --bs-btn-border-color: #0f5f66;
  --bs-btn-hover-bg: #0b4d53;
  --bs-btn-hover-border-color: #0b4d53;
  --bs-btn-active-bg: #0b4d53;
  --bs-btn-active-border-color: #0b4d53;
  --bs-btn-disabled-bg: #0f5f66;
  --bs-btn-disabled-border-color: #0f5f66;
  --bs-btn-focus-shadow-rgb: 15, 95, 102;
}

[data-bs-theme="dark"] .btn-primary {
  --bs-btn-color: #0e1717;
  --bs-btn-bg: #5cc8d0;
  --bs-btn-border-color: #5cc8d0;
  --bs-btn-hover-color: #0e1717;
  --bs-btn-hover-bg: #8fdde3;
  --bs-btn-hover-border-color: #8fdde3;
  --bs-btn-active-color: #0e1717;
  --bs-btn-active-bg: #8fdde3;
  --bs-btn-active-border-color: #8fdde3;
  --bs-btn-disabled-color: #0e1717;
  --bs-btn-disabled-bg: #5cc8d0;
  --bs-btn-disabled-border-color: #5cc8d0;
  --bs-btn-focus-shadow-rgb: 92, 200, 208;
}

.form-control {
  border-color: var(--cl-input-border);
}

/* Confirm buttons for decline and void; Bootstrap compiles its own red into .btn-danger. */
:root {
  --bs-form-invalid-color: #b42318;
  --bs-form-invalid-border-color: #b42318;
}

/* The rule above would also win in dark mode (this file loads after Bootstrap), where #b42318
   on the dark page is too faint for text; Bootstrap's dark values keep it readable. */
[data-bs-theme="dark"] {
  --bs-form-invalid-color: #ea868f;
  --bs-form-invalid-border-color: #ea868f;
}

.btn-danger {
  --bs-btn-bg: #b42318;
  --bs-btn-border-color: #b42318;
  --bs-btn-hover-bg: #912018;
  --bs-btn-hover-border-color: #912018;
  --bs-btn-active-bg: #912018;
  --bs-btn-active-border-color: #912018;
  --bs-btn-focus-shadow-rgb: 180, 35, 24;
}

[data-bs-theme="dark"] .btn-danger {
  --bs-btn-bg: #c9302c;
  --bs-btn-border-color: #c9302c;
  --bs-btn-hover-bg: #dc3545;
  --bs-btn-hover-border-color: #dc3545;
  --bs-btn-active-bg: #dc3545;
  --bs-btn-active-border-color: #dc3545;
  --bs-btn-focus-shadow-rgb: 220, 53, 69;
}

/*
  Bootstrap compiles its default blue into some components instead of reading --bs-primary,
  so these are re-pointed at the brand colour, so slices can use them freely.
*/
:root {
  --bs-focus-ring-color: rgba(var(--bs-primary-rgb), .25);
  --bs-primary-text-emphasis: #0b4d53;
  --bs-primary-bg-subtle: #e6f1f2;
  --bs-primary-border-subtle: #c4dfe1;
  --cl-on-primary: #fff;
}

[data-bs-theme="dark"] {
  --bs-primary-text-emphasis: #a8e3e7;
  --bs-primary-bg-subtle: #123234;
  --bs-primary-border-subtle: #1f4a4d;
  --cl-on-primary: #0e1717;
}

.btn-outline-primary {
  --bs-btn-color: var(--bs-primary);
  --bs-btn-border-color: var(--bs-primary);
  --bs-btn-hover-color: var(--cl-on-primary);
  --bs-btn-hover-bg: var(--bs-primary);
  --bs-btn-hover-border-color: var(--bs-primary);
  --bs-btn-active-color: var(--cl-on-primary);
  --bs-btn-active-bg: var(--bs-primary);
  --bs-btn-active-border-color: var(--bs-primary);
  --bs-btn-disabled-color: var(--bs-primary);
  --bs-btn-disabled-border-color: var(--bs-primary);
  --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}

.dropdown-menu {
  --bs-dropdown-link-active-color: var(--cl-on-primary);
  --bs-dropdown-link-active-bg: var(--bs-primary);
}

.nav-pills {
  --bs-nav-pills-link-active-color: var(--cl-on-primary);
  --bs-nav-pills-link-active-bg: var(--bs-primary);
}

.pagination {
  --bs-pagination-color: var(--bs-link-color);
  --bs-pagination-hover-color: var(--bs-link-hover-color);
  --bs-pagination-focus-color: var(--bs-link-hover-color);
  --bs-pagination-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color);
  --bs-pagination-active-color: var(--cl-on-primary);
  --bs-pagination-active-bg: var(--bs-primary);
  --bs-pagination-active-border-color: var(--bs-primary);
}

.list-group {
  --bs-list-group-active-color: var(--cl-on-primary);
  --bs-list-group-active-bg: var(--bs-primary);
  --bs-list-group-active-border-color: var(--bs-primary);
}

.progress,
.progress-stacked {
  --bs-progress-bar-bg: var(--bs-primary);
  --bs-progress-bar-color: var(--cl-on-primary);
}

.form-check-input:checked {
  background-color: var(--bs-primary);
  border-color: var(--bs-primary);
}

/* Bootstrap hard-codes white text here, which is unreadable on the light dark-mode teal. */
.text-bg-primary {
  color: var(--cl-on-primary) !important;
}

.form-check-input:focus,
.form-select:focus {
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color);
}

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

.brand-mark {
  flex: none;
}

/* Theme switcher: show the icon for the current choice; hide the switcher without JavaScript. */
.theme-icon {
  display: none;
}

html[data-theme-choice="light"] .theme-icon-light,
html[data-theme-choice="dark"] .theme-icon-dark,
html[data-theme-choice="auto"] .theme-icon-auto {
  display: inline-block;
}

html:not([data-theme-choice]) .theme-switcher {
  display: none;
}

/* The navbar shows only the icon on wide screens, where the menu is a single row. */
@media (min-width: 992px) {
  .navbar .theme-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
}

/* Every other page (fragments/layout.html and the error pages) is a column at least as tall as the
   window, so the footer (mt-auto) sits at the bottom of short pages instead of mid-screen. */
.app-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Sign-in and sign-up pages (fragments/auth.html). */
.auth-page {
  background: var(--cl-page-bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(2rem, 10vh, 6rem) 1rem 1.5rem;
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: .625rem;
  margin-bottom: 1.5rem;
  color: var(--bs-body-color);
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -.01em;
  text-decoration: none;
}

.auth-brand:hover {
  color: var(--bs-body-color);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 1.5rem;
  background: var(--cl-card-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: .75rem;
}

@media (min-width: 576px) {
  .auth-card {
    padding: 2rem;
  }
}

.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: .25rem;
}

.auth-card .form-label {
  font-size: .9375rem;
  font-weight: 500;
  margin-bottom: .375rem;
}

/* 16px inputs stop iOS from zooming in on focus; 48px keeps the touch target comfortable. */
.auth-card .form-control,
.auth-card .btn {
  min-height: 3rem;
  font-size: 1rem;
  border-radius: .5rem;
}

.auth-card .input-group > .btn {
  border-color: var(--cl-input-border);
  min-width: 4.5rem;
}

.auth-card .btn-primary {
  font-weight: 600;
}

.alert-info {
  --bs-alert-color: #0b4d53;
  --bs-alert-bg: #e6f1f2;
  --bs-alert-border-color: #c4dfe1;
}

[data-bs-theme="dark"] .alert-info {
  --bs-alert-color: #a8e3e7;
  --bs-alert-bg: #123234;
  --bs-alert-border-color: #1f4a4d;
}

/* A notice that is part of the page settles in once on load. Decoration only: it is fully
   visible without the animation, and there is none when the user asks for reduced motion. */
@media (prefers-reduced-motion: no-preference) {
  .notice-settle {
    animation: notice-settle 200ms ease-out;
  }
}

@keyframes notice-settle {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.auth-caps {
  min-height: 1.25rem;
  color: var(--cl-warning-text);
}

.auth-alt {
  border-top: 1px solid var(--bs-border-color);
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  font-size: .9375rem;
}

.auth-footer {
  margin-top: auto;
  padding-top: 2rem;
  font-size: .875rem;
  color: var(--bs-secondary-color);
}

.auth-footer a {
  color: inherit;
}

@media (prefers-reduced-motion: reduce) {
  .spinner-border {
    animation-duration: 1.5s;
  }
}

/* A wide table scrolls inside its own box on a phone. Bootstrap's screen-reader-only text (such as
   an "Actions" column heading) is absolutely positioned, and a box only clips that when it is
   positioned itself; without this, the hidden heading made the whole page wider than the screen. */
.table-responsive {
  position: relative;
}

/*
  Tables with class table-stack become compact cards below 992px (phones, tablets and a laptop zoomed
  to 150%: between 768 and 991px a page has only 696px for content, too little for a table with row
  buttons), laid out with CSS grid so the same markup serves both sizes. The decision queue:
    requester ........ amount
    description
    budget · date .... available
    [ action ]
  The header row stays for screen readers only.
*/
/*
  Decision buttons and the decline/void forms. Each form sits in its own table row right under its
  request (class decision-panel, a Bootstrap collapse), lined up under the buttons that open it.
*/
.decision-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: flex-end;
}

/* The Members page's role and deactivate buttons, side by side at the end of the row. */
.member-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: flex-end;
}

/* "Skip to main content" is hidden until a keyboard user tabs to it, then shows over the navbar's
   corner in the page colours. */
.skip-link:focus {
  position: absolute;
  top: .5rem;
  left: .5rem;
  z-index: 1080;
  padding: .5rem 1rem;
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  border: 2px solid var(--bs-primary);
  border-radius: var(--bs-border-radius);
}

/* Keyboard focus in the navbar, which is dark in both themes. Bootstrap's ring there is its own blue at
   25% (about 1.3:1 on the navbar), so a solid light-teal outline marks it instead (about 10:1). */
.navbar :is(.navbar-brand, .nav-link, .btn, .navbar-toggler):focus-visible {
  outline: 2px solid #8fdde3;
  outline-offset: 2px;
  box-shadow: none;
}

/* The phone menu button carries the unread notice count while the menu is closed. */
.navbar-toggler {
  position: relative;
}

.toggler-count {
  position: absolute;
  top: -.375rem;
  right: -.375rem;
  font-size: .75rem;
}

/* The footer's link is a 24px target (WCAG 2.5.8) without making the footer taller. */
.app-footer a {
  display: inline-block;
  padding: .25rem 0;
  margin: -.25rem 0;
}

/* A highlighted (table-warning) row: Bootstrap's cream stays light in dark mode, a bright band with
   black text there. Dark mode gets the amber tint of the dark "Submitted" badge, with the page's text. */
[data-bs-theme="dark"] .table-warning {
  --bs-table-color: var(--bs-body-color);
  --bs-table-bg: #3a2c0b;
  --bs-table-border-color: #5c4613;
  --bs-table-striped-bg: #43340f;
  --bs-table-striped-color: var(--bs-body-color);
  --bs-table-active-bg: #4c3b12;
  --bs-table-active-color: var(--bs-body-color);
  --bs-table-hover-bg: #43340f;
  --bs-table-hover-color: var(--bs-body-color);
}

/* Secondary buttons (Decline, Void, Cancel, Withdraw, Show): Bootstrap's grey outline text is
   below 4.5:1 on the dark page and cards, and an enabled button looked like a disabled one, so they
   use the body text colour in both themes (disabled ones fade). */
.btn-outline-secondary {
  --bs-btn-color: var(--bs-body-color);
  --bs-btn-border-color: var(--cl-input-border);
  --bs-btn-hover-color: var(--bs-body-color);
  --bs-btn-hover-bg: rgba(var(--bs-body-color-rgb), .06);
  --bs-btn-hover-border-color: var(--bs-body-color);
  --bs-btn-active-color: var(--bs-body-color);
  --bs-btn-active-bg: rgba(var(--bs-body-color-rgb), .1);
  --bs-btn-active-border-color: var(--bs-body-color);
  --bs-btn-disabled-color: var(--bs-body-color);
  --bs-btn-disabled-border-color: var(--cl-input-border);
  --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}

/*
  Request status badges (My requests): a tinted pill per status, keyed by data-status (the enum name,
  so no locale-dependent lower-casing). The words carry the meaning; colour only helps scanning.
  Waiting amber, money reserved teal, paid green, refused red, withdrawn grey, voided a dashed outline.
  Every text colour is at least 4.5:1 on its own background in both themes.
*/
.status-badge {
  display: inline-block;
  padding: .3em .6em;
  font-size: .8125rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  border: 1px solid;
  border-radius: 50rem;
}

.status-badge[data-status="SUBMITTED"] { background: #fff4d6; color: #7a4a00; border-color: #f2d08a; }
.status-badge[data-status="APPROVED"] { background: #e6f1f2; color: #0b4d53; border-color: #c4dfe1; }
.status-badge[data-status="REIMBURSED"] { background: #e3f4ea; color: #136c3a; border-color: #b9e2c8; }
.status-badge[data-status="DECLINED"] { background: #fdecea; color: #a2221a; border-color: #f5c2bd; }
.status-badge[data-status="WITHDRAWN"] { background: #eef1f1; color: #4a5656; border-color: #d5dcdc; }
.status-badge[data-status="VOIDED"] { background: transparent; color: #4a5656; border: 1px dashed #7e8c8c; }

[data-bs-theme="dark"] .status-badge[data-status="SUBMITTED"] { background: #3a2c0b; color: #f2c66d; border-color: #5c4613; }
[data-bs-theme="dark"] .status-badge[data-status="APPROVED"] { background: #123234; color: #a8e3e7; border-color: #1f4a4d; }
[data-bs-theme="dark"] .status-badge[data-status="REIMBURSED"] { background: #11301f; color: #8edbae; border-color: #1e4a31; }
[data-bs-theme="dark"] .status-badge[data-status="DECLINED"] { background: #3a1614; color: #f4a39c; border-color: #5a221e; }
[data-bs-theme="dark"] .status-badge[data-status="WITHDRAWN"] { background: #1e2a2a; color: #c2cece; border-color: #334444; }
[data-bs-theme="dark"] .status-badge[data-status="VOIDED"] { color: #c2cece; border-color: #7c9090; }

/* "Won't go ahead" (My requests, /decisions, /reimbursements): the requester says an approved request
   won't happen. An amber outline next to the status, so it reads as "needs the treasurer" without
   looking like another status. Text is at least 4.5:1 on the page and table colours in both themes. */
.wont-go-ahead-badge {
  padding: .3em .6em;
  font-size: .8125rem;
  font-weight: 600;
  color: #7a4a00;
  background: transparent;
  border: 1px solid #b07d12;
}

[data-bs-theme="dark"] .wont-go-ahead-badge { color: #f2c66d; border-color: #8a6a1f; }

/* On My requests the requester's mark sits on its own line under the request, joined to it. */
.table > tbody > tr:has(+ tr.request-note-row) > :is(td, th) {
  border-bottom-width: 0;
}

.request-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem 1rem;
}

.decision-form {
  max-width: 30rem;
  margin-left: auto;
  text-align: left;
}

.decision-form-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .75rem;
}

/* An open form reads as part of its request: no line between them, and no height animation,
   which table rows can't do smoothly. */
.table > tbody > tr:has(+ tr.decision-panel.show) > :is(td, th),
.table > tbody > tr:has(+ tr.decision-panel.collapsing) > :is(td, th) {
  border-bottom-width: 0;
}

.decision-panel.collapsing {
  transition: none;
}

/* The character count under a note or a request description (note-count.js). Over the limit it says so in words
   and turns the form-error colour, which has light and dark values above. The colour change is
   eased only when motion is welcome. */
.note-count.is-over {
  color: var(--bs-form-invalid-color);
  font-weight: 600;
}

@media (prefers-reduced-motion: no-preference) {
  .note-count {
    transition: color 150ms ease-out;
  }
}

@media (max-width: 991.98px) {
  .table-stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .table-stack tr {
    display: grid;
    /* The budget column takes what's left and wraps, so a long budget name can't push the card past
       the screen; the date and the available amount keep their width. */
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "requester requester amount"
      "description description description"
      "budget date available"
      "action action action";
    column-gap: .5rem;
    row-gap: .25rem;
    padding: 1rem;
    border-bottom: 1px solid var(--bs-border-color);
  }

  .table-stack tbody tr:last-child {
    border-bottom: 0;
  }

  .table-stack td {
    display: block;
    padding: 0 !important;
    border: 0;
    text-align: left !important;
  }

  .table-stack .cell-requester {
    grid-area: requester;
    font-weight: 600;
  }

  .table-stack .cell-amount {
    grid-area: amount;
    font-size: 1.0625rem;
    text-align: right !important;
  }

  .table-stack .cell-description {
    grid-area: description;
  }

  .table-stack .cell-budget,
  .table-stack .cell-date,
  .table-stack .cell-available {
    font-size: .875rem;
    color: var(--bs-secondary-color);
  }

  .table-stack .cell-budget {
    grid-area: budget;
    overflow-wrap: anywhere;
  }

  .table-stack .cell-date {
    grid-area: date;
  }

  .table-stack .cell-date::before {
    content: "\00b7";
    margin-right: .5rem;
  }

  .table-stack .cell-available {
    grid-area: available;
    text-align: right !important;
  }

  /*
    The ledger has no buttons but a long timestamp and a two-line balance, so its rows get their own
    grid, each part on a row of its own and allowed to wrap, so words are never split:
      who ............ amount
      action
      request
      date
      budget ......... balance after
  */
  .table-stack.ledger-stack tr {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "requester amount"
      "action action"
      "description description"
      "date date"
      "budget available";
  }

  .table-stack.ledger-stack .cell-action {
    grid-area: action;
  }

  /* An entry without a request (an allocation) has nothing to say in that line of the card. */
  .table-stack.ledger-stack .cell-empty {
    display: none;
  }

  .table-stack.ledger-stack .cell-date::before {
    content: none;
  }

  .table-stack.ledger-stack .cell-date,
  .table-stack.ledger-stack .cell-available {
    white-space: normal !important;
  }

  .table-stack.ledger-stack .cell-budget {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  /*
    Members: the name is the row's header cell, and the buttons share the card's width:
      name ........... role
      username ....... status
      [ role ] [ deactivate ]
  */
  .table-stack.members-stack tr {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name role"
      "username status"
      "actions actions";
  }

  .table-stack.members-stack th {
    display: block;
    padding: 0 !important;
    border: 0;
    grid-area: name;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .table-stack.members-stack .cell-role {
    grid-area: role;
    text-align: right !important;
  }

  .table-stack.members-stack .cell-username {
    grid-area: username;
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: .875rem;
    color: var(--bs-secondary-color);
  }

  .table-stack.members-stack .cell-status {
    grid-area: status;
    text-align: right !important;
  }

  .table-stack.members-stack .cell-actions {
    grid-area: actions;
    padding-top: .5rem !important;
  }

  .table-stack.members-stack .member-actions {
    display: flex;
  }

  .table-stack.members-stack .member-actions > form {
    flex: 1;
  }

  .table-stack.members-stack .member-actions .btn {
    width: 100%;
    min-height: 2.75rem;
  }

  /*
    My requests: the budget is the row's header cell; empty "decided by" and note cells are left out:
      budget ......... amount
      description
      status badges
      Decided by treasurer
      Decision note: ...
      [ action ]
    A "won't go ahead" line or form continues the card below it.
  */
  .table-stack.requests-stack tr {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "budget amount"
      "description description"
      "status status"
      "decider decider"
      "note note"
      "actions actions";
  }

  .table-stack.requests-stack th {
    display: block;
    padding: 0 !important;
    border: 0;
    grid-area: budget;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .table-stack.requests-stack .cell-amount {
    font-weight: 600;
  }

  .table-stack.requests-stack .cell-status {
    grid-area: status;
    white-space: normal !important;
  }

  .table-stack.requests-stack .cell-decider {
    grid-area: decider;
  }

  .table-stack.requests-stack .cell-note {
    grid-area: note;
  }

  .table-stack.requests-stack .cell-decider,
  .table-stack.requests-stack .cell-note {
    font-size: .875rem;
    color: var(--bs-secondary-color);
  }

  .table-stack.requests-stack .cell-decider::before {
    content: "Decided by ";
  }

  .table-stack.requests-stack .cell-note::before {
    content: "Decision note: ";
  }

  .table-stack.requests-stack .is-empty {
    display: none;
  }

  .table-stack.requests-stack .cell-actions {
    grid-area: actions;
  }

  .table-stack.requests-stack .cell-actions:has(.btn) {
    padding-top: .5rem !important;
  }

  .table-stack.requests-stack .cell-actions .btn {
    width: 100%;
    min-height: 2.75rem;
  }

  .table-stack tr.request-note-row {
    display: block;
    padding: 0 1rem 1rem;
  }

  .table-stack tr:has(+ tr.request-note-row) {
    border-bottom: 0;
  }

  .table-stack .request-note .btn {
    width: 100%;
    min-height: 2.75rem;
  }

  .table-stack .request-note > form {
    flex: 1 0 100%;
  }

  .table-stack .decision-cell {
    grid-area: action;
    padding-top: .5rem !important;
  }

  .table-stack .decision-cell .btn {
    width: 100%;
    min-height: 2.75rem;
  }

  .table-stack .decision-cell div {
    text-align: left;
  }

  /* Approve and Decline share the card's width. */
  .table-stack .decision-actions {
    display: flex;
  }

  .table-stack .decision-actions > * {
    flex: 1;
  }

  /* An open form continues its request's card. (.collapse:not(.show) still hides closed ones.) */
  .table-stack tr.decision-panel.show,
  .table-stack tr.decision-panel.collapsing {
    display: block;
    padding: 0 1rem 1rem;
  }

  .table-stack tr:has(+ tr.decision-panel.show),
  .table-stack tr:has(+ tr.decision-panel.collapsing) {
    border-bottom: 0;
  }

  .table-stack .decision-form {
    max-width: none;
  }

  .table-stack .decision-form-actions .btn {
    flex: 1;
    min-height: 2.75rem;
  }

  /* A highlighted row (Insights) is tinted as a whole card, not only behind its cells. */
  .table-stack tr.table-warning {
    background-color: var(--bs-table-bg);
  }

  /*
    Budgets: the name is the row's header cell; what's available is the card's headline, the other
    three amounts sit under it with their labels, and a treasurer's button takes the card's width:
      name ............. available
      Allocated  Committed  Spent
      [ Change allocation ]
    A wrapping flex row, not a grid: amounts as large as $1,000,000.00 that don't fit side by side on a
    narrow phone move to a second line instead of overlapping, and the name gives way to what's available.
  */
  .table-stack.budgets-stack tr {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem .75rem;
  }

  /* An empty full-width item between the headline and the amounts starts their line. */
  .table-stack.budgets-stack tr::before {
    content: "";
    flex-basis: 100%;
    order: 2;
  }

  .table-stack.budgets-stack th {
    display: block;
    order: 1;
    flex: 1 1 0;
    min-width: 0;
    padding: 0 !important;
    border: 0;
    overflow-wrap: anywhere;
  }

  .table-stack.budgets-stack .cell-available {
    order: 1;
    flex: none;
    font-size: 1.0625rem;
    color: inherit;
  }

  .table-stack.budgets-stack .cell-available::after {
    content: "available";
    display: block;
    font-size: .8125rem;
    font-weight: 400;
    color: var(--bs-secondary-color);
  }

  /* Equal columns while the amounts fit in 4.5rem (three fit a 320px phone); a longer one keeps its width
     and the row wraps. */
  .table-stack.budgets-stack :is(.cell-allocated, .cell-committed, .cell-spent) {
    order: 3;
    flex: 1 1 4.5rem;
    min-width: max-content;
  }

  .table-stack.budgets-stack .cell-allocated::before { content: "Allocated"; }
  .table-stack.budgets-stack .cell-committed::before { content: "Committed"; }
  .table-stack.budgets-stack .cell-spent::before { content: "Spent"; }

  .table-stack.budgets-stack :is(.cell-allocated, .cell-committed, .cell-spent)::before {
    display: block;
    font-size: .8125rem;
    color: var(--bs-secondary-color);
  }

  .table-stack.budgets-stack .cell-actions {
    order: 4;
    flex-basis: 100%;
    padding-top: .5rem !important;
  }

  /* A link styled as a button: flex centres its text in the taller touch target. */
  .table-stack.budgets-stack .cell-actions .btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 2.75rem;
  }

  /*
    Insights: the name and status on top, the utilization bar, then available and pending with their
    labels; the warning goes under pending:
      name ............ status
      [bar......] 66.66%
      Available ....... $75.00
      Pending ......... $100.00
      ⚠ $25.00 more than available
  */
  .table-stack.insights-stack tr {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name status"
      "utilization utilization"
      "available available"
      "pending pending";
    row-gap: .375rem;
  }

  .table-stack.insights-stack th {
    display: block;
    padding: 0 !important;
    border: 0;
    grid-area: name;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .table-stack.insights-stack .cell-utilization { grid-area: utilization; }
  .table-stack.insights-stack .cell-status { grid-area: status; }

  .table-stack.insights-stack .cell-available,
  .table-stack.insights-stack .cell-pending {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    column-gap: 1rem;
    font-size: inherit;
    color: inherit;
  }

  .table-stack.insights-stack .cell-pending { grid-area: pending; }
  .table-stack.insights-stack .cell-available::before { content: "Available"; }
  .table-stack.insights-stack .cell-pending::before { content: "Pending"; }

  .table-stack.insights-stack :is(.cell-available, .cell-pending)::before {
    color: var(--bs-secondary-color);
  }

  .table-stack.insights-stack .exposure-warning {
    flex-basis: 100%;
  }
}

/* Service status (#110). A state's word and icon share one colour (the request badges' green and
   red, which pass AA in both themes); the word carries the meaning, so colour is never alone. */
.service-state {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.service-icon {
  flex: none;
}

.service-state[data-state="WORKING"] { color: #136c3a; }
.service-state[data-state="NOT_RESPONDING"] { color: #a2221a; }
.service-state[data-state="CHECKING"] { color: var(--bs-secondary-color); }
[data-bs-theme="dark"] .service-state[data-state="WORKING"] { color: #8edbae; }
[data-bs-theme="dark"] .service-state[data-state="NOT_RESPONDING"] { color: #f4a39c; }

.status-parts .status-part {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .25rem 1rem;
  padding: .75rem 1.5rem;
  border-top: var(--bs-border-width) solid var(--bs-card-border-color);
}

.status-parts dd {
  margin: 0;
}

/* While checking, the three dots fade in turn, only when motion is welcome. Nothing depends on it. */
@media (prefers-reduced-motion: no-preference) {
  .service-state[data-state="CHECKING"] .service-icon circle {
    animation: status-dots 1.2s ease-in-out infinite;
  }

  .service-state[data-state="CHECKING"] .service-icon circle:nth-child(2) { animation-delay: .2s; }
  .service-state[data-state="CHECKING"] .service-icon circle:nth-child(3) { animation-delay: .4s; }
}

@keyframes status-dots {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}
