/* Base chrome (P3.1) + tree view (Task 25 / P3.2). A calm "archival paper"
   palette -- warm off-white / ink in light mode, warm charcoal in dark --
   deliberately NOT the vendored family-chart library's stock near-black
   demo look (family-chart.css still ships, but only for structural rules;
   every color/typography choice here overrides it -- see the `--f3-*`
   custom-property block under ".tree-chart.f3" below). */

:root {
  color-scheme: light dark;
  --fg: #1b1b1b;
  --bg: #fafaf7;
  --accent: #3a6b52;
  --card-bg: #fffdf8;
  --card-border: rgba(58, 107, 82, 0.28);
  --muted: #6b6459;
  --disputed: #a8631f;
  --admin: #7a5a2e;
  --surface: #f1ede3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #eaeaea;
    --bg: #14171a;
    --accent: #7fbf9e;
    --card-bg: #1d2320;
    --card-border: rgba(127, 191, 158, 0.3);
    --muted: #a3a99f;
    --disputed: #e0a458;
    --admin: #d9b876;
    --surface: #1a1e1c;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid rgba(127, 127, 127, 0.25);
}

.brand {
  font-weight: 600;
  text-decoration: none;
  color: var(--fg);
}

/* Top nav (Task 27 / P3.4): wraps to its own full-width row on narrow
   screens (below the brand/lang-toggle row, via `order`), sits centered
   inline between them on wider ones -- mobile-friendly without any JS. */
.site-nav {
  order: 3;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1rem;
}

@media (min-width: 40rem) {
  .site-nav {
    order: 0;
    width: auto;
    flex: 1;
    justify-content: center;
  }
}

.site-nav a {
  color: var(--fg);
  text-decoration: none;
  font-size: 0.92rem;
  padding: 0.15rem 0;
}

.site-nav a:hover {
  color: var(--accent);
}

.lang-toggle {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}

.site-main {
  max-width: 32rem;
  margin: 2.5rem auto;
  padding: 0 1.5rem;
  line-height: 1.5;
}

.dev-login,
.back-link {
  display: inline-block;
  margin-top: 0.75rem;
  color: var(--accent);
}

/* ---------------------------------------------------------------------
   Tree view (Task 25 / P3.2)
   ------------------------------------------------------------------- */

.tree-page .site-main.tree-main {
  max-width: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  /* Fill the viewport below the header so pan/zoom has real room, on
     phones too -- a family tree in a 32rem centered column (the default
     .site-main width) would be unusable. */
  min-height: calc(100dvh - 3.5rem);
}

/* Below 40rem the top nav (Task 27 / P3.4) wraps onto its own row (see
   `.site-nav`'s `order: 3; width: 100%`), so the header is taller than the
   single-row 3.5rem this rule otherwise assumes -- bump the subtracted
   height to match, same breakpoint the nav itself wraps at. */
@media (max-width: 40rem) {
  .tree-page .site-main.tree-main {
    min-height: calc(100dvh - 6.5rem);
  }
}

.tree-root {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tree-search {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--card-border);
  background: var(--surface);
}

.tree-search .f3-form-field,
.tree-search input[type="text"] {
  width: 100%;
  max-width: 22rem;
}

.tree-search input[type="text"] {
  font: inherit;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--fg);
}

.tree-status {
  margin: 2.5rem auto;
  padding: 0 1.5rem;
  max-width: 28rem;
  text-align: center;
  color: var(--muted);
  line-height: 1.5;
}

.tree-chart {
  flex: 1;
  min-height: 60vh;
  touch-action: none; /* let the library's own pan/zoom own touch gestures */
}

.tree-chart[hidden] {
  display: none;
}

/* Reskin the vendored family-chart canvas: override its CSS custom
   properties (family-chart.css defines --background-color/--text-color/
   --male-color/--female-color/--genderless-color on `.f3`) with this
   project's own archival palette instead of the library's stock dark
   demo look. Drevo has no gender predicate (see migrations/001_initial.sql)
   so every card renders "genderless" -- only that variable matters for
   card fill, but all five are set for consistency if that ever changes. */
.tree-chart.f3 {
  --background-color: var(--bg);
  --text-color: var(--fg);
  --male-color: var(--card-bg);
  --female-color: var(--card-bg);
  --genderless-color: var(--card-bg);
  font-family: inherit;
  background: var(--bg);
}

.tree-chart.f3 svg.main_svg text {
  fill: var(--muted);
  font-family: inherit;
}

/* Relationship lines: the library draws these as SVG `<path class="link">`
   elements with a hardcoded `stroke="#fff"` PRESENTATION ATTRIBUTE (not a
   CSS custom property) -- invisible against this project's light "paper"
   background. Any stylesheet rule outranks a presentation attribute in the
   CSS cascade regardless of specificity, so this alone is enough to win. */
.tree-chart.f3 .link {
  stroke: var(--muted);
}

/* Disputed relationship (a claim marked `disputed` for this specific
   pair, e.g. two conflicting accounts of who's related to whom) -- the
   connecting line itself, not just the node badge. Class applied by
   `tree.js`'s `markDisputedLinks` (see its comment for why this needs a
   DOM walk rather than a plain selector). */
.tree-chart.f3 .link.tree-link-disputed {
  stroke: var(--disputed);
  stroke-dasharray: 4 3;
}

/* Our own card markup (set via tree.js's `setCardInnerHtmlCreator`) is
   what's actually visible -- neutralize the library's default card
   chrome so it never fights this project's design. */
.tree-chart.f3 div.card {
  background: transparent;
  box-shadow: none;
}

.tree-card-inner {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.5rem 0.65rem;
  border-radius: 0.6rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  text-align: center;
  overflow: hidden;
}

.tree-card-inner.is-disputed {
  border-style: dashed;
  border-color: var(--disputed);
}

.tree-card-name {
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-card-years {
  font-size: 0.78rem;
  color: var(--muted);
}

.tree-card-badges {
  position: absolute;
  top: 2px;
  right: 4px;
  display: flex;
  gap: 0.2rem;
  font-size: 0.8rem;
  line-height: 1;
}

.tree-card-badge--disputed {
  color: var(--disputed);
}

.tree-card-badge--admin {
  color: var(--admin);
}

@media (max-width: 30rem) {
  .tree-card-name {
    font-size: 0.82rem;
  }
  .tree-card-years {
    font-size: 0.7rem;
  }
}

/* ---------------------------------------------------------------------
   Person page (Task 26 / P3.3) -- same archival "paper" palette as the
   tree (the `--fg`/--bg/--accent/--card-bg/--card-border/--muted/
   --disputed/--admin/--surface custom properties defined at the top of
   this file), reused rather than reinvented so the two pages read as one
   site, not two.
   ------------------------------------------------------------------- */

.person-page .site-main {
  max-width: 42rem;
}

.person-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.person-header-photo {
  width: 4.5rem;
  height: 4.5rem;
  flex: none;
  border-radius: 0.75rem;
  object-fit: cover;
  border: 1px solid var(--card-border);
  background: var(--surface);
}

.person-name {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.25;
}

.person-years {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.person-section {
  margin: 2rem 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--card-border);
}

.person-section h2 {
  margin: 0 0 0.9rem;
  font-size: 1.05rem;
  color: var(--fg);
}

.person-section h3.relation-label {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.empty-hint {
  color: var(--muted);
  font-style: italic;
  margin: 0;
}

/* Facts -- a definition list read as a compact wiki infobox: label
   (dt) above its value line(s) (dd), each value line its own
   provenance. */
.fact-list {
  margin: 0;
}

.fact-row {
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(127, 127, 127, 0.15);
}

.fact-row:last-child {
  border-bottom: none;
}

.fact-row--disputed {
  border-left: 3px solid var(--disputed);
  padding-left: 0.6rem;
  margin-left: -0.6rem;
}

.fact-label {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.fact-values {
  margin: 0;
}

.fact-value {
  padding: 0.1rem 0;
  line-height: 1.45;
}

.fact-value-text {
  font-weight: 500;
}

.fact-provenance,
.story-provenance {
  color: var(--muted);
  font-size: 0.85rem;
}

.disputed-marker {
  margin-right: 0.15rem;
}

.admin-only-badge {
  color: var(--admin);
  margin-left: 0.3rem;
}

.fact-value--admin-only,
.story-item--admin-only {
  opacity: 0.95;
}

/* Relationships */
.relation-group {
  margin-bottom: 1.1rem;
}

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

.relation-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.relation-links a {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--fg);
  text-decoration: none;
  font-size: 0.9rem;
}

.relation-links a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Gallery */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 0.9rem;
}

.gallery-item {
  margin: 0;
  padding: 0.5rem;
  border-radius: 0.6rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
}

.gallery-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 0.45rem;
  background: var(--surface);
}

.gallery-caption {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.gallery-orig-link {
  display: inline-block;
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--accent);
}

/* Истории (stories) -- each a small archival note card. */
.story-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.story-item {
  padding: 0.9rem 1rem;
  border-radius: 0.6rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
}

.story-text {
  margin: 0 0 0.6rem;
  white-space: pre-wrap;
  line-height: 1.5;
}

.story-item audio {
  width: 100%;
  margin-bottom: 0.5rem;
}

@media (max-width: 30rem) {
  .person-header {
    gap: 0.75rem;
  }

  .person-header-photo {
    width: 3.5rem;
    height: 3.5rem;
  }

  .person-name {
    font-size: 1.25rem;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(6rem, 1fr));
  }
}

/* ---------------------------------------------------------------------
   Media library (Task 27 / P3.4) -- same archival "paper" palette as the
   tree/person page, and the same tile-card language the person page's
   gallery already established (`.gallery-item`/`.gallery-thumb`), scaled
   up into a full Drive-style grid with a filter bar above it.
   ------------------------------------------------------------------- */

.media-page .site-main {
  max-width: 60rem;
}

.media-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.9rem;
  margin: 1.25rem 0 0.5rem;
  padding: 1rem;
  border-radius: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--card-border);
}

.media-filter {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
}

.media-filter-label {
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.75rem;
}

.media-filter select {
  font: inherit;
  padding: 0.4rem 0.5rem;
  border-radius: 0.4rem;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--fg);
  min-width: 9rem;
}

.media-filter-submit {
  font: inherit;
  padding: 0.45rem 1rem;
  border-radius: 0.4rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
}

.media-filter-submit:hover {
  opacity: 0.9;
}

.media-filter-clear {
  align-self: center;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}

.media-filter-clear:hover {
  color: var(--accent);
}

.media-count {
  margin: 0.75rem 0 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 1rem;
}

.media-tile {
  margin: 0;
  padding: 0.6rem;
  border-radius: 0.6rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
}

.media-tile--admin-only {
  border-style: dashed;
  border-color: var(--admin);
}

.media-tile-photo-link {
  display: block;
}

.media-tile-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 0.45rem;
  background: var(--surface);
}

.media-tile-orig-link {
  display: inline-block;
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--accent);
}

.media-tile-voice,
.media-tile-file {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 6rem;
  padding: 0.75rem 0.25rem;
  border-radius: 0.45rem;
  background: var(--surface);
  text-align: center;
}

.media-tile-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.media-tile-audio {
  width: 100%;
  max-width: 100%;
}

.media-tile-duration {
  font-size: 0.78rem;
  color: var(--muted);
}

.media-tile-file-link {
  color: var(--accent);
  font-size: 0.85rem;
  text-decoration: none;
  word-break: break-word;
}

.media-tile-file-link:hover {
  text-decoration: underline;
}

.media-tile-caption {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.media-tile-caption-text {
  color: var(--fg);
}

.media-tile-meta {
  margin: 0.5rem 0 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.media-more-link {
  display: inline-block;
  margin: 1.5rem 0;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}

.media-more-link:hover {
  border-color: var(--accent);
  background: var(--surface);
}

@media (max-width: 30rem) {
  .media-filters {
    padding: 0.75rem;
  }

  .media-filter select {
    min-width: 0;
    width: 100%;
  }

  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  }
}

/* ---------------------------------------------------------------------
   Search (Task 27 / P3.4) -- grouped results, each a short snippet card
   in the same archival "paper" language as the story cards on the
   person page.
   ------------------------------------------------------------------- */

.search-page .site-main {
  max-width: 42rem;
}

.search-form {
  display: flex;
  gap: 0.6rem;
  margin: 1.25rem 0 2rem;
}

.search-input {
  flex: 1;
  font: inherit;
  padding: 0.55rem 0.8rem;
  border-radius: 0.5rem;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--fg);
}

.search-submit {
  font: inherit;
  padding: 0.5rem 1.2rem;
  border-radius: 0.5rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
}

.search-submit:hover {
  opacity: 0.9;
}

.search-group {
  margin: 0 0 2rem;
}

.search-group-heading {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  color: var(--fg);
}

.search-group-count {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
}

.search-results-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.search-result {
  padding: 0.75rem 0.9rem;
  border-radius: 0.6rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
}

.search-result-link {
  font-weight: 600;
  color: var(--fg);
  text-decoration: none;
}

.search-result-link:hover {
  color: var(--accent);
}

.search-snippet {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.search-group-capped {
  margin: 0.6rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}
