/* Bakunye-nathi theme — warm, dignified South African earth tones for a family
   burial-site register. Re-skin by editing the tokens in :root only; every rule
   below consumes variables, never hard-coded colour. Mobile-first, one centred
   column so the header, content and nav all share the exact same width. */
:root {
  /* --- Palette: ochre / umber / gold (ancestral, earthy, respectful) ------ */
  --bg: #F5EEE1;          /* warm sand */
  --panel: #FFFFFF;
  --panel-alt: #FBF5EA;   /* faint cream for nested cards */
  --primary: #5C2E1B;     /* deep umber brown */
  --primary-deep: #40200F;/* darker umber (header gradient foot) */
  --accent: #C8A96A;      /* gold */
  --accent-soft: #EAD8B2;
  --terracotta: #B4623A;  /* warm clay (secondary accent) */
  --ink: #2A241F;
  --muted: #897C6C;
  --border: #E3D7C2;
  --good: #4F7341;
  --danger: #9B2C2C;
  --danger-soft: #F6E4E1;

  /* --- Chart palette (validated — see docs/chart-palette.md) --------------
     Do NOT substitute --primary or --accent for a chart mark: --primary is too
     dark and too grey to carry identity (OKLCH L 0.36 / C 0.074) and --accent
     reads as grey at 2.19:1 on white. Both fail the categorical checks. These
     slots were snapped from the brand hues and validated as a set; changing one
     by eye breaks the colour-blind separation the order was chosen for. */
  --chart-1: #B4623A;     /* terracotta (brand --terracotta) */
  --chart-2: #6B5CA5;     /* violet */
  --chart-3: #118A78;     /* teal */
  --chart-4: #B58A2B;     /* ochre */
  --chart-5: #9C4368;     /* plum */
  --chart-6: #6E8B3D;     /* olive */
  --chart-other: #8C8578; /* the folded tail past six series */

  /* Sequential ramp for magnitude (per-family bars); ends on --primary. */
  --chart-seq-1: #D2A184;
  --chart-seq-2: #B87F5E;
  --chart-seq-3: #9E5F3C;
  --chart-seq-4: #7E4527;
  --chart-seq-5: #5C2E1B;

  --chart-grid: #EDE3D2;  /* recessive gridlines */
  --chart-axis: #B8A98F;  /* axis rules */

  /* --- Shape & elevation -------------------------------------------------- */
  --radius: 14px;
  --radius-sm: 9px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(64, 32, 15, .08);
  --shadow: 0 2px 6px rgba(64, 32, 15, .07), 0 14px 30px rgba(64, 32, 15, .06);

  /* --- Spacing scale (use these everywhere for a consistent rhythm) ------- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 28px;
  --space-7: 40px;

  --tap: 48px;            /* min tap target (M-901) — still ≥44px */
  --maxw: 600px;          /* the single column width shared by every region */
  --gutter: var(--space-4);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --gradient: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink);
  background: var(--bg); line-height: 1.45; font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
body.text-small { font-size: 15px; }
body.text-large { font-size: 18px; }
body.text-xlarge { font-size: 21px; }

a { color: var(--primary); }
h1, h2, h3 { color: var(--primary); line-height: 1.25; margin: 0 0 var(--space-2); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 var(--space-3); }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ===========================================================================
 * App shell — one centred column; header, content and nav all inset by the
 * same --gutter so their left/right edges line up exactly.
 * ==========================================================================*/
.shell {
  max-width: var(--maxw); margin: 0 auto; min-height: 100dvh;
  display: flex; flex-direction: column;
}

/* Header: a rounded bar the SAME width as the content cards (shares --gutter),
   brand + icon on the left, prominent sign-out on the right. */
.topbar {
  display: flex; align-items: center; gap: var(--space-3);
  margin: var(--gutter) var(--gutter) 0;
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-3);
  min-height: var(--tap);
  background: var(--gradient); color: #fff;
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.topbar__brand {
  display: flex; align-items: center; gap: var(--space-3);
  color: #fff; text-decoration: none; min-width: 0; flex: 1;
}
.topbar__logo {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .22);
  display: grid; place-items: center; overflow: hidden;
}
.topbar__logo img, .topbar__logo svg { width: 26px; height: 26px; display: block; }
.topbar__titles { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.topbar__title { font-weight: 700; letter-spacing: .2px; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__family { font-size: .78rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__actions { display: flex; align-items: center; gap: var(--space-2); flex: 0 0 auto; }

/* Prominent, labelled sign-out (icon + word) top-right. */
.iconbtn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); min-height: 40px;
  background: rgba(255, 255, 255, .16); color: #fff;
  border: 1px solid rgba(255, 255, 255, .26); border-radius: var(--radius-pill);
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
}
.iconbtn:hover { background: rgba(255, 255, 255, .26); }
.iconbtn__ico { font-size: 1rem; line-height: 1; }

/* Context sub-bar (family switcher) — same column width, rounded, sits under header. */
.subbar {
  display: flex; align-items: center; gap: var(--space-3);
  margin: var(--space-3) var(--gutter) 0;
  padding: var(--space-2) var(--space-3);
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.subbar__label { flex: 0 0 auto; font-size: .8rem; font-weight: 600; color: var(--muted); }
.subbar select { flex: 1; min-height: 40px; border-radius: var(--radius-sm); }

/* Bottom padding reserves clearance for the sticky floating nav so the last
   card never hides behind it. */
.content { flex: 1; padding: var(--gutter) var(--gutter) calc(var(--tap) + var(--space-6)); }

/* Bottom nav — a rounded floating bar that matches the header's card language. */
.bottomnav {
  position: sticky; bottom: 0; display: flex; background: var(--panel);
  margin: var(--space-3) var(--gutter) var(--gutter);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.bottomnav a {
  flex: 1; text-align: center; padding: var(--space-2) 0; min-height: var(--tap);
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600;
  display: flex; flex-direction: column; gap: 2px; justify-content: center;
}
.bottomnav a.active { color: var(--primary); background: var(--panel-alt); }
.bottomnav a.active .ico { transform: translateY(-1px); }
.bottomnav .ico { display: inline-flex; align-items: center; justify-content: center; height: 24px; }
.bottomnav .ico svg { width: 24px; height: 24px; display: block; }

/* ===========================================================================
 * Cards, lists, badges
 * ==========================================================================*/
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space-4); margin-bottom: var(--space-4); box-shadow: var(--shadow-sm);
}
.card:last-child { margin-bottom: 0; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.list .card { margin-bottom: 0; }
.memorial { display: flex; gap: var(--space-3); align-items: center; }
.memorial .meta { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.meta { color: var(--muted); font-size: .9rem; }
.badge {
  display: inline-block; background: var(--accent-soft); color: var(--primary);
  border-radius: var(--radius-pill); padding: .1rem .55rem; font-size: .75rem; font-weight: 600;
}

/* ===========================================================================
 * Forms
 * ==========================================================================*/
label { display: block; font-weight: 600; margin: var(--space-3) 0 var(--space-1); }
input, select, textarea {
  width: 100%; padding: .6rem .8rem; font: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); min-height: var(--tap);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(200, 169, 106, .25);
}
textarea { min-height: 6rem; }
.hint { color: var(--muted); font-size: .85rem; margin-top: var(--space-1); }
/* Composed phone field: fixed +27 prefix + local-number input. */
.phone-field { display: flex; align-items: stretch; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.phone-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(200, 169, 106, .25); }
.phone-field__cc { display: flex; align-items: center; padding: 0 var(--space-3); background: var(--panel-alt); border-right: 1px solid var(--border); font-weight: 600; white-space: nowrap; }
.phone-field [data-phone-input] { flex: 1; min-width: 0; border: 0; border-radius: 0; }
.phone-field [data-phone-input]:focus { box-shadow: none; }
/* Consent checkbox: inline box + wrapping label, not the full-width input styling. */
.check { display: flex; gap: var(--space-2); align-items: flex-start; font-weight: 400; margin-top: var(--space-3); }
.check input { width: auto; min-height: 0; margin-top: 4px; flex: 0 0 auto; }
.check a { font-weight: 600; }
.error { color: var(--danger); font-size: .9rem; margin-top: var(--space-2); }
.notice {
  background: var(--panel-alt); border: 1px solid var(--accent-soft);
  border-radius: var(--radius-sm); padding: var(--space-3); margin-top: var(--space-3);
}

/* ===========================================================================
 * Buttons
 * ==========================================================================*/
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap); padding: .6rem 1.1rem; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--primary); color: #fff; font: inherit; font-weight: 600; cursor: pointer; width: 100%;
  text-decoration: none;
  transition: background .15s ease, transform .05s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
/* Consistent vertical rhythm: every button in a form, and any stacked buttons,
   sit a fixed gap below the control above them. */
form .btn, .btn + .btn { margin-top: var(--space-3); }
.btn.secondary { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn.secondary:hover { background: var(--panel-alt); }
.btn.accent { background: var(--accent); color: var(--primary); border-color: var(--accent); }
.btn[disabled], .btn.htmx-request { opacity: .6; cursor: not-allowed; }
.btn.fab {
  position: fixed; width: auto; border-radius: var(--radius-pill); margin: 0;
  right: max(var(--space-4), calc(50% - var(--maxw) / 2 + var(--space-4)));
  bottom: calc(var(--tap) + var(--space-6)); box-shadow: var(--shadow); z-index: 6;
}

/* Language picker / choice grids. margin-top:0 overrides the generic stacked-button
   rule (.btn + .btn) so grid items align — otherwise every button except the first
   (English) is nudged down and looks taller/misaligned. */
.lang-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.lang-grid .btn, .lang-grid button { min-height: var(--tap); margin-top: 0; }
/* The currently-selected choice in a grid (e.g. text size) reads as filled. */
.lang-grid .btn[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Collapsible language picker on sign-in — expanded on first visit, a tappable
   line once a language is remembered (change here or in Settings). */
.lang-picker > summary {
  cursor: pointer; font-weight: 600; color: var(--primary); list-style: none;
  display: flex; align-items: center; justify-content: space-between; min-height: 32px;
}
.lang-picker > summary::-webkit-details-marker { display: none; }
.lang-picker > summary::after { content: '⌄'; font-size: 1.2em; line-height: 1; }
.lang-picker[open] > summary { margin-bottom: var(--space-3); }
.lang-picker[open] > summary::after { content: '⌃'; }

/* "Sign in with an SMS code instead" — the quiet fallback under a passkey-first button. */
.otp-fallback { margin-top: var(--space-3); }
.otp-fallback > summary {
  cursor: pointer; text-align: center; color: var(--primary); font-weight: 600;
  list-style: none; min-height: var(--tap, 44px); display: flex; align-items: center; justify-content: center;
}
.otp-fallback > summary::-webkit-details-marker { display: none; }
.otp-fallback[open] > summary { margin-bottom: var(--space-3); }

/* First-time hint under the sign-in form: how to enrol a passkey once signed in. */
.passkey-tip {
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--panel-alt);
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.5;
}

.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* Global htmx request progress bar (top of viewport). */
.bn-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: var(--accent); box-shadow: 0 0 8px var(--accent);
  z-index: 2000; opacity: 0; transition: opacity .2s;
  pointer-events: none;
}
.bn-progress--on {
  opacity: 1; width: 100%;
  animation: bn-progress-slide 1.4s ease-in-out infinite;
  transform-origin: left;
}
@keyframes bn-progress-slide {
  0% { transform: scaleX(0); } 50% { transform: scaleX(.7); } 100% { transform: scaleX(1); }
}

/* Inline button spinner (replaces the bare "…" htmx-indicator). */
.spinner {
  display: inline-block; width: 1em; height: 1em; vertical-align: -0.15em;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: bn-spin .6s linear infinite;
}
@keyframes bn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .bn-progress--on, .spinner { animation: none; }
}

/* ===========================================================================
 * Guest (auth) layout — centred column, brand emblem, same card language.
 * ==========================================================================*/
.guest { max-width: 460px; margin: 0 auto; min-height: 100dvh; padding: var(--gutter); display: flex; flex-direction: column; justify-content: center; }
.brandmark { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); margin: var(--space-5) 0 var(--space-4); }
.brandmark__logo {
  width: 64px; height: 64px; border-radius: var(--radius); background: var(--gradient);
  display: grid; place-items: center; box-shadow: var(--shadow-sm);
}
.brandmark__logo svg, .brandmark__logo img { width: 40px; height: 40px; }
.brandmark h1 { margin: 0; }

/* ===========================================================================
 * Back-office scales up for laptop
 * ==========================================================================*/
.office { max-width: 1100px; }
@media (min-width: 900px) {
  .office .content { padding: var(--space-5) var(--space-6); }
}

/* ===========================================================================
 * Location capture + photo gallery
 * ==========================================================================*/
.geo { margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px solid var(--border); }
.geo[data-captured-ok] label { color: var(--good); }
.geo-map { margin-top: var(--space-3); border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
#geo-map { height: 240px; }
/* Detail-page map is an <iframe>; without explicit size it falls back to 300x150. */
.geo-map iframe { display: block; width: 100%; height: 240px; border: 0; }
.map-pin { background: var(--terracotta); border: 2px solid #fff; border-radius: 50%; box-shadow: var(--shadow-sm); }

/* Family map (M-401/402/403): full pin overview, verified check-mark badge, list search + sync. */
#family-map { height: 320px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); margin-bottom: var(--space-3); }
.map-pin { position: relative; }
.map-pin.verified { background: #2f7d5b; }
.map-pin.verified::after { content: '\2713'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; line-height: 1; }
.map-search { width: 100%; margin-bottom: var(--space-3); }
.list [data-memorial-id].is-active { background: var(--panel-alt); box-shadow: var(--shadow-sm); }

/* Birth/death date group with an exact-vs-year toggle, and the invite form's
 * access-scope toggle (.scope-toggle): both are a bordered fieldset whose
 * options are a nested .seg row, so they share this box + legend treatment. */
.datefield, .scope-toggle { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-3); margin-top: var(--space-4); }
.datefield legend, .scope-toggle legend { font-weight: 600; padding: 0 var(--space-2); }
.seg { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-bottom: var(--space-3); }
.seg label { display: inline-flex; align-items: center; gap: var(--space-2); font-weight: 400; margin: 0; cursor: pointer; }
/* Reset the base full-width input styling for the toggle radios (native control size). */
.seg input[type="radio"] { width: auto; min-height: 0; padding: 0; margin: 0; border: 0; background: none; box-shadow: none; flex: 0 0 auto; -webkit-appearance: radio; appearance: radio; }

/* Place-search results: tappable rows under the search box. */
.geo-results { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.geo-result { width: 100%; text-align: left; background: var(--panel-alt); color: var(--ink); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); font: inherit; cursor: pointer; }
.geo-result:hover { border-color: var(--accent); }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); margin-bottom: var(--space-3); }
.photo-grid:empty { display: none; }
.photo-thumb {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--panel-alt);
}
/* A <label class="btn"> that wraps a hidden file input (tap-to-upload). */
label.btn { cursor: pointer; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); margin-top: var(--space-3); }
.btn-row .btn { margin-top: 0; }

/* Edit + Remove on a memory sit side by side rather than stacking full-width.
   No :empty rule: the Blade comment + two @if blocks inside .story-actions
   leave whitespace-only text nodes even when neither button renders, which
   :empty does not ignore. Left un-hidden: the div has no visible box (no
   border/background) other than this margin, so an empty one is harmless. */
.story-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2); margin-top: var(--space-2); }
.story-actions .btn { width: auto; flex: 0 0 auto; margin-top: 0; }

/* --- Family management -------------------------------------------------- */
.topbar__title { color: #fff; text-decoration: none; }
.topbar__family { color: var(--accent); text-decoration: none; }
.member { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.member__badge {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; color: #fff;
  background: var(--primary);
}
.member__badge svg { width: 20px; height: 20px; }
.member__meta { flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.member__name { font-weight: 600; }
/* Actions drop to their own full-width line under a divider, so the role <select>
   and the Make-Head/Remove buttons never crowd the member's name on a narrow screen. */
.member__actions {
  display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center;
  flex: 1 1 100%; margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--border);
}
.member__actions select { min-height: 40px; border-radius: var(--radius-sm); }
.member__label { flex: 1 1 100%; min-height: 40px; border-radius: var(--radius-sm); }
.pill {
  align-self: flex-start; font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  padding: 2px 10px; border-radius: var(--radius-pill); background: var(--border); color: var(--ink);
}
.pill--head { background: var(--primary); color: #fff; }
.pill--co_admin { background: var(--accent); color: var(--primary-deep); }
/* Member role shown as a small muted line under the name (M-104). */
.member__role { font-size: .8rem; color: var(--muted); }
.member__role--head { color: var(--primary); font-weight: 600; }
.btn--sm { min-height: 40px; padding: 6px 12px; font-size: .85rem; }
.btn.danger-outline { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.invite-result { margin-top: var(--space-3); }
.copy-field { display: flex; gap: var(--space-3); }
.copy-field input { flex: 1; min-width: 0; }
/* Buttons in these flex rows must not take the full-width base .btn sizing. */
.copy-field .btn, .member__actions .btn { width: auto; flex: 0 0 auto; }
.member__actions select { flex: 1 1 160px; }
.qr { margin-top: var(--space-2); width: 180px; max-width: 100%; }
.qr svg { display: block; width: 100%; height: auto; }
.notice { background: var(--accent-soft); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); margin: 0 0 var(--space-3); }
.pending { display: flex; align-items: center; gap: var(--space-3); }
.danger-zone { margin-top: var(--space-5); }

/* ===========================================================================
 * Back-office (laptop, staff-facing)
 * ==========================================================================*/
.office-nav { display: flex; gap: var(--space-4); flex: 1; }
.office-nav a { color: rgba(255, 255, 255, .85); text-decoration: none; font-weight: 600; padding: var(--space-1) 0; }
.office-nav a.active { color: #fff; border-bottom: 2px solid var(--accent); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-4); margin-top: var(--space-4); }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); box-shadow: var(--shadow-sm); }
.stat__num { display: block; font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat__label { color: var(--muted); font-size: .9rem; }
.admin-table { width: 100%; border-collapse: collapse; margin-top: var(--space-4); background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.admin-table th, .admin-table td { text-align: left; padding: var(--space-3); border-bottom: 1px solid var(--border); }
.admin-table th { background: var(--panel-alt); font-size: .85rem; color: var(--muted); }
.admin-table tr:last-child td { border-bottom: 0; }

/* Back-office: tenant lifecycle */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.page-head .btn { width: auto; margin-top: 0; }
.flash { background: var(--accent-soft); color: var(--primary-deep); border: 1px solid var(--accent); border-radius: var(--radius); padding: var(--space-3); margin-bottom: var(--space-4); }
.flash--error { background: #F9E9E7; color: #8A2A22; border-color: #E3B5AF; }
.badge--suspended { background: #F3D9B1; color: #7A4A12; }
.badge--offboarding { background: #F1C7C2; color: #8A2A22; }
.logo-preview { display: block; max-width: 160px; max-height: 80px; margin: var(--space-2) 0; border: 1px solid var(--border); border-radius: var(--radius); }

/* --- Charts (back-office analytics) -------------------------------------- */
.chart { margin: 0; }
/* The SVG scales with its container, and its text scales with it — below about
   520px the axis labels drop under 6px and stop being readable. So the chart
   keeps a floor and scrolls sideways inside its own wrapper instead. The page
   itself must never scroll horizontally. */
.chart-wrap { position: relative; overflow-x: auto; }
.chart__svg { width: 100%; min-width: 520px; height: auto; display: block; overflow: visible; }
.chart__tick { fill: var(--chart-axis); font-size: 11px; font-family: var(--font); }
/* Transparent hit targets span the full plot height so hovering is forgiving —
   they are the interaction surface, the marks are only what you look at. */
.chart__hit { fill: transparent; cursor: crosshair; outline: none; }
.chart__hit:hover, .chart__hit:focus-visible { fill: var(--primary); fill-opacity: .05; }
.chart__hit:focus-visible { stroke: var(--primary); stroke-width: 2; stroke-opacity: .5; }

.chart__empty { padding: var(--space-6) var(--space-4); text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius); background: var(--panel-alt); }
.chart__empty p { margin: 0 0 var(--space-1); }

.chart__legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4);
  margin-top: var(--space-3); font-size: .85rem; color: var(--ink); }
.chart__key { display: inline-flex; align-items: center; gap: var(--space-2); }
.chart__swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }

.chart__data { margin-top: var(--space-3); font-size: .9rem; }
.chart__data summary { cursor: pointer; color: var(--muted); }
.chart__data summary:hover { color: var(--primary); }
.admin-table--compact th, .admin-table--compact td { padding: var(--space-2) var(--space-3); font-size: .85rem; }

/* Tooltip is positioned by app.js; it lives outside the SVG so it can escape
   the plot bounds without being clipped. */
.chart__tip { position: absolute; z-index: 20; pointer-events: none; background: var(--primary);
  color: #fff; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
  font-size: .82rem; line-height: 1.3; box-shadow: var(--shadow-sm); white-space: nowrap;
  transform: translate(-50%, -120%); opacity: 0; transition: opacity .08s ease; }
.chart__tip[data-show] { opacity: 1; }
.chart__tip b { display: block; font-weight: 600; }

/* Sparkline inside a stat tile */
.spark { display: block; width: 100%; height: 24px; margin-top: var(--space-2); }
.spark--none { display: block; height: 24px; margin-top: var(--space-2); }

/* Horizontal comparison bars */
.barlist { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.barlist__row { display: grid; grid-template-columns: minmax(90px, 30%) 1fr auto; align-items: center; gap: var(--space-3); }
.barlist__name { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barlist__track { background: var(--panel-alt); border-radius: var(--radius-pill); height: 14px; overflow: hidden; }
.barlist__fill { display: block; height: 100%; border-radius: var(--radius-pill); min-width: 3px; }
.barlist__value { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--primary); font-size: .9rem; }

/* Dashboard panels + toggles */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space-4); box-shadow: var(--shadow-sm); margin-top: var(--space-4); }
.panel__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--space-3); margin-bottom: var(--space-3); }
.panel__head h2, .panel__head h3 { margin: 0; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-pill);
  overflow: hidden; background: var(--panel-alt); }
.segmented a { padding: 6px var(--space-3); font-size: .82rem; text-decoration: none; color: var(--muted);
  border-right: 1px solid var(--border); }
.segmented a:last-child { border-right: 0; }
.segmented a[aria-current="true"] { background: var(--primary); color: #fff; font-weight: 600; }
.toggle-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }

/* Grid toolbar (search, status filter, export) */
.grid-toolbar { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center;
  justify-content: space-between; margin-top: var(--space-4); }
.grid-search { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin: 0; }
.grid-search input[type="search"], .grid-search select { margin: 0; min-height: 38px; width: auto; }
.grid-search input[type="search"] { min-width: 220px; }
.grid-clear, .grid-export { font-size: .85rem; }
.admin-table th a { text-decoration: none; color: inherit; }
.admin-table th a:hover { color: var(--primary); text-decoration: underline; }
.cell-spark { width: 110px; min-width: 90px; }
.cell-spark .spark { height: 20px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* A caveat printed next to the chart it applies to, not buried in a doc */
.note-attribution { font-size: .85rem; margin-top: var(--space-3); max-width: 70ch; }

/* Notification opt-ins */
.optin { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3);
  margin: var(--space-4) 0; background: var(--panel-alt); }
.optin legend { padding: 0 var(--space-2); font-weight: 600; color: var(--primary); }
.optin__row { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-2) 0;
  cursor: pointer; font-weight: 400; }
.optin__row input[type="checkbox"] { margin: 3px 0 0; width: 20px; height: 20px; flex: 0 0 auto; }
.optin__row small { display: block; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.resend-form { margin-top: var(--space-3); }

/* Revealed family contact — deliberately plain, never styled as a grid cell */
.contact-reveal { display: flex; flex-direction: column; gap: 2px; font-size: .85rem; }
.contact-reveal strong { color: var(--primary); }

.stat__delta { display: block; font-size: .8rem; color: var(--muted); margin-top: 2px; }
.stat__delta--up { color: var(--good); font-weight: 600; }
.stat a { text-decoration: none; }

/* --- Tenant white-label (Slice 3a) --------------------------------------- */
.btn { color: var(--on-primary, #fff); }
.topbar__tenantlogo { height: 30px; width: auto; max-width: 120px; border-radius: 6px; display: block; }
.topbar__cobrand { font-size: .72rem; color: var(--accent); opacity: .85; }
.welcome-card { border-left: 4px solid var(--accent); }
.welcome-card__msg { margin: 0; }
.banner { margin: 0 0 var(--space-3); padding: var(--space-3); border-radius: var(--radius-md, 10px); font-size: .95rem; }
.banner--readonly { background: var(--accent-soft); color: var(--primary); border: 1px solid var(--accent); }
/* A refusal, not a state: the answer to something the person just pressed. Warmer than a
   raw red block — this is a family being told their credit ran out, not an error page. */
.banner--error { background: #F9E9E7; color: #8A2A22; border: 1px solid #E3B5AF; }
.link-danger { background: none; border: 0; color: var(--danger); padding: 0; margin-left: .5rem; font: inherit; cursor: pointer; text-decoration: underline; }

.or-sep { text-align: center; color: var(--muted); margin: .75rem 0; font-size: .9rem; }
.voice-review { margin: .5rem 0; }

.avatar { flex: 0 0 auto; border-radius: 50%; object-fit: cover; background: var(--primary); }
.avatar--initial { display: grid; place-items: center; font-weight: 700; color: #fff; }
.avatar--sm { width: 44px; height: 44px; font-size: 1.1rem; }
.avatar--lg { width: 64px; height: 64px; font-size: 1.6rem; }
.memorial-header { display: flex; align-items: center; gap: var(--space-3); }

/* Gallery photo cards (image + caption + thumbnail control) */
.photo-card { display: flex; flex-direction: column; gap: var(--space-1); }
.photo-card__current { font-size: .8rem; color: var(--primary); font-weight: 600; }
/* Remove sits alongside "Use as photo" rather than as an ✕ over the thumbnail —
   the tiles are small on a phone and the content is irreplaceable. Remove comes
   first: every photo has one, not every photo has the rest. */
.photo-card__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.photo-card__actions .link-danger { margin-left: 0; }
.photo-card__locked { font-size: .78rem; margin: 0; }
.photo-card__caption { color: var(--muted); font-size: .85rem; margin: 0; }
.photo-card__caption summary { cursor: pointer; list-style: none; }
.photo-card__caption summary::-webkit-details-marker { display: none; }
.photo-card__caption input { width: 100%; margin-top: var(--space-1); }

/* Events calendar */
.event-section { margin: var(--space-4) 0 var(--space-2); font-size: 1rem; color: var(--primary); }
.event-item { padding: var(--space-3) 0; border-top: 1px solid var(--border); }
.event-item:first-of-type { border-top: 0; }
.event-item__head { display: flex; gap: var(--space-2); align-items: baseline; flex-wrap: wrap; }
.event-item__type { font-weight: 600; }
.event-item__title { color: var(--muted); }
.event-item__when { margin: var(--space-1) 0; font-size: .9rem; color: var(--muted); }
.event-item__where { margin: var(--space-1) 0; }
.event-item__desc { margin: var(--space-2) 0; white-space: pre-line; }

/* Coming up (home) */
.coming-up__list { list-style: none; margin: 0; padding: 0; }
.coming-up__item { border-top: 1px solid var(--border); }
.coming-up__item:first-child { border-top: 0; }
.coming-up__link { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0; color: inherit; text-decoration: none; }
.coming-up__icon { font-size: 1.25rem; }
.coming-up__body { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.coming-up__title { font-weight: 600; }
.coming-up__sub { color: var(--muted); font-size: 0.9em; }
.coming-up__when { color: var(--muted); font-size: 0.85em; white-space: nowrap; }

/* Anniversary opt-in toggle (memorial page) */
.anniversary-toggle__label { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
/* Same gap as .scope-toggle/.check: reset the base full-width input styling so
   the checkbox renders at native size instead of a 44px-tall full-width box. */
.anniversary-toggle__label input[type="checkbox"] { width: auto; min-height: 0; margin: 0; flex: 0 0 auto; }

/* ===========================================================================
 * Button roles (soft-tint palette) — B2
 * Doubled-class selectors (.btn.btn--role, specificity 0,2,0) so these beat
 * the later branding override `.btn { color: var(--on-primary,#fff) }` above.
 * Existing .btn/.btn.secondary/.btn.accent/.btn.fab rules are untouched;
 * call-sites migrate to these roles in B6.
 * ==========================================================================*/
.btn.btn--primary { background: var(--accent); color: var(--primary); border-color: transparent; }
.btn.btn--secondary { background: var(--accent-soft); color: var(--primary); border-color: transparent; }
.btn.btn--utility { background: var(--panel-alt); color: var(--primary); border-color: var(--border); }
.btn.btn--tertiary { background: transparent; color: var(--primary); border-color: transparent; }
.btn.btn--destructive { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn.btn--tertiary:hover { background: var(--panel-alt); }

.btn .ico { display: inline-flex; align-items: center; }
.btn .ico svg { width: 20px; height: 20px; }

/* Line-icons used inside meta badges and the coming-up list glyphs. */
.badge svg { width: 14px; height: 14px; vertical-align: -2px; }
.coming-up__icon svg { width: 20px; height: 20px; }

/* ===========================================================================
 * Topbar account menu (avatar → Profile/Settings/Sign out) — B4
 * ==========================================================================*/
.acctmenu { position: relative; }
.acctmenu__avatar {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255, 255, 255, .16); color: #fff;
  border: 1px solid rgba(255, 255, 255, .26);
  font: inherit; font-weight: 700; cursor: pointer;
}
.acctmenu__avatar:hover { background: rgba(255, 255, 255, .26); }
.acctmenu__avatar .ico svg { width: 20px; height: 20px; }
.acctmenu__pop {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); min-width: 180px; padding: var(--space-2); z-index: 20;
}
.acctmenu__pop[hidden] { display: none; }
.acctmenu__item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: .55rem .6rem; border-radius: var(--radius-sm);
  color: var(--ink); text-decoration: none; width: 100%;
  background: none; border: 0; font: inherit; cursor: pointer;
}
.acctmenu__item:hover { background: var(--panel-alt); }
.acctmenu__item--danger { color: var(--danger); }

/* Account-menu identity header (back-office: shows the signed-in staff member). */
.acctmenu__id { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.acctmenu__id strong { display: block; color: var(--primary); }
.acctmenu__id .muted { display: block; font-size: .8rem; word-break: break-all; }

/* ===========================================================================
 * Photo lightbox (tap-to-zoom) — B7
 * ==========================================================================*/
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-3); background: rgba(0, 0, 0, .9); padding: var(--space-4);
}
.lightbox[hidden] { display: none; }
.lightbox__backdrop { position: absolute; inset: 0; z-index: -1; }
.lightbox__img { max-width: 100%; max-height: 78vh; object-fit: contain; border-radius: var(--radius-sm); }
.lightbox__caption { color: #fff; text-align: center; }
.lightbox__close,
.lightbox__nav {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255, 255, 255, .16); color: #fff;
  border: 1px solid rgba(255, 255, 255, .26);
  font-size: 1.25rem; line-height: 1; cursor: pointer;
}
.lightbox__close:hover,
.lightbox__nav:hover { background: rgba(255, 255, 255, .26); }
.lightbox__close { position: absolute; top: var(--space-4); right: var(--space-4); }
.lightbox__nav--prev { position: absolute; left: var(--space-4); top: 50%; transform: translateY(-50%); }
.lightbox__nav--next { position: absolute; right: var(--space-4); top: 50%; transform: translateY(-50%); }

/* ===========================================================================
 * Idle auto-logout warning (S-103)
 * ==========================================================================*/
.idlemodal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
}
.idlemodal[hidden] { display: none; }
.idlemodal__backdrop { position: absolute; inset: 0; background: rgba(40, 20, 8, .55); }
.idlemodal__card {
  position: relative; z-index: 1;
  width: 100%; max-width: 360px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: var(--space-5); text-align: center;
}
.idlemodal__title { margin: 0 0 var(--space-2); }
.idlemodal__desc { margin: 0 0 var(--space-3); }
.idlemodal__count { margin: 0 0 var(--space-4); font-size: 1rem; color: var(--muted, var(--primary)); }
.idlemodal__count strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.idlemodal__actions { display: flex; flex-direction: column; gap: 0; }
