/*
  bf-ui.css: the shared BellForge look (design "A+", D-059).

  1. Design tokens, copied unchanged from the approved mockups
     (bf-memory-bank/design/mockups-r2/tokens.css, where contrast is checked:
     132 of 132 WCAG AA pairs). Keep the token names; apps may use them.
  2. Base styles and the few components that bf_ui's templates and macros use,
     written only against the tokens.

  Light and dark: every color token is light-dark(<light>, <dark>). Pages
  follow the device setting; data-theme="light|dark" on any element forces a
  theme for it and everything inside it.

  Density: data-density="comfortable|compact|kiosk" on <html> (or any
  container). Comfortable is the default: members, 18px text, 52px targets.
  Compact is for staff screens: 16px text, 48px targets. Kiosk tokens are here
  because they are part of the token set, but no kiosk components are built.

  Fonts: "Nunito" (headings, wordmark) and "Inter" (body) are named first in
  the stacks but are not bundled yet, so the system fonts after them are what
  you see. Nothing here loads anything from another site.

  Breakpoints are literal rem values (CSS cannot read custom properties in
  media queries): 40rem tables stack below it, 48rem header, 64rem and 80rem
  page layout with rail and panel.
*/

/* ================= 1. Tokens ================= */

/* ----- Theme-independent tokens and color (light + dark) ----- */

:root {
  color-scheme: light dark;

  /* ---- Fonts ---- */
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-heading: "Nunito", ui-rounded, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-ui: var(--font-body);
  --font-wordmark: var(--font-heading);

  --weight-body: 400;
  --weight-ui: 600;
  --weight-heading: 700;
  --weight-display: 700;
  --weight-strong: 700;
  --tracking-display: -0.015em;
  --tracking-heading: -0.005em;
  --tracking-code: 0.14em;

  /* ---- Wordmark and mark ---- */
  --wordmark-tracking: -0.02em;
  --wordmark-weight-bell: 600;
  --wordmark-weight-forge: 800;
  --mark-size: 0.42em;          /* ember diamond: a spark from the forge */
  --mark-radius: 0.08em;
  --mark-gap: 0.36em;
  --mark-shift: -0.12em;

  /* ---- Borders, motion ---- */
  --border-width: 1px;
  --border-width-strong: 2px;
  --border-width-heavy: 3px;
  --radius-pill: 999px;
  --radius-round: 50%;
  --duration: 160ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);

  /* ---- Color: neutrals ---- */
  --color-bg: light-dark(#f5f6f6, #12161b);
  --color-surface: light-dark(#ffffff, #1a2028);
  --color-surface-sunken: light-dark(#ebedee, #0d1014);
  --color-header-bg: var(--color-surface);
  --color-border: light-dark(#d5d9dd, #2e3742);          /* hairlines (decorative) */
  --color-border-strong: light-dark(#6f7883, #77828f);   /* control edges, 3:1+ */
  --color-text: light-dark(#1f2731, #e7eaee);
  --color-text-muted: light-dark(#4d5662, #a9b2bd);
  --color-heading: light-dark(#151b23, #f6f7f9);
  --color-link: light-dark(#9e3b16, #f5a27c);

  /* ---- Color: ember accent (used sparingly: one primary action per view) ---- */
  --color-accent: light-dark(#a8401a, #ee8a5c);
  --color-accent-hover: light-dark(#8c3412, #f4a07a);
  --color-accent-border: var(--color-accent);
  --color-on-accent: light-dark(#ffffff, #1a0d06);
  --color-accent-text: light-dark(#9e3b16, #f5a27c);
  --color-accent-soft: light-dark(#fbeae2, #3b241a);
  --color-on-accent-soft: light-dark(#6b2a10, #fbd4c1);

  /* Focus is blue, never ember, so it never looks like a button or an error. */
  --color-focus: light-dark(#1f5fbf, #8fbcff);

  /* ---- Color: wordmark ---- */
  --color-bell: light-dark(#2b3644, #dde3ea);
  --color-forge: light-dark(#a8401a, #f0885a);
  --color-mark: light-dark(#c9541f, #f0885a);

  /* ---- Color: primary tile (My Church) ---- */
  --color-feature-bg: light-dark(#2b3644, #5a2914);
  --color-feature-text: light-dark(#ffffff, #fff4ee);
  --color-feature-muted: light-dark(#cfd6df, #f2cdb9);
  --color-feature-deco: light-dark(#e06a35, #f0885a);

  /* ---- Color: status. Always paired with words, never color alone. ---- */
  --color-success: light-dark(#1b6e3f, #6fcf97);
  --color-success-soft: light-dark(#e4f3e9, #11291b);
  --color-warning: light-dark(#7f5200, #f0bf5a);
  --color-warning-soft: light-dark(#fbf0d6, #2e230b);
  --color-error: light-dark(#a3193b, #ff8fa6);
  --color-error-soft: light-dark(#fbe8ec, #36141c);
  /* Info doubles as the "Suggested by AI" color: calm blue, distinct from ember. */
  --color-info: light-dark(#2b5a8a, #9cc2f0);
  --color-info-soft: light-dark(#e6eef7, #14243a);

  /* Strong alert fill (allergy and medical flags at Check-In). */
  --color-danger-strong: light-dark(#a3193b, #a3193b);
  --color-on-danger-strong: light-dark(#ffffff, #ffffff);

  /* ---- Shadows (decorative only; every card also has a real border) ---- */
  --color-shadow: light-dark(rgba(21, 27, 35, 0.07), rgba(0, 0, 0, 0.4));
  --color-shadow-strong: light-dark(rgba(21, 27, 35, 0.16), rgba(0, 0, 0, 0.55));
  --shadow-card: 0 1px 2px var(--color-shadow);
  --shadow-pop: 0 14px 34px var(--color-shadow-strong), 0 2px 6px var(--color-shadow);
}

:root[data-theme="light"],
[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"],
[data-theme="dark"] {
  color-scheme: dark;
}

/* ----- Fixed brand and print colors (same in light and dark) ----- */

:root {
  /* One-color wordmarks and avatars: for print, email, social avatars. */
  --brand-ink: #1f2731;
  --brand-paper: #ffffff;
  --brand-slate: #2b3644;
  --brand-ember: #a8401a;
  --brand-ember-bright: #f0885a;
  --brand-night: #12161b;

  /* Printed check-in labels: thermal label printers print black only. */
  --color-print-paper: #ffffff;
  --color-print-ink: #111418;
}

/* ----- Density ----- */

/* Comfortable (default): members. 18px text, 52px targets. */
:root,
[data-density="comfortable"] {
  --text-xs: 0.9375rem;   /* 15px: tags and date labels only */
  --text-sm: 1rem;        /* 16px */
  --text-base: 1.125rem;  /* 18px */
  --text-md: 1.3125rem;   /* 21px */
  --text-lg: 1.5rem;      /* 24px */
  --text-xl: clamp(1.625rem, 1.4rem + 1vw, 2rem);
  --text-2xl: clamp(1.875rem, 1.5rem + 1.6vw, 2.5rem);
  --text-3xl: clamp(2.25rem, 1.7rem + 2.4vw, 3.25rem);
  --leading-body: 1.6;
  --leading-snug: 1.35;
  --leading-tight: 1.2;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2.25rem;
  --space-7: 3.5rem;
  --space-8: 4.5rem;
  --space-card: 1.5rem;
  --space-section: clamp(2.5rem, 1.75rem + 3vw, 4.5rem);
  --gap-grid: 1.25rem;
  --page-pad: clamp(1rem, 0.5rem + 2.2vw, 2.5rem);

  --control-height: 3.25rem;    /* 52px */
  --control-height-lg: 4rem;    /* 64px */
  --control-pad-x: 1.375rem;
  --choice-size: 1.5rem;

  --radius-sm: 8px;
  --radius-control: 12px;
  --radius-button: 12px;
  --radius-card: 16px;
  --radius-feature: 22px;
  --radius-panel: 16px;

  --focus-width: 3px;
  --focus-offset: 2px;

  --wordmark-size: 1.625rem;
  --wordmark-size-lg: clamp(2.5rem, 1.8rem + 3vw, 3.75rem);

  --content-max: 72rem;
  --content-narrow: 34rem;
  --measure: 36em;
}

/* Compact: staff data screens. 16px text, 48px targets, tighter space. */
[data-density="compact"] {
  --text-xs: 0.875rem;    /* 14px: the smallest text anywhere in compact */
  --text-sm: 0.9375rem;   /* 15px */
  --text-base: 1rem;      /* 16px */
  --text-md: 1.125rem;    /* 18px */
  --text-lg: 1.25rem;     /* 20px */
  --text-xl: 1.5rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2.125rem;
  --leading-body: 1.5;
  --leading-snug: 1.3;
  --leading-tight: 1.2;

  --space-1: 0.25rem;
  --space-2: 0.375rem;
  --space-3: 0.5rem;
  --space-4: 0.75rem;
  --space-5: 1rem;
  --space-6: 1.5rem;
  --space-7: 2.25rem;
  --space-8: 3rem;
  --space-card: 1rem;
  --space-section: 2rem;
  --gap-grid: 0.75rem;
  --page-pad: clamp(0.75rem, 0.5rem + 1vw, 1.5rem);

  --control-height: 3rem;       /* 48px */
  --control-height-lg: 3rem;
  --control-pad-x: 1rem;
  --choice-size: 1.25rem;

  --radius-sm: 6px;
  --radius-control: 8px;
  --radius-button: 8px;
  --radius-card: 12px;
  --radius-feature: 14px;
  --radius-panel: 12px;

  --focus-width: 3px;
  --focus-offset: 2px;

  --wordmark-size: 1.375rem;
  --wordmark-size-lg: 2.5rem;

  --content-max: 90rem;
  --content-narrow: 34rem;
  --measure: 44em;
}

/* Kiosk: a tablet at a door. 24px text, 72px targets (tokens only for now). */
[data-density="kiosk"] {
  --text-xs: 1.125rem;    /* 18px */
  --text-sm: 1.25rem;     /* 20px */
  --text-base: 1.5rem;    /* 24px */
  --text-md: 1.75rem;     /* 28px */
  --text-lg: 2rem;        /* 32px */
  --text-xl: clamp(2rem, 1.6rem + 1.6vw, 2.5rem);
  --text-2xl: clamp(2.25rem, 1.7rem + 2.4vw, 3.25rem);
  --text-3xl: clamp(2.75rem, 2rem + 3.2vw, 4rem);
  --leading-body: 1.45;
  --leading-snug: 1.3;
  --leading-tight: 1.15;

  --space-1: 0.375rem;
  --space-2: 0.75rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  --space-6: 3rem;
  --space-7: 4rem;
  --space-8: 6rem;
  --space-card: clamp(1.25rem, 0.75rem + 2vw, 2rem);
  --space-section: clamp(2rem, 1rem + 3vw, 3rem);
  --gap-grid: clamp(1rem, 0.5rem + 1.5vw, 1.5rem);
  --page-pad: clamp(1rem, 0.5rem + 2.5vw, 3rem);

  --control-height: 4.5rem;     /* 72px */
  --control-height-lg: 5.5rem;  /* 88px */
  --control-pad-x: 2rem;
  --choice-size: 2.25rem;

  --radius-sm: 10px;
  --radius-control: 16px;
  --radius-button: 16px;
  --radius-card: 24px;
  --radius-feature: 28px;
  --radius-panel: 20px;

  --focus-width: 4px;
  --focus-offset: 3px;

  --wordmark-size: 1.875rem;
  --wordmark-size-lg: 3rem;

  --content-max: 64rem;
  --content-narrow: 40rem;
  --measure: 32em;
}

/* ================= 2. Reset ================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--color-bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-body);
  line-height: var(--leading-body);
  color: var(--color-text);
  background: var(--color-bg);
  overflow-wrap: break-word;
}

/* A density or theme set on an inner container re-applies the base text
   size and colors there. (Not on <html>: that would change what 1rem is.) */
body [data-density] {
  font-size: var(--text-base);
  line-height: var(--leading-body);
}

body [data-theme] {
  color: var(--color-text);
  background: var(--color-bg);
}

h1, h2, h3, h4, p, ul, ol, dl, dd, figure, blockquote, fieldset {
  margin: 0;
}

fieldset {
  min-width: 0;
  padding: 0;
  border: 0;
}

legend {
  padding: 0;
}

ul[role="list"],
ol[role="list"] {
  list-style: none;
  padding: 0;
}

svg {
  flex: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

table {
  border-collapse: collapse;
}

/* ================= 3. Accessibility helpers ================= */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 100;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-ui);
  font-weight: var(--weight-ui);
  color: var(--color-text);
  background: var(--color-surface);
  border: var(--border-width-strong) solid var(--color-focus);
  border-radius: var(--radius-control);
  transform: translateY(-300%);
}

.skip-link:focus {
  transform: none;
}

:focus-visible {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: var(--focus-offset);
}

/* ================= 4. Layout helpers ================= */

.container {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--page-pad);
}

.stack > * + * {
  margin-block-start: var(--space-4);
}

.stack-lg > * + * {
  margin-block-start: var(--space-section);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

/* Responsive grid for cards and tiles: as many 18rem columns as fit. */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
  gap: var(--gap-grid);
  align-items: stretch;
}

.grid > li {
  max-width: none;
}

.page-intro {
  margin-block-end: var(--space-6);
}

.page-intro > * + * {
  margin-block-start: var(--space-2);
}

/* ================= 5. Typography ================= */

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  font-weight: var(--weight-heading);
  line-height: var(--leading-tight);
  color: var(--color-heading);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-2xl);
  font-weight: var(--weight-display);
  letter-spacing: var(--tracking-display);
}

h2 {
  font-size: var(--text-xl);
  letter-spacing: var(--tracking-display);
}

h3 {
  font-size: var(--text-lg);
  letter-spacing: var(--tracking-heading);
  line-height: var(--leading-snug);
}

h4 {
  font-size: var(--text-md);
  line-height: var(--leading-snug);
}

p,
li,
dd {
  max-width: var(--measure);
}

.lead {
  font-size: var(--text-md);
  line-height: var(--leading-snug);
}

.muted {
  color: var(--color-text-muted);
}

.small {
  font-size: var(--text-sm);
}

a {
  color: var(--color-link);
  text-decoration-thickness: var(--border-width);
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-thickness: var(--border-width-strong);
}

/* Sentence case, not uppercase: easier to read for everyone. */
.eyebrow {
  display: block;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--weight-ui);
  line-height: var(--leading-snug);
  color: var(--color-accent-text);
}

/* Inline SVG icons follow the text size. */
.icon {
  display: inline-block;
  width: 1.25em;
  height: 1.25em;
  vertical-align: middle;
}

.icon--sm {
  width: 1em;
  height: 1em;
}

/* ================= 6. Wordmark ================= */

.wordmark {
  display: inline-flex;
  align-items: baseline;
  padding-block: max(0px, calc((var(--control-height) - 1em) / 2));
  font-family: var(--font-wordmark);
  font-size: var(--wordmark-size);
  line-height: 1;
  letter-spacing: var(--wordmark-tracking);
  white-space: nowrap;
  text-decoration: none;
}

.wordmark--static {
  padding-block: 0;
}

.wordmark__mark {
  display: inline-block;
  flex: none;
  width: var(--mark-size);
  height: var(--mark-size);
  margin-inline-end: var(--mark-gap);
  background: var(--color-mark);
  border-radius: var(--mark-radius);
  transform: translateY(var(--mark-shift)) rotate(45deg);
}

.wordmark__bell {
  font-weight: var(--wordmark-weight-bell);
  color: var(--color-bell);
}

.wordmark__forge {
  font-weight: var(--wordmark-weight-forge);
  color: var(--color-forge);
}

/* ================= 7. Buttons ================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  min-width: var(--control-height);
  padding: var(--space-2) var(--control-pad-x);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: var(--weight-ui);
  line-height: var(--leading-tight);
  text-align: center;
  text-decoration: none;
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-button);
  cursor: pointer;
  transition: background-color var(--duration) var(--ease),
    border-color var(--duration) var(--ease),
    color var(--duration) var(--ease);
}

.btn--primary {
  color: var(--color-on-accent);
  background: var(--color-accent);
  border-color: var(--color-accent-border);
}

.btn--primary:hover {
  background: var(--color-accent-hover);
}

.btn--secondary {
  color: var(--color-text);
  background: var(--color-surface);
  border-color: var(--color-border-strong);
}

.btn--secondary:hover {
  background: var(--color-surface-sunken);
}

.btn--danger {
  color: var(--color-error);
  background: var(--color-surface);
  border-color: var(--color-error);
}

.btn--danger:hover {
  background: var(--color-error-soft);
}

.btn--quiet {
  padding-inline: var(--space-3);
  color: var(--color-link);
  background: transparent;
  text-decoration: underline;
  text-decoration-thickness: var(--border-width);
  text-underline-offset: 0.2em;
}

.btn--quiet:hover {
  text-decoration-thickness: var(--border-width-strong);
}

.btn--block {
  width: 100%;
}

.btn[disabled] {
  color: var(--color-text-muted);
  background: var(--color-surface-sunken);
  border-color: var(--color-border-strong);
  border-style: dashed;
  cursor: not-allowed;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

/* ================= 8. Form fields ================= */

.field {
  display: grid;
  gap: var(--space-2);
}

.label {
  font-family: var(--font-ui);
  font-weight: var(--weight-ui);
  color: var(--color-heading);
}

.hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.input {
  width: 100%;
  min-height: var(--control-height);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-control);
}

.input[aria-invalid="true"] {
  border-color: var(--color-error);
  border-width: var(--border-width-strong);
}

/* The error sits above the input, so it stays visible with a phone keyboard
   open. Icon plus words: never color alone. */
.field-error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-family: var(--font-ui);
  font-weight: var(--weight-ui);
  color: var(--color-error);
}

.field-error .icon {
  margin-block-start: 0.15em;
}

/* ================= 9. Badges and avatar ================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.125em 0.625em;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: var(--weight-ui);
  line-height: var(--leading-snug);
  white-space: nowrap;
  color: var(--color-text-muted);
  background: var(--color-surface-sunken);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-pill);
  vertical-align: middle;
}

.badge--accent {
  color: var(--color-on-accent-soft);
  background: var(--color-accent-soft);
}

.badge--success {
  color: var(--color-success);
  background: var(--color-success-soft);
}

.badge--warning {
  color: var(--color-warning);
  background: var(--color-warning-soft);
}

.badge--error {
  color: var(--color-error);
  background: var(--color-error-soft);
}

.badge--info {
  color: var(--color-info);
  background: var(--color-info-soft);
}

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 2.5em;
  height: 2.5em;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--weight-ui);
  line-height: 1;
  color: var(--color-on-accent-soft);
  background: var(--color-accent-soft);
  border-radius: var(--radius-round);
}

/* ================= 10. Cards and tiles ================= */

.card {
  padding: var(--space-card);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.card__title {
  margin-block-end: var(--space-3);
  font-size: var(--text-lg);
}

.card__body > * + * {
  margin-block-start: var(--space-3);
}

/* Large link tile. The link sits on the title (its name is just the title)
   and stretches over the whole tile with ::before. */
.tile {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  height: 100%;
  min-height: var(--control-height-lg);
  padding: var(--space-card);
  color: var(--color-text);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  transition: border-color var(--duration) var(--ease);
}

.tile:hover {
  border-color: var(--color-border-strong);
}

.tile__link {
  color: inherit;
  text-decoration: none;
}

.tile__link::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
}

.tile:hover .tile__link {
  text-decoration: underline;
  text-decoration-thickness: var(--border-width-strong);
}

.tile__link:focus-visible {
  outline: none;
}

.tile:has(.tile__link:focus-visible) {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: var(--focus-offset);
}

.tile__body {
  flex: 1;
  min-width: 0;
}

.tile__title {
  font-size: var(--text-md);
  line-height: var(--leading-snug);
}

.tile__desc {
  margin-block-start: var(--space-1);
  color: var(--color-text-muted);
}

.tile__go {
  align-self: center;
  color: var(--color-text-muted);
}

/* ================= 11. Tables ================= */

/* The wrapper scrolls sideways instead of the whole page when a table is too
   wide. Use stack=True in the macro to turn rows into blocks on phones. */
.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  font-size: var(--text-sm);
  text-align: start;
}

.table caption {
  padding-block-end: var(--space-2);
  font-family: var(--font-ui);
  font-weight: var(--weight-ui);
  text-align: start;
  color: var(--color-heading);
}

.table th,
.table td {
  padding: var(--space-2) var(--space-3);
  text-align: start;
  vertical-align: top;
  border-bottom: var(--border-width) solid var(--color-border);
}

.table thead th {
  font-family: var(--font-ui);
  font-weight: var(--weight-ui);
  color: var(--color-heading);
  background: var(--color-surface-sunken);
  border-bottom-color: var(--color-border-strong);
}

.table tbody th {
  font-family: var(--font-ui);
  font-weight: var(--weight-ui);
  color: var(--color-heading);
}

.table td {
  overflow-wrap: anywhere;
}

/* Narrow screens: each row becomes a small block, labels come from
   data-label on each cell (no sideways scrolling). */
@media (max-width: 39.99rem) {
  .table--stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .table--stack,
  .table--stack caption,
  .table--stack tbody,
  .table--stack tr,
  .table--stack th,
  .table--stack td {
    display: block;
  }

  .table--stack tr {
    padding-block: var(--space-2);
    border-bottom: var(--border-width) solid var(--color-border);
  }

  .table--stack th,
  .table--stack td {
    padding: var(--space-1) 0;
    border: 0;
  }

  .table--stack td[data-label]::before {
    content: attr(data-label) ": ";
    font-weight: var(--weight-ui);
    color: var(--color-text-muted);
  }
}

/* ================= 12. Empty state ================= */

.empty-state {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-card);
  text-align: center;
  background: var(--color-surface-sunken);
  border: var(--border-width-strong) dashed var(--color-border-strong);
  border-radius: var(--radius-card);
}

.empty-state__title {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: var(--weight-heading);
  line-height: var(--leading-snug);
  color: var(--color-heading);
}

.empty-state__text {
  color: var(--color-text-muted);
}

.empty-state__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
  margin-block-start: var(--space-2);
}

/* ================= 13. App header ================= */

/* Phones: wordmark, user and Menu in row 1; church in row 2.
   48rem and up: wordmark, church and user in row 1; the top navigation in
   row 2. Source order (wordmark, church, user, nav) matches the visual order
   of the focusable items at both sizes. */
.app-header {
  position: relative;
  z-index: 10;
  background: var(--color-header-bg);
  border-bottom: var(--border-width) solid var(--color-border);
}

.app-header__bar {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas:
    "brand user nav"
    "church church church";
  align-items: center;
  gap: 0 var(--space-2);
  padding-block: var(--space-1);
}

.app-header__brand {
  grid-area: brand;
  justify-self: start;
}

.app-header__church {
  grid-area: church;
  display: grid;
  min-width: 0;
  padding-block-end: var(--space-2);
  font-family: var(--font-ui);
  line-height: var(--leading-tight);
}

.app-header__church-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.app-header__church-name {
  font-weight: var(--weight-ui);
  color: var(--color-heading);
}

.app-header .menu--user {
  grid-area: user;
}

.app-nav {
  grid-area: nav;
}

/* Phones: row 1 must fit in 320px, so the user's name (and, on the
   narrowest phones, the word "Menu") is for screen readers only, and the
   user menu drops its chevron. */
@media (max-width: 47.99rem) {
  .app-header__user-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .app-header .menu--user .menu__chevron {
    display: none;
  }
}

@media (max-width: 22.4rem) {
  .app-nav__menu-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

@media (min-width: 48rem) {
  .app-header__bar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand church user"
      "nav nav nav";
    gap: 0 var(--space-4);
  }

  .app-header__church {
    justify-self: end;
    padding-block-end: 0;
    text-align: end;
  }

  .app-header__user-name {
    max-width: 14em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* The optional header badge (the header_badge block): on phones a row of
   its own under the church; from 48rem right after the wordmark. Without a
   badge the header grid is unchanged. */
.app-header__badge {
  grid-area: badge;
  min-width: 0;
  padding-block-end: var(--space-2);
}

.app-header__bar:has(> .app-header__badge) {
  grid-template-areas:
    "brand user nav"
    "church church church"
    "badge badge badge";
}

@media (min-width: 48rem) {
  .app-header__bar:has(> .app-header__badge) {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand badge church user"
      "nav nav nav nav";
  }

  .app-header__badge {
    padding-block-end: 0;
  }
}

/* Top navigation: a Menu button on phones, a row of links from 48rem. */
.app-nav__list {
  display: none;
}

@media (min-width: 48rem) {
  .app-nav__menu {
    display: none;
  }

  .app-nav__list {
    display: flex;
    flex-wrap: wrap;
    gap: 0 var(--space-1);
    margin: 0 0 calc(-1 * var(--space-1)) calc(-1 * var(--space-3));
    padding: 0;
    list-style: none;
  }
}

.app-nav__link {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-height);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-ui);
  font-weight: var(--weight-ui);
  color: var(--color-text-muted);
  text-decoration: none;
  border-bottom: var(--border-width-heavy) solid transparent;
}

.app-nav__link:hover {
  color: var(--color-heading);
  border-bottom-color: var(--color-border-strong);
}

.app-nav__link[aria-current] {
  color: var(--color-heading);
  border-bottom-color: var(--color-accent-border);
}

/* ================= 14. Dropdown menus (native <details>; work without JS) ================= */

.menu {
  position: relative;
}

.menu > summary {
  list-style: none;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu__button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: var(--control-height);
  min-height: var(--control-height);
  padding: var(--space-1) var(--space-3);
  font-family: var(--font-ui);
  font-weight: var(--weight-ui);
  color: var(--color-text);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-control);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--duration) var(--ease);
}

.menu__button:hover,
.menu[open] > .menu__button {
  background: var(--color-surface-sunken);
}

.menu__button--plain {
  padding-inline: var(--space-1) var(--space-2);
  border-color: transparent;
  background: transparent;
}

.menu__chevron {
  transition: transform var(--duration) var(--ease);
}

.menu[open] .menu__chevron {
  transform: rotate(180deg);
}

.menu__panel {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 20;
  width: max-content;
  min-width: 16rem;
  max-width: calc(100vw - 2 * var(--page-pad));
  padding: var(--space-2);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-pop);
}

/* In the header on phones every dropdown spans the header width. */
.app-header .menu {
  position: static;
}

.app-header .menu__panel {
  left: var(--page-pad);
  right: var(--page-pad);
  top: calc(100% - var(--space-1));
  width: auto;
  min-width: 0;
  max-width: none;
}

@media (min-width: 48rem) {
  .app-header .menu {
    position: relative;
  }

  .app-header .menu__panel {
    left: auto;
    right: 0;
    top: calc(100% + var(--space-2));
    width: max-content;
    min-width: 16rem;
    max-width: calc(100vw - 2 * var(--page-pad));
  }
}

.menu__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.menu__list > li {
  max-width: none;
}

.menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--control-height);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  text-align: start;
  color: var(--color-text);
  text-decoration: none;
  background: transparent;
  border: 0;
  border-radius: var(--radius-control);
  cursor: pointer;
}

.menu__item:hover {
  background: var(--color-surface-sunken);
}

.menu__item[aria-current] {
  font-weight: var(--weight-ui);
  color: var(--color-on-accent-soft);
  background: var(--color-accent-soft);
}

.menu__divider {
  height: 0;
  margin: var(--space-2) 0;
  border: 0;
  border-top: var(--border-width) solid var(--color-border);
}

.menu__profile {
  display: grid;
  max-width: none;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-ui);
  line-height: var(--leading-snug);
}

.menu__profile span {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.menu__profile strong {
  color: var(--color-heading);
  overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: no-preference) {
  .menu[open] > .menu__panel {
    animation: menu-in var(--duration) var(--ease);
  }
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(calc(-1 * var(--space-1)));
  }
}

/* ================= 15. Page layout: rail, main, panel ================= */

/* One column on phones (rail, then content, then panel). From 64rem the rail
   sits on the left and the panel on the right; with both, the panel moves to
   the right only from 80rem so the content keeps its width. */
.app-layout {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-5) var(--space-6);
  align-items: start;
  padding-block: var(--space-6) var(--space-section);
}

.app-layout__main {
  min-width: 0;
}

.app-layout__panel {
  padding: var(--space-card);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-panel);
}

@media (min-width: 64rem) {
  .app-layout--rail {
    grid-template-columns: 14rem minmax(0, 1fr);
  }

  .app-layout--rail > .app-layout__panel {
    grid-column: 2;
  }

  .app-layout--panel:not(.app-layout--rail) {
    grid-template-columns: minmax(0, 1fr) 22rem;
  }

  .side-nav {
    position: sticky;
    top: var(--space-4);
  }
}

@media (min-width: 80rem) {
  .app-layout--rail.app-layout--panel {
    grid-template-columns: 14rem minmax(0, 1fr) 22rem;
  }

  .app-layout--rail > .app-layout__panel {
    grid-column: auto;
  }
}

/* Left rail: sub-pages of the current top item. A wrapping row of links on
   phones, a column from 64rem. */
.side-nav__list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  list-style: none;
  margin: 0;
  padding: 0;
}

@media (min-width: 64rem) {
  .side-nav__list {
    flex-direction: column;
    flex-wrap: nowrap;
  }
}

.side-nav__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--control-height);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-ui);
  color: var(--color-text);
  text-decoration: none;
  border-radius: var(--radius-control);
}

.side-nav__item:hover {
  background: var(--color-surface-sunken);
}

.side-nav__item[aria-current] {
  font-weight: var(--weight-ui);
  color: var(--color-on-accent-soft);
  background: var(--color-accent-soft);
}

/* ================= 16. Footer ================= */

.site-footer {
  padding-block: var(--space-5);
  background: var(--color-surface-sunken);
  border-top: var(--border-width) solid var(--color-border);
}

.site-footer .wordmark {
  font-size: var(--text-base);
}

/* ================= 17. Motion and forced colors ================= */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (forced-colors: active) {
  .wordmark__mark {
    background: CanvasText;
  }

  .btn--primary,
  .badge {
    border: var(--border-width) solid CanvasText;
  }

  .app-nav__link[aria-current],
  .side-nav__item[aria-current],
  .menu__item[aria-current] {
    border-color: Highlight;
    outline: var(--border-width-strong) solid Highlight;
  }

  .tile:has(.tile__link:focus-visible) {
    outline-color: Highlight;
  }
}
