:root {
  /* core palette */
  --bg: #E8E9EB;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #242424;
  --text-strong: #111111;
  --text-muted: #374151;

  /* borders */
  --border-strong: #000000;
  --border: rgba(0, 0, 0, 0.25);
  --border-soft: #e5e7eb;

  /* accent */
  --accent: #38bdf8;
  --accent-soft: #eef2ff;

  /* typography */
  --font-sans: 'Inter', system-ui, -apple-system, "Segoe UI", Arial, Helvetica, sans-serif;

  /* sizing */
  --radius-xs: 2px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* spacing */
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;

  /* shadows */
  --shadow-1: 0 2px 6px rgba(0, 0, 0, 0.08);

  /* nav (aliases so you can keep your naming) */
  --nav-bg: var(--bg);
  --nav-fg: var(--text-strong);
  --nav-fg-dim: #cbd5e1;
  --nav-accent: var(--accent);

  /* viewer/tag styling */
  --letterbox: #000;

  /* settings card */
  --card-bg: var(--surface);
  --card-shadow: var(--shadow-1);

  /* table */
  --table-bg: var(--surface);
  --table-head-bg: var(--surface-2);
  --table-row-alt: var(--surface-2);
  --table-hover: var(--accent-soft);
  --table-border: var(--border-soft);

  /* svg */
  --svg-border: #333;
  --svg-bg: #f5f5f5;
}

* { box-sizing: border-box; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: #dc2626;
  color: #fff;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  box-shadow: var(--shadow-1);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 9999;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.site-nav {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--nav-bg);
  border-bottom: 2px solid var(--accent);
  display: flex;
  justify-content: center;
}

.site-nav .nav-inner {
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: center; /* center the menu */
}

.menu {
  display: flex;
  justify-content: center;
  list-style: none;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
}

.menu li {
  display: flex;
  align-items: center;
}

.menu li form { margin: 0; }

/* shared styles for links + logout button */
.menu a,
.menu-button-link {
  color: var(--nav-fg);
  text-decoration: none;
  font-weight: 700;
  font-size: inherit;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  display: inline-block;
}

/* make button look like a link */
.menu-button-link {
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
}

/* shared hover/focus behavior */
.menu a:hover,
.menu a:focus,
.menu-button-link:hover,
.menu-button-link:focus {
  color: var(--accent);
  outline: none;
}

/* divider between groups */
.menu .divider {
  width: 1px;
  background: var(--border);
  margin: 0 var(--space-3);
}

@media (max-width: 700px) {
  .site-nav .nav-inner {
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .menu {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
}

body {
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: 16.5pt;
  color: var(--text);
}

header h1 {
  text-align: center;
  margin: 0.5rem 0;
}

.viewer {
  position: relative;
  height: 75vh;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* The wrapper shrink-wraps to the rendered image size */
.image-wrap {
  position: relative;
  z-index: 1;
  display: inline-block; /* shrink to content (the img) */
  max-height: 100%;
}

/* The image keeps your letterbox behavior */
.image-wrap img {
  display: block; /* remove inline-gap */
  max-width: 100%;
  max-height: 75vh; /* matches .viewer height cap */
  object-fit: contain;
  border-radius: var(--radius-md);
  background: var(--letterbox); /* letterbox color inside image box */
  border: 2px solid var(--surface-2);
}

/* The overlay sits exactly on top of the image area */
#tagLayer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

/* Optional: how each tag box looks */
.tag-box {
  position: absolute;
  border: 1px solid transparent;
  box-sizing: border-box;
  border-radius: var(--radius-xs);
}

.tag-box span {
  position: absolute;
  top: -3em; /* position label above box */
  left: 0;
  background: rgba(255, 255, 255, 0.85);
  color: #000000;
  font-size: 0.9rem;
  padding: 1px 4px;
  border-radius: var(--radius-xs);
  pointer-events: none;
  white-space: nowrap;
}

#photoDescription {
  margin-top: var(--space-2);
  font-size: 1.5rem;
  color: var(--text);
  text-align: center;
  font-weight: bold;
  letter-spacing: 0.6px;
}

.info-panel #photoDescription {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  text-align: left;
  font-weight: normal;
  letter-spacing: normal;
}

.btn.arrow {
  font-size: 1.6rem;
  width: 71px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-md);
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  transition: background 0.15s, opacity 0.15s, transform 0.1s, box-shadow 0.15s;
}

.btn.arrow:hover { box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
.btn.arrow:active { transform: scale(0.94); box-shadow: none; }

.settings-container {
  max-width: 400px;
  margin: 2rem auto;
  padding: 1.2rem 1.5rem;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  text-align: center;
  font-family: var(--font-sans);
}

.settings-container h3 {
  margin-bottom: var(--space-4);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text-strong); 
}

.settings-grid {
  display: grid;
  gap: 0.8rem;
}

.settings-grid label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--text);
}

.settings-grid select,
.settings-grid input[type="checkbox"] {
  width: auto;
  min-width: 160px;
  flex-shrink: 0;
}

select {
  padding: 0.3rem;
  border: 1px solid #ccc;
  border-radius: var(--radius-sm);
  background: #fff;
}

/* Family Member Table */
#memberTable {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  background-color: var(--table-bg);
}

/* Header */
#memberTable thead th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-weight: 600;
  border-bottom: 2px solid var(--table-border);
  background-color: var(--table-head-bg);
  white-space: nowrap;
}

/* Body cells */
#memberTable tbody td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--table-border);
}

/* Center short/status columns: Birth, Death, Gender, Alive */
#memberTable thead th:nth-child(4),
#memberTable thead th:nth-child(5),
#memberTable thead th:nth-child(6),
#memberTable thead th:nth-child(7),
#memberTable tbody td:nth-child(4),
#memberTable tbody td:nth-child(5),
#memberTable tbody td:nth-child(6),
#memberTable tbody td:nth-child(7) {
  text-align: center;
}

/* Zebra striping */
#memberTable tbody tr:nth-child(even) {
  background-color: var(--table-row-alt);
}

/* Hover highlight */
#memberTable tbody tr:hover {
  background-color: var(--accent-soft);
}

.date-cell { white-space: nowrap; }

/* Sortable headers */
.th-sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.1s;
}
.th-sortable:hover { color: var(--accent); }
.th-sort-active { color: var(--accent); }
.sort-indicator { font-size: 0.7em; margin-left: 0.2rem; opacity: 0.8; }

/* Search bar */
.table-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}
input.table-search:not([type="submit"]):not([type="button"]):not([type="reset"]) {
  border-color: var(--border-strong);
}
.table-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

svg {
  border: 2px solid var(--svg-border);
  background: var(--svg-bg);
}

#familyTree {
  display: block;
  width: 100%;
  height: 78vh;
  border-radius: var(--radius-lg);
  margin-top: 1rem;
}

/* ── Dark theme ──────────────────────────────────────────────────────── */
:root[data-theme="indigo-flare"]{
  /* base surfaces */
  --bg: #222226;                  /* dark gray */
  --surface: #2e2e33;             /* panel gray */
  --surface-2: #3a3a40;           /* elevated gray */

  /* text */
  --text: #f0f0f2;
  --text-strong: #ffffff;
  --text-muted: rgba(240,240,242,0.6);

  /* borders */
  --border-strong: rgba(255,255,255,0.18);
  --border: rgba(255,255,255,0.11);
  --border-soft: rgba(255,255,255,0.06);

  /* accents */
  --accent: #1e90ff;               /* orange — same as light theme */
  --accent-soft: rgba(30,144,255,0.18);

  /* nav */
  --nav-bg: #2e2e33;
  --nav-fg: #f0f0f2;

  /* table */
  --table-bg: #2e2e33;
  --table-head-bg: #222226;
  --table-row-alt: #333338;
  --table-hover: rgba(246,128,72,0.10);
  --table-border: rgba(255,255,255,0.07);

  /* svg / canvas */
  --svg-bg: var(--surface);
  --svg-border: rgba(30,144,255,0.5);
}


/* ── Light theme ─────────────────────────────────────────────────────── */

:root[data-theme="light"] {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #e4e8ef;

  --text: #1a1d2e;
  --text-strong: #0d0f1a;
  --text-muted: #4a5568;

  --border: rgba(0, 0, 0, 0.14);
  --border-soft: #d1d9e0;
  --border-strong: #1a1d2e;

  --accent: #1e90ff;
  --accent-soft: rgba(30, 144, 255, 0.13);

  --nav-bg: #ffffff;
  --nav-fg: #1a1d2e;
  --nav-fg-dim: #94a3b8;
  --nav-accent: var(--accent);

  --table-bg: #ffffff;
  --table-head-bg: #f0f2f5;
  --table-row-alt: #f7f9fb;
  --table-hover: rgba(30, 144, 255, 0.08);
  --table-border: #d1d9e0;

  --card-bg: #ffffff;
  --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.09);

  --svg-bg: #f7f9fb;
  --svg-border: rgba(0, 0, 0, 0.2);
  --letterbox: #1a1d2e;
}

/* ── Page layout ────────────────────────────────────────────────────── */

.page-content {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.page-actions {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1.1rem;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { opacity: 0.85; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--accent);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger {
  background: #dc2626;
  color: #fff;
  font-size: 0.78rem;
  padding: 0.28rem 0.65rem;
}
.btn-danger:hover { opacity: 0.85; }

/* ── Inputs ──────────────────────────────────────────────────────────── */

input:not([type="submit"]):not([type="button"]):not([type="reset"]),
select {
  padding: 0.42rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  width: 100%;
}

input:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

/* ── Dialogs ─────────────────────────────────────────────────────────── */

dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  min-width: 360px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

.dialog-header {
  padding: 1.1rem 1.5rem 1rem;
  border-bottom: 2px solid var(--accent);
}

.dialog-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-strong);
}

.dialog-body {
  padding: 1.25rem 1.5rem;
}

.dialog-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  padding-top: 1.25rem;
  margin-top: 0.75rem;
  border-top: 1px solid var(--border-soft);
}

.dialog-section {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.dialog-section h4 {
  margin: 0 0 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Form layout ─────────────────────────────────────────────────────── */

.form-fields {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-group > span {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Spouse table ────────────────────────────────────────────────────── */

.spouse-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.spouse-table th,
.spouse-table td {
  padding: 0.5rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
}

.spouse-table thead th {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--surface-2);
}

/* ── Photo page layout ───────────────────────────────────────────────── */

.photo-layout {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.5rem;
  max-width: 1600px;
  margin: 0 auto;
}

.viewer-area {
  flex: 1 1 auto;
  min-width: 0;
}

/* ── Controls bar (arrows + toggle) ─────────────────────────────────── */

.viewer-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  padding: 0.6rem 0 0.25rem;
}

.controls-arrows {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.btn.details-toggle {
  padding: 0.35rem 1.2rem;
}

.viewer-controls .btn {
  height: 2.1rem;
  padding-top: 0;
  padding-bottom: 0;
  box-sizing: border-box;
}

/* ── Focus mode ──────────────────────────────────────────────────────── */

#focusExit {
  display: none;
}

body.focus-mode nav,
body.focus-mode .viewer-controls {
  display: none;
}

body.focus-mode .photo-layout {
  padding: 0;
  max-width: 100%;
}

body.focus-mode .photo-panels {
  display: none !important;
}

body.focus-mode .viewer-area {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

body.focus-mode .viewer {
  height: 100vh;
  width: 100vw;
  border-radius: 0;
}

body.focus-mode .image-wrap img {
  max-height: 100vh;
  max-width: 100vw;
  border-radius: 0;
  border: none;
}

body.focus-mode #focusExit {
  display: block;
  position: fixed;
  top: 1rem;
  right: 1.25rem;
  z-index: 1001;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

body.focus-mode #focusExit:hover {
  background: rgba(0, 0, 0, 0.85);
}

body.focus-mode .focus-arrow {
  display: flex;
}

.focus-arrow {
  display: none;
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1001;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  border: none;
  font-size: 2rem;
  padding: 1rem 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}

.focus-arrow:hover {
  background: rgba(0, 0, 0, 0.75);
}

#focusArrowLeft  { left: 0;  border-radius: 0 6px 6px 0; }
#focusArrowRight { right: 0; border-radius: 6px 0 0 6px; }

/* ── Side panels ─────────────────────────────────────────────────────── */

.photo-panels {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  width: 360px;
  flex-shrink: 0;
  padding-top: 0.5rem;
}

.photo-layout.panels-open .photo-panels {
  display: flex;
}

.panel {
  background: var(--card-bg, var(--surface));
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow, var(--shadow-1));
  padding: 1rem 1.2rem;
}

.panel-title {
  margin: 0 0 0.75rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

/* Filter panel reuses settings-grid style */
.panel-filters {
  display: grid;
  gap: 0.7rem;
}

.panel-filters label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.88rem;
  color: var(--text);
}

.panel-filters select {
  width: 100%;
  min-width: 0;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center !important;
  gap: 0.4rem !important;
  width: fit-content !important;
}

.checkbox-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
}

#autoScrollInterval {
  width: auto;
  max-width: 5rem;
  font-size: 0.78rem;
  padding: 0.1rem 0.2rem;
}

.checkbox-label input[type="checkbox"]:focus {
  outline: none;
}

.filter-divider {
  border: none;
  border-top: 1px solid var(--border-soft);
  margin: 0.75rem 0;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  min-width: unset;
  flex-shrink: 0;
}

/* ── Info panel ──────────────────────────────────────────────────────── */

.photo-event {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-strong);
}

.photo-source {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.photo-source-member {
  font-style: italic;
}

.tag-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.tag-list li {
  font-size: 0.88rem;
  color: var(--text);
  font-weight: normal;
}

.tag-list-empty {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-style: italic;
  font-weight: normal;
  margin: 0;
}

.tag-list-header {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.filter-status {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
}

.filter-status--none {
  color: var(--danger, #c0392b);
  font-style: italic;
}

.filter-status--count {
  color: var(--text, inherit);
  font-style: italic;
}

/* ── Tag chips ───────────────────────────────────────────────────────── */

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  background: var(--accent-soft);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text);
}

.tag-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
}

.tag-chip-remove:hover { color: var(--danger, #c0392b); }

/* ── Spinner ─────────────────────────────────────────────────────────── */

.image-wrap { position: relative; }

.img-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: img-spin 0.75s linear infinite;
  pointer-events: none;
}

.img-spinner.hidden { display: none; }

@keyframes img-spin {
  to { transform: rotate(360deg); }
}

/* ── Photo meta (photo-meta class on the description container) ──────── */

.photo-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

/* ── Responsive: panels stack below on narrow screens ────────────────── */

@media (max-width: 860px) {
  .photo-layout {
    flex-direction: column;
  }
  .photo-panels {
    width: 100%;
  }
}

/* ── Info page ───────────────────────────────────────────────────────── */

.info-page {
  max-width: 680px;
  margin: 2rem auto;
  padding: 0 1.25rem 4rem;
  color: var(--text);
}

.info-page h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-strong);
  margin-bottom: 0.5rem;
}

.info-page h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-strong);
  margin: 0 0 0.5rem;
}

.info-page p {
  margin: 0 0 0.75rem;
  line-height: 1.6;
}

.info-page ul {
  margin: 0 0 0.5rem 1.25rem;
  padding: 0;
  line-height: 1.7;
}

.info-page li {
  margin-bottom: 0.2rem;
}

.info-divider {
  border: none;
  border-top: 1px solid var(--border-soft);
  margin: 1.5rem 0;
}

