/* ============================================================
   Ahuja Family Tree -- Base Stylesheet
   Mobile-first. All styles live here -- no inline styles.
   Written for non-developer maintainability.
   ============================================================ */

/* Ensure the HTML hidden attribute always wins over CSS display rules.
   Without this, classes like .tree-login { display: flex } override
   the browser default and the element stays visible when hidden is set. */
[hidden] { display: none !important; }

/* ------------------------------------------------------------
   CSS Custom Properties (design tokens)
   Change these to update colours and spacing site-wide.
   ------------------------------------------------------------ */
:root {
  /* Colours */
  --colour-primary:       #b5451b;  /* Deep terracotta — warm, familial */
  --colour-primary-dark:  #8c3214;  /* Hover/active state */
  --colour-bg:            #fdf8f4;  /* Off-white warm background */
  --colour-surface:       #ffffff;  /* Card / panel background */
  --colour-text:          #1a1a1a;  /* Main body text */
  --colour-text-muted:    #6b6b6b;  /* Secondary / helper text */
  --colour-border:        #e0d6cc;  /* Subtle dividers */
  --colour-success:       #2d7a4f;  /* Success messages */
  --colour-error:         #c0392b;  /* Error messages */

  /* Typography */
  --font-family:   'Georgia', 'Times New Roman', serif;
  --font-sans:     system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-size-base: 1rem;       /* 16px */
  --font-size-sm:   0.875rem;   /* 14px */
  --font-size-lg:   1.125rem;   /* 18px */
  --font-size-xl:   1.375rem;   /* 22px */
  --font-size-2xl:  1.75rem;    /* 28px */
  --font-size-3xl:  2.25rem;    /* 36px */
  --line-height:    1.6;

  /* Spacing scale */
  --space-xs:  0.25rem;   /* 4px */
  --space-sm:  0.5rem;    /* 8px */
  --space-md:  1rem;      /* 16px */
  --space-lg:  1.5rem;    /* 24px */
  --space-xl:  2rem;      /* 32px */
  --space-2xl: 3rem;      /* 48px */
  --space-3xl: 4rem;      /* 64px */

  /* Layout */
  --max-width:      680px;
  --border-radius:  8px;
  --border-radius-lg: 16px;
}

/* ------------------------------------------------------------
   Reset & Base
   ------------------------------------------------------------ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--colour-text);
  background-color: var(--colour-bg);
  min-height: 100vh;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--colour-primary);
  text-decoration: underline;
}

a:hover,
a:focus {
  color: var(--colour-primary-dark);
}

/* ------------------------------------------------------------
   Typography
   ------------------------------------------------------------ */
h1, h2, h3, h4 {
  font-family: var(--font-family);
  line-height: 1.2;
  color: var(--colour-text);
}

h1 { font-size: var(--font-size-2xl); }
h2 { font-size: var(--font-size-xl); }
h3 { font-size: var(--font-size-lg); }

p {
  margin-bottom: var(--space-md);
}

p:last-child {
  margin-bottom: 0;
}

/* ------------------------------------------------------------
   Layout utilities
   ------------------------------------------------------------ */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-md);
  padding-right: var(--space-md);
}

/* ------------------------------------------------------------
   Buttons
   ------------------------------------------------------------ */
.btn {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: var(--font-size-lg);
  font-weight: 600;
  line-height: 1;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: var(--border-radius);
  padding: var(--space-md) var(--space-xl);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;

  /* Make buttons easy to tap on mobile — minimum 44px touch target */
  min-height: 52px;
}

.btn:focus-visible {
  outline: 3px solid var(--colour-primary);
  outline-offset: 3px;
}

.btn-primary {
  background-color: var(--colour-primary);
  color: #ffffff;
  border-color: var(--colour-primary);
}

.btn-primary:hover,
.btn-primary:focus {
  background-color: var(--colour-primary-dark);
  border-color: var(--colour-primary-dark);
  color: #ffffff;
}

.btn-secondary {
  background-color: transparent;
  color: var(--colour-primary);
  border-color: var(--colour-primary);
}

.btn-secondary:hover,
.btn-secondary:focus {
  background-color: var(--colour-primary);
  color: #ffffff;
}

/* Full-width button modifier */
.btn-full {
  display: block;
  width: 100%;
}

/* ------------------------------------------------------------
   Site header
   ------------------------------------------------------------ */
.site-header {
  background-color: var(--colour-surface);
  border-bottom: 1px solid var(--colour-border);
  padding: var(--space-md) 0;
}

.site-header .container {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.site-header__name {
  font-family: var(--font-family);
  font-size: var(--font-size-lg);
  font-weight: normal;
  color: var(--colour-text-muted);
  letter-spacing: 0.03em;
}

/* Groups logo + title so they stay together when the admin header
   uses space-between to push the logout button to the right */
.site-header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Logo in the site header — mix-blend-mode:multiply makes the white
   logo background disappear into the white header, leaving only the marks */
.site-header__logo {
  height: 48px;
  width: auto;
  display: block;
  mix-blend-mode: multiply;
}

/* ------------------------------------------------------------
   Hero section (landing page)
   ------------------------------------------------------------ */
.hero {
  padding: var(--space-2xl) 0;
  text-align: center;
}

.hero__eyebrow {
  font-size: var(--font-size-sm);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--colour-primary);
  margin-bottom: var(--space-md);
}

.hero__title {
  font-size: var(--font-size-2xl);
  margin-bottom: var(--space-lg);
  color: var(--colour-text);
}

.hero__subtitle {
  font-size: var(--font-size-lg);
  color: var(--colour-text-muted);
  margin-bottom: var(--space-2xl);
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}

.hero__cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.hero__note {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
}

/* ------------------------------------------------------------
   Info cards (landing page "how it works" section)
   ------------------------------------------------------------ */
.info-section {
  padding: var(--space-2xl) 0;
  border-top: 1px solid var(--colour-border);
}

.info-section__title {
  font-size: var(--font-size-xl);
  text-align: center;
  margin-bottom: var(--space-xl);
}

.info-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.info-card {
  background-color: var(--colour-surface);
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-lg);
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
}

.info-card__icon {
  font-size: 1.75rem;
  flex-shrink: 0;
  line-height: 1;
}

.info-card__body {}

.info-card__heading {
  font-size: var(--font-size-base);
  font-weight: 700;
  margin-bottom: var(--space-xs);
}

.info-card__text {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
  margin-bottom: 0;
}

/* ------------------------------------------------------------
   Site footer
   ------------------------------------------------------------ */
.site-footer {
  padding: var(--space-xl) 0;
  border-top: 1px solid var(--colour-border);
  text-align: center;
}

.site-footer p {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
  margin-bottom: var(--space-xs);
}

/* ------------------------------------------------------------
   Form styles (used in add.html)
   ------------------------------------------------------------ */
.form-page {
  padding: var(--space-xl) 0 var(--space-3xl);
}

.form-page__title {
  font-size: var(--font-size-2xl);
  margin-bottom: var(--space-sm);
}

.form-page__intro {
  color: var(--colour-text-muted);
  margin-bottom: var(--space-xl);
}

.form-section {
  background-color: var(--colour-surface);
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.form-section__title {
  font-size: var(--font-size-lg);
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--colour-border);
}

.field {
  margin-bottom: var(--space-lg);
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 600;
  margin-bottom: var(--space-xs);
  color: var(--colour-text);
}

.field label .optional {
  font-weight: 400;
  color: var(--colour-text-muted);
  margin-left: var(--space-xs);
}

.field input[type="text"],
.field input[type="email"],
.field input[type="date"],
.field input[type="tel"],
.field select,
.field textarea {
  display: block;
  width: 100%;
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  color: var(--colour-text);
  background-color: var(--colour-surface);
  border: 2px solid var(--colour-border);
  border-radius: var(--border-radius);
  padding: var(--space-sm) var(--space-md);
  min-height: 48px;
  transition: border-color 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--colour-primary);
}

.field input.error,
.field select.error,
.field textarea.error {
  border-color: var(--colour-error);
}

.field__error {
  font-size: var(--font-size-sm);
  color: var(--colour-error);
  margin-top: var(--space-xs);
}

.field__hint {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
  margin-top: var(--space-xs);
}

/* Checkbox and radio fields */
.field--check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  cursor: pointer;
}

.field--check input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-height: unset;
  flex-shrink: 0;
  margin-top: 2px;
  accent-color: var(--colour-primary);
  cursor: pointer;
}

.field--check label {
  margin-bottom: 0;
  cursor: pointer;
  font-weight: 400;
}

/* Phone field — country code + number side by side */
.phone-group {
  display: flex;
  gap: var(--space-sm);
}

.phone-group select {
  width: 110px;
  flex-shrink: 0;
}

.phone-group input {
  flex: 1;
}

/* Short description line below a section heading */
.form-section__intro {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
  margin-top: calc(var(--space-sm) * -1);
  margin-bottom: var(--space-lg);
}

/* Two-column layout for paired fields (e.g. first name + last name) */
/* Mobile: stacked. Desktop: side by side — see media query at bottom */
.field-row {
  display: flex;
  flex-direction: column;
}

/* Sub-group inside a form section (e.g. Father, Mother) */
.field-group {
  margin-bottom: var(--space-lg);
}

.field-group:last-child {
  margin-bottom: 0;
}

.field-group__label {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--colour-text);
  margin-bottom: var(--space-sm);
}

/* Radio button group (e.g. Spouse / Partner toggle) */
.radio-fieldset {
  border: none;
  padding: 0;
  margin: 0 0 var(--space-lg);
}

.radio-fieldset__legend {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--colour-text);
  margin-bottom: var(--space-xs);
  padding: 0;
}

.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-lg);
}

.radio-option {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--font-size-base);
  cursor: pointer;
}

.radio-option input[type="radio"] {
  accent-color: var(--colour-primary);
  width: 20px;
  height: 20px;
  min-height: unset;
  cursor: pointer;
}

/* Individual child entry row */
.child-row {
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}

.child-row__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}

.child-row__label {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--colour-text);
}

.child-row__remove {
  background: none;
  border: 1px solid var(--colour-error);
  color: var(--colour-error);
  font-size: var(--font-size-sm);
  font-family: var(--font-sans);
  cursor: pointer;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--border-radius);
  min-height: unset;
  line-height: 1.4;
}

.child-row__remove:hover {
  background-color: #fdecea;
}

/* Photo preview thumbnail shown after a file is selected */
.photo-preview {
  display: block;
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--border-radius);
  border: 2px solid var(--colour-border);
  margin-top: var(--space-sm);
}

/* ------------------------------------------------------------
   Success and error messages
   ------------------------------------------------------------ */
.message {
  border-radius: var(--border-radius);
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-lg);
  font-size: var(--font-size-sm);
}

.message--success {
  background-color: #e8f5ed;
  border: 1px solid #a8d5b5;
  color: var(--colour-success);
}

.message--error {
  background-color: #fdecea;
  border: 1px solid #f5b7b1;
  color: var(--colour-error);
}

.message--warning {
  background-color: #fff8e6;
  border: 1px solid #f5d87a;
  color: #7a5c00;
}

/* ------------------------------------------------------------
   Admin page
   ------------------------------------------------------------ */
.admin-page {
  padding: var(--space-xl) 0 var(--space-3xl);
}

/* Header modifier — right-aligns the logout button */
.site-header--admin .container {
  justify-content: space-between;
}

/* Small button variant used in the admin header and table */
.btn-sm {
  font-size: var(--font-size-sm);
  padding: var(--space-xs) var(--space-md);
  min-height: 36px;
}

/* Stats bar — two equal cards */
.admin-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.admin-stat {
  background-color: var(--colour-surface);
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-md) var(--space-lg);
  text-align: center;
}

.admin-stat__value {
  font-size: var(--font-size-2xl);
  font-family: var(--font-family);
  font-weight: bold;
  color: var(--colour-primary);
  line-height: 1;
  margin-bottom: var(--space-xs);
}

.admin-stat__label {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
  margin-bottom: 0;
}

/* Section wrappers */
.admin-section {
  margin-bottom: var(--space-2xl);
}

.admin-section__title {
  font-size: var(--font-size-xl);
  margin-bottom: var(--space-sm);
}

.admin-section__intro {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
  margin-bottom: var(--space-md);
}

.admin-count {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
  margin-top: var(--space-sm);
}

/* People table — contained within the viewport so the scrollbar is always
   reachable without scrolling the full page */
.admin-table-wrap {
  max-height: 60vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius-lg);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  white-space: nowrap;
}

.admin-table th {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  background-color: var(--colour-bg);
  border-bottom: 2px solid var(--colour-border);
  font-weight: 700;
  color: var(--colour-text-muted);
  font-size: var(--font-size-sm);
}

.admin-table td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--colour-border);
  vertical-align: middle;
}

.admin-person-row {
  cursor: pointer;
}

.admin-person-row:hover {
  background-color: #fdf8f4;
}

.admin-person-row.is-expanded {
  background-color: #fdf0eb;
}

/* Photo thumbnail in the table */
.admin-table__photo {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--border-radius);
  border: 1px solid var(--colour-border);
  display: block;
}

/* Expand / collapse indicator */
.admin-table__expand {
  color: var(--colour-text-muted);
  font-size: var(--font-size-sm);
  user-select: none;
}

/* Deceased badge */
.admin-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px var(--space-xs);
  border-radius: var(--border-radius);
  vertical-align: middle;
  margin-left: var(--space-xs);
}

.admin-badge--deceased {
  background-color: #f0f0f0;
  color: var(--colour-text-muted);
}

.admin-badge--duplicate {
  background-color: #fff3cd;
  color: #856404;
}

/* Cross-branch checkbox label — inline with status dropdown */
.admin-rel-cross-branch-label {
  font-size: 0.75rem;
  color: var(--colour-text-muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  vertical-align: middle;
  margin-left: var(--space-xs);
  cursor: pointer;
}

/* Branch parent picker — inside the edit drawer */
.branch-parent__current {
  font-size: 0.875rem;
  margin-bottom: var(--space-xs);
  min-height: 1.4em;
}

.branch-parent__search {
  width: 100%;
  margin-bottom: var(--space-xs);
}

/* hint text below a field label */
.field__hint {
  font-size: 0.8rem;
  color: var(--colour-text-muted);
  margin: 0 0 var(--space-xs);
}

/* Relationship status dropdown inside expanded rows */
.admin-rel-status-select {
  font-size: 0.75rem;
  padding: 1px var(--space-xs);
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius);
  background: var(--colour-surface);
  cursor: pointer;
  vertical-align: middle;
}

/* Unlinked relationship item — row layout and link search form */
.unlinked-item__row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-xs);
}

.unlinked-item__sep {
  color: var(--colour-text-muted);
}

.link-search {
  margin-top: var(--space-xs);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  align-items: flex-start;
}

.link-search__input {
  flex: 1 1 200px;
  min-width: 0;
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius);
  font-size: 0.875rem;
}

.link-search__results {
  flex: 0 0 100%;
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius);
  background: var(--colour-surface);
  max-height: 200px;
  overflow-y: auto;
}

.link-search__results li + li {
  border-top: 1px solid var(--colour-border);
}

.link-search__suggestion {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.875rem;
  cursor: pointer;
  line-height: 1.4;
}

.link-search__suggestion:hover,
.link-search__suggestion:focus {
  background: var(--colour-bg);
  outline: none;
}

.link-search__no-results {
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.875rem;
  color: var(--colour-text-muted);
}

/* Truncate long place of birth values */
.admin-pob {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Inline generation edit — click-to-edit display */
.admin-gen-display {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 2px var(--space-xs);
  border-radius: var(--border-radius);
  border: 1px dashed transparent;
}

.admin-gen-display:hover {
  border-color: var(--colour-border);
  background-color: var(--colour-bg);
}

/* Edit mode: input + save/cancel buttons */
.admin-gen-edit {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.admin-gen-input {
  width: 56px;
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-sm);
  font-family: var(--font-sans);
  color: var(--colour-text);
  background-color: var(--colour-surface);
  border: 2px solid var(--colour-primary);
  border-radius: var(--border-radius);
  min-height: unset;
}

.admin-gen-input.error {
  border-color: var(--colour-error);
}

/* ------------------------------------------------------------
   Admin records editor — toolbar, completeness cues, edit drawer
   ------------------------------------------------------------ */

/* Search + filter toolbar above the table */
.admin-toolbar {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}

.admin-toolbar__search {
  flex: 1;
  min-width: 160px;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius);
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  background-color: var(--colour-surface);
  color: var(--colour-text);
}

.admin-toolbar__search:focus {
  outline: none;
  border-color: var(--colour-primary);
}

/* Active state for the "Incomplete only" toggle */
#filter-incomplete.is-active {
  background-color: var(--colour-primary);
  color: #ffffff;
  border-color: var(--colour-primary);
}

/* Amber "needs details" badge + row accent */
.admin-badge--incomplete {
  background-color: #fff3cd;
  color: #8a6100;
}

.admin-person-row.is-incomplete td:first-child {
  box-shadow: inset 3px 0 0 #e0a23a;
}

/* Edit button column */
.admin-edit-cell {
  text-align: right;
  white-space: nowrap;
}

/* ---- Edit drawer ---- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(26, 16, 8, 0.5);
  z-index: 90;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: 100;
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  background-color: var(--colour-bg);
  border-left: 1px solid var(--colour-border);
  box-shadow: -16px 0 50px rgba(0, 0, 0, 0.25);
}

.drawer__head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background-color: var(--colour-surface);
  border-bottom: 1px solid var(--colour-border);
}

.drawer__title {
  font-size: var(--font-size-lg);
  margin: 0;
}

.drawer__close {
  border: none;
  background: none;
  font-size: 1.7rem;
  line-height: 1;
  color: var(--colour-text-muted);
  cursor: pointer;
  padding: 0 var(--space-xs);
}

.drawer__close:hover,
.drawer__close:focus {
  color: var(--colour-text);
}

.drawer__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
}

.drawer__body .form-section {
  margin-bottom: var(--space-lg);
}

.drawer__error {
  background-color: #fdecea;
  color: var(--colour-error);
  border: 1px solid #f5c6c2;
  border-radius: var(--border-radius);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
  font-size: var(--font-size-sm);
}

.drawer__actions {
  display: flex;
  gap: var(--space-md);
}

.drawer__actions .btn {
  flex: 1;
}

/* Stop the page behind the drawer from scrolling */
body.drawer-open {
  overflow: hidden;
}

/* Gentle amber cue on a field still missing a value */
.field--needed > label,
.field--needed > label:first-child {
  color: #9a6b16;
}

.field--needed input,
.field--needed select,
.field--needed .drawer-phone-row input {
  border-color: #e0a23a;
  background-color: #fffaf0;
}

/* Phone code + number side by side (even on mobile) */
.drawer-phone-row {
  display: flex;
  gap: var(--space-sm);
}

.drawer-phone-row .drawer-phone-code {
  max-width: 84px;
}

/* Photo control inside the drawer */
.drawer-photo__label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 700;
  margin-bottom: var(--space-sm);
}

.drawer-photo {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.drawer-photo__img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--colour-border);
}

.drawer-photo__placeholder {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 0.7rem;
  color: var(--colour-text-muted);
  background-color: #f0e9e2;
  border: 1px solid var(--colour-border);
}

.drawer-photo__btn {
  margin-bottom: 0;
  cursor: pointer;
}

/* Save confirmation toast */
#admin-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background-color: var(--colour-text);
  color: #ffffff;
  padding: var(--space-sm) var(--space-lg);
  border-radius: 999px;
  font-size: var(--font-size-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 120;
}

#admin-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Expanded detail row */
.admin-detail-row td {
  padding: 0;
  border-bottom: 2px solid var(--colour-border);
  background-color: #fdf8f4;
}

.admin-detail-row__inner {
  padding: var(--space-md) var(--space-lg);
}

.admin-detail-row__title {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--colour-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-sm);
}

.admin-detail-empty {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
  margin: 0;
}

/* Relationship pills */
.admin-rel-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.admin-rel-item {
  background-color: var(--colour-surface);
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius);
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-sm);
}

.admin-rel-item__type {
  font-weight: 700;
  color: var(--colour-primary);
  text-transform: capitalize;
}

.admin-rel-linked {
  font-size: 0.7rem;
  color: var(--colour-success);
  font-weight: 600;
  margin-left: var(--space-xs);
}

.admin-rel-unlinked {
  font-size: 0.7rem;
  color: var(--colour-text-muted);
  margin-left: var(--space-xs);
}

/* Unlinked relationships list */
.unlinked-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
}

.unlinked-item {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--colour-border);
  font-size: var(--font-size-sm);
}

.unlinked-item:last-child {
  border-bottom: none;
}

.unlinked-item__type {
  font-weight: 600;
  color: var(--colour-primary);
  text-transform: capitalize;
}

.unlinked-item__name {
  color: var(--colour-text-muted);
}

/* Display ID code label — used in relationships panels and unlinked list */
.admin-display-id {
  font-size: 0.7rem;
  font-family: monospace;
  color: var(--colour-text-muted);
  background-color: var(--colour-surface);
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--colour-border);
  vertical-align: middle;
}

/* Required field indicator — the red * next to required labels */
.required-indicator {
  color: var(--colour-error);
  margin-left: 2px;
  font-weight: 700;
}

/* Disabled state for buttons — used during form submission */
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* Success panel — shown after a successful form submission */
.success-panel {
  text-align: center;
  padding: var(--space-xl) 0;
}

.success-panel__icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: var(--space-md);
}

.success-panel__title {
  font-size: var(--font-size-xl);
  margin-bottom: var(--space-sm);
}

.success-panel__body {
  color: var(--colour-text-muted);
  margin-bottom: var(--space-xl);
}

.success-panel__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.success-panel__share {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
  margin-top: var(--space-md);
}

/* ------------------------------------------------------------
   Utility classes
   ------------------------------------------------------------ */
.sr-only {
  /* Visually hidden but readable by screen readers */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-muted  { color: var(--colour-text-muted); }
.text-center { text-align: center; }
.mt-md       { margin-top: var(--space-md); }
.mt-lg       { margin-top: var(--space-lg); }
.mt-xl       { margin-top: var(--space-xl); }

/* ------------------------------------------------------------
   Desktop enhancements — 600px and above
   Mobile is the default above. These rules kick in on larger
   screens.
   ------------------------------------------------------------ */
@media (min-width: 600px) {
  h1 { font-size: var(--font-size-3xl); }

  .hero {
    padding: var(--space-3xl) 0;
  }

  .hero__title {
    font-size: var(--font-size-3xl);
  }

  .info-cards {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .info-card {
    flex: 1 1 calc(50% - var(--space-md) / 2);
  }

  /* Side-by-side name fields on wider screens */
  .field-row {
    flex-direction: row;
    gap: var(--space-md);
  }

  .field-row .field {
    flex: 1;
    margin-bottom: 0;
  }
}

@media (min-width: 800px) {
  .info-card {
    flex: 1;
  }
}

/* ------------------------------------------------------------
   Photo crop overlay
   Full-screen overlay shown after a photo is selected.
   The user drags the image to centre their face in the circle.
   ------------------------------------------------------------ */
#photo-crop-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #0d0d0d;
  overflow: hidden;
  /* touch-action:none stops the browser panning the page during drag */
  touch-action: none;
}

/* The photo itself — absolutely positioned and draggable */
#crop-img {
  position: absolute;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
}

#crop-img:active {
  cursor: grabbing;
}

/* Dark ring around the circle — box-shadow spreads to cover the whole screen */
.crop-mask {
  position: absolute;
  border-radius: 50%;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.68);
  pointer-events: none;
}

/* Thin white border around the circle viewport */
.crop-ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

/* Buttons and hint at the bottom of the overlay */
.crop-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 24px 36px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 60%, transparent);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.crop-hint {
  color: rgba(255, 255, 255, 0.72);
  font-size: var(--font-size-sm);
  text-align: center;
  margin: 0;
}

.crop-confirm-btn {
  width: 100%;
  max-width: 340px;
}

.crop-reselect-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.55);
  font-size: var(--font-size-sm);
  font-family: var(--font-sans);
  cursor: pointer;
  padding: 4px;
  text-decoration: underline;
}

.crop-reselect-btn:hover {
  color: rgba(255, 255, 255, 0.9);
}

/* Circular thumbnail shown in the form after a crop is confirmed */
.photo-preview--circle {
  border-radius: 50%;
  width: 120px;
  height: 120px;
  object-fit: cover;
}


/* ============================================================
   Potential duplicates panel
   ============================================================ */

.duplicate-pair {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--colour-border);
}

.duplicate-pair:last-of-type {
  border-bottom: none;
}

.duplicate-pair__records {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
  min-width: 0;
}

.duplicate-pair__record {
  flex: 1 1 180px;
  min-width: 0;
}

.duplicate-pair__name {
  font-weight: 600;
}

.duplicate-pair__meta {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
}

.duplicate-pair__vs {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--colour-text-muted);
  flex-shrink: 0;
}

.duplicate-pair__actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.duplicate-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

.duplicate-badge--strong {
  background: #fff3cd;
  color: #856404;
}

.duplicate-badge--possible {
  background: var(--colour-bg);
  color: var(--colour-text-muted);
  border: 1px solid var(--colour-border);
}


/* ============================================================
   Merge review modal
   ============================================================ */

.merge-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 16, 8, 0.6);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: var(--space-md);
}

.merge-modal {
  background: var(--colour-surface);
  border-radius: var(--border-radius-lg);
  width: 100%;
  max-width: 620px;
  margin: auto;
  display: flex;
  flex-direction: column;
}

.merge-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--colour-border);
  position: sticky;
  top: 0;
  background: var(--colour-surface);
  z-index: 1;
  border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
}

.merge-modal__title {
  font-size: var(--font-size-lg);
  margin: 0;
}

.merge-modal__body {
  padding: var(--space-lg);
  overflow-y: auto;
}

/* Section inside the modal body */
.merge-section {
  margin-bottom: var(--space-xl);
}

.merge-section__title {
  font-size: var(--font-size-base);
  font-weight: 700;
  margin-bottom: var(--space-xs);
}

.merge-section__desc {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
  margin-bottom: var(--space-md);
}

/* Survivor picker */
.merge-survivor-picker {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.merge-survivor-option {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: 2px solid var(--colour-border);
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: border-color 0.15s;
}

.merge-survivor-option:hover {
  border-color: var(--colour-primary);
}

.merge-survivor-option--selected {
  border-color: var(--colour-primary);
  background: #fdf3ee;
}

.merge-survivor-option input[type="radio"] {
  flex-shrink: 0;
  margin-top: 3px;
}

.merge-survivor-option__name {
  font-weight: 600;
}

.merge-survivor-option__meta {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
}

/* Field comparison rows */
.merge-fields {
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius);
  overflow: hidden;
}

.merge-field {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--colour-border);
}

.merge-field:last-child {
  border-bottom: none;
}

.merge-field__label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--colour-text-muted);
  margin-bottom: var(--space-xs);
}

.merge-field--match {
  opacity: 0.55;
}

.merge-field--conflict {
  background: #fff8f0;
}

.merge-conflict-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #a05c00;
  background: #ffe8cc;
  border-radius: 3px;
  padding: 1px 5px;
  vertical-align: middle;
  margin-left: 4px;
}

.merge-field__value {
  font-size: var(--font-size-sm);
}

.merge-field__choices {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
}

.merge-choice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--colour-border);
  border-radius: var(--border-radius);
  cursor: pointer;
  background: var(--colour-surface);
  transition: border-color 0.1s;
}

.merge-choice:hover {
  border-color: var(--colour-primary);
}

.merge-choice--selected {
  border-color: var(--colour-primary);
  background: #fdf3ee;
}

.merge-choice input[type="radio"] {
  flex-shrink: 0;
  margin-top: 3px;
}

.merge-choice__source {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--colour-text-muted);
}

.merge-choice__value {
  font-size: var(--font-size-sm);
}

/* Preview panel */
.merge-preview {
  background: var(--colour-bg);
  border-radius: var(--border-radius);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}

.merge-preview__title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--colour-text-muted);
  margin-bottom: var(--space-sm);
}

.merge-preview__id {
  font-size: var(--font-size-sm);
  color: var(--colour-text-muted);
  margin-bottom: var(--space-sm);
}

.merge-preview__row {
  display: flex;
  gap: var(--space-sm);
  font-size: var(--font-size-sm);
  padding: 2px 0;
}

.merge-preview__row--pending {
  color: #a05c00;
}

.merge-preview__key {
  flex-shrink: 0;
  width: 130px;
  color: var(--colour-text-muted);
}

.merge-preview__val--pending {
  font-style: italic;
}

/* Photo thumbnail inside merge choices */
.merge-photo-thumb {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: var(--border-radius);
}

/* Actions row at the bottom of the modal */
.merge-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--colour-border);
}
