/* ===================================
   UI COMPONENTS
   Consolidates: nav-styles.css, loading.css, toast.css
   Plus: Modern component enhancements
   =================================== */

/* ===================================
   MODAL COMPONENTS
   =================================== */

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes scaleIn {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ===================================
   LOADING COMPONENTS
   =================================== */

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.loading-overlay.active {
  display: flex;
}

.loading-spinner {
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.btn-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}

.btn-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text::after {
  content: '';
  animation: loading-dots 1.5s infinite;
}

@keyframes loading-dots {
  0%,
  20% {
    content: '.';
  }
  40% {
    content: '..';
  }
  60%,
  100% {
    content: '...';
  }
}

/* Skeleton Loading */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.1) 25%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0.1) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 16px;
  margin-bottom: 8px;
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: 16px;
}

.skeleton-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.pulse {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.spinner-small {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-top: 2px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}

.loading-message {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 15px;
  background-color: rgba(221, 114, 0, 0.1);
  border-left: 3px solid var(--primary-color);
  border-radius: var(--radius-md);
  margin: 10px 0;
}

.loading-message .spinner-small {
  margin-left: 0;
}

/* ===================================
   RESPONSIVE DESIGN
   =================================== */

/* Content spacing for fixed nav */
body {
  padding-top: 70px;
}

@media (max-width: 768px) {
  /* Loading overlay mobile improvements */
  .loading-spinner {
    width: 40px;
    height: 40px;
  }
}

/* ===================================
   REDESIGN FOUNDATION (v2)
   Additive shared classes for the visual redesign (design_handoff).
   Unused by current pages; later phases opt in per page.
   =================================== */

/* --- Buttons: one hierarchy --- */

.btn-primary-v2 {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  /* --brand-solid, not --brand: this label is 14px/600 = SMALL text by WCAG,
     so it needs 4.5:1, and raw --brand only clears 3:1 in 15 of the 30 themes
     (The House orange measures 3.24:1 against white). --brand-solid is the
     same hue darkened just far enough to clear the bar; --brand itself is
     unchanged and still correct for icons, borders and fills with no text
     on them. Mirrors iOS `appBrandSolid`. Enforced by themeContrast.test.js. */
  background: var(--brand-solid, var(--brand));
  color: var(--on-brand, #ffffff);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 150ms ease-out;
}

.btn-primary-v2:hover {
  background: var(--brand-solid-hover, var(--brand-hover));
}

.btn-primary-v2:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn-primary-v2:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost-v2 {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1.5px solid var(--input-border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-color);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition:
    background-color 150ms ease-out,
    border-color 150ms ease-out;
}

.btn-ghost-v2:hover {
  background: var(--hover-bg);
  border-color: var(--text-faint);
}

.btn-ghost-v2:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

.btn-ghost-v2:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-danger-ghost-v2 {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1.5px solid var(--danger-border);
  border-radius: 8px;
  background: transparent;
  color: var(--danger-text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition:
    background-color 150ms ease-out,
    border-color 150ms ease-out;
}

.btn-danger-ghost-v2:hover {
  background: var(--danger-bg);
  border-color: var(--danger-text);
}

.btn-danger-ghost-v2:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(209, 36, 47, 0.18);
}

.btn-danger-ghost-v2:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Status badges: one system (pill 11.5px/600, 3px 10px, radius 99px) --- */

.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.badge-member {
  background: #e3f2e5;
  color: #1a7f37;
}

.badge-staff {
  background: #e3ecfa;
  color: #1f5fbf;
}

.badge-client {
  background: #efe7f8;
  color: #6f42c1;
}

.badge-guest {
  background: #fcf0d8;
  color: #9a6700;
}

.badge-daypass {
  background: #dff3f6;
  color: #0e7a8a;
}

.badge-danger {
  background: #fde8e8;
  color: #b42318;
}

/* Deep-ink status pairs shared with the Dashboard/census badge set.
   Bright --success-color/--warning-color are icon/chart colors, never
   badge text — these use the deep-ink pairs from the design handoff. */
.badge-promotional {
  background: #e3f2e5;
  color: #1a7f37;
}

.badge-summer-hold {
  background: #fcf0d8;
  color: #9a6700;
}

.badge-neutral {
  background: #f4f1ec;
  color: #57534e;
}

/* Parent portal accounts — neutral purple, deliberately muted next to the
   saturated client purple (parents are never lounge attendees). */
.badge-parent {
  background: #ece9f4;
  color: #5e548e;
}

/* Dark-mode badge values (per design handoff badge table).
   Keyed on the -dark suffix so thehouse-dark AND all accent-dark
   themes get the same semantic badge treatment. */
[data-theme$='-dark'] .badge-member,
[data-theme='custom'] .badge-member {
  background: rgba(87, 196, 106, 0.16);
  color: #57c46a;
}

[data-theme$='-dark'] .badge-staff,
[data-theme='custom'] .badge-staff {
  background: rgba(121, 174, 242, 0.16);
  color: #79aef2;
}

[data-theme$='-dark'] .badge-client,
[data-theme='custom'] .badge-client {
  background: rgba(183, 148, 240, 0.18);
  color: #b794f0;
}

[data-theme$='-dark'] .badge-guest,
[data-theme='custom'] .badge-guest {
  background: rgba(227, 179, 65, 0.16);
  color: #e3b341;
}

[data-theme$='-dark'] .badge-daypass,
[data-theme='custom'] .badge-daypass {
  background: rgba(94, 200, 216, 0.16);
  color: #5ec8d8;
}

[data-theme$='-dark'] .badge-danger,
[data-theme='custom'] .badge-danger {
  background: rgba(244, 112, 103, 0.16);
  color: #f47067;
}

[data-theme$='-dark'] .badge-promotional,
[data-theme='custom'] .badge-promotional {
  background: rgba(87, 196, 106, 0.16);
  color: #57c46a;
}

[data-theme$='-dark'] .badge-summer-hold,
[data-theme='custom'] .badge-summer-hold {
  background: rgba(227, 179, 65, 0.16);
  color: #e3b341;
}

[data-theme$='-dark'] .badge-neutral,
[data-theme='custom'] .badge-neutral {
  background: rgba(179, 172, 164, 0.16);
  color: #b3aca4;
}

[data-theme$='-dark'] .badge-parent,
[data-theme='custom'] .badge-parent {
  background: rgba(158, 148, 196, 0.16);
  color: #9e94c4;
}

/* --- Cards: borders at rest, shadow only on hover-lift --- */

.card-v2 {
  background: var(--surface);
  border: 1px solid var(--border-color-soft);
  border-radius: 12px;
  box-shadow: none;
  transition:
    transform 150ms ease-out,
    border-color 150ms ease-out,
    box-shadow 150ms ease-out;
}

.card-v2:hover {
  transform: translateY(-2px);
  border-color: var(--input-border);
  box-shadow: 0 6px 16px rgba(41, 37, 36, 0.08);
}

/* --- Section label --- */

.section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* --- Toasts (v2): bottom-left stack, dark surface in both modes.
       CSS only for now; the toast queue JS lands in a later phase. --- */

.toast-stack-v2 {
  position: fixed;
  left: 24px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: var(--z-toast);
  pointer-events: none;
}

.toast-v2 {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 360px;
  padding: 12px 16px;
  border: 1px solid #35302b;
  border-radius: 12px;
  background: #262220;
  color: #f4f1ec;
  font-size: 14px;
  box-shadow: 0 12px 32px rgba(41, 37, 36, 0.14);
  pointer-events: auto;
}

.toast-v2-action {
  padding: 4px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #f5a04c;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.toast-v2-action:hover {
  background: rgba(245, 160, 76, 0.12);
}

/* --- Inputs & focus ring utility --- */

.input-v2 {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--input-border);
  border-radius: 8px;
  background: var(--canvas);
  color: var(--text-color);
  font-family: inherit;
  font-size: 14px;
  box-sizing: border-box;
  transition:
    border-color 150ms ease-out,
    box-shadow 150ms ease-out;
}

.input-v2::placeholder {
  color: var(--text-faint);
}

.input-v2:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

/* --- Closed-day banner (maintenance.js) — warning surface, left-aligned
       row with a 34px icon chip; sentence-case title + secondary body. --- */

.closed-day-banner {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--warning-bg);
  border: 1px solid var(--warning-color);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 20px;
}

.closed-day-banner__chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--warning-color) 18%, transparent);
  color: #9a6700;
  font-size: 16px;
}

[data-theme$='-dark'] .closed-day-banner__chip,
[data-theme='custom'] .closed-day-banner__chip {
  color: #e3b341;
}

.closed-day-banner__title {
  margin: 0 0 3px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-color);
}

.closed-day-banner__body {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
}

/* ===================================================================
   Wave 3 — shared modal shell (.modal-v2), confirm dialog (.confirm-v2),
   and toast additions. Additive only; recreates the design_handoff shared
   modal shell WITHOUT touching existing .modal / .modal-content rules.
   Pages opt in by adding the v2 classes. Theme-aware via tokens (works
   under every accent + light/dark); toasts are intentionally always-dark.
   =================================================================== */

/* --- Modal shell (per Modals Light.dc.html) --- */

@keyframes modal-v2-overlay-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modal-v2-pop-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-v2-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  /* Dim backdrop — no token for this exact scrim, matches the design. */
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal);
  animation: modal-v2-overlay-in 160ms ease-out;
}

/* Confirm dialogs (and any drop-in overlay) sit above page-level modals. */
.modal-v2-overlay.is-top {
  z-index: 100000;
}

.modal-v2 {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: hidden;
  border: 1px solid var(--border-color-soft);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text-color);
  box-shadow: var(--shadow-xl);
  animation: modal-v2-pop-in 220ms var(--spring);
}

.modal-v2-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  padding: 18px 24px;
  border-bottom: 1px solid var(--hairline);
}

.modal-v2-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  /* Brand tint that follows the active accent. */
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  color: var(--brand);
  font-size: 15px;
}

.modal-v2-icon.is-danger {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.modal-v2-titles {
  flex: 1;
  min-width: 0;
}

.modal-v2-title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-color);
}

.modal-v2-subtitle {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-secondary);
}

.modal-v2-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  transition:
    background-color 150ms ease-out,
    color 150ms ease-out;
}

.modal-v2-close:hover {
  background: var(--hover-bg);
  color: var(--text-color);
}

.modal-v2-close:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.modal-v2-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px;
  color: var(--text-color);
}

.modal-v2-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
  padding: 16px 24px;
  border-top: 1px solid var(--hairline);
  background: var(--canvas);
}

/* Push a secondary/left-aligned footer action to the left edge. */
.modal-v2-footer-lead {
  margin-right: auto;
}

/* Form helpers for the design's form modals (inputs reuse .input-v2). */
.modal-v2-label {
  display: block;
  margin-bottom: 5px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-color);
}

.modal-v2-section-label {
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* --- Solid destructive button (design's confirm uses a solid red) --- */

.btn-danger-v2 {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  background: var(--danger-solid);
  color: #ffffff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 150ms ease-out;
}

.btn-danger-v2:hover {
  background: color-mix(in srgb, var(--danger-solid) 85%, #000);
}

.btn-danger-v2:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(209, 36, 47, 0.3);
}

.btn-danger-v2:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Confirm dialog (per Interactions.dc.html) — compact modal-v2 variant
       for destructive confirmation; replaces window.confirm. --- */

.confirm-v2 {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 400px;
  overflow: hidden;
  border: 1px solid var(--border-color-soft);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text-color);
  box-shadow: var(--shadow-xl);
  animation: modal-v2-pop-in 220ms var(--spring);
}

.confirm-v2-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px 24px 0;
}

.confirm-v2-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--danger-bg);
  color: var(--danger-text);
  font-size: 17px;
}

.confirm-v2-title {
  margin-bottom: 4px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-color);
}

.confirm-v2-message {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-secondary);
}

.confirm-v2-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 20px 24px;
}

/* --- Toasts (v2) — extends the foundation-phase .toast-v2 / .toast-stack-v2
       with a leading status icon and enter/exit transitions. The base
       classes (bottom-left fixed dark stack, action button) already exist
       above; these are additive and unused by any current page. --- */

.toast-v2 {
  /* Added: enter/exit motion. Base .toast-v2 (dark surface, layout) is
     defined earlier; this only layers on the transition. */
  transition:
    transform 320ms var(--spring),
    opacity 250ms ease-out;
}

.toast-v2.is-entering,
.toast-v2.is-leaving {
  opacity: 0;
  transform: translateY(16px) scale(0.98);
}

.toast-v2-message {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  line-height: 1.4;
}

/* Status icon badges. Toasts are always dark, so these fixed colors are
   intentional (mode-varying status tokens would be wrong on a fixed-dark
   surface); they mirror the design_handoff toast icons. */
.toast-v2-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: #ffffff;
  font-size: 11px;
}

.toast-v2-icon.is-success {
  background: #1a7f37;
}

.toast-v2-icon.is-error {
  background: #b42318;
}

.toast-v2-icon.is-warning {
  background: #9a6700;
}

.toast-v2-icon.is-info {
  background: #2f6feb;
}

/* ============================================================
   Wide data tables → stacked cards on phones
   ------------------------------------------------------------
   Opt in with class="cards-on-mobile" on the <table>. Column
   names come from the table's own <thead>, stamped onto each
   cell as data-label by js/responsive-tables.js.

   Why: an 8-column roster inside overflow-x:auto forces staff to
   scroll sideways to read one record, losing the name column on
   the way. Cards keep every value on screen and readable
   top-to-bottom. Above the breakpoint the table is untouched.
   ============================================================ */
@media (max-width: 768px) {
  table.cards-on-mobile,
  table.cards-on-mobile tbody,
  table.cards-on-mobile tr,
  table.cards-on-mobile td {
    display: block;
    width: 100%;
    min-width: 0;
    /* border-box or the card's padding is ADDED to width:100% and every
       value clips off the right edge. */
    box-sizing: border-box;
  }

  table.cards-on-mobile thead {
    display: none;
  }

  table.cards-on-mobile tr {
    background: var(--surface);
    border: 1.5px solid var(--border-color-soft);
    border-radius: var(--radius-md, 10px);
    padding: 10px 14px;
    margin-bottom: 10px;
  }

  table.cards-on-mobile td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    padding: 5px 0;
    border-bottom: none;
    text-align: right;
    white-space: normal;
    word-break: break-word;
  }

  table.cards-on-mobile td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    text-align: left;
  }

  /* First cell leads the card like a heading. */
  table.cards-on-mobile td:first-child {
    display: block;
    text-align: left;
    font-size: 15px;
    font-weight: 600;
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-color-soft);
  }

  table.cards-on-mobile td:first-child::before,
  table.cards-on-mobile td[data-no-label]::before {
    content: none;
  }

  /* Empty-state / colspan rows stay plain full-width text. */
  table.cards-on-mobile td[data-no-label] {
    display: block;
    text-align: center;
  }

  /* A cell whose content is itself a control set gets the full card width. */
  table.cards-on-mobile td:has(button + button) {
    display: block;
    text-align: left;
  }
}

/* ============================================================
   Two-up fields inside a card — add class="cards-2col"
   ------------------------------------------------------------
   The one-value-per-row card is honest but tall: an 8-column
   session row becomes eight full-width lines, so three records
   fill a phone screen. Most of those values are SHORT (a status,
   an IP, a clock time) and waste the right half of the card.

   This lays the value cells out two-up with the label ABOVE the
   value (side-by-side label/value would leave ~60px for the
   value at 320px). Cells that can't take half a card — the
   leading name cell, action buttons, a full user-agent string,
   empty-state rows — span the full width.
   ============================================================ */
@media (max-width: 768px) {
  table.cards-on-mobile.cards-2col tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 12px;
    align-items: start;
  }

  table.cards-on-mobile.cards-2col td {
    display: block;
    text-align: left;
    padding: 6px 0 0;
  }

  table.cards-on-mobile.cards-2col td::before {
    display: block;
    margin-bottom: 1px;
    font-size: 11px;
  }

  /* Full-width cells: the card heading, controls, long free text
     (user agents), and colspan empty-state rows. */
  table.cards-on-mobile.cards-2col td:first-child,
  table.cards-on-mobile.cards-2col td[data-no-label],
  table.cards-on-mobile.cards-2col td:has(button),
  table.cards-on-mobile.cards-2col td:has(.user-agent),
  table.cards-on-mobile.cards-2col td.card-span {
    grid-column: 1 / -1;
  }

  /* Action rows read as a control strip, not a labelled field. */
  table.cards-on-mobile.cards-2col td:has(button) {
    padding-top: 10px;
  }

  table.cards-on-mobile.cards-2col td:has(button)::before {
    content: none;
  }
}

/* ============================================================
   FORM tables → cards on mobile — class="form-cards-on-mobile"
   ------------------------------------------------------------
   The sibling of .cards-on-mobile above, for tables whose cells
   hold INPUTS rather than text.

   Why they need their own treatment: a read-only cell that gets
   50px wide is merely cramped, but a text INPUT that gets 50px
   wide is unusable — you cannot see what you are typing. The
   Create/Edit User modal shipped two of them: Emergency Contacts
   (5 columns) and Education (6 columns of text inputs, under
   table-layout:fixed). Preston reported it 2026-08-09:
   "hard to see your inputs with everything squished onto one
   line."

   Shape: one card per row, fields laid out in a two-column grid.
   A field is FULL WIDTH by default; a table pairs up its short
   ones by opting them into `grid-column: span 1`. Labels sit
   ABOVE their input (side-by-side leaves ~60px for the value at
   320px — the same finding that shaped .cards-2col) and come
   from the table's own <thead> via js/responsive-tables.js.

   Space is the constraint, not just width: add
   `no-field-labels` where the inputs already carry placeholders
   that say the same thing, and the row's action buttons pin to
   the card's top-right instead of spending a row of their own.
   ============================================================ */
@media (max-width: 768px) {
  table.form-cards-on-mobile,
  table.form-cards-on-mobile tbody {
    display: block;
    width: 100%;
  }

  table.form-cards-on-mobile thead {
    display: none;
  }

  table.form-cards-on-mobile tr {
    /* Anchors the pinned action cell below. */
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
    width: 100%;
    margin-bottom: 12px;
    padding: 10px;
    border: 1.5px solid var(--border-color-soft);
    border-radius: var(--radius-md, 10px);
    background: var(--surface);
    /* border-box or the padding is ADDED to width:100% and the right
       edge clips — the same trap .cards-on-mobile documents. */
    box-sizing: border-box;
  }

  table.form-cards-on-mobile td {
    display: block;
    /* Full width unless the table pairs this column up. */
    grid-column: 1 / -1;
    min-width: 0;
    padding: 0;
    border: none;
    box-sizing: border-box;
  }

  table.form-cards-on-mobile td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 3px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
  }

  /* Placeholders already name every field — skip the labels and the
     ~16px each of them costs. */
  table.form-cards-on-mobile.no-field-labels td::before {
    content: none;
  }

  table.form-cards-on-mobile td input,
  table.form-cards-on-mobile td select,
  table.form-cards-on-mobile td textarea {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    box-sizing: border-box;
  }

  /* Last cell is the row's controls. Pinned to the card's top-right,
     out of grid flow; the first field reserves room for it. */
  table.form-cards-on-mobile td:last-child {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 6px;
    width: auto;
  }

  table.form-cards-on-mobile td:last-child::before {
    content: none;
  }

  table.form-cards-on-mobile td:last-child .btn-icon,
  table.form-cards-on-mobile td:last-child button {
    width: auto;
    min-width: 44px;
    min-height: 44px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Room for a single icon button; `actions-wide` for a pair. */
  table.form-cards-on-mobile td:first-child {
    padding-right: 56px;
  }

  table.form-cards-on-mobile.actions-wide td:first-child {
    padding-right: 124px;
  }
}

/* ============================================================
   Emergency-contact editor on Settings → Account
   ------------------------------------------------------------
   The same editor as the check-in modal's, built as flex rows of
   divs rather than a table. It used to carry its layout in INLINE
   styles, which no media query can reach — so it kept its desktop
   flex row on a phone and wrapped into uneven fragments.

   Desktop keeps the single flex line. On phones it takes the same
   card shape as .form-cards-on-mobile so both editors in the app
   look and behave alike.
   ============================================================ */
.account-ec-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.account-ec-row .ec-name,
.account-ec-row .ec-phone,
.account-ec-row .ec-email {
  flex: 2;
  min-width: 110px;
}

.account-ec-row .ec-relationship,
.account-ec-row .ec-other-relationship {
  flex: 1;
  min-width: 110px;
}

@media (max-width: 768px) {
  .account-ec-row {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
    padding: 10px;
    margin-bottom: 12px;
    border: 1.5px solid var(--border-color-soft);
    border-radius: var(--radius-md, 10px);
    background: var(--surface);
    box-sizing: border-box;
  }

  /* [Name .............][x] / [Phone | Relationship] / [Email]
     Explicit areas, because the DOM order is name, phone, email,
     relationship — auto-flow would drop Relationship below Email.
     "Specify relationship" only exists when Other is picked, and
     takes the full width under the pair. */
  .account-ec-row .ec-name {
    grid-area: 1 / 1 / 2 / -1;
    padding-right: 52px;
  }

  .account-ec-row .ec-phone {
    grid-area: 2 / 1 / 3 / 2;
  }

  .account-ec-row .ec-relationship {
    grid-area: 2 / 2 / 3 / 3;
  }

  .account-ec-row .ec-email {
    grid-area: 3 / 1 / 4 / -1;
  }

  .account-ec-row .ec-other-relationship {
    grid-area: 4 / 1 / 5 / -1;
  }

  .account-ec-row input,
  .account-ec-row select {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    box-sizing: border-box;
  }

  .account-ec-row .ec-remove {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* ============================================================
   Year/month history folders — js/history-folders.js
   ------------------------------------------------------------
   The staff counterpart of the portal's GroupedHistory. Used by
   the user-lookup modal's lounge notes, visit table and
   checklist submissions.

   Tokens throughout, so the folders inherit whatever surface
   they sit on — including the print-coupled lookup modals,
   which pin --canvas/--text-color/--input-border on themselves
   and therefore get light folders on their light card without
   needing a rule of their own.
   ============================================================ */
.history-folder {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  /* These are the modal's primary controls; keep them thumb-sized. */
  min-height: 44px;
  padding: 8px 12px;
  margin: 6px 0;
  border: 1px solid var(--border-color-soft);
  border-radius: var(--radius-md, 8px);
  background: var(--hover-bg);
  color: var(--text-color);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-sizing: border-box;
}

.history-folder:hover {
  background: var(--card-background-hover);
}

.history-folder-year {
  font-weight: 700;
  font-size: 1rem;
}

.history-folder-month {
  font-weight: 600;
  font-size: 0.9rem;
  /* Indented so a month reads as living inside its year. */
  margin-left: 12px;
  width: calc(100% - 12px);
}

.history-folder-caret {
  flex-shrink: 0;
  width: 12px;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.history-folder-label {
  flex: 1 1 auto;
  min-width: 0;
}

.history-folder-count {
  flex-shrink: 0;
  /* --text-secondary, not --text-muted: muted measured 4.37:1 on the folder
     fill in emerald-dark, just under the AA bar. Caught by the live sweep. */
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.8rem;
}

.history-month-items {
  margin-left: 12px;
}

/* Table mode: the folder rows span the whole table, and carry no cell
   chrome of their own so the button is the only thing you see. */
.history-folder-tr > td {
  padding: 0 !important;
  border: none !important;
  background: none !important;
}

/* ============================================================
   Touch targets for bare checkboxes/radios on phones
   ------------------------------------------------------------
   Unstyled inputs render ~13x13 CSS px, well under the ~44px
   comfortable-touch guidance — the closed-day grids in System
   Config had 21 of them. Scaling the control (rather than
   wrapping every one in new markup) keeps the existing layouts
   intact while making them reliably tappable.
   ============================================================ */
@media (max-width: 768px) {
  input[type='checkbox'],
  input[type='radio'] {
    width: 20px;
    height: 20px;
    /* Extra hit area without shifting neighbours: the outline grows,
       the box doesn't. */
    outline-offset: 6px;
    cursor: pointer;
  }

  /* Labels next to them become part of the target. */
  label > input[type='checkbox'],
  label > input[type='radio'] {
    margin-right: 8px;
  }
}
