/*
 * Fees Collection System — application styles.
 *
 * Colour choices are checked against WCAG 2.1 AA: body text and all status
 * chips exceed a 4.5:1 contrast ratio, and every status is carried by a text
 * label and an icon glyph as well as by colour.
 */

:root {
  --colour-bg: #ffffff;
  --colour-surface: #f5f7f9;
  --colour-surface-alt: #eaeef2;
  --colour-text: #16202a; /* 15.3:1 on white */
  --colour-text-muted: #4a5764; /* 7.6:1 on white */
  --colour-border: #9aa7b4;
  --colour-border-strong: #5c6b7a;
  --colour-primary: #0f3d5c; /* 11.1:1 with white text */
  --colour-primary-hover: #0a2b41;
  --colour-danger: #8a1c1c; /* 7.9:1 on white */
  --colour-danger-bg: #fdecec;
  --colour-success: #14532d; /* 9.6:1 on white */
  --colour-success-bg: #e3f4e8;
  --colour-warning: #6b4a00; /* 7.3:1 on white */
  --colour-warning-bg: #fff3d4;
  --colour-info: #4c2a86; /* 9.1:1 on white */
  --colour-info-bg: #eee6fc;
  --focus-ring: 3px solid #16202a;
  --focus-halo: 0 0 0 6px #ffd24d;
  --radius: 6px;
  --space: 1rem;
  --font-stack: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

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

/* The `hidden` attribute must win over any component display rule. */
[hidden] {
  display: none !important;
}

html {
  font-family: var(--font-stack);
  font-size: 100%;
  line-height: 1.5;
  color: var(--colour-text);
  background: var(--colour-bg);
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--colour-bg);
}

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
  box-shadow: var(--focus-halo);
  border-radius: 3px;
}

/* Fallback for browsers without :focus-visible support. */
:focus:not(:focus-visible) {
  outline: none;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--colour-primary);
  color: #ffffff;
  padding: 0.75rem 1rem;
  z-index: 100;
}

.skip-link:focus {
  left: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------- app chrome */

.app-header {
  background: var(--colour-primary);
  color: #ffffff;
}

.app-header__bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  max-width: 76rem;
  margin: 0 auto;
  width: 100%;
}

.app-header__brand {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
}

.app-header__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
  font-size: 0.875rem;
}

.app-header__meta p {
  margin: 0;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: #ffffff;
  color: var(--colour-success);
  font-weight: 600;
}

.connection[data-state='offline'] {
  color: var(--colour-danger);
}

.unsynced {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #ffffff;
  color: var(--colour-warning);
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}

.identity {
  font-weight: 600;
}

.app-nav {
  background: var(--colour-primary-hover);
}

.app-nav__list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0 auto;
  padding: 0 0.5rem;
  max-width: 76rem;
}

.app-nav__list a {
  display: block;
  padding: 0.7rem 0.9rem;
  color: #ffffff;
  text-decoration: none;
  font-weight: 600;
  border-bottom: 4px solid transparent;
}

.app-nav__list a:hover {
  text-decoration: underline;
}

.app-nav__list a[aria-current='page'] {
  border-bottom-color: #ffd24d;
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: 76rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

/*
 * Focus moves to <main> after each client-side navigation so screen reader
 * users land on the new page. That is programmatic focus on a container, not
 * a keyboard stop, so it does not carry the interactive focus ring.
 */
.app-main:focus,
.app-main:focus-visible {
  outline: none;
  box-shadow: none;
}

/* ------------------------------------------------------------ live regions */

.live-region:empty {
  display: none;
}

.live-region {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border-left: 6px solid var(--colour-primary);
  background: var(--colour-surface);
  font-weight: 600;
}

#live-alert {
  border-left-color: var(--colour-danger);
  background: var(--colour-danger-bg);
  color: var(--colour-danger);
}

/* ------------------------------------------------------------------ typography */

h1 {
  font-size: 1.6rem;
  margin: 0 0 0.35rem;
}

h2 {
  font-size: 1.25rem;
  margin: 1.75rem 0 0.75rem;
}

h3 {
  font-size: 1.05rem;
  margin: 1.25rem 0 0.5rem;
}

.meta-line {
  color: var(--colour-text-muted);
  margin: 0.5rem 0 1.25rem;
  max-width: 60ch;
}

/* The sign-in page is the form and nothing else, so it centres in the viewport. */
.signin {
  max-width: 24rem;
  margin: 3rem auto 0;
}

.signin h1 {
  margin-bottom: 1.25rem;
}

/* ---------------------------------------------------------------- controls */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.75rem;
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius);
  border: 2px solid var(--colour-primary);
  background: var(--colour-primary);
  color: #ffffff;
  cursor: pointer;
}

.button:hover {
  background: var(--colour-primary-hover);
  border-color: var(--colour-primary-hover);
}

.button[disabled] {
  cursor: not-allowed;
  background: var(--colour-surface-alt);
  border-color: var(--colour-border-strong);
  color: var(--colour-text-muted);
}

.button--secondary {
  background: #ffffff;
  color: var(--colour-primary);
}

.button--secondary:hover {
  background: var(--colour-surface);
  color: var(--colour-primary-hover);
}

.button--danger {
  background: var(--colour-danger);
  border-color: var(--colour-danger);
}

.button--danger:hover {
  background: #6d1515;
  border-color: #6d1515;
}

.button--ghost {
  background: transparent;
  border-color: #ffffff;
  color: #ffffff;
  min-height: 2.25rem;
  padding: 0.35rem 0.75rem;
}

.button--ghost:hover {
  background: #ffffff;
  color: var(--colour-primary);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

/* ------------------------------------------------------------------- forms */

.form {
  max-width: 44rem;
}

.field {
  margin-bottom: 1.1rem;
}

.field > label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.field__hint {
  display: block;
  color: var(--colour-text-muted);
  font-size: 0.875rem;
  margin-bottom: 0.3rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.5rem 0.65rem;
  font: inherit;
  color: var(--colour-text);
  background: #ffffff;
  border: 2px solid var(--colour-border-strong);
  border-radius: var(--radius);
}

.field textarea {
  min-height: 6rem;
  resize: vertical;
}

.field input[aria-invalid='true'],
.field select[aria-invalid='true'],
.field textarea[aria-invalid='true'] {
  border-color: var(--colour-danger);
  background: var(--colour-danger-bg);
}

.field__error {
  display: block;
  margin-top: 0.3rem;
  color: var(--colour-danger);
  font-weight: 600;
}

.field__error:empty {
  display: none;
}

.field--inline {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1.25rem;
}

.filters .field {
  margin-bottom: 0;
  min-width: 11rem;
}

fieldset {
  border: 2px solid var(--colour-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0 0 1.25rem;
}

legend {
  font-weight: 700;
  padding: 0 0.4rem;
}

/* ------------------------------------------------------------------ tables */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--colour-border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 40rem;
}

caption {
  text-align: left;
  padding: 0.75rem;
  font-weight: 700;
  background: var(--colour-surface);
  border-bottom: 1px solid var(--colour-border);
}

th,
td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--colour-border);
  vertical-align: top;
}

thead th {
  background: var(--colour-surface-alt);
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tbody tr:last-child td {
  border-bottom: none;
}

td.numeric,
th.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ status */

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  border: 1px solid currentColor;
}

.status[data-status='pending'] {
  background: var(--colour-warning-bg);
  color: var(--colour-warning);
}

.status[data-status='verified'] {
  background: var(--colour-success-bg);
  color: var(--colour-success);
}

.status[data-status='rejected'] {
  background: var(--colour-danger-bg);
  color: var(--colour-danger);
}

.status[data-status='flagged'] {
  background: var(--colour-info-bg);
  color: var(--colour-info);
}

.sync-state {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--colour-text-muted);
}

.sync-state[data-sync='pending_sync'] {
  color: var(--colour-warning);
}

.sync-state[data-sync='failed'],
.sync-state[data-sync='conflict'] {
  color: var(--colour-danger);
}

/* ------------------------------------------------------------ assessment */

/*
 * What the system worked out, shown to the collector rather than typed by
 * them. It is styled as a statement of fact — a panel, not a field — so it
 * does not read as something waiting to be filled in.
 */
.assessment {
  border: 1px solid var(--colour-border);
  border-left: 6px solid var(--colour-primary);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  background: var(--colour-surface);
}

.assessment__title {
  margin: 0 0 0.6rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--colour-text-muted);
}

.assessment .detail-list {
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.6rem 1.25rem;
}

.assessment__total {
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

/* An override standing in for the assessed figure, wherever it is read. */
.override {
  border-left-color: var(--colour-info);
  background: var(--colour-info-bg);
}

/* ----------------------------------------------------- checkbox groups */

.checkbox-group {
  border: 1px solid var(--colour-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem 1rem;
  margin: 0 0 1rem;
  min-width: 0;
}

.checkbox-group legend {
  font-weight: 700;
  padding: 0 0.35rem;
}

/*
 * The boxes wrap into as many columns as fit. A class list is short words and
 * a fee category list is a few more, so a fixed column count would either
 * waste half the row or cut the longest label in half.
 */
.checkbox-group__items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 0.35rem 1rem;
  margin-top: 0.5rem;
}

.checkbox-group .field--inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-group input[type='checkbox'] {
  /* A deliberate touch target: these are ticked with a thumb. */
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
}

.checkbox-group label {
  font-weight: 400;
}

/* The filter panel's own grid: the two long lists sit side by side on a desk. */
.filter-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 0 1.5rem;
  align-items: start;
  border: 1px solid var(--colour-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
  background: var(--colour-surface);
}

.filter-panel__actions {
  grid-column: 1 / -1;
}

/* ----------------------------------------------------------------- ledger */

/*
 * A balance is never shown as a bare negative number: a parent handed
 * "-2,000" has to work out which way round it is. The figure is the amount and
 * the word underneath says which direction, so colour is carrying emphasis
 * rather than meaning.
 */
.owing {
  color: var(--colour-danger);
  font-weight: 700;
}

.in-credit {
  color: var(--colour-success);
  font-weight: 700;
}

/* ---------------------------------------------------------------- combobox */

/*
 * The suggestion list sits in the flow under its input rather than floating
 * over it. An overlay inside a scrolling sheet gets clipped or left behind by
 * the scroll on exactly the devices this app is used on; pushing the fields
 * below it down instead is never wrong, and on a phone it keeps the list clear
 * of the on-screen keyboard.
 */
.combobox__list {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  max-height: 14rem;
  overflow-y: auto;
  border: 1px solid var(--colour-border-strong);
  border-radius: var(--radius);
  background: var(--colour-bg);
}

.combobox__option {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  /* A comfortable touch target: this is picked with a thumb, in a hurry. */
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--colour-surface-alt);
}

.combobox__option:last-child {
  border-bottom: 0;
}

/*
 * The keyboard's active option and the pointer's hover are the same state, so
 * they look the same. Colour is not carrying it alone — the whole row changes
 * background and the name stays at full contrast.
 */
.combobox__option.is-active,
.combobox__option:hover {
  background: var(--colour-surface-alt);
}

.combobox__name {
  font-weight: 600;
}

.combobox__meta {
  font-size: 0.85rem;
  color: var(--colour-text-muted);
}

/* ----------------------------------------------------------------- balance */

/*
 * The balance verdict is deliberately not shaped like a review status: one
 * says where the entry is in the workflow, the other says what the money did,
 * and a verifier reading them as the same thing is the mistake the whole
 * cross-check exists to catch. So it is a square-cornered tag, not a pill,
 * and it carries a sign glyph as well as its colour and label.
 */
.balance-state {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  border: 1px solid currentColor;
  background: var(--colour-surface);
  color: var(--colour-text);
}

.balance-state[data-balance='fully_paid'] {
  background: var(--colour-success-bg);
  color: var(--colour-success);
}

.balance-state[data-balance='overpaid'] {
  background: var(--colour-info-bg);
  color: var(--colour-info);
}

.balance-state[data-balance='underpaid'] {
  background: var(--colour-warning-bg);
  color: var(--colour-warning);
}

/* The collector's figures and the same sum done independently, side by side. */
.balance-compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1rem 1.5rem;
}

.balance-compare__title {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--colour-text-muted);
}

.balance-problems {
  margin: 0 0 0.25rem;
  padding-left: 1.2rem;
  font-weight: 600;
  color: var(--colour-danger);
}

.balance-problems li + li {
  margin-top: 0.35rem;
}

/* ------------------------------------------------------------------- cards */

.card {
  border: 1px solid var(--colour-border);
  border-radius: var(--radius);
  padding: 1rem;
  background: #ffffff;
  margin-bottom: 1rem;
}

.card h3 {
  margin-top: 0;
}

/*
 * A card holding figures that contradict themselves. The heavy left edge
 * matches the danger notice inside it, so the whole section reads as one
 * warning rather than as a card that happens to contain one.
 */
.card--mismatch {
  border-color: var(--colour-danger);
  border-left-width: 6px;
  background: var(--colour-danger-bg);
}

/* Label-above-value pairs that wrap into as many columns as will fit. */
.detail-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.9rem 1.5rem;
  margin: 0;
}

.detail-list > div {
  min-width: 0;
}

.detail-list dt {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--colour-text-muted);
}

.detail-list dd {
  margin: 0.15rem 0 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.notice {
  border-left: 6px solid var(--colour-warning);
  background: var(--colour-warning-bg);
  color: var(--colour-warning);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin: 0.75rem 0;
  font-weight: 600;
}

.notice--inline {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.85rem;
}

.notice--danger {
  border-left-color: var(--colour-danger);
  background: var(--colour-danger-bg);
  color: var(--colour-danger);
}

.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--colour-text-muted);
  background: var(--colour-surface);
  border-radius: var(--radius);
}

/* ------------------------------------------------------------------- stats */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 0;
  list-style: none;
}

.stat {
  border: 1px solid var(--colour-border);
  border-radius: var(--radius);
  padding: 1rem;
  background: var(--colour-surface);
}

/* A count worth acting on rather than a figure worth reading. */
.stat--warn {
  border-color: var(--colour-danger);
  background: var(--colour-danger-bg);
  color: var(--colour-danger);
}

.stat--warn .stat__label,
.stat--warn .stat__sub {
  color: var(--colour-danger);
}

.stat__label {
  display: block;
  font-size: 0.875rem;
  color: var(--colour-text-muted);
  margin-bottom: 0.25rem;
}

.stat__value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat__sub {
  display: block;
  font-size: 0.85rem;
  color: var(--colour-text-muted);
}

.proof-preview {
  max-width: 18rem;
  max-height: 14rem;
  border: 1px solid var(--colour-border);
  border-radius: var(--radius);
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 40rem) {
  .app-header__bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-nav__list {
    flex-direction: column;
  }

  .app-nav__list a {
    border-bottom: none;
    border-left: 4px solid transparent;
  }

  .app-nav__list a[aria-current='page'] {
    border-left-color: #ffd24d;
  }

  h1 {
    font-size: 1.35rem;
  }
}

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

/* --------------------------------------------------------- route progress */

/*
 * Feedback for the rare navigation that has to wait on the network. The
 * animation is delayed, so a view served from IndexedDB or the service worker
 * is already painted before the bar would have appeared — no flicker on the
 * navigations that are instant, and no silent pause on the ones that are not.
 */
.route-progress {
  height: 3px;
  overflow: hidden;
  background: var(--colour-primary-hover);
}

.route-progress::after {
  content: '';
  display: block;
  height: 100%;
  width: 35%;
  background: #ffd24d;
  transform: translateX(-100%);
}

[data-route-busy='true'] .route-progress::after {
  animation: route-progress 1s linear 0.18s infinite;
}

@keyframes route-progress {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(340%);
  }
}

/* ------------------------------------------------------------- action bar */

/*
 * `body` is a full-height column with `.app-main` flexing, so the bar sits on
 * the bottom edge of the viewport whether the page is short or long, and stays
 * there while the list scrolls behind it.
 */
.action-bar {
  /*
   * Sticky, not fixed: it stays on screen the whole way down a long list, but
   * it is still in flow, so it reserves its own space and can never come to
   * rest on top of the last row of a table the way a fixed bar would.
   */
  position: sticky;
  bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: var(--colour-bg);
  border-top: 1px solid var(--colour-border);
}

.button--action {
  width: 100%;
  max-width: 26rem;
  min-height: 3rem;
  font-size: 1.05rem;
}

.button__glyph {
  font-size: 1.25em;
  line-height: 1;
}

/* ----------------------------------------------------------- payment sheet */

/*
 * The sheet fills the viewport and centres its own panel, so a click anywhere
 * beside the panel lands on the dialog element itself. That is what the
 * dismiss handler reads as "clicked outside".
 */
.sheet {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
}

.sheet[open] {
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet::backdrop {
  background: rgba(16, 24, 32, 0.55);
}

.sheet__panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 40rem;
  max-height: 92vh;
  background: var(--colour-bg);
  color: var(--colour-text);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 28px rgba(16, 24, 32, 0.3);
  animation: sheet-in 0.18s ease-out;
}

@keyframes sheet-in {
  from {
    transform: translateY(1.5rem);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--colour-border);
}

.sheet__title {
  margin: 0;
  font-size: 1.25rem;
}

.sheet__close {
  min-width: 2.75rem;
  min-height: 2.75rem;
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  background: transparent;
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--colour-text);
  cursor: pointer;
}

.sheet__close:hover {
  background: var(--colour-surface-alt);
}

.sheet__body {
  overflow-y: auto;
  padding: 1rem 1rem 0;
}

.sheet__body .form {
  max-width: none;
}

.sheet__message {
  padding-bottom: 1rem;
}

/* The save and cancel pair stays reachable however long the form runs. */
.sheet__body .form__actions {
  position: sticky;
  bottom: 0;
  margin-top: 1.5rem;
  padding: 0.75rem 0 1rem;
  background: var(--colour-bg);
  border-top: 1px solid var(--colour-border);
}

/*
 * The discard question. It covers the form rather than replacing it, so the
 * details at stake stay visible while the choice is made; the form beneath is
 * made inert at the same time, so nothing under the overlay can be reached.
 */
.sheet__confirm {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(16, 24, 32, 0.6);
}

.sheet__confirm-panel {
  max-width: 26rem;
  padding: 1.25rem;
  background: var(--colour-bg);
  border-radius: var(--radius);
  box-shadow: 0 4px 28px rgba(16, 24, 32, 0.35);
}

.sheet__confirm-panel h2 {
  margin-top: 0;
  font-size: 1.15rem;
}

.sheet__confirm-panel p {
  margin-bottom: 0;
  color: var(--colour-text-muted);
}

@media (min-width: 40rem) {
  .sheet[open] {
    align-items: center;
  }

  .sheet__panel {
    max-height: 88vh;
    border-radius: var(--radius);
  }
}

/* ------------------------------------------------------------------ search */

.search {
  margin-bottom: 1.25rem;
}

.search fieldset {
  margin: 0;
  padding: 0.75rem 1rem 1rem;
  border: 1px solid var(--colour-border);
  border-radius: var(--radius);
  background: var(--colour-surface);
}

.search legend {
  padding: 0 0.4rem;
  font-weight: 600;
}

/*
 * The fields wrap into as many columns as fit rather than a fixed grid: the
 * same panel serves a phone held one-handed at a gate and a desktop.
 */
.search__fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0.5rem 1rem;
}

.search__fields .field {
  margin-bottom: 0;
}

.search__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.9rem;
}

/* The less-used filters, folded away until asked for or already in use. */
.search__more {
  margin-top: 0.75rem;
}

.search__more > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--colour-primary);
  padding: 0.35rem 0;
  min-height: 2.75rem;
  display: flex;
  align-items: center;
}

.search__more > summary:focus-visible {
  outline: var(--focus-ring);
  box-shadow: var(--focus-halo);
  border-radius: var(--radius);
}

.search__more[open] > summary {
  margin-bottom: 0.5rem;
}

/*
 * A filter over a list that is already on the page. It filters as you type,
 * so there is no submit button — only the count of what is left.
 */
.list-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--colour-border);
  border-radius: var(--radius);
  background: var(--colour-surface);
}

.list-filter .field {
  margin-bottom: 0;
  flex: 1 1 11rem;
  min-width: 0;
}

.list-filter .field--wide {
  flex: 2 1 16rem;
}

.list-filter__count {
  flex-basis: 100%;
  margin: 0;
  color: var(--colour-text-muted);
}

/* ------------------------------------------------------------------- pager */

.pager {
  display: flex;
  justify-content: center;
  margin: 1rem 0 0;
}

.pager .button {
  min-width: 14rem;
}
