/* ============================================================
 * Henikoff Family Tree — Design System
 * Heritage palette · classical serif headings · refined components
 * ============================================================ */

:root {
  /* Palette — warm parchment + deep forest + brass accents */
  --bg-page-start: #fdfaf0;
  --bg-page-end: #f3ead2;
  --surface: #fffdf6;
  --surface-alt: #faf3df;
  --surface-hover: #f5edd2;
  --primary: #1f4429;
  --primary-hover: #163018;
  --primary-light: #2c5530;
  --primary-soft: #d9e3d7;
  --accent: #a07a2f;
  --accent-soft: #f0e1ba;
  --text: #2a2a26;
  --text-muted: #6e6757;
  --text-subtle: #8e8773;
  --border: #e6dec5;
  --border-strong: #d4c89e;
  --danger: #a8392d;
  --danger-soft: #f2dad7;

  /* Layered shadows for warmth and depth */
  --shadow-sm: 0 1px 2px rgba(58,46,16,0.06), 0 2px 4px rgba(58,46,16,0.04);
  --shadow-md: 0 2px 6px rgba(58,46,16,0.08), 0 8px 18px rgba(58,46,16,0.05);
  --shadow-lg: 0 4px 12px rgba(58,46,16,0.10), 0 18px 40px rgba(58,46,16,0.10);

  /* Type */
  --font-display: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

  /* Geometry */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Motion */
  --t-fast: 130ms cubic-bezier(0.2, 0, 0.2, 1);
  --t-med: 220ms cubic-bezier(0.2, 0, 0.2, 1);
}

* { box-sizing: border-box; }

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-page-start) 0%, var(--bg-page-end) 100%);
  background-attachment: fixed;
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--text);
  font-weight: 600;
  letter-spacing: 0.005em;
  margin-top: 0;
}
h1 { font-size: 2.1rem; line-height: 1.15; }
h2 { font-size: 1.4rem; line-height: 1.25; }
h3 { font-size: 1.1rem; line-height: 1.3; }

a {
  color: var(--primary);
  transition: color var(--t-fast);
}
a:hover { color: var(--primary-hover); }

.muted { color: var(--text-muted); font-size: 0.92rem; }
.small { font-size: 0.85rem; }
.lead { font-size: 1.08rem; color: var(--text-muted); }

/* ----- Header ----- */

.site-header {
  background:
    linear-gradient(135deg, #1f4429 0%, #2c5530 55%, #2a4d2c 100%);
  color: #fff;
  box-shadow: 0 2px 14px rgba(31,68,41,0.18);
  position: relative;
}
.site-header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, transparent 5%, var(--accent) 50%, transparent 95%);
  opacity: 0.5;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  font-family: var(--font-display);
  font-weight: 600;
  color: #fff;
  font-size: 1.4rem;
  letter-spacing: 0.015em;
  text-decoration: none;
  text-shadow: 0 1px 2px rgba(0,0,0,0.20);
}
.version-pill {
  display: inline-block;
  margin-left: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.20);
  color: rgba(255, 255, 255, 0.78);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  vertical-align: 3px;
}
.site-header nav {
  display: flex;
  gap: 24px;
  align-items: center;
}
.site-header nav a,
.site-header .user {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: color var(--t-fast);
}
.site-header nav a:hover { color: #fff; }

/* ----- Main ----- */

.site-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 28px 56px;
}

/* ----- Flashes ----- */

.flashes { list-style: none; padding: 0; margin: 0 0 20px; }
.flash {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  font-size: 0.95rem;
  border: 1px solid transparent;
  animation: slide-down 0.3s var(--t-fast);
  box-shadow: var(--shadow-sm);
}
.flash-error   { background: var(--danger-soft); color: #7a1f1f; border-color: #e8c0bb; }
.flash-success { background: #e3f0dc; color: #1f5a1f; border-color: #c5dfbb; }
.flash-info    { background: #dfe9f2; color: #1f3a7a; border-color: #c0d0df; }

@keyframes slide-down {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ----- Cards ----- */

.card,
.auth-card,
.placeholder-card {
  background: var(--surface);
  padding: 26px 30px;
  border-radius: var(--radius-lg);
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: box-shadow var(--t-med);
}

.auth-card,
.placeholder-card {
  max-width: 460px;
  margin: 60px auto;
  padding: 36px 40px;
}
.placeholder-card { max-width: 720px; padding: 44px 48px; }
.auth-card h1,
.placeholder-card h1 {
  font-size: 1.9rem;
  color: var(--primary);
  margin: 0 0 12px;
}

.card h2 {
  font-size: 1.3rem;
  color: var(--primary);
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.01em;
}
.card h3 {
  font-size: 1rem;
  color: var(--text);
  margin: 22px 0 10px;
  font-weight: 600;
  font-family: var(--font-body);
}
.card.placeholder { opacity: 0.72; }

/* ----- Page header ----- */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin: 6px 0 26px;
}
.page-header h1 {
  margin: 0;
  color: var(--primary);
  font-size: 2.2rem;
  line-height: 1.1;
}
.page-header .lead {
  margin: 8px 0 0;
  font-size: 1.1rem;
  color: var(--text-muted);
  font-style: italic;
  font-family: var(--font-display);
}
.page-header .actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
.person-header { align-items: center; }
.person-id-block {
  display: flex;
  gap: 22px;
  align-items: center;
}

/* ----- Buttons ----- */

.btn {
  display: inline-block;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 8px 18px;
  border-radius: var(--radius-md);
  text-decoration: none;
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
  box-shadow: var(--shadow-sm);
  line-height: 1.4;
}
.btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(180deg, #2c5530 0%, #1f4429 100%);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #2a4d2c 0%, #163018 100%);
  border-color: var(--primary-hover);
  color: #fff;
}

.btn-danger {
  background: linear-gradient(180deg, #b8483c 0%, #9c2c20 100%);
  color: #fff;
  border-color: #9c2c20;
}
.btn-danger:hover {
  background: linear-gradient(180deg, #a8392d 0%, #82211a 100%);
  border-color: #82211a;
  color: #fff;
}

.btn-link {
  background: none;
  border: 0;
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  transition: color var(--t-fast);
}
.btn-link:hover { color: var(--accent); }
.btn-link-danger { color: var(--danger); }
.btn-link-danger:hover { color: #82211a; }
.btn-link:disabled {
  color: var(--accent);
  cursor: default;
  text-decoration: none;
  opacity: 0.85;
}

/* ----- Filter bar ----- */

.filter-bar {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 22px;
  flex-wrap: wrap;
  background: var(--surface);
  padding: 14px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.filter-bar input[type="search"] {
  flex: 1;
  min-width: 220px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  background: #fff;
  font-family: var(--font-body);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.filter-bar input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31,68,41,0.10);
}
.filter-bar .checkbox {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 0.92rem;
  color: var(--text-muted);
}
.filter-bar button {
  background: var(--primary);
  color: #fff;
  border: 0;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-body);
  transition: background var(--t-fast);
}
.filter-bar button:hover { background: var(--primary-hover); }

/* ----- People & admin tables ----- */

.people-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}
.people-table th,
.people-table td {
  text-align: left;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
}
.people-table th {
  background: var(--surface-alt);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.10em;
}
.people-table tr:last-child td { border-bottom: 0; }
.people-table tbody tr {
  transition: background var(--t-fast);
}
.people-table tbody tr:hover td { background: var(--surface-hover); }
.people-table .row-deleted { opacity: 0.55; }
.people-table .dates { white-space: nowrap; }
.people-table .name-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}
.row-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.row-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: var(--apx, 50%) var(--apy, 50%);
  transform: scale(var(--apz, 1));
  transform-origin: var(--apx, 50%) var(--apy, 50%);
}
.row-avatar-placeholder {
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.people-table a {
  font-weight: 500;
  text-decoration: none;
  color: var(--text);
}
.people-table a:hover { color: var(--primary); }

/* ----- Badges ----- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge-review { background: var(--accent-soft); color: #7a5a16; }
.badge-deleted { background: #e9ecef; color: #6c757d; }

/* ----- Banners ----- */

.banner {
  padding: 14px 20px;
  border-radius: var(--radius-md);
  margin-bottom: 22px;
  border: 1px solid;
  font-size: 0.95rem;
  box-shadow: var(--shadow-sm);
}
.banner-warn {
  background: var(--accent-soft);
  border-color: #d8c180;
  color: #7a5a16;
}

/* ----- Auth forms ----- */

.auth-card form label {
  display: block;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.auth-card form label.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.93rem;
  font-weight: 400;
}
.auth-card input[type="text"],
.auth-card input[type="email"],
.auth-card input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-family: var(--font-body);
  background: #fff;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.auth-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31,68,41,0.12);
}
.auth-card button {
  background: linear-gradient(180deg, #2c5530 0%, #1f4429 100%);
  color: #fff;
  border: 0;
  padding: 12px 22px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  width: 100%;
  cursor: pointer;
  font-family: var(--font-body);
  letter-spacing: 0.02em;
  transition: all var(--t-fast);
  box-shadow: var(--shadow-sm);
}
.auth-card button:hover {
  background: linear-gradient(180deg, #2a4d2c 0%, #163018 100%);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.auth-card p {
  margin: 18px 0 0;
  font-size: 0.92rem;
  color: var(--text-muted);
}

/* ----- Person form ----- */

.person-form fieldset {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px 28px;
  margin: 0 0 18px;
  box-shadow: var(--shadow-sm);
}
.person-form legend {
  padding: 0 12px;
  color: var(--primary);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.2rem;
  letter-spacing: 0.01em;
}
.person-form .grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 22px;
}
.person-form label {
  display: block;
  font-size: 0.84rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.person-form label.full { grid-column: 1 / -1; }
.person-form input[type="text"],
.person-form input[type="url"],
.person-form textarea,
.person-form select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-family: var(--font-body);
  background: #fff;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.person-form input:focus,
.person-form textarea:focus,
.person-form select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31,68,41,0.12);
}
.person-form label.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text);
}
.person-form .deceased-toggle {
  margin: 14px 0;
  padding: 10px 16px;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  display: inline-flex;
  border: 1px solid var(--border);
}

.form-actions {
  display: flex;
  gap: 18px;
  align-items: center;
  margin-top: 18px;
}

/* ----- Vitals dl ----- */

.vitals {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 12px 28px;
  margin: 0;
}
.vitals dt {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.vitals dd { margin: 0; }

/* ----- Bio ----- */

.bio {
  white-space: pre-wrap;
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.7;
  color: var(--text);
}

/* ----- Sources ----- */

.sources {
  list-style: none;
  padding: 0;
  margin: 0;
}
.sources li {
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.55;
}
.sources li:last-child { border-bottom: 0; }

.add-source {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}
.add-source h3 { grid-column: 1 / -1; margin: 0; }
.add-source input {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-family: var(--font-body);
  background: #fff;
}
.add-source input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31,68,41,0.12);
}
.add-source button {
  background: var(--primary);
  color: #fff;
  border: 0;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  font-family: var(--font-body);
  transition: background var(--t-fast);
}
.add-source button:hover { background: var(--primary-hover); }

/* ----- Hourglass family-at-a-glance ----- */

.hourglass .hg-row {
  margin-bottom: 18px;
  text-align: center;
}
.hourglass h4 {
  margin: 0 0 10px;
  font-family: var(--font-body);
  font-size: 0.72rem;
  color: var(--text-subtle);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}
.hourglass .hg-people {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}
.hourglass .hg-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text);
  font-size: 0.92rem;
  min-width: 148px;
  line-height: 1.35;
  transition: all var(--t-fast);
  box-shadow: var(--shadow-sm);
}
.hourglass .hg-box:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.hourglass .hg-name {
  font-weight: 600;
  font-family: var(--font-display);
  font-size: 1.08rem;
  letter-spacing: 0.005em;
}
.hourglass .hg-self {
  background: linear-gradient(180deg, #2c5530 0%, #1f4429 100%);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
  min-width: 210px;
  padding: 18px 28px;
  box-shadow: var(--shadow-md);
  transform: scale(1.06);
}
.hourglass .hg-self .hg-name { font-size: 1.28rem; }
.hourglass .hg-self .muted { color: rgba(255,255,255,0.84); }
.hourglass .hg-spouse {
  background: linear-gradient(180deg, #fbf3da 0%, #f5e3b3 100%);
  border-color: #d8be7a;
  color: var(--text);
}
.hourglass .hg-spouse .muted { color: #876a30; }
.hourglass .hg-focus { margin: 26px 0; }

.hg-thumb {
  display: inline-block;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  margin-bottom: 6px;
  background: var(--surface-alt);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(58,46,16,0.15);
  flex-shrink: 0;
}
.hg-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: var(--apx, 50%) var(--apy, 50%);
  transform: scale(var(--apz, 1));
  transform-origin: var(--apx, 50%) var(--apy, 50%);
}
.hg-self .hg-thumb {
  width: 68px;
  height: 68px;
  border-color: rgba(255,255,255,0.95);
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

/* ----- Tree (D3) container ----- */

#tree-container {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 24px;
  min-height: 440px;
  overflow: auto;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
#tree-container svg { display: block; }
#tree-container a { text-decoration: none; }
#tree-container a:hover text { fill: var(--primary); font-weight: 600; }

.tree-controls {
  display: flex;
  gap: 14px;
  align-items: center;
}
/* Layout switcher */
.layout-switch {
  display: flex;
  gap: 10px;
  margin-top: 26px;
  padding: 16px 18px;
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}
.layout-switch .btn {
  font-size: 0.88rem;
  padding: 7px 16px;
}

/* Outline list view */
.tree-list-container {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 24px 30px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.tree-list,
.tree-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.tree-list ul {
  padding-left: 22px;
  margin-left: 8px;
  border-left: 1px dashed var(--border-strong);
}
.tree-list li {
  padding: 5px 0 5px 10px;
  position: relative;
  font-size: 0.96rem;
}
.tree-list > li {
  font-size: 1.05rem;
  font-weight: 500;
}
.tree-list li::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 14px;
  width: 18px;
  height: 1px;
  background: var(--border-strong);
}
.tree-list > li::before { display: none; }
.tree-list a {
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
}
.tree-list a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.tree-controls select {
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: #fff;
  font-size: 0.93rem;
  font-family: var(--font-body);
  margin-left: 8px;
  transition: border-color var(--t-fast);
}
.tree-controls select:focus {
  outline: none;
  border-color: var(--primary);
}

/* ----- Profile photo ----- */

.profile-photo {
  display: inline-block;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface-alt);
  border: 3px solid #fff;
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
}
.profile-photo img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: var(--apx, 50%) var(--apy, 50%);
  transform: scale(var(--apz, 1));
  transform-origin: var(--apx, 50%) var(--apy, 50%);
}

/* ----- Profile photo editor ----- */

.profile-editor-form .form-actions { margin-top: 16px; }

.profile-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 24px;
  align-items: start;
  margin-top: 12px;
}
@media (max-width: 760px) {
  .profile-editor { grid-template-columns: 1fr; }
}

.cropper {
  position: relative;
  max-width: 560px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}
.cropper img {
  display: block;
  width: 100%;
  height: auto;
  -webkit-user-drag: none;
}

/* Circular crop overlay — width set in JS from image aspect ratio & zoom. */
.crop-marker {
  position: absolute;
  aspect-ratio: 1 / 1;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow:
    0 0 0 2px rgba(0,0,0,0.6),
    0 0 0 9999px rgba(0,0,0,0.45);
  pointer-events: none;
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  max-width: 560px;
}
.zoom-control input[type="range"] {
  flex: 1;
}

.profile-previews h3 {
  margin: 0 0 12px 0;
  font-size: 1rem;
}
.preview-cluster {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.preview-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.preview-item p { margin: 0; }

/* ----- Photo gallery ----- */

.photo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.photo-thumb {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
}
.photo-thumb a { display: block; }
.photo-thumb img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  transition: all var(--t-med);
}
.photo-thumb img:hover {
  border-color: var(--accent);
  transform: translateY(-2px) scale(1.02);
  box-shadow: var(--shadow-md);
}
.thumb-caption {
  font-size: 0.82rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.photo-thumb .btn-link { font-size: 0.78rem; }
.photo-thumb-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  font-size: 0.78rem;
}
.profile-badge {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.78rem;
}

.photo-upload {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.photo-upload h3 { width: 100%; margin: 0; }
.photo-upload input[type="text"] {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  flex: 1;
  min-width: 220px;
  font-family: var(--font-body);
  background: #fff;
}
.photo-upload input[type="file"] { font-size: 0.9rem; }
.photo-upload button {
  background: var(--primary);
  color: #fff;
  border: 0;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 500;
  transition: background var(--t-fast);
}
.photo-upload button:hover { background: var(--primary-hover); }
.also-details { width: 100%; }
.also-in-photo {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 4px 12px;
  margin-top: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.also-in-photo label {
  display: flex;
  gap: 6px;
  font-size: 0.85rem;
  align-items: center;
}

.photo-large {
  text-align: center;
  margin-bottom: 22px;
  position: relative;
}
.photo-large img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 6px solid #fff;
  vertical-align: middle;
}

.photo-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 54px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,253,246,0.88);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  font-size: 2.2rem;
  color: var(--primary);
  text-decoration: none;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(4px);
  transition: all var(--t-fast);
  font-family: var(--font-display);
  line-height: 1;
  padding-bottom: 4px;
  z-index: 5;
}
.photo-arrow:hover {
  background: var(--surface);
  color: var(--primary-hover);
  transform: translateY(-50%) scale(1.08);
  box-shadow: var(--shadow-lg);
}
.photo-arrow-prev { left: 16px; }
.photo-arrow-next { right: 16px; }

.photo-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.photo-nav-btn {
  display: inline-block;
  padding: 7px 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--primary);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: all var(--t-fast);
}
.photo-nav-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateY(-1px);
}
.photo-nav-btn.disabled {
  color: var(--text-subtle);
  background: transparent;
  border-color: var(--border);
  cursor: default;
  opacity: 0.6;
}
.photo-nav-pos {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--text-muted);
  font-style: italic;
}

.photo-edit-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 2fr;
  gap: 24px;
  align-items: start;
}
.photo-edit-preview {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  position: sticky;
  top: 16px;
}
.photo-edit-preview img {
  width: 100%;
  border-radius: var(--radius-sm);
  display: block;
}
.tag-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 4px 14px;
  max-height: 420px;
  overflow-y: auto;
  padding: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.tag-pick {
  display: flex;
  gap: 8px;
  font-size: 0.92rem;
  align-items: center;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: background var(--t-fast);
  cursor: pointer;
}
.tag-pick:hover { background: var(--surface-hover); }
.tag-pick em { color: var(--text-muted); font-style: italic; }

@media (max-width: 720px) {
  .photo-edit-layout { grid-template-columns: 1fr; }
  .photo-edit-preview { position: static; }
}

/* ----- Memories & comments ----- */

.memory {
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
}
.memory:first-child { padding-top: 4px; }
.memory:last-of-type { border-bottom: 0; }
.memory-title {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--primary);
}
.memory-body {
  white-space: pre-wrap;
  margin: 0 0 10px;
  line-height: 1.7;
  font-size: 1.02rem;
}
.memory-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}
.memory-photos img {
  width: 110px;
  height: 110px;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  transition: all var(--t-fast);
  box-shadow: var(--shadow-sm);
}
.memory-photos img:hover {
  border-color: var(--accent);
  transform: scale(1.04);
}
.memory-meta { margin: 8px 0 0; }

.memory-form,
.comment-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}
.memory-form h3 { margin: 0; }
.memory-form input[type="text"],
.memory-form textarea,
.comment-form textarea {
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.95rem;
  background: #fff;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.memory-form input:focus,
.memory-form textarea:focus,
.comment-form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31,68,41,0.12);
}
.memory-form textarea,
.comment-form textarea { resize: vertical; }
.memory-form button,
.comment-form button {
  align-self: flex-start;
  background: var(--primary);
  color: #fff;
  border: 0;
  padding: 10px 22px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.95rem;
  font-family: var(--font-body);
  font-weight: 500;
  transition: background var(--t-fast);
}
.memory-form button:hover,
.comment-form button:hover { background: var(--primary-hover); }

.photo-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  max-height: 220px;
  overflow-y: auto;
  padding: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.photo-pick { position: relative; cursor: pointer; }
.photo-pick img {
  width: 74px;
  height: 74px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  display: block;
  transition: border-color var(--t-fast);
}
.photo-pick input { position: absolute; top: 4px; left: 4px; }
.photo-pick:has(input:checked) img {
  border-color: var(--primary);
}

.comment-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.comment-list li {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.comment-list li:last-child { border-bottom: 0; }
.comment-body { margin: 0; white-space: pre-wrap; line-height: 1.65; }

/* ----- Relationships ----- */

.relations {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
}
.relations li {
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.55;
}
.relations li:last-child { border-bottom: 0; }
.relations a {
  text-decoration: none;
  font-weight: 500;
  color: var(--text);
  transition: color var(--t-fast);
}
.relations a:hover { color: var(--primary); }

.add-relation {
  display: flex;
  gap: 10px;
  margin: 12px 0 24px;
  flex-wrap: wrap;
  align-items: center;
}
.add-relation select,
.add-relation input[type="text"] {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  background: #fff;
  font-family: var(--font-body);
  transition: border-color var(--t-fast);
}
.add-relation select:focus,
.add-relation input:focus {
  outline: none;
  border-color: var(--primary);
}
.add-relation select[name$="_id"] {
  min-width: 240px;
  flex: 1;
}
.add-relation button {
  background: var(--primary);
  color: #fff;
  border: 0;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 500;
  transition: background var(--t-fast);
}
.add-relation button:hover { background: var(--primary-hover); }

/* ----- Empty state ----- */

.empty {
  padding: 60px 28px;
  text-align: center;
  background: var(--surface);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 1.05rem;
  border: 1px dashed var(--border-strong);
  font-family: var(--font-display);
  font-style: italic;
}

/* ----- Pager ----- */

.pager {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  justify-content: center;
}

/* ----- Inline confirm popover ----- */

.confirm-form {
  position: relative;
  display: inline-block;
  vertical-align: middle;
  margin: 0;
}
.confirm-popover {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 16px 18px;
  min-width: 260px;
  max-width: 340px;
  z-index: 1000;
  text-align: left;
  white-space: normal;
  animation: pop-in 0.18s var(--t-fast);
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.confirm-popover::before {
  content: "";
  position: absolute;
  top: -7px;
  right: 18px;
  width: 12px;
  height: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
  border-left: 1px solid var(--border-strong);
  transform: rotate(45deg);
}
.confirm-popover.confirm-above::before {
  top: auto;
  bottom: -7px;
  border-top: 0;
  border-left: 0;
  border-bottom: 1px solid var(--border-strong);
  border-right: 1px solid var(--border-strong);
}
.confirm-msg {
  margin: 0 0 14px;
  font-size: 0.94rem;
  color: var(--text);
  line-height: 1.55;
}
.confirm-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.confirm-popover .btn {
  padding: 6px 14px;
  font-size: 0.88rem;
}

/* ----- Searchable combobox & checkbox filter ----- */

.searchable-select {
  position: relative;
  min-width: 260px;
  flex: 1;
}
.searchable-select .ss-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: #fff;
  font-family: var(--font-body);
  font-size: 0.92rem;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.searchable-select .ss-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31,68,41,0.12);
}
.ss-options {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 300px;
  overflow-y: auto;
  z-index: 200;
  animation: pop-in 0.15s var(--t-fast);
}
.ss-option {
  padding: 9px 14px;
  cursor: pointer;
  font-size: 0.93rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--t-fast), color var(--t-fast);
}
.ss-option:last-child { border-bottom: 0; }
.ss-option:hover {
  background: var(--surface-hover);
  color: var(--primary);
}
.ss-option-add {
  background: var(--surface-alt);
  color: var(--accent);
  font-weight: 500;
  border-top: 1px solid var(--border-strong);
  font-family: var(--font-display);
  font-style: italic;
}
.ss-option-add:hover {
  background: var(--accent-soft);
  color: var(--text);
}
.ss-add-name { font-style: normal; font-weight: 600; }
.ss-option .muted { font-size: 0.85rem; }
.ss-options.ss-no-matches::after {
  content: "No matches";
  display: block;
  padding: 16px 14px;
  color: var(--text-muted);
  font-style: italic;
  font-family: var(--font-display);
  text-align: center;
}

.check-filter {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: #fff;
  font-family: var(--font-body);
  font-size: 0.92rem;
  margin-bottom: 10px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.check-filter:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31,68,41,0.12);
}

/* ----- Sortable tables ----- */

.sortable th[data-sort] {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 28px;
  transition: background var(--t-fast);
}
.sortable th[data-sort]:hover {
  background: var(--surface-hover);
}
.sortable th[data-sort]::after {
  content: "↕";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.72rem;
  color: var(--text-subtle);
  opacity: 0.5;
}
.sortable th.sort-asc::after { content: "▲"; opacity: 1; color: var(--primary); }
.sortable th.sort-desc::after { content: "▼"; opacity: 1; color: var(--primary); }

/* ----- Responsive ----- */

@media (max-width: 720px) {
  .site-main { padding: 22px 18px 36px; }
  .header-inner { padding: 14px 18px; flex-wrap: wrap; gap: 10px; }
  .site-header nav { gap: 14px; font-size: 0.88rem; }
  .person-form .grid { grid-template-columns: 1fr; }
  .add-source { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar input[type="search"] { width: 100%; }
  .page-header { flex-direction: column; }
  .person-id-block { flex-direction: column; text-align: center; }
  .hourglass .hg-self { transform: scale(1); }
  .photo-gallery { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  h1 { font-size: 1.8rem; }
  h2 { font-size: 1.25rem; }
}
