/* ==========================================================================
   Sapyn — feuille de style globale
   Variables thématiques (clair/sombre × normal/daltonien) + composants.
   ========================================================================== */

/* --- Variables de thème -------------------------------------------------- */

:root {
  --base-font-size: 16px;

  /* Mode clair (défaut) */
  --bg:           #FAF7F2;
  --bg-elevated:  #FFFFFF;
  --fg:           #14241F;
  --muted:        #6B7660;
  --border:       #EFEAE1;
  --border-strong:#D8D0BF;

  --primary:      #0F4C3A;
  --primary-hover:#1B6B53;
  --primary-fg:   #FFFFFF;
  --accent:       #D4A574;

  --success:      #2D7A3F;
  --success-bg:   #E8F4EE;
  --warn:         #B86C00;
  --warn-bg:      #FFF4E0;
  --danger:       #A8442A;
  --danger-bg:    #FBEAE2;

  --focus:        #0F4C3A;
  --shadow:       0 4px 24px rgba(15, 76, 58, 0.08);
  --shadow-lg:    0 8px 32px rgba(15, 76, 58, 0.12);

  --radius:       12px;
  --radius-lg:    16px;
}

html.dark {
  --bg:           #0E1916;
  --bg-elevated:  #14241F;
  --fg:           #FAF7F2;
  --muted:        #9CA89C;
  --border:       #1F302A;
  --border-strong:#2A3D34;

  --primary:      #4FAD8A;
  --primary-hover:#6BC4A1;
  --primary-fg:   #0E1916;
  --accent:       #E5C098;

  --success:      #5EC97A;
  --success-bg:   #143323;
  --warn:         #FFB347;
  --warn-bg:      #3A2810;
  --danger:       #E07060;
  --danger-bg:    #3A1A14;

  --focus:        #6BC4A1;
  --shadow:       0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg:    0 8px 32px rgba(0, 0, 0, 0.6);
}

/* Mode daltonien : palette ColorBrewer "qualitative safe"
   (deutéranopie/protanopie). Bleu et orange sont distinguables par tous. */
html.cb {
  --primary:      #1F77B4;
  --primary-hover:#3A8FCC;
  --accent:       #FF7F0E;
  --success:      #1F77B4;
  --success-bg:   #E5EFF7;
  --warn:         #B5A000;
  --warn-bg:      #FAF6D8;
  --danger:       #FF7F0E;
  --danger-bg:    #FFEBD6;
  --focus:        #1F77B4;
}

html.dark.cb {
  --primary:      #66B2DD;
  --primary-hover:#85C5E8;
  --accent:       #FFA64D;
  --success:      #66B2DD;
  --success-bg:   #102A3F;
  --warn:         #E5C944;
  --warn-bg:      #2E2810;
  --danger:       #FFA64D;
  --danger-bg:    #3A2410;
  --focus:        #85C5E8;
}

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

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

html {
  font-size: var(--base-font-size);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
}

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

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

h1, h2, h3 { color: var(--fg); margin-top: 0; line-height: 1.25; }
h1 { font-size: 2rem; font-weight: 700; }
h2 { font-size: 1.5rem; font-weight: 600; }
h3 { font-size: 1.2rem; font-weight: 600; }

/* --- Skip link (a11y : sauter au contenu principal) --------------------- */

.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  z-index: 1000;
  padding: 0.75rem 1rem;
  background: var(--primary);
  color: var(--primary-fg);
  border-radius: 0 0 var(--radius) 0;
  font-weight: 600;
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: 0;
  outline: none;
  text-decoration: none;
}

/* --- Focus visible ------------------------------------------------------- */

:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* --- Layout (header / main / footer) ------------------------------------ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}
.brand:hover { text-decoration: none; color: var(--primary-hover); }
.brand svg, .brand img {
  width: 36px;
  height: 36px;
  color: var(--primary);
}

.main-nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  flex: 1;
}
.main-nav a {
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  color: var(--fg);
  font-weight: 500;
  font-size: 0.95rem;
  transition: background-color 0.15s, color 0.15s;
}
.main-nav a:hover {
  background: var(--bg);
  color: var(--primary);
  text-decoration: none;
}
.main-nav a.active {
  background: var(--primary);
  color: var(--primary-fg);
}

/* --- User menu (auth) -------------------------------------------------- */

.user-menu {
  position: relative;
}
.user-menu summary {
  cursor: pointer;
  list-style: none;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 100;
  min-width: 14rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  box-shadow: var(--shadow-lg);
}
.user-menu-item {
  display: block;
  padding: .4rem .5rem;
  margin: 0 -.5rem;
  border-radius: 6px;
  color: var(--fg);
  text-decoration: none;
  font-size: .9rem;
  border: none;
  background: transparent;
  font-family: inherit;
}
.user-menu-item:hover {
  background: var(--bg);
  color: var(--primary);
  text-decoration: none;
}

/* --- Pages d'auth (centrées, sans nav) -------------------------------- */

body.auth-page {
  min-height: 100vh;
  background: var(--bg);
}
.auth-main {
  max-width: 26rem;
  margin: 4rem auto;
  padding: 0 1.25rem;
}
.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  margin-bottom: 2rem;
}
.auth-logo img {
  width: 40px; height: 40px;
  color: var(--primary);
}
.auth-logo:hover { text-decoration: none; }
.auth-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

/* --- Toolbar a11y -------------------------------------------------------- */

.a11y-toolbar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.a11y-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 0.5rem;
  background: transparent;
  border: none;
  border-radius: 999px;
  color: var(--fg);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s;
}
.a11y-toolbar button:hover {
  background: var(--bg-elevated);
}
.a11y-toolbar button[aria-pressed="true"] {
  background: var(--primary);
  color: var(--primary-fg);
}
.a11y-toolbar svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}
.a11y-toolbar .text-btn {
  font-variant-numeric: tabular-nums;
}

/* État "en cours de lecture" du bouton TTS */
.a11y-toolbar button.speaking {
  background: var(--accent);
  color: var(--bg);
}
.a11y-toolbar button.speaking svg {
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

/* --- Main et conteneur --------------------------------------------------- */

main.main {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

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

.flash-container {
  max-width: 1280px;
  margin: 1rem auto 0;
  padding: 0 1.25rem;
}
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  border: 1px solid transparent;
  font-weight: 500;
}
.flash::before {
  content: "";
  display: inline-block;
  width: 1.1em;
  margin-right: 0.5em;
  font-weight: 700;
}
.flash-success { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.flash-success::before { content: "✓"; }
.flash-warn    { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.flash-warn::before    { content: "⚠"; }
.flash-error   { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.flash-error::before   { content: "✗"; }
.flash-info    { background: var(--bg-elevated); color: var(--fg); border-color: var(--border-strong); }
.flash-info::before    { content: "ℹ"; }

/* --- Composants : carte ------------------------------------------------- */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.card h2:first-child, .card h3:first-child { margin-top: 0; }

/* --- Composants : boutons ----------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { text-decoration: none; }
.btn-primary  { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { background: var(--primary-hover); color: var(--primary-fg); }
.btn-secondary { background: var(--bg-elevated); color: var(--fg); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.btn-danger    { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger); opacity: 0.9; color: white; }

/* --- Composants : tableau de compteurs (page d'accueil) ----------------- */

.stats-table {
  width: 100%;
  border-collapse: collapse;
}
.stats-table td {
  padding: 0.7rem 0.25rem;
  border-bottom: 1px solid var(--border);
}
.stats-table tr:last-child td { border-bottom: none; }
.stats-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--primary);
}

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

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 1.5rem;
}
.page-header h1 { margin: 0; }
.page-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* --- Grilles ------------------------------------------------------------- */

.grid-2col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 720px) {
  .grid-2col { grid-template-columns: 1fr; }
}

/* --- Listes d'entités ---------------------------------------------------- */

.entity-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.entity-list li {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}
.entity-list li:last-child { border-bottom: none; }
.entity-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  min-width: 0;
}
.entity-main strong {
  font-weight: 600;
  font-size: 1.05rem;
  word-break: break-word;
}

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

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

/* --- Actions sur ligne --------------------------------------------------- */

.actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}
.actions .btn { padding: 0.35rem 0.75rem; font-size: 0.85rem; }

@media (max-width: 720px) {
  .entity-list li { flex-direction: column; align-items: flex-start; }
  .actions { width: 100%; }
  .actions .btn, .actions form { flex: 1; }
  .actions .btn { width: 100%; }
}

/* --- État vide ----------------------------------------------------------- */

.empty {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  padding: 1.5rem 0.5rem;
  margin: 0;
}

/* --- Back link ----------------------------------------------------------- */

.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}
.back-link:hover { color: var(--primary); text-decoration: none; }

/* --- Formulaires --------------------------------------------------------- */

form label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  color: var(--fg);
}
form input[type="text"],
form input[type="email"],
form input[type="date"],
form input[type="number"],
form input[type="password"],
form select,
form textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 1rem;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  margin-bottom: 0.25rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
form input:focus,
form select:focus,
form textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 76, 58, 0.15);
  outline: none;
}
html.dark form input:focus,
html.dark form select:focus,
html.dark form textarea:focus {
  box-shadow: 0 0 0 3px rgba(79, 173, 138, 0.25);
}

.form-help {
  margin: 0.25rem 0 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1rem;
  align-items: center;
}

/* --- Avatars ------------------------------------------------------------- */

.avatar {
  display: inline-block;
  border-radius: 50%;
  flex-shrink: 0;
  vertical-align: middle;
  background: var(--bg);
}
.avatar-photo {
  object-fit: cover;
  border: 2px solid var(--border);
}
.avatar-default {
  /* Le SVG inline a déjà sa propre couleur de fond */
  border: 2px solid transparent;
}

/* --- Member card (utilisée dans la grille des membres d'une famille) ----- */

.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}

.member-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--fg);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.member-card:hover {
  border-color: var(--primary);
  text-decoration: none;
  color: var(--fg);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.member-card-body {
  flex: 1;
  min-width: 0;
}
.member-card-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.member-card-meta {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.15rem;
}

/* --- Family detail header (avatar + nom + meta) ------------------------ */

.family-detail-header {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
}

/* --- Member detail (fiche membre) --------------------------------------- */

.member-detail-header {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  flex-wrap: wrap;
}
.member-detail-info { flex: 1; min-width: 12rem; }
.member-detail-info h1 { margin: 0 0 0.5rem; }
.member-detail-meta {
  margin: 0.25rem 0;
  color: var(--muted);
}
.member-detail-meta a { color: var(--primary); }

/* --- Photo actuelle (formulaire édition) -------------------------------- */

.current-photo {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}
.current-photo img {
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
}
.inline-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  margin-bottom: 0;
}
.inline-checkbox input { width: auto; margin: 0; }

/* --- Form row (champs côte à côte) -------------------------------------- */

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}
.form-col label { margin-bottom: 0.4rem; }

/* --- Variantes de badge ------------------------------------------------- */

.badge-warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn);
}
.badge-success {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success);
}
.badge-deceased {
  background: var(--bg);
  color: var(--muted);
  border-color: var(--border-strong);
  font-style: italic;
}
.badge-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
}

/* --- Statut décédé ------------------------------------------------------- */

.deceased-marker {
  display: inline-block;
  color: var(--muted);
  font-weight: 400;
  margin-right: 0.15em;
  /* Le † reste lisible en mode daltonien (pas de couleur seule pour info) */
}

.member-card-deceased {
  opacity: 0.75;
  background: linear-gradient(0deg, var(--bg-elevated), var(--bg-elevated)) padding-box;
  position: relative;
}
.member-card-deceased:hover { opacity: 1; }

.member-detail-header.is-deceased .avatar {
  filter: grayscale(0.6);
}

.status-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  font-size: 0.95rem;
}
.status-list li {
  padding: 0.3rem 0;
  color: var(--muted);
}

/* Action inline pliable (ex. « Décédé(e)… » dans le groupe d'actions) */
.action-details {
  display: inline-block;
  position: relative;
}
.action-details > summary {
  cursor: pointer;
  display: inline-flex;
  list-style: none;
}
.action-details > summary::-webkit-details-marker { display: none; }
.action-details-form {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 10;
  min-width: 18rem;
  background: var(--warn-bg);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  box-shadow: var(--shadow);
}
@media (max-width: 720px) {
  .action-details-form { left: 0; right: 0; min-width: auto; }
}

/* --- File input stylé (fallback hors dropzone) ------------------------- */

input[type="file"]:not(.dropzone input) {
  padding: 0.5rem;
  background: var(--bg);
  border: 1px dashed var(--border-strong);
  cursor: pointer;
}
input[type="file"]:not(.dropzone input):hover {
  border-color: var(--primary);
}
input[type="file"]::file-selector-button {
  padding: 0.4rem 0.85rem;
  margin-right: 0.75rem;
  background: var(--primary);
  color: var(--primary-fg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
}
input[type="file"]::file-selector-button:hover {
  background: var(--primary-hover);
}

/* --- Dropzone (drag & drop pour upload photo) -------------------------- */

.dropzone {
  position: relative;
  display: block;
  padding: 1.5rem;
  background: var(--bg);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  transition: border-color 0.15s, background-color 0.15s;
  cursor: pointer;
  margin-bottom: 0.5rem;
}
.dropzone:hover { border-color: var(--primary); }
.dropzone:focus-within {
  border-color: var(--primary);
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.dropzone.dragging {
  border-color: var(--primary);
  background: var(--success-bg);
  border-style: solid;
}

/* L'input file est masqué visuellement mais reste fonctionnel
   (clic depuis le bouton Parcourir + accessible aux lecteurs d'écran). */
.dropzone > input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.dropzone-prompt {
  text-align: center;
  pointer-events: auto;
}
.dropzone-prompt svg {
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.dropzone-prompt p {
  margin: 0.25rem 0;
}
.dropzone-prompt .btn {
  margin: 0 0.25rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
}

.dropzone-selected {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.dropzone-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  flex-shrink: 0;
}
.dropzone-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.dropzone-info .dropzone-filename {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dropzone-clear {
  flex-shrink: 0;
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
}
.dropzone.dragging .dropzone-prompt strong {
  color: var(--primary);
}

/* --- Settings (sidebar + content) --------------------------------------- */

.settings-container {
  display: grid;
  grid-template-columns: 16rem 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 720px) {
  .settings-container { grid-template-columns: 1fr; }
}

.settings-sidebar {
  position: sticky;
  top: 5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
@media (max-width: 720px) {
  .settings-sidebar { position: static; }
}

.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.settings-nav a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  color: var(--fg);
  font-weight: 500;
  font-size: 0.95rem;
  text-decoration: none;
  transition: background-color 0.15s;
}
.settings-nav a:hover { background: var(--bg); text-decoration: none; }
.settings-nav a.active {
  background: var(--primary);
  color: var(--primary-fg);
}
.settings-nav a.muted {
  color: var(--muted);
  font-style: italic;
}
.settings-nav a small {
  font-size: 0.75rem;
  opacity: 0.7;
}

.settings-main {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.info-block {
  background: var(--warn-bg);
  border-left: 3px solid var(--warn);
  padding: 0.75rem 1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 1rem 0;
  font-size: 0.95rem;
}

/* --- Fieldsets pour les groupes de settings ----------------------------- */

.settings-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem 0.75rem;
  margin: 1rem 0;
}
.settings-fieldset legend {
  padding: 0 0.5rem;
  font-weight: 600;
  color: var(--primary);
}

/* Toggle / radio rows ---------------------------------------------------- */

.toggle-row,
.radio-row {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 0.65rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  margin: 0;
}
.toggle-row:hover,
.radio-row:hover {
  background: var(--bg);
}
.toggle-row input,
.radio-row input {
  margin: 0;
  margin-top: 0.2rem;
  flex-shrink: 0;
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--primary);
  cursor: pointer;
}
.toggle-row strong,
.radio-row strong {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
}
.toggle-row small,
.radio-row small {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.15rem;
}

.inline-number {
  width: 4rem !important;
  display: inline-block !important;
  margin: 0 0.25rem !important;
  padding: 0.2rem 0.4rem !important;
  text-align: center;
}

.advanced-fieldset {
  margin: 1.25rem 0;
  padding: 0.5rem 0.75rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.advanced-fieldset > summary {
  cursor: pointer;
  padding: 0.4rem 0;
  font-weight: 600;
  color: var(--muted);
}
.advanced-fieldset[open] > summary {
  color: var(--primary);
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

/* --- Table types de filiations ----------------------------------------- */

.rel-types-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.rel-types-table th,
.rel-types-table td {
  padding: 0.6rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.rel-types-table th {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.rel-types-table tr:last-child td { border-bottom: none; }
.rel-types-table code {
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--primary);
}
@media (max-width: 720px) {
  .rel-types-table th:nth-child(2),
  .rel-types-table td:nth-child(2),
  .rel-types-table th:nth-child(5),
  .rel-types-table td:nth-child(5) {
    display: none;  /* Cache code et parental sur mobile */
  }
}

/* --- Règles spécifiques (forbidden/forced) ----------------------------- */

.rule-types-explainer {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}
.rule-types-explainer li {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}
.rule-types-explainer li:last-child { border-bottom: none; }
.rule-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 1rem;
}
.rule-icon-forbidden { background: var(--danger-bg); }
.rule-icon-forced    { background: var(--success-bg); }

.rules-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.rules-table th,
.rules-table td {
  padding: 0.7rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.rules-table th {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.rules-table tr:last-child td { border-bottom: none; }
.rule-row.rule-forbidden td:first-child {
  border-left: 3px solid var(--danger);
}
.rule-row.rule-forced td:first-child {
  border-left: 3px solid var(--success);
}
@media (max-width: 720px) {
  /* Sur mobile, masquer la "raison" et la "portée" pour gagner de la place */
  .rules-table th:nth-child(5),
  .rules-table td:nth-child(5),
  .rules-table th:nth-child(6),
  .rules-table td:nth-child(6) {
    display: none;
  }
}

/* --- Lien WhatsApp sur fiche membre ------------------------------------ */

.phone-link-wa {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.15rem 0.6rem;
  background: var(--success-bg);
  color: var(--success);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.15s;
}
.phone-link-wa:hover {
  background: var(--success);
  color: white;
  text-decoration: none;
}

/* --- Filiations (relationship-list sur fiche membre) -------------------- */

.relationship-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}
.relationship-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.relationship-item:last-child { border-bottom: none; }

.rel-label-badge {
  display: inline-flex;
  padding: 0.25rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  flex-shrink: 0;
}
.rel-label-badge.rel-parental {
  background: var(--success-bg);
  border-color: var(--success);
  color: var(--success);
}
.rel-arrow {
  color: var(--muted);
  font-size: 0.9rem;
}

.rel-target {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--fg);
  flex: 1;
  min-width: 0;
  transition: background-color 0.15s;
}
.rel-target:hover {
  background: var(--bg);
  text-decoration: none;
  color: var(--primary);
}
.rel-target strong {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rel-target small {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

/* --- Toggle "Ajouter une filiation" ------------------------------------ */

.add-relationship-toggle {
  margin-top: 0.5rem;
}
.add-relationship-toggle > summary {
  cursor: pointer;
  display: inline-flex;
  list-style: none;
}
.add-relationship-toggle > summary::-webkit-details-marker { display: none; }
.add-relationship-toggle[open] > summary {
  margin-bottom: 0.75rem;
}
.add-relationship-form {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.add-relationship-form select { margin-bottom: 0.25rem; }

/* --- Page d'accueil : grille 2 colonnes ------------------------------- */

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 720px) {
  .home-grid { grid-template-columns: 1fr; }
}

/* --- Page sélection modes arbre --------------------------------------- */

.tree-modes-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}
@media (max-width: 720px) {
  .tree-modes-grid { grid-template-columns: 1fr; }
}

/* --- Arbre généalogique (vue centrée + vue liste) --------------------- */

.view-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.2rem;
}
.view-toggle a {
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}
.view-toggle a:hover { color: var(--fg); text-decoration: none; }
.view-toggle a.active {
  background: var(--primary);
  color: var(--primary-fg);
}

.tree-canvas-card {
  overflow-x: auto;
  padding: 1rem;
}

.tree-canvas {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  min-width: max-content;
  position: relative;
}

.tree-svg-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  color: var(--primary);
}
.tree-canvas > .tree-generation { position: relative; z-index: 2; }

.tree-generation {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  position: relative;
}
.tree-generation::before {
  content: "";
  position: absolute;
  top: -0.75rem;
  left: 0;
  right: 0;
  border-top: 1px dashed var(--border);
}
.tree-generation:first-child::before { display: none; }

.tree-gen-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.75rem;
  background: var(--bg-elevated);
  border-radius: 999px;
}
.tree-generation-center .tree-gen-label {
  background: var(--success-bg);
  color: var(--success);
}

.tree-gen-cards {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  padding: 0.5rem 0;
}

/* --- Carte d'arbre -------------------------------------------------- */

.tree-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.85rem;
  min-width: 10rem;
  max-width: 12rem;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--fg);
  text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.tree-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--fg);
  transform: translateY(-2px);
}
.tree-card-center {
  border-color: var(--primary);
  background: var(--success-bg);
  cursor: default;
  box-shadow: 0 0 0 4px rgba(15, 76, 58, 0.15);
}
html.dark .tree-card-center {
  box-shadow: 0 0 0 4px rgba(79, 173, 138, 0.25);
}
.tree-card-deceased { opacity: 0.7; }
.tree-card-deceased .avatar { filter: grayscale(0.6); }
.tree-card-inactive { opacity: 0.6; }

.tree-card-label {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  background: var(--bg);
  color: var(--muted);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tree-card-name {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.2;
}
.tree-card-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.tree-empty-notice {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

/* --- Vue liste indentée -------------------------------------------- */

.tree-list-indent {
  list-style: none;
  padding-left: 0;
  margin: 0.5rem 0;
}
.tree-list-indent ul {
  list-style: none;
  padding-left: 1.5rem;
  margin: 0.5rem 0;
  border-left: 2px dashed var(--border);
}
.tree-list-indent li {
  padding: 0.35rem 0;
}
.tree-list-indent .tree-card {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
  text-align: left;
  min-width: 0;
  max-width: none;
  padding: 0.5rem 0.85rem;
}
.tree-list-indent .tree-card-body { display: flex; flex-direction: column; }
.tree-list-level { padding: 0.5rem 0; }

/* --- Tirages : preview + détail (pair cards) ------------------------- */

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

.pair-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.pair-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }

.pair-side {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}
.pair-side > div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.pair-side strong {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pair-side small {
  color: var(--muted);
  font-size: 0.75rem;
}

.pair-arrow {
  flex-shrink: 0;
  color: var(--primary);
  font-size: 1.5rem;
  font-weight: 700;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

/* --- Cartes giver isolé sur la preview --------------------------------- */

.isolated-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  margin-bottom: .75rem;
  flex-wrap: wrap;
}
.isolated-card .entity-main {
  flex: 1;
  min-width: 14rem;
}
.isolated-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: flex-start;
  position: relative;
}
.isolated-manual {
  display: inline-block;
  position: relative;
}
.isolated-manual > summary {
  cursor: pointer;
  display: inline-flex;
  list-style: none;
}
.isolated-manual > summary::-webkit-details-marker { display: none; }
.isolated-manual-form {
  position: absolute;
  top: calc(100% + .4rem);
  right: 0;
  z-index: 10;
  min-width: 18rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  box-shadow: var(--shadow-lg);
}
.preview-actions form { margin: 0; }
@media (max-width: 720px) {
  .preview-actions { flex-direction: column; align-items: stretch; }
  .preview-actions form { width: 100%; }
  .preview-actions .btn { width: 100%; }
}

/* --- Historique sur fiche membre --------------------------------------- */

.history-list {
  list-style: none;
  padding: 0;
  margin: .5rem 0 1rem;
}
.history-list li {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  font-size: .95rem;
}
.history-list li:last-child { border-bottom: none; }
.history-list strong {
  min-width: 3.5rem;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.hist-arrow {
  color: var(--muted);
  font-weight: 600;
}
.hist-target {
  font-weight: 600;
}

/* --- Import CSV preview table ----------------------------------------- */

.import-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.import-preview-table th,
.import-preview-table td {
  padding: .65rem .5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.import-preview-table th {
  font-weight: 600;
  font-size: .8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.import-preview-table select {
  min-width: 12rem;
  padding: .3rem .5rem;
  margin-bottom: 0;
}
.import-row-ok        { background: var(--bg-elevated); }
.import-row-ambiguous { background: var(--warn-bg); }
.import-row-not_found { background: var(--danger-bg); }
.import-row-error     { background: var(--danger-bg); opacity: .7; }
.import-row .inline-checkbox {
  display: flex;
  margin-bottom: .25rem;
  font-size: .85rem;
}
.import-row .inline-checkbox input { margin-right: .35rem; }

@media (max-width: 720px) {
  .import-preview-table th:nth-child(1),
  .import-preview-table td:nth-child(1) { display: none; }  /* Cache # */
}

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

.site-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

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

@media (max-width: 720px) {
  .header-inner {
    padding: 0.6rem 0.85rem;
  }
  .main-nav {
    order: 3;
    width: 100%;
    justify-content: flex-start;
  }
  .a11y-toolbar {
    margin-left: auto;
  }
  main.main { padding: 1.5rem 0.85rem; }
  h1 { font-size: 1.6rem; }
}

/* Animation subtile à l'apparition des cartes */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.card { animation: fadeInUp 0.3s ease-out; }

/* Reduce motion respecté */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .card { animation: none; }
}
