/* Admin UI — SGDC design system (see docs/design-system.md).
   Warm-paper, legible, comfortable density for non-technical volunteer
   secretaries. §1 tokens are defined once here and referenced everywhere.
   The old token names (--panel/--line/--red/--muted/…) are kept as
   aliases mapped onto the new palette so screens not yet individually
   migrated inherit the new look automatically. */

:root {
  /* Surfaces */
  --bg: #f6f4ef;            /* app background — warm paper */
  --surface: #ffffff;       /* cards, tables, inputs */
  --surface-sunk: #fcfbf8;  /* card footers, table header row */
  --row-hover: #fbfaf6;

  /* Lines */
  --border: #e7e2d7;
  --border-strong: #d8d2c4;
  --divider: #eee9df;
  --divider-soft: #f0ece3;

  /* Brand */
  --navy: #1f2a44;          /* top nav, structural buttons, headings */
  --garnet: #9b2c3b;        /* primary actions, links, active accents */
  --gold: #c9a24b;          /* hairline accents only — use sparingly */

  /* Text */
  --ink: #232a38;           /* body text */
  --text-2: #5b5447;        /* secondary / cell text */
  --text-muted: #756f63;
  --label: #8a8374;         /* uppercase overlines / table headers */
  --hint: #9c9484;          /* helper text, placeholders */

  /* Fonts */
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-sans: "Hanken Grotesk", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, sans-serif;
  --font-mono: "Source Serif 4", ui-monospace, Menlo, monospace;

  --shadow-card: 0 1px 3px rgba(31, 42, 68, 0.05);
  --radius-card: 14px;

  /* --- Back-compat aliases: old names → new palette --- */
  --panel: var(--surface);
  --line: var(--border);
  --red: var(--garnet);
  --muted: var(--text-muted);
  --navy-soft: #2b3a5e;
  --gold-soft: #e0cf9a;
  --accent: #3f6b43;        /* muted success/approve green */
  --warn: #a2493a;          /* muted danger text */
  --status-bg: #eceae4;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
}
body {
  font: 15px/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
:where(input, button, select, textarea) {
  font-family: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 62px;
  padding: 0 24px;
  background: var(--navy);
  color: rgb(255 255 255 / 90%);
  border-bottom: 2px solid var(--gold);
}
.topbar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  flex: none;
}
.topbar__crest {
  height: 34px;
  width: auto;
  display: block;
}
.topbar .brand {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 19px;
  color: #ffffff;
}
.topbar__nav {
  flex: 1;
  display: flex;
  /* Centre when there's room; fall back to start (never clip the first
     link) when cramped, then scroll. Account cluster stays put. */
  justify-content: safe center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  height: 100%;
}
.topbar__nav::-webkit-scrollbar {
  display: none;
}
.topbar__nav a {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 12px;
  color: rgb(255 255 255 / 78%);
  text-decoration: none;
  font-size: 14.5px;
  white-space: nowrap;
}
.topbar__nav a:hover {
  color: #ffffff;
}
.topbar__nav a.is-active {
  color: #ffffff;
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--gold);
}
.topbar__account {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}
.topbar .logout {
  margin: 0;
}
.topbar .who {
  color: rgb(255 255 255 / 65%);
  font-size: 13px;
}
.topbar button {
  border: 1px solid rgb(255 255 255 / 30%);
  background: transparent;
  color: rgb(255 255 255 / 90%);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.topbar button:hover {
  border-color: var(--gold);
  color: #ffffff;
}
.topbar__help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgb(255 255 255 / 30%);
  color: rgb(255 255 255 / 90%);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  flex: none;
}
.topbar__help:hover {
  border-color: var(--gold);
  background: var(--navy-soft);
  color: #ffffff;
}

main {
  padding: 28px;
  max-width: 1240px;
  margin: 0 auto;
}

h1 {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--navy);
}
h2 {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  margin: 32px 0 12px;
  color: var(--navy);
}
code {
  font: 13px/1.4 var(--font-mono);
  letter-spacing: 0.02em;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}
.page-header h1 .muted {
  font-family: var(--font-sans);
  font-size: 20px;
  font-weight: 400;
}
.filter label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}
.filter select {
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--line);
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
th,
td {
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--divider-soft);
  vertical-align: top;
}
th {
  font-weight: 700;
  color: var(--label);
  background: var(--surface-sunk);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
tr:last-child td {
  border-bottom: 0;
}
td.empty {
  color: var(--text-muted);
  padding: 28px;
  text-align: center;
}

/* Data table (§2.4): comfortable rows, clickable, garnet name cell,
   "Open ›" affordance in the last cell. */
table.queue td {
  padding-top: 17px;
  padding-bottom: 17px;
  color: var(--text-2);
}
table.queue tbody tr[data-href] {
  cursor: pointer;
}
table.queue tbody tr:hover {
  background: var(--row-hover);
}
/* Keyboard focus for whole-row navigation (tabindex added by admin-ui.js). */
table.queue tbody tr[data-href]:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: -2px;
}
table.queue td a {
  color: var(--garnet);
  font-weight: 600;
  text-decoration: none;
}
table.queue td a:hover {
  text-decoration: underline;
}
.cell-open {
  color: var(--garnet);
  font-weight: 600;
  white-space: nowrap;
}

/* Status badges — muted pills, never saturated (§1). */
.status {
  display: inline-block;
  padding: 3px 11px;
  background: #eceae4;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 600;
  color: #6e685b;
  white-space: nowrap;
}
/* Active / success family */
.status--active,
.status--approved,
.status--payment_captured,
.status--onboarded,
.status--sent,
.status--fulfilled,
.status--paid {
  background: #e7efe7;
  color: #3f6b43;
}
/* Grace / awaiting / in-progress family (amber) */
.status--grace,
.status--awaiting_admin,
.status--on_hold,
.status--pending,
.status--sending,
.status--paused,
.status--warn,
.status--partially-refunded {
  background: #f4ecd9;
  color: #876a2c;
}
/* Lapsed / failure family (garnet-tinted) */
.status--lapsed,
.status--rejected,
.status--expired,
.status--payment_failed,
.status--declined {
  background: #f6e7e3;
  color: #a2493a;
}
/* Suspended */
.status--suspended {
  background: #f1e7e7;
  color: #8a4a4a;
}
/* Informational / navy family */
.status--honorary,
.status--awaiting_sponsors,
.status--payment_authorised,
.status--draft,
.status--queued {
  background: #e8ecf4;
  color: #3a4e7a;
}
/* Neutral / closed family */
.status--deceased,
.status--cancelled,
.status--refunded {
  background: #eceae4;
  color: #6e685b;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 11px;
  border-radius: 2px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink);
  margin-right: 4px;
}
.badge--primary {
  background: #e4ede4;
  color: var(--accent);
  border-color: #c9d7c9;
}
.badge--warn {
  background: #f3ecd2;
  color: #7a5a08;
  border-color: var(--gold-soft);
}
.badge--danger {
  background: #fbf1f2;
  color: var(--garnet);
  border-color: #e3c4c8;
}

table.emails code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 13px;
}

dl.kv {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 6px 16px;
  margin: 16px 0;
}
dl.kv dt {
  color: var(--muted);
}
dl.kv dd {
  margin: 0;
}

.auth-card {
  max-width: 320px;
  margin: 80px auto;
  background: var(--panel);
  padding: 24px;
  border: 1px solid var(--line);
}
.auth-card form label {
  display: block;
  margin: 12px 0;
  color: var(--muted);
  font-size: 12px;
}
.auth-card form input {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  font: inherit;
}
.auth-card form button {
  width: 100%;
  padding: 10px;
  background: var(--red);
  color: white;
  border: 0;
  font: inherit;
  cursor: pointer;
  letter-spacing: 0.04em;
}
.auth-card form button:hover {
  background: #d11a36;
}
.auth-card .error {
  color: var(--warn);
  margin: 12px 0;
}

.empty {
  color: var(--muted);
}

.flash {
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  margin: 0 0 16px;
  font-size: 13px;
}
.flash--ok {
  background: #e4ede4;
  border-color: #c9d7c9;
  color: var(--accent);
}
.flash--warn {
  background: #f4e6df;
  border-color: #e5cdc1;
  color: var(--warn);
}
.flash--err {
  background: #f6e2e2;
  border-color: #e0b4b4;
  color: var(--warn);
}

dl.kv dd.address {
  font-style: normal;
}

.muted {
  color: var(--muted);
  font-weight: 400;
}

section.decision,
section.decision-record {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px;
  margin: 24px 0;
}
section.decision h2,
section.decision-record h2 {
  margin-top: 0;
}
.decision-form {
  display: grid;
  gap: 6px;
  margin: 12px 0;
  padding: 12px;
  border: 1px dashed var(--line);
}
.decision-form label {
  font-size: 12px;
  color: var(--muted);
}
.decision-form textarea {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  resize: vertical;
}
.decision-form button {
  justify-self: start;
  padding: 6px 14px;
}
.btn-approve {
  background: var(--garnet);
  color: white;
  border: 0;
  border-radius: 9px;
  padding: 11px 20px;
  font-size: 14.5px;
  font-weight: 600;
}
.btn-approve:hover {
  filter: brightness(1.08);
}
.btn-reject {
  background: var(--surface);
  color: var(--garnet);
  border: 1px solid #e3c4c8;
  border-radius: 9px;
  padding: 11px 20px;
  font-size: 14.5px;
  font-weight: 600;
}
.btn-reject:hover {
  background: #fbf1f2;
}
.notes {
  color: var(--ink);
  margin: 8px 0 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}
.muted-link {
  color: var(--muted);
  font-size: 13px;
}

.row-archived td {
  opacity: 0.7;
}

.form-section {
  max-width: 640px;
}
.record-form .field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}
.record-form input,
.record-form textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}
/* Buttons (§2.2). Default .btn = garnet primary (one key CTA per
   context). Modifiers cover the structural-navy, secondary and
   danger-ghost variants. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;          /* comfortable hit target (§3.4) */
  background: var(--garnet);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 11px 20px;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.1;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover {
  filter: brightness(1.08);
  color: #fff;
}
.btn--navy {
  background: var(--navy);
}
.btn--navy:hover {
  filter: brightness(1.12);
}
.btn--secondary,
.btn--ghost {
  background: var(--surface);
  color: #2c3447;
  border-color: var(--border-strong);
  filter: none;
}
.btn--secondary:hover,
.btn--ghost:hover {
  border-color: #b9b1a0;
  background: var(--surface-sunk);
  color: #2c3447;
  filter: none;
}
.btn--danger {
  background: var(--surface);
  color: var(--garnet);
  border-color: #e3c4c8;
  filter: none;
}
.btn--danger:hover {
  background: #fbf1f2;
  color: var(--garnet);
  filter: none;
}
.btn--block {
  width: 100%;
}
.btn-mini {
  background: var(--garnet);
  color: white;
  border: 0;
  border-radius: 7px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}
.btn-mini:hover {
  filter: brightness(1.08);
}
.btn-danger {
  background: var(--surface);
  color: var(--garnet);
  border: 1px solid #e3c4c8;
  border-radius: 9px;
  padding: 10px 16px;
  cursor: pointer;
}
.btn-danger:hover {
  background: #fbf1f2;
}
.link-danger {
  background: transparent;
  border: 0;
  color: var(--warn);
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.inline-form {
  display: inline-block;
  margin: 0;
}

.inline-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.inline-row input[type="email"] {
  flex: 1;
  min-width: 220px;
}

.merge-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 12px;
}
.merge-tags__label {
  color: var(--muted);
  margin-right: 4px;
}
.merge-tag {
  font: inherit;
  font-size: 12px;
  padding: 3px 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  cursor: pointer;
  border-radius: 2px;
}
.merge-tag:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* EasyMDE: align toolbar to admin look + give labels a bit more
   prominence so older users can read them. */
.EasyMDEContainer .editor-toolbar {
  border: 1px solid var(--line);
  border-bottom: 0;
  background: var(--bg);
}
.EasyMDEContainer .CodeMirror {
  border: 1px solid var(--line);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 14px;
  min-height: 260px;
}
.EasyMDEContainer .editor-toolbar button {
  color: var(--ink);
}
.EasyMDEContainer .editor-toolbar button:hover {
  background: var(--panel);
  border-color: var(--line);
}
/* Image-preview lines: EasyMDE renders the picture as an ::after on the
   line that carries data-img-src, but leaves the raw ![](…) source text
   visible above it. That line never reaches the sent email, so shrink and
   fade it to a whisper; hovering the line brings it back so the image can
   still be selected, edited or deleted. (The ::after box is sized by the
   --width/--height custom properties, so it's unaffected.) */
.EasyMDEContainer .CodeMirror [data-img-src] {
  font-size: 9px;
}
.EasyMDEContainer .CodeMirror [data-img-src] span {
  opacity: 0.3;
}
.EasyMDEContainer .CodeMirror [data-img-src]:hover {
  font-size: inherit;
}
.EasyMDEContainer .CodeMirror [data-img-src]:hover span {
  opacity: 1;
}
.EasyMDEContainer .editor-toolbar button.active {
  background: var(--panel);
  border-color: var(--accent);
}
.editor-preview.sgdc-preview {
  font-family: Georgia, "Playfair Display", "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.6;
  background: #fbfaf6;
  padding: 24px 28px;
}

.rule-soft {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 24px 0;
}

.subnav {
  display: flex;
  gap: 16px;
  align-items: baseline;
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.subnav a {
  color: var(--muted);
  text-decoration: none;
}
.subnav a:hover {
  text-decoration: underline;
}
.subnav [aria-current="page"] {
  font-weight: 600;
}

.member-search {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 12px;
  margin: 12px 0;
}
.member-search label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.member-search input {
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.search-results {
  margin-top: 12px;
}
.search-hits {
  list-style: none;
  padding: 0;
  margin: 0;
}
.search-hits li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.search-hits li:last-child {
  border-bottom: 0;
}
.search-hits .muted {
  margin: 0 8px;
}

.group-chips {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.group-chips li {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chip {
  display: inline-block;
  padding: 4px 10px;
  background: var(--status-bg);
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
}
.chip:hover {
  border-color: var(--accent);
}
.chip--archived {
  opacity: 0.6;
}

.members-in-group {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
}
.members-in-group th,
.members-in-group td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.members-in-group th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg);
}

.variant-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
@media (min-width: 48rem) {
  .variant-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

/* Order/campaign status colours are defined in the consolidated badge
   block near the top (§1). */

/* Campaign status grid */
.status-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 14px;
}
@media (min-width: 48rem) {
  .status-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat .num {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  color: var(--ink);
}
.num--ok {
  color: #2a5a3a;
}
.num--warn {
  color: #7a5a08;
}
.num--err {
  color: var(--warn);
}

.next-up {
  margin-top: 12px;
  font-size: 13px;
}
.next-up ul {
  margin: 6px 0 0 18px;
  padding: 0;
}

/* Audience picker */
.audience {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 12px;
}
.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
}
.radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.audience-detail {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.audience-detail summary {
  cursor: pointer;
  font-weight: 500;
  margin-bottom: 6px;
}
.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
@media (min-width: 48rem) {
  .checkbox-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
.picked-members {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.picked-members li {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 4px 8px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.row {
  display: flex;
  gap: 14px;
}
.row .field {
  flex: 1;
}

.preview-banner {
  background: var(--bg);
  border: 1px solid var(--gold-soft);
  padding: 12px 14px;
  margin: 16px 0;
}

/* Sent-campaign Content panel: the rendered email in a sandboxed iframe. */
.email-preview {
  width: 100%;
  height: 640px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.body-preview {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 12px;
  white-space: pre-wrap;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 13px;
}

.queue-action {
  margin: 16px 0;
}

.photo-grid {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.photo {
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.photo img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--bg);
  display: block;
}
.photo__meta {
  padding: 6px 8px 0;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.photo__meta .alt {
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.photo__actions {
  padding: 4px 6px 8px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}
.photo__actions .link,
.photo__actions .link-danger {
  background: none;
  border: 0;
  padding: 2px 4px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
}
.photo__actions .link-danger {
  color: #b00020;
}

/* Members admin overhaul */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px 18px;
  margin: 16px 0;
}
.card > h2 {
  margin: 0 0 12px;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.card > h3 {
  margin: 16px 0 8px;
  font-size: 13px;
  color: var(--ink);
}
.member-detail .page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.inline-edit {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin: 8px 0;
  flex-wrap: wrap;
}
.inline-edit .field {
  margin: 0;
}
.inline-edit .muted {
  margin-left: 8px;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 16px;
}
.filter-chips .chip {
  display: inline-block;
  padding: 4px 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
  text-decoration: none;
  text-transform: capitalize;
}
.filter-chips .chip:hover {
  border-color: var(--ink);
}
.filter-chips .chip--active {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 8px 0 4px;
}
.search-form input[type="search"] {
  flex: 1 1 280px;
  max-width: 360px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 16px 0 0;
  font-size: 13px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.row-actions .link {
  background: transparent;
  border: 0;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.row-actions .link:hover {
  color: var(--gold, var(--ink));
}

.group-chips li {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* --- Audit timeline ------------------------------------------------------ */
.audit-timeline__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.audit-timeline__buckets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.audit-timeline__bucket {
  display: inline-block;
  padding: 2px 10px;
  border: 1px solid #ccc;
  border-radius: 999px;
  font-size: 0.85em;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.audit-timeline__bucket:hover { background: #f3f3f3; }
.audit-timeline__bucket.is-active {
  background: #1f3a5f;
  color: #fff;
  border-color: #1f3a5f;
}
.audit-timeline__list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.audit-timeline__item {
  display: grid;
  grid-template-columns: 145px auto 1fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
  font-size: 0.92em;
  align-items: baseline;
}
.audit-timeline__time { color: #666; font-variant-numeric: tabular-nums; }
.audit-timeline__action {
  background: #f3f3f3;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.85em;
}
.audit-timeline__actor { color: #666; font-size: 0.88em; }
.audit-timeline__details {
  grid-column: 2 / -1;
  margin-top: 4px;
}
.audit-timeline__details summary {
  cursor: pointer;
  color: #1f3a5f;
  font-size: 0.85em;
}
.audit-timeline__details pre {
  margin: 4px 0 0;
  padding: 8px;
  background: #fafafa;
  border: 1px solid #eee;
  border-radius: 4px;
  font-size: 0.82em;
  overflow-x: auto;
}
.audit-timeline__paging {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  gap: 8px;
}
.audit-timeline__empty { padding: 12px 0; }

/* --- Tags + notes -------------------------------------------------------- */
.chip--tag {
  background: #eef3eb;
  border-color: #d2dccb;
  color: #44593a;
  text-decoration: none;
  font-family: var(--font-mono, monospace);
  font-size: 0.85em;
}
.chip--tag:hover { background: #e2ecdb; }
.chip--xs { padding: 1px 6px; font-size: 0.78em; }
.tag-chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0;
  margin: 0 0 12px;
}
.row-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: 8px;
  vertical-align: middle;
}
.filter-chips--tags {
  margin-top: 6px;
  opacity: 0.95;
}

.notes-list {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
}
.note {
  border-top: 1px solid #eee;
  padding: 10px 0;
}
.note__meta {
  font-size: 0.82em;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.note__meta .inline-form { margin-left: auto; }
.note__body {
  margin: 4px 0 0;
  white-space: pre-wrap;
}
.small { font-size: 0.82em; }

/* --- Banner -------------------------------------------------------------- */
.banner {
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  margin: 0 0 16px;
  font-size: 14px;
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}
.banner--info {
  background: #f3ecd2;
  border-color: var(--gold-soft);
  color: #5b4516;
}
.banner .inline-form { margin-left: auto; }
.banner button.link {
  background: none;
  border: none;
  color: var(--red);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

/* --- Column picker + resizable tables ----------------------------------- */
.col-picker {
  margin: 0 0 12px;
}
.col-picker > summary {
  cursor: pointer;
  display: inline-block;
  padding: 4px 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 13px;
}
.col-picker__form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  padding: 12px 14px;
  margin-top: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
}
.col-picker__form label {
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.col-picker__form button {
  margin-left: auto;
}

table.queue--resizable th {
  position: relative;
  user-select: none;
}
table.queue--resizable th .col-resizer {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  background: transparent;
}
table.queue--resizable th .col-resizer:hover {
  background: var(--gold-soft);
}

/* --- Bulk-select toolbar (members list) -------------------------------- */
.bulk-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
  padding: 8px 12px;
  background: #f3ecd2;
  border-left: 3px solid var(--gold);
  font-size: 13px;
}
.bulk-toolbar[hidden] {
  display: none;
}
.col-select {
  width: 28px;
  text-align: center;
}

/* --- Auth-page security notice ------------------------------------------ */
.auth-notice {
  margin: 0 0 20px;
  padding: 10px 12px;
  border-left: 3px solid var(--gold);
  background: #f3ecd2;
  color: #5b4516;
  font-size: 13px;
  line-height: 1.45;
}
.auth-notice strong {
  display: block;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 11px;
  color: #7a5a08;
  margin-bottom: 4px;
}

/* Help — in-portal admin manual (index + rendered markdown articles). */
.help-index__intro {
  color: var(--muted);
  margin: 8px 0 24px;
  max-width: 760px;
}
.help-index__section {
  margin-bottom: 4px;
}
.help-index__list {
  list-style: none;
  padding: 0;
  margin: 0 0 8px;
  max-width: 760px;
}
.help-index__list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.help-index__list a {
  font-weight: 600;
  text-decoration: none;
  color: var(--navy-soft);
}
.help-index__list a:hover {
  text-decoration: underline;
  text-decoration-color: var(--gold);
  text-underline-offset: 3px;
}
.help-index__summary {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.help-article {
  max-width: 820px;
}
.help-article__nav {
  margin-bottom: 8px;
}
.help-article__nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
}
.help-article__nav a:hover {
  text-decoration: underline;
}
.help-article__body {
  line-height: 1.55;
}
.help-article__body h1 {
  margin-bottom: 8px;
}
.help-article__body h2 {
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}
.help-article__body h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 20px 0 8px;
}
.help-article__body p {
  margin: 10px 0;
}
.help-article__body blockquote {
  margin: 12px 0 20px;
  padding: 8px 14px;
  border-left: 3px solid var(--gold);
  background: var(--panel);
  color: var(--muted);
}
.help-article__body ul,
.help-article__body ol {
  padding-left: 22px;
}
.help-article__body li {
  margin: 4px 0;
}
.help-article__body table {
  margin: 12px 0;
}
.help-article__body code {
  background: var(--panel);
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 3px;
}
.help-article__body a {
  color: var(--navy-soft);
}

/* Application onboarding stepper — a horizontal row of pips that turn
   green as each joining stage completes. Wraps to multiple rows on
   narrow screens. */
.stepper {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  list-style: none;
  margin: 4px 0 24px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: var(--panel);
}
.stepper__step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.stepper__pip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--status-bg);
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.stepper__step.is-done {
  color: var(--accent);
  font-weight: 600;
}
.stepper__step.is-done .stepper__pip {
  background: var(--accent);
  border-color: var(--accent);
}

/* ===================================================================== *
 *  DESIGN SYSTEM — shared components (docs/design-system.md §2)          *
 *  Appended last so the new system wins over legacy rules of equal       *
 *  specificity. Screens are migrated to these classes one at a time.     *
 * ===================================================================== */

/* --- Forms (§2.3) ------------------------------------------------------- */
.ds-field {
  display: grid;
  gap: 6px;
}
.ds-field > label,
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.input,
.ds-field input[type="text"],
.ds-field input[type="email"],
.ds-field input[type="search"],
.ds-field input[type="tel"],
.ds-field input[type="number"],
.ds-field input[type="date"],
.ds-field select,
.ds-field textarea {
  width: 100%;
  min-height: 44px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 11px 13px;
  font-size: 15px;
  color: var(--ink);
}
.ds-field textarea {
  min-height: 76px;
}
.input::placeholder,
.ds-field input::placeholder,
.ds-field textarea::placeholder {
  color: var(--hint);
}
.input:focus,
.ds-field input:focus,
.ds-field select:focus,
.ds-field textarea:focus {
  outline: 0;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(31, 42, 68, 0.1);
}
.ds-field textarea {
  resize: vertical;
  min-height: 76px;
}
.field-hint {
  font-size: 12.5px;
  color: var(--hint);
}

/* --- Filters: segmented status tabs (§2.5) ------------------------------ */
.seg-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 18px;
}
.seg-tabs a,
.seg-tabs button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 9px 16px;
  border-radius: 20px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  text-transform: capitalize;
}
.seg-tabs a:hover,
.seg-tabs button:hover {
  border-color: #b9b1a0;
}
.seg-tabs a.is-active,
.seg-tabs button.is-active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

/* Restyle the legacy filter-chips to the segmented look so list screens
   not yet hand-migrated still match. */
.filter-chips .chip {
  border-radius: 20px;
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font-weight: 600;
  padding: 6px 14px;
}
.filter-chips .chip--active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

/* --- Section panel / card with gold-dot header (§2 Card) ---------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  margin: 0 0 22px;
}
.panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--divider);
}
.panel__head::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  flex: none;
}
.panel__head h2,
.panel__head h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
}
.panel__head .panel__aside {
  margin-left: auto;
}
.panel__body {
  padding: 24px 28px;
}
.panel__foot {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  align-items: center;
  padding: 16px 28px;
  background: var(--surface-sunk);
  border-top: 1px solid var(--divider);
  border-radius: 0 0 var(--radius-card) var(--radius-card);
}

/* Field grid inside a panel body (§1 spacing). */
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 22px;
}
.field-grid .span-2 {
  grid-column: 1 / -1;
}
@media (max-width: 640px) {
  .field-grid {
    grid-template-columns: 1fr;
  }
}

/* Definition-style facts (read-only key/value inside a panel). */
.facts {
  display: grid;
  gap: 14px 22px;
  margin: 0;
}
.facts > div {
  display: grid;
  gap: 2px;
}
.facts dt,
.fact-label {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--label);
}
.facts dd,
.fact-value {
  margin: 0;
  font-size: 15px;
  color: var(--ink);
}

/* --- Detail two-column layout (§2 Detail layout) ----------------------- */
.detail-grid {
  display: grid;
  grid-template-columns: 336px 1fr;
  gap: 32px;
  align-items: start;
}
@media (max-width: 900px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
}
.detail-side {
  position: sticky;
  top: 90px;
  display: grid;
  gap: 22px;
}
@media (max-width: 900px) {
  .detail-side {
    position: static;
  }
}
.detail-main {
  min-width: 0;
}
.detail-section {
  scroll-margin-top: 84px;
}

/* Summary card (left rail) */
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 24px 24px 20px;
  text-align: center;
}
.monogram {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--navy);
  box-shadow: 0 0 0 2px var(--gold), 0 0 0 4px var(--surface);
  color: #fff;
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.summary-card__name {
  font-family: var(--font-serif);
  font-size: 23px;
  font-weight: 700;
  color: var(--navy);
  margin: 0 0 8px;
  word-break: break-word;
}
.summary-card__id {
  font-family: var(--font-serif);
  letter-spacing: 0.02em;
  color: var(--text-2);
}
.summary-facts {
  text-align: left;
  margin: 18px 0 0;
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--divider);
  padding-top: 16px;
}
.summary-facts > div {
  display: grid;
  gap: 2px;
}
.quick-actions {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}
.quick-actions .btn,
.quick-actions form {
  width: 100%;
}

/* Section-nav card (left rail) */
.section-nav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 8px;
}
.section-nav a {
  display: block;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
  font-size: 14.5px;
  font-weight: 500;
}
.section-nav a:hover {
  background: var(--surface-sunk);
}
.section-nav a.is-active {
  background: #f6eef0;
  color: var(--garnet);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--garnet);
}

/* --- Notice / banner, parchment (§1) ----------------------------------- */
.notice {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 18px;
  margin: 0 0 22px;
  background: #fbf4e2;
  border: 1px solid #ead9a8;
  border-left: 4px solid var(--gold);
  border-radius: 10px;
}
.notice__icon {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #f2e4bc;
  color: #8a6d2f;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.notice__title {
  font-weight: 700;
  color: #5b4a1e;
  margin: 0 0 2px;
}
.notice__body {
  color: #6f5e34;
  font-size: 14px;
}
/* Success variant — used as the no-JS fallback for confirmation flashes
   (JS enhances these into a toast; see html.toast-ready rule below). */
.notice--ok {
  background: #e7efe7;
  border-color: #c9d7c9;
  border-left-color: #3f6b43;
}
.notice--ok .notice__icon {
  background: #d3e3d3;
  color: #3f6b43;
}
.notice--ok .notice__body {
  color: #2f5234;
}
/* Hide the server-rendered flash fallback ONLY once admin-ui.js has loaded
   and added .toast-ready — it then fires the message as a toast and removes
   the element. If the script 404s or throws, .toast-ready is never set and
   the visible notice remains (no-JS / failed-JS users keep their message). */
html.toast-ready [data-toast] {
  display: none;
}

/* --- Tag chip (§1) ------------------------------------------------------ */
.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 6px;
  background: #efeadf;
  color: #6b6456;
  font-size: 12.5px;
  text-decoration: none;
}

/* --- Toast (§2 Toast) --------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  z-index: 100;
  background: var(--navy);
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 24px;
  box-shadow: 0 8px 28px rgba(31, 42, 68, 0.3);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --- Detail sub-blocks (nested action cards inside a panel body) -------- */
.subpanel {
  margin-top: 20px;
  padding: 18px 20px;
  background: var(--surface-sunk);
  border: 1px solid var(--divider);
  border-radius: 10px;
}
.subpanel > h3 {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
}
.subpanel-rule {
  border: 0;
  border-top: 1px solid var(--divider);
  margin: 22px 0;
}
.stack-form {
  display: grid;
  gap: 12px;
  margin: 14px 0 0;
  justify-items: start;
}
.stack-form .ds-field {
  width: 100%;
  max-width: 520px;
}

/* --- Entity card grid (list screens that suit tiles over a table) ------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(264px, 1fr));
  gap: 20px;
}
.entity-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 22px 24px;
  text-decoration: none;
  color: inherit;
}
.entity-card:hover {
  border-color: var(--border-strong);
  background: var(--row-hover);
}
.entity-card--archived {
  opacity: 0.75;
}
.entity-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.entity-card__title {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
  color: var(--navy);
}
.entity-card__count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--garnet);
  white-space: nowrap;
}
.entity-card__desc {
  color: var(--text-2);
  font-size: 14px;
}
.entity-card__meta {
  margin-top: auto;
  color: var(--hint);
  font-size: 12.5px;
}

/* Constrained width for standalone form pages (create/edit). */
.form-narrow {
  max-width: 720px;
}
