/* ==========================================================================
   LPTR — Arbre généalogique — design system
   ========================================================================== */

:root {
  /* Palette — noir sur blanc, à l'image du sceau LPTR */
  --color-paper: #ffffff;
  --color-paper-raised: #ffffff;
  --color-ink: #000000;
  --color-ink-soft: #3d3d3d;
  --color-ink-faint: #767676;
  --color-line: #e4e4e4;
  --color-line-strong: #b8b8b8;
  --color-accent: #000000;
  --color-accent-strong: #2b2b2b;
  --color-accent-soft: #f2f2f2;

  /* Typographie */
  --font-display: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --step--1: clamp(0.8rem, 0.78rem + 0.1vw, 0.875rem);
  --step-0: clamp(1rem, 0.97rem + 0.15vw, 1.0625rem);
  --step-1: clamp(1.2rem, 1.14rem + 0.3vw, 1.375rem);
  --step-2: clamp(1.5rem, 1.4rem + 0.5vw, 1.875rem);
  --step-3: clamp(1.9rem, 1.7rem + 1vw, 2.5rem);
  --step-4: clamp(2.4rem, 2.1rem + 1.5vw, 3.4rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --space-16: 4rem;

  --radius: 4px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 14px rgba(0, 0, 0, 0.05);
  --shadow-raised: 0 8px 28px rgba(0, 0, 0, 0.12);

  color-scheme: light;
}

/* Reset ------------------------------------------------------------------ */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  background-color: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.55;
  display: flex;
  flex-direction: column;
}

img, picture, svg { display: block; max-width: 100%; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  color: var(--color-ink);
  text-wrap: balance;
}

h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); }

p { text-wrap: pretty; }

a {
  color: inherit;
  text-decoration-color: var(--color-line-strong);
  text-underline-offset: 0.15em;
}

a:hover { text-decoration-color: currentColor; }

button, input, select, textarea { font: inherit; color: inherit; }

/* Layout ------------------------------------------------------------------ */

.container {
  width: 100%;
  max-width: 72rem;
  margin-inline: auto;
  padding-inline: var(--space-6);
}

.site-main { flex: 1; padding-block: var(--space-8) var(--space-16); }

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

.site-header {
  border-bottom: 1px solid var(--color-line);
  background: color-mix(in srgb, var(--color-paper) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 40;
}

.site-header__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  padding-block: var(--space-3);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
}

.brand__text { display: flex; flex-direction: column; line-height: 1.2; }

.brand__wordmark {
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--color-ink);
}

.brand__tagline {
  font-family: var(--font-body);
  font-size: var(--step--1);
  color: var(--color-ink-faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.logo-mark { width: 44px; height: 44px; flex-shrink: 0; }

.main-nav { display: flex; align-items: center; gap: var(--space-6); }

.main-nav__links { display: flex; align-items: center; gap: var(--space-4); list-style: none; padding: 0; }

.main-nav__links a {
  text-decoration: none;
  font-size: var(--step--1);
  letter-spacing: 0.02em;
  color: var(--color-ink-soft);
}

.main-nav__links a:hover, .main-nav__links a[aria-current="page"] { color: var(--color-accent); }

/* Footer -------------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--color-line);
  padding-block: var(--space-8);
  color: var(--color-ink-faint);
  font-size: var(--step--1);
}

.site-footer__row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: center;
  justify-content: space-between;
}

/* Buttons & forms ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.6em 1.1em;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn--primary { background: var(--color-accent); color: var(--color-paper-raised); }
.btn--primary:hover { background: var(--color-accent-strong); }

.btn--ghost { background: transparent; border-color: var(--color-line-strong); color: var(--color-ink); }
.btn--ghost:hover { border-color: var(--color-accent); color: var(--color-accent); }

.btn--danger { background: transparent; border-color: var(--color-line-strong); color: var(--color-accent-strong); }
.btn--danger:hover { background: var(--color-accent-soft); border-color: var(--color-accent); }

.field { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }

.field label { font-size: var(--step--1); font-weight: 600; color: var(--color-ink-soft); }

.field input, .field select, .field textarea {
  padding: 0.55em 0.75em;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius);
  background: var(--color-paper-raised);
  font-size: var(--step-0);
}

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

.field .form-error { color: var(--color-accent-strong); font-size: var(--step--1); }

.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); }

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

.card {
  background: var(--color-paper-raised);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

.card--padded { padding: var(--space-6); }

/* Search box -------------------------------------------------------------------- */

.search-box { display: flex; gap: var(--space-2); }
.search-box input { flex: 1; }

/* Ligne « personne » — recherche et fiche individuelle */

.person-row { text-decoration: none; align-items: center; transition: border-color 0.15s ease, box-shadow 0.15s ease; }
.person-row:hover { border-color: var(--color-line-strong); box-shadow: var(--shadow-raised); }

.person-row__avatar { flex-shrink: 0; }

.person-row__last { text-transform: uppercase; }

.person-row__meta { font-size: var(--step--1); color: var(--color-ink-faint); line-height: 1.35; }

.person-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-3);
}

/* Person avatar / initials fallback ----------------------------------------------- */

.avatar {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--color-paper-raised);
  box-shadow: 0 0 0 1px var(--color-line-strong);
  background: var(--color-accent-soft);
}

.avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--color-accent);
}

/* Arbre interactif ---------------------------------------------------------------- */

.tree-wrapper { position: relative; padding-block: var(--space-8); overflow-x: auto; }

.tree { position: relative; display: flex; flex-direction: column; align-items: center; gap: var(--space-16); min-width: fit-content; padding-inline: var(--space-8); }

.tree__connectors { position: absolute; inset: 0; pointer-events: none; overflow: visible; z-index: 0; }

.tree-connector { fill: none; stroke: var(--color-line-strong); stroke-width: 1.5; }

.tree__row { display: flex; gap: var(--space-6); justify-content: center; position: relative; z-index: 1; }

.tree-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  width: 128px;
  padding: var(--space-3) var(--space-2);
  background: var(--color-paper-raised);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  text-decoration: none;
  text-align: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

a.tree-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-raised); border-color: var(--color-line-strong); }

.tree-card--center { border-color: var(--color-accent); border-width: 2px; cursor: default; }

.tree-card__avatar { width: 56px; margin-bottom: var(--space-1); }

.tree-card__first { font-size: 0.85rem; line-height: 1.2; }

.tree-card__last { font-size: 0.85rem; font-weight: 700; line-height: 1.2; text-transform: uppercase; }

.tree-card__date { font-size: 0.7rem; line-height: 1.3; color: var(--color-ink-faint); margin-top: 2px; }

.tree-card__age { font-size: 0.7rem; line-height: 1.3; color: var(--color-ink-faint); }

.tree-empty { text-align: center; padding-block: var(--space-16); }

/* Arbre complet (descendance) ------------------------------------------------------- */

/* Page d'accueil --------------------------------------------------------------------- */

.hero {
  position: relative;
  display: flex;
  align-items: center;
  min-height: min(78vh, 720px);
  padding-block: var(--space-12);
  overflow: hidden;
}

/* La roue réelle, floutée, sert de filigrane : présente sans jamais gêner la lecture. */
.hero__wheel {
  position: absolute;
  top: 50%;
  right: -14%;
  translate: 0 -50%;
  width: min(72vw, 780px);
  aspect-ratio: 1;
  pointer-events: none;
  filter: blur(2.5px);
  opacity: 0.16;
  mask-image: radial-gradient(circle at center, #000 55%, transparent 78%);
  animation: hero-turn 240s linear infinite;
}

.hero__wheel svg { width: 100%; height: 100%; }

.hero__wheel path,
.hero__wheel circle {
  fill: none;
  stroke: var(--color-ink);
  stroke-width: 1.4;
}

@keyframes hero-turn {
  from { rotate: 0deg; }
  to { rotate: 360deg; }
}

@media (prefers-reduced-motion: reduce) {
  .hero__wheel { animation: none; }
}

.hero__content { position: relative; max-width: 40rem; }

.hero__eyebrow {
  font-size: var(--step--1);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--color-ink-faint);
  margin-bottom: var(--space-4);
}

.hero__title {
  font-size: clamp(2.6rem, 1.9rem + 3.2vw, 4.6rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-6);
}

.hero__title em { font-style: italic; color: var(--color-ink-soft); }

.hero__lede {
  font-size: clamp(1.05rem, 1rem + 0.3vw, 1.25rem);
  color: var(--color-ink-soft);
  max-width: 34rem;
  margin-bottom: var(--space-8);
}

.hero__search { display: flex; gap: var(--space-2); max-width: 30rem; margin-bottom: var(--space-6); }
.hero__search input { flex: 1; }

.hero__actions { margin-bottom: var(--space-12); }

.hero__stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-line);
}

.hero__stats dt {
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-ink-faint);
  margin-bottom: var(--space-1);
}

.hero__stats dd {
  font-family: var(--font-display);
  font-size: var(--step-2);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
  .hero__wheel { right: -30%; opacity: 0.1; }
}

/* Zoom au pincement ------------------------------------------------------------------ */

.zoom__controls { gap: var(--space-2); margin-bottom: var(--space-3); }

.zoom__controls .btn { min-width: 2.5rem; }

.zoom__level { font-variant-numeric: tabular-nums; min-width: 3.5rem; text-align: center; }

.zoom__viewport {
  overflow: auto;
  overscroll-behavior: contain;
  /* Le défilement reste au navigateur ; seul le pincement est intercepté. */
  touch-action: pan-x pan-y;
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  background: var(--color-paper-raised);
  max-height: 80vh;
}

.zoom__content {
  transform-origin: 0 0;
  width: max-content;
  min-width: 100%;
  padding-block: var(--space-6);
}

.dtree, .dtree ul { list-style: none; margin: 0; padding: 0; }

.dtree { display: flex; justify-content: center; min-width: max-content; padding-inline: var(--space-8); }

.dtree ul {
  display: flex;
  justify-content: center;
  position: relative;
  padding-top: var(--space-8);
}

.dtree li {
  position: relative;
  padding: var(--space-8) var(--space-3) 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Traits horizontaux reliant les frères et sœurs à leur parent */
.dtree li::before,
.dtree li::after {
  content: '';
  position: absolute;
  top: 0;
  right: 50%;
  width: 50%;
  height: var(--space-8);
  border-top: 1px solid var(--color-line-strong);
}

.dtree li::after {
  right: auto;
  left: 50%;
  border-left: 1px solid var(--color-line-strong);
}

.dtree li:only-child { padding-top: var(--space-6); }
.dtree li:only-child::before,
.dtree li:only-child::after { display: none; }

.dtree li:first-child::before,
.dtree li:last-child::after { border: 0 none; }

.dtree li:last-child::before {
  border-right: 1px solid var(--color-line-strong);
  border-radius: 0 6px 0 0;
}

.dtree li:first-child::after { border-radius: 6px 0 0 0; }

/* Trait vertical descendant depuis un foyer vers ses enfants */
.dtree ul::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 0;
  height: var(--space-8);
  border-left: 1px solid var(--color-line-strong);
}

.dtree__household {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
  padding: var(--space-2);
  border-radius: var(--radius);
  background: var(--color-accent-soft);
}

.dtree__member { display: flex; flex-direction: column; gap: var(--space-1); }

/* Génération parente affichée au-dessus du point de départ */
.dtree__household--ancestors { background: transparent; }
.dtree__household--ancestors .dcard { border-style: dashed; box-shadow: none; }
.dtree__household--ancestors .dcard:hover { border-style: solid; box-shadow: var(--shadow-card); }

.dtree__link {
  align-self: center;
  color: var(--color-ink-faint);
  font-family: var(--font-display);
  font-size: var(--step-0);
  padding-bottom: var(--space-4);
}

.dcard__origin {
  font-size: 0.65rem;
  line-height: 1.3;
  text-align: center;
  color: var(--color-ink-faint);
  width: 118px;
}

.dcard__origin a { color: var(--color-ink-soft); text-decoration-color: var(--color-line-strong); }
.dcard__origin a:hover { color: var(--color-ink); }

.dcard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: var(--space-2);
  width: 118px;
  background: var(--color-paper-raised);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  text-decoration: none;
  text-align: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.dcard:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-raised);
  border-color: var(--color-accent);
}

.dcard--focus { border-color: var(--color-accent); border-width: 2px; }

.dcard__avatar { width: 48px; margin-bottom: var(--space-1); }

.dcard__first {
  font-size: 0.8rem;
  line-height: 1.2;
  color: var(--color-ink);
}

.dcard__last {
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--color-ink);
}

.dcard__date { font-size: 0.68rem; line-height: 1.3; color: var(--color-ink-faint); margin-top: 2px; }

.dcard__age { font-size: 0.68rem; line-height: 1.3; color: var(--color-ink-faint); }

/* Roue généalogique ----------------------------------------------------------------- */

.wheel-scroll { display: flex; justify-content: center; overflow-x: auto; padding-block: var(--space-4); }

/* Taille naturelle, quitte à défiler : la réduire rapetisserait le texte d'autant. */
.wheel { height: auto; flex-shrink: 0; }

.wheel__slice {
  fill: var(--color-paper-raised);
  stroke: var(--color-line-strong);
  stroke-width: 1;
  transition: fill 0.15s ease;
  /* Évide l'anneau des générations n'ayant qu'une seule personne. */
  fill-rule: evenodd;
}

/* Dégradé de gris : les générations lointaines s'estompent vers l'extérieur. */
.wheel__slice--gen1 { fill: #ececec; }
.wheel__slice--gen2 { fill: #f2f2f2; }
.wheel__slice--gen3 { fill: #f7f7f7; }
.wheel__slice--gen4 { fill: #fbfbfb; }
.wheel__slice--gen5 { fill: #ffffff; }

/* Prolongement des branches éteintes : referme le disque sans rien affirmer. */
.wheel__slice--empty { fill: #fcfcfc; stroke: var(--color-line); }

/* Le conjoint partage la case du descendant, en teinte plus légère. */
.wheel__label--spouse { fill: #6b6b6b; }
.wheel__sector:hover .wheel__label--spouse { fill: #d8d8d8; }

.wheel__sector { cursor: pointer; }
.wheel__sector:hover .wheel__slice { fill: var(--color-ink); }
.wheel__sector:hover .wheel__label { fill: #ffffff; }

.wheel__sector--empty { cursor: default; }

.wheel__label {
  fill: var(--color-ink);
  text-anchor: middle;
  dominant-baseline: middle;
  font-family: var(--font-body);
  pointer-events: none;
}

.wheel__hub { fill: var(--color-paper-raised); stroke: var(--color-ink); stroke-width: 2; }

/* Moitiés du moyeu : invisibles au repos, elles se révèlent au survol pour
   signaler qu'on peut remonter vers le père ou vers la mère. */
.wheel__hub-half { cursor: pointer; }
.wheel__hub-half path { fill: transparent; transition: fill 0.15s ease; }
.wheel__hub-half:hover path { fill: color-mix(in srgb, var(--color-ink) 12%, transparent); }

.wheel__label--hub { font-family: var(--font-display); pointer-events: none; }

/* Admin ----------------------------------------------------------------------------- */

.admin-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); flex-wrap: wrap; }

.admin-table { width: 100%; border-collapse: collapse; background: var(--color-paper-raised); border: 1px solid var(--color-line); border-radius: var(--radius); overflow: hidden; }

.admin-table th, .admin-table td { text-align: left; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-line); font-size: var(--step--1); }

.admin-table th { color: var(--color-ink-faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; font-size: 0.7rem; }

.admin-table tr:last-child td { border-bottom: none; }

.admin-table td.actions { display: flex; gap: var(--space-2); justify-content: flex-end; }

.tag { display: inline-block; padding: 0.15em 0.6em; border-radius: 999px; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.02em; background: var(--color-accent-soft); color: var(--color-accent-strong); }

.form-section { padding-bottom: var(--space-4); margin-bottom: var(--space-4); border-bottom: 1px solid var(--color-line); }
.form-section:last-of-type { border-bottom: none; }

/* Flash messages ------------------------------------------------------------------ */

.flash { padding: var(--space-3) var(--space-4); border-radius: var(--radius); margin-bottom: var(--space-4); font-size: var(--step--1); }
.flash--success { background: var(--color-accent-soft); color: var(--color-ink); border: 1px solid var(--color-line-strong); border-left: 3px solid var(--color-ink); }
.flash--error { background: #fdf0f0; color: #8c1d1d; border: 1px solid #f0cccc; border-left: 3px solid #8c1d1d; }

/* Utility ------------------------------------------------------------------------- */

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.text-muted { color: var(--color-ink-faint); }
.text-center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }

/* Pas de variante sombre : l'identité LPTR est volontairement noir sur blanc. */

/* Saisie du code de connexion : quatre chiffres, bien espacés. */
.code-input {
  font-size: 2rem;
  letter-spacing: 0.6em;
  text-align: center;
  text-indent: 0.6em;
  font-variant-numeric: tabular-nums;
}

.tree-card-link { text-decoration: none; gap: var(--space-2); transition: border-color 0.15s ease, box-shadow 0.15s ease; }
.tree-card-link:hover { border-color: var(--color-line-strong); box-shadow: var(--shadow-raised); }

/* Pages légales : colonne de lecture étroite, hiérarchie sobre. */
.legal { max-width: 44rem; margin-inline: auto; }
.legal h1 { font-size: var(--step-3); margin-bottom: var(--space-8); }
.legal h2 { font-size: var(--step-1); margin-top: var(--space-8); margin-bottom: var(--space-3); }
.legal p, .legal ul { margin-bottom: var(--space-4); color: var(--color-ink-soft); }
.legal ul { padding-left: var(--space-6); }
.legal li { margin-bottom: var(--space-2); }
.legal__updated { margin-top: var(--space-12); font-size: var(--step--1); color: var(--color-ink-faint); }
.site-footer__row nav { gap: var(--space-4); }

/* Barre de vues : la vue courante est pleine, les autres en retrait. */
.view-switch {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: 3px;
  width: fit-content;
  background: var(--color-paper-raised);
}

.view-switch__item {
  padding: 0.45em 0.9em;
  border-radius: 3px;
  font-size: var(--step--1);
  font-weight: 600;
  text-decoration: none;
  color: var(--color-ink-soft);
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.view-switch__item:hover { background: var(--color-accent-soft); color: var(--color-ink); }

.view-switch__item.is-current {
  background: var(--color-ink);
  color: var(--color-paper-raised);
}
