/* 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;

  /* --- Shape & elevation -------------------------------------------------- */
  --radius: 16px;
  --radius-sm: 10px;
  --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: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --tap: 52px;            /* min tap target (M-901) */
  --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.55; font-size: 17px;
  -webkit-font-smoothing: antialiased;
}
body.text-small { font-size: 15px; }
body.text-large { font-size: 19px; }
body.text-xlarge { font-size: 22px; }

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: .75rem .85rem; 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: .75rem 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%;
  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: '⌃'; }

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

/* ===========================================================================
 * 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. */
.datefield { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-3); margin-top: var(--space-4); }
.datefield 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; }

/* --- 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); }
.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); }

/* --- 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); }
.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; }
