/* =============================================================
   AQUASOL APP — Styles communs
   Palette cohérente avec aquasolenvironnement.fr (bleu/vert/anthracite)
   Mobile-first, utilitaire (app interne)
   ============================================================= */

:root {
  --blue:         #019CDE;
  --blue-dark:    #01679B;
  --blue-light:   #4FB8E5;
  --blue-pale:    #E6F4FB;
  --green:        #8DC63F;
  --green-light:  #B4D87E;
  --green-pale:   #F0F8E1;
  --anthracite:   #1B1B1B;
  --dark-bg:      #252220;   /* fond du header sombre, identique au site vitrine */
  --text-main:    #3D3733;
  --text-muted:   #6e6360;
  --text-faint:   #9CA3AF;
  --bg-light:     #f5fbfe;
  --bg-white:     #ffffff;
  --bg-card:      #ffffff;
  --bg-hover:     #f0f8fd;
  --border:       #cce8f4;
  --border-soft:  #e5e7eb;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.04);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.1);
  --radius-sm:    6px;
  --radius-md:    10px;
  --radius-lg:    14px;
  --header-h:     56px;

  /* Statuts — couleurs distinctes */
  --statut-demande:        #6B7280;   /* gris */
  --statut-devis_envoye:   #019CDE;   /* bleu */
  --statut-devis_valide:   #0EA5E9;   /* bleu plus clair */
  --statut-rdv_planifie:   #F59E0B;   /* orange */
  --statut-releve_termine: #8B5CF6;   /* violet */
  --statut-rapport_redige: #EC4899;   /* rose */
  --statut-rapport_envoye: #10B981;   /* vert */
  --statut-archive:        #9CA3AF;   /* gris clair */
  --statut-abandonne:      #DC2626;   /* rouge */

  /* Accent teal — pages changelog.html / rapport-diff.html uniquement */
  --teal: #2a9d8f;
  /* Fond « encart » utilisé par du HTML injecté en JS (fiche.js/app.js) */
  --bg-soft: #f6f7f9;

  color-scheme: light;
}

/* =============================================================
   MODE SOMBRE — activé via [data-theme="dark"] sur <html>
   (posé par assets/theme-toggle.js). Ne redéfinit que les jetons
   de surface/texte : les couleurs de statut/badges pastel restent
   inchangées (elles se comportent comme des étiquettes colorées,
   lisibles quel que soit le thème). --blue-pale et --blue-dark sont
   redéfinis ensemble car ils forment toujours une paire fond-pâle /
   texte-foncé (badges inclus) : les assombrir de concert préserve
   le contraste de cette paire au lieu de le casser.
   ============================================================= */
:root[data-theme="dark"] {
  color-scheme: dark;

  --text-main:    #E4E1DC;
  --text-muted:   #9B9691;
  --text-faint:   #767f89;
  --bg-light:     #14181c;
  --bg-white:     #1e2328;
  --bg-card:      #1e2328;
  --bg-hover:     #262c33;
  --border:       #333c44;
  --border-soft:  #2a3138;
  --anthracite:   #F0EEEB;

  --blue-pale:    #123244;
  --blue-dark:    #6EC6EF;
  --teal:         #2DD4BF;
  --bg-soft:      #262c33;

  --shadow-sm:    0 1px 3px rgba(0,0,0,0.35);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.45);
  --shadow-lg:    0 8px 40px rgba(0,0,0,0.6);
}

/* .btn-primary:hover utilise --blue-dark comme FOND (texte blanc dessus) :
   en clair c'est un bleu foncé (assombrit au survol), mais --blue-dark
   devient un bleu clair en sombre (pensé pour du texte sur fond sombre).
   On fige donc ce survol sur une teinte intermédiaire, indépendante du thème. */
:root[data-theme="dark"] .btn-primary:hover { background: #0489C4; }

/* Chip/texte sur grande surface qui n'a pas de fond pâle dédié : passe par
   la variable de texte plutôt que --blue-dark (réservé aux paires pâle/foncé). */
:root[data-theme="dark"] .modal-fieldset legend { color: var(--blue-dark); }
:root[data-theme="dark"] a:hover { color: var(--blue-dark); }

/* Surfaces à fond blanc/pâle codées en dur (hors badges pastel, laissés
   inchangés) : bascule vers les jetons de surface pour suivre le thème. */
:root[data-theme="dark"] .carte-card,
:root[data-theme="dark"] .modal-card,
:root[data-theme="dark"] .extrait-item,
:root[data-theme="dark"] .rich-btn,
:root[data-theme="dark"] .rich-editor,
:root[data-theme="dark"] .voisin-card {
  background: var(--bg-card);
}
:root[data-theme="dark"] .fiche-header {
  background: linear-gradient(135deg, var(--blue-pale) 0%, var(--bg-card) 100%);
}
:root[data-theme="dark"] .login-page {
  background: linear-gradient(135deg, var(--bg-light) 0%, #0d1c25 100%);
}
:root[data-theme="dark"] .modal-close:hover { background: var(--bg-hover); }
:root[data-theme="dark"] .rich-btn:active { background: var(--bg-hover); }
:root[data-theme="dark"] .btn-extraits {
  background: var(--bg-hover); color: var(--blue-dark);
  border-color: var(--border);
}
:root[data-theme="dark"] .btn-extraits:hover { background: var(--border-soft); border-color: var(--border); }

/* Bandeaux de retour fonctionnel (erreur login, géocodage GPS) : gardent
   leur teinte sémantique mais en version assombrie pour rester lisibles
   sur fond sombre (au lieu de pastel clair qui jurerait). */
:root[data-theme="dark"] .login-error {
  background: rgba(220,38,38,0.15); color: #FCA5A5;
}
:root[data-theme="dark"] .gps-reverse-note.ok      { background: rgba(16,185,129,0.14); border-color: rgba(16,185,129,0.35); color: #6EE7B7; }
:root[data-theme="dark"] .gps-reverse-note.warn    { background: rgba(245,158,11,0.14); border-color: rgba(245,158,11,0.35); color: #FCD34D; }
:root[data-theme="dark"] .gps-reverse-note.error   { background: rgba(220,38,38,0.14); border-color: rgba(220,38,38,0.35); color: #FCA5A5; }
:root[data-theme="dark"] .gps-reverse-note.loading { background: var(--bg-hover); border-color: var(--border); color: var(--text-muted); }

/* Bouton bascule de thème (☀️/🌙), injecté dans le header à côté des
   liens de nav — même langage visuel que .nav-link (texte clair sur
   header toujours sombre, quel que soit le thème de la page). */
.theme-toggle-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex-shrink: 0;
  background: transparent; border: none; border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.66); font-size: 1rem; line-height: 1;
  cursor: pointer; transition: color 0.18s, background 0.18s;
}
.theme-toggle-btn:hover { color: #fff; background: rgba(255,255,255,0.09); }

/* Bouton flottant pour les pages sans header (login) */
.theme-toggle-floating {
  position: fixed; top: 16px; right: 16px; z-index: 50;
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 50%; box-shadow: var(--shadow-sm);
  color: var(--text-muted); font-size: 1.05rem; cursor: pointer;
  transition: color 0.18s, border-color 0.18s;
}
.theme-toggle-floating:hover { color: var(--blue); border-color: var(--blue-light); }

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

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-light);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-dark); }

button { font-family: inherit; cursor: pointer; }

input, select, textarea { font-family: inherit; font-size: inherit; }

code { font-family: 'SF Mono', Monaco, Consolas, monospace; font-size: 0.86em;
       background: var(--bg-light); padding: 1px 5px; border-radius: 3px; }

/* =============================================================
   HEADER de l'app
   ============================================================= */
.app-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: var(--dark-bg);
  border-bottom: 1px solid rgba(1,156,222,0.18);
  padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}
.app-header .brand { display: flex; align-items: center; gap: 11px; font-weight: 700; }
.app-header .brand-logo-link { display: inline-flex; align-items: center; flex-shrink: 0; }
.app-header .brand-logo {
  width: 36px; height: 36px; border-radius: 6px;
  background: #fff; padding: 3px;
  object-fit: contain; flex-shrink: 0;
}
.app-header .brand-name { font-size: 0.9rem; font-weight: 800; color: #fff; letter-spacing: 0.06em; text-transform: uppercase; }
.app-header .brand-sub { font-size: 0.62rem; color: rgba(255,255,255,0.42); text-transform: uppercase; letter-spacing: 0.1em; text-decoration: none; display: inline-block; }
.app-header a.brand-sub:hover { color: var(--blue-light); }
.app-header nav { display: flex; align-items: center; gap: 4px; min-width: 0; }
.app-header .user-info { font-size: 0.8rem; color: inherit; }

/* Lien nav (Carte, Planning, Stats) — texte clair sur fond sombre, comme le site */
.nav-link { display: inline-flex; align-items: center; gap: 5px; flex-shrink: 0;
  background: transparent !important; color: rgba(255,255,255,0.66) !important;
  border: none; padding: 7px 11px; border-radius: var(--radius-sm);
  font-size: 0.78rem; font-weight: 500; letter-spacing: 0.04em;
  text-transform: uppercase; transition: color 0.18s, background 0.18s; }
.nav-link:hover { color: #fff !important; background: rgba(255,255,255,0.09) !important; }
.nav-link[aria-current="page"] { color: #fff !important; background: rgba(1,156,222,0.22) !important; }
.nav-link .nav-icon { font-size: 1rem; }
.nav-link .nav-label { font-size: 0.78rem; }

/* Menu utilisateur (dropdown) */
.user-menu { position: relative; flex-shrink: 0; }
.user-menu-toggle {
  background: transparent; border: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 11px;
  color: rgba(255,255,255,0.78); font-size: 0.8rem; font-family: inherit;
  border-radius: var(--radius-sm);
  max-width: 220px;
}
.user-menu-toggle:hover { background: rgba(255,255,255,0.09); color: #fff; }
.user-menu-toggle[aria-expanded="true"] { background: rgba(255,255,255,0.12); color: #fff; }
.user-menu-toggle .user-info {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0; color: inherit;
}
.user-menu-caret { font-size: 0.7rem; opacity: 0.7; flex-shrink: 0; }
.user-menu-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  min-width: 180px; z-index: 200; padding: 4px;
}
.user-menu-dropdown[hidden] { display: none; }
.user-menu-item {
  display: block; width: 100%; padding: 8px 12px;
  background: transparent; border: none; text-align: left;
  font-size: 0.85rem; color: var(--text-main); font-family: inherit;
  border-radius: 4px; cursor: pointer;
}
.user-menu-item:hover { background: var(--bg-hover); color: var(--blue); }

/* Mobile : header compact + labels nav masqués */
@media (max-width: 640px) {
  html, body { overflow-x: hidden; }
  .app-header { padding: 0 10px; gap: 6px; }
  .app-header .brand { gap: 8px; min-width: 0; }
  .app-header .brand-logo { width: 32px; height: 32px; }
  .app-header .brand-name { font-size: 0.8rem; letter-spacing: 0.03em; white-space: nowrap; }
  .nav-link .nav-label { display: none; }
  .nav-link { padding: 7px 8px; }
  .user-menu-toggle { padding: 7px 8px; max-width: 130px; }
  .user-menu-toggle .user-info { max-width: 90px; font-size: 0.76rem; }
}

/* =============================================================
   LAYOUT principal
   ============================================================= */
.app-main { padding: 20px 16px; max-width: 1400px; margin: 0 auto; }

@media (min-width: 768px) {
  .app-header { padding: 0 28px; }
  .app-main { padding: 28px; }
}

/* =============================================================
   BOUTONS
   ============================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  font-size: 0.85rem; font-weight: 600;
  background: var(--bg-white); color: var(--text-main);
  transition: all 0.15s;
  text-decoration: none;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary {
  background: var(--blue); color: #fff;
  border-color: var(--blue);
}
.btn-primary:hover { background: var(--blue-dark); color: #fff; }
.btn-secondary { border-color: var(--border); color: var(--text-main); }
.btn-secondary:hover { border-color: var(--blue); color: var(--blue); }
.btn-ghost { background: transparent; color: var(--text-muted); border: none; padding: 6px 10px; }
.btn-ghost:hover { color: var(--blue); background: var(--bg-hover); }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* =============================================================
   INPUTS / FORMS
   ============================================================= */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 0.78rem; font-weight: 600; color: var(--anthracite); }
.field .hint { font-size: 0.72rem; color: var(--text-muted); }
.input, .select, .textarea {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-white); color: var(--text-main);
  font-size: 0.88rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(1,156,222,0.15);
}
.textarea { min-height: 80px; resize: vertical; }
.input-row { display: flex; gap: 8px; align-items: center; }

/* =============================================================
   CARDS
   ============================================================= */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.card-title { font-size: 1.02rem; font-weight: 700; color: var(--anthracite); }
.card-subtitle { font-size: 0.78rem; color: var(--text-muted); }

/* =============================================================
   BADGES (statut, précision, etc.)
   ============================================================= */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px;
  font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  border-radius: 100px;
  background: var(--bg-light); color: var(--text-muted);
  white-space: nowrap;
}
.badge-statut { background: var(--bg-light); color: var(--anthracite); border: 1px solid currentColor; }

/* Couleurs spécifiques par statut */
.badge-statut[data-statut="demande"]        { color: var(--statut-demande); background: #F3F4F6; }
.badge-statut[data-statut="devis_envoye"]   { color: var(--statut-devis_envoye); background: var(--blue-pale); }
.badge-statut[data-statut="devis_valide"]   { color: var(--statut-devis_valide); background: #E0F2FE; }
.badge-statut[data-statut="rdv_planifie"]   { color: var(--statut-rdv_planifie); background: #FEF3C7; }
.badge-statut[data-statut="releve_termine"] { color: var(--statut-releve_termine); background: #EDE9FE; }
.badge-statut[data-statut="rapport_redige"] { color: var(--statut-rapport_redige); background: #FCE7F3; }
.badge-statut[data-statut="rapport_envoye"] { color: var(--statut-rapport_envoye); background: var(--green-pale); }
.badge-statut[data-statut="archive"]        { color: var(--statut-archive); background: #F3F4F6; }
.badge-statut[data-statut="abandonne"]      { color: var(--statut-abandonne); background: #FEE2E2; }

/* Précision GPS */
.badge-precision { font-size: 0.66rem; padding: 1px 7px; }
.badge-precision[data-prec="gps_client"] { background: var(--green-pale); color: #065F46; }
.badge-precision[data-prec="high"]       { background: var(--green-pale); color: #065F46; }
.badge-precision[data-prec="medium"]     { background: #FEF3C7; color: #92400E; }
.badge-precision[data-prec="commune"]    { background: #FEE2E2; color: #991B1B; }

/* Badges BRGM (interprétation IDPR) */
.badge-red    { background: #FEE2E2; color: #991B1B; }
.badge-orange { background: #FED7AA; color: #9A3412; }
.badge-amber  { background: #FEF3C7; color: #92400E; }
.badge-green  { background: var(--green-pale, #D1FAE5); color: #065F46; }
.badge-teal   { background: #CCFBF1; color: #115E59; }

/* =============================================================
   TABLEAU (liste clients sur desktop)
   ============================================================= */
.table-wrap { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: left; font-size: 0.85rem; }
.table th {
  background: var(--bg-light); color: var(--text-muted);
  font-weight: 600; font-size: 0.74rem;
  text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
.table tr { border-bottom: 1px solid var(--border-soft); }
.table tr:last-child { border-bottom: none; }
.table tbody tr { cursor: pointer; transition: background 0.12s; }
.table tbody tr:hover { background: var(--bg-hover); }
.table td.primary { font-weight: 600; color: var(--anthracite); }
.table td.muted { color: var(--text-muted); }
.table td.numeric { text-align: right; font-variant-numeric: tabular-nums; }

/* Pastille de complétude (tableau de bord) — mini-barre + % coloré, même code
   couleur que le widget de la fiche terrain. */
.cmpl-pill { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.cmpl-bar {
  display: inline-block; width: 46px; height: 6px; border-radius: 4px;
  background: var(--bg-light, #eef0f3); overflow: hidden; flex-shrink: 0;
}
.cmpl-bar > span { display: block; height: 100%; border-radius: 4px; transition: width 0.2s; }
.cmpl-num { font-size: 0.78rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Liste mobile (cards) */
.client-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 14px; margin-bottom: 10px;
  cursor: pointer; transition: border-color 0.15s, transform 0.12s;
}
.client-card:hover { border-color: var(--blue); }
.client-card:active { transform: scale(0.99); }
.client-card-top { display: flex; justify-content: space-between; align-items: start; gap: 10px; margin-bottom: 8px; }
.client-card-name { font-weight: 700; color: var(--anthracite); font-size: 0.94rem; }
.client-card-meta { font-size: 0.78rem; color: var(--text-muted); }
.client-card-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; font-size: 0.78rem; }

/* =============================================================
   FILTRES
   ============================================================= */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px;
  align-items: center;
}
.filters .input, .filters .select { width: auto; min-width: 0; flex: 1 1 140px; max-width: 280px; }
.filters .filter-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.filter-counter {
  font-size: 0.78rem; color: var(--text-muted);
  margin-left: auto; padding: 4px 10px;
  background: var(--bg-white); border: 1px solid var(--border); border-radius: 100px;
}

/* Boutons de filtre rapide par statut */
.quick-filters {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px;
}
.quick-filter-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 10px; font-size: 0.82rem; font-weight: 500;
  background: var(--bg-white); color: var(--text-main);
  border: 1px solid var(--border); border-radius: 100px;
  cursor: pointer; transition: all 0.15s;
}
.quick-filter-btn:hover { background: var(--bg-hover); border-color: var(--blue-light); }
.quick-filter-btn.active {
  background: var(--blue); color: white; border-color: var(--blue);
}
.quick-filter-btn .qf-count {
  background: rgba(0,0,0,0.08); padding: 1px 7px; border-radius: 100px;
  font-size: 0.72rem; font-weight: 700;
}
.quick-filter-btn.active .qf-count { background: rgba(255,255,255,0.25); }

/* =============================================================
   ÉTATS — empty, loading, error
   ============================================================= */
.empty, .loading, .error {
  text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.empty .icon, .loading .icon, .error .icon { font-size: 32px; margin-bottom: 10px; opacity: 0.6; }
.empty .title, .loading .title, .error .title { font-weight: 700; color: var(--anthracite); margin-bottom: 6px; }
.error { color: var(--statut-abandonne); }

/* =============================================================
   DÉTAIL CLIENT — panel à droite ou page entière
   ============================================================= */
.detail { display: grid; gap: 16px; }
.detail-section { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 18px; }
.detail-section-title {
  font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--blue); margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.detail-grid { display: grid; grid-template-columns: 1fr; gap: 8px 18px; font-size: 0.86rem; }
@media (min-width: 600px) { .detail-grid { grid-template-columns: minmax(140px, 180px) 1fr; } }
.detail-grid dt { color: var(--text-muted); font-size: 0.78rem; }
.detail-grid dd { color: var(--text-main); font-weight: 500; }
.detail-grid dd.numeric { font-variant-numeric: tabular-nums; }
.detail-grid dd.mono { font-family: 'SF Mono', Monaco, monospace; font-size: 0.82rem; color: var(--text-muted); }
.input-inline { width: auto; min-width: 160px; max-width: 100%; padding: 4px 8px; font-size: 0.82rem; }

/* =============================================================
   PAGE LOGIN
   ============================================================= */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--bg-light) 0%, #e6f4fb 100%);
}
.login-card {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  max-width: 380px; width: 100%;
}
.login-card .brand-logo {
  width: 64px; height: 64px; border-radius: 14px;
  background: #fff; padding: 5px; object-fit: contain;
  display: block; margin: 0 auto 16px;
  box-shadow: var(--shadow-sm);
}
.login-card h1 { font-size: 1.2rem; text-align: center; margin-bottom: 4px; }
.login-card .subtitle { text-align: center; color: var(--text-muted); font-size: 0.86rem; margin-bottom: 22px; }
.login-error {
  background: #FEF2F2; color: #991B1B; padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 0.82rem; margin-bottom: 14px; border-left: 3px solid var(--statut-abandonne);
}
.login-error[hidden] { display: none; }

/* =============================================================
   RESPONSIVE — afficher le tableau seulement >= 768px
   ============================================================= */
.show-mobile { display: block; }
.show-desktop { display: none; }
@media (min-width: 768px) {
  .show-mobile { display: none; }
  .show-desktop { display: block; }
}

/* =============================================================
   FICHE TERRAIN
   ============================================================= */
.fiche-toolbar {
  position: sticky; top: var(--header-h); z-index: 50;
  background: var(--bg-light);
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; margin-bottom: 12px;
  border-bottom: 1px solid var(--border-soft);
}
.autosave-indicator {
  font-size: 0.78rem; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
  min-height: 20px;
}
.autosave-indicator.saving  { color: var(--blue); }
.autosave-indicator.saved   { color: #065F46; }
.autosave-indicator.error   { color: var(--statut-abandonne); }

.fiche-header {
  background: linear-gradient(135deg, var(--blue-pale) 0%, #fff 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.fiche-header h1 { font-size: 1.1rem; margin-bottom: 3px; }
.fiche-header .meta { font-size: 0.82rem; color: var(--text-muted); }

.fiche-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  overflow: hidden;
}
.fiche-section > header {
  background: var(--bg-light);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  cursor: pointer;
}
.fiche-section > header h3 {
  font-size: 0.86rem; color: var(--anthracite);
  font-weight: 700; display: flex; align-items: center; gap: 8px;
}
.fiche-section > header .toggle { font-size: 0.86rem; color: var(--text-muted); transition: transform 0.2s; }
.fiche-section.collapsed > header .toggle { transform: rotate(-90deg); }
.fiche-section > .body { padding: 16px; }
.fiche-section.collapsed > .body { display: none; }

.fiche-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 600px) { .fiche-grid { grid-template-columns: 1fr 1fr; } }

.fiche-grid .field-full { grid-column: 1 / -1; }

/* Checkbox custom */
.check-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
  font-size: 0.88rem;
}
.check-row input[type="checkbox"] {
  width: 18px; height: 18px; flex-shrink: 0;
  accent-color: var(--blue); cursor: pointer;
}
.check-row label { cursor: pointer; user-select: none; }

/* ──────────────────────────────────────────────────────────────────────────
   P5-1 — Mode saisie rapide terrain
   Activé via la classe .mode-terrain sur #ficheView (toggle via le bouton
   📱 Mode terrain dans le header). Cible la saisie au bord d'un champ :
   - zones tactiles agrandies (16px font + min-height)
   - masque certaines sections optionnelles
   - sections collapsées par défaut sauf affaire/sondages/essais
   ────────────────────────────────────────────────────────────────────────── */
.mode-terrain .input,
.mode-terrain .select,
.mode-terrain .textarea {
  font-size: 1rem;
  min-height: 44px;        /* taille tactile recommandée Apple/Material */
  padding: 10px 12px;
}
.mode-terrain .field label {
  font-size: 0.85rem;
  font-weight: 600;
}
.mode-terrain .btn {
  min-height: 44px;
  font-size: 0.95rem;
}
.mode-terrain .fiche-grid {
  grid-template-columns: 1fr;  /* une seule colonne en mode tactile */
}
@media (min-width: 800px) {
  .mode-terrain .fiche-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Masquer les sections rédactionnelles peu utiles sur le terrain */
.mode-terrain .fiche-section[data-section="brgm"],
.mode-terrain .fiche-section[data-section="hydrographie-secondaire"] {
  display: none;
}

/* Masquer les champs marqués optionnels (en attribut data-optional) */
.mode-terrain .field[data-optional="1"] {
  display: none;
}

/* Section "Analyse & Rapport" : ne garder que perméabilité + scénario */
.mode-terrain .fiche-section[data-section="analyse"] details { display: none; }

/* Encart suggestions auto : plus visible en mode terrain */
.mode-terrain .auto-suggest > div {
  font-size: 0.85rem !important;
  padding: 8px 12px !important;
}
.mode-terrain .auto-apply-btn {
  min-height: 36px !important;
  padding: 6px 14px !important;
}

/* Bouton ajout (sondage, essai) */
.add-item-btn {
  width: 100%; padding: 12px;
  background: var(--bg-light); border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--blue); font-weight: 600; font-size: 0.86rem;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.add-item-btn:hover { background: var(--bg-hover); border-color: var(--blue); }

/* Card sondage / essai */
.item-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
  background: var(--bg-light);
}
.item-card .item-card-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; gap: 10px;
}
.item-card .item-card-head .item-num {
  background: var(--blue); color: #fff;
  width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.82rem;
}
.item-card .item-card-title { font-weight: 600; flex: 1; }
.item-card .item-delete {
  background: transparent; border: none; color: var(--statut-abandonne);
  font-size: 1.05rem; cursor: pointer; padding: 4px 8px;
}
.item-card .item-delete:hover { background: #FEE2E2; border-radius: 4px; }

/* Tableau mesures Porchet */
.mesures-table {
  width: 100%; border-collapse: collapse; margin-top: 8px;
  font-size: 0.84rem;
}
.mesures-table th {
  background: var(--bg-white);
  padding: 6px 8px; text-align: center;
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
}
.mesures-table td { padding: 4px; }
.mesures-table input {
  width: 100%; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg-white); text-align: center;
  font-variant-numeric: tabular-nums;
}
.mesures-table input:focus { border-color: var(--blue); outline: none; }
.mesures-table .row-delete {
  background: transparent; border: none; color: var(--text-faint);
  cursor: pointer; padding: 4px;
}
.mesures-table .row-delete:hover { color: var(--statut-abandonne); }

.k-display {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--bg-white);
  border-left: 4px solid var(--green);
  border-radius: var(--radius-sm);
  display: flex; justify-content: space-between; align-items: baseline;
  flex-wrap: wrap; gap: 10px;
}
.k-display .k-label { font-size: 0.78rem; color: var(--text-muted); }
.k-display .k-value { font-family: 'Lora', Georgia, serif; font-size: 1.3rem; font-weight: 700; color: var(--green); }
.k-display .k-value.empty { color: var(--text-faint); font-style: italic; font-weight: 400; font-size: 0.88rem; font-family: inherit; }
.k-display .k-soil { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

/* =============================================================
   CONSTRUCTEUR D'HORIZONS (saisie guidée sondages)
   ============================================================= */
.horizon-builder {
  margin-top: 8px;
  padding: 10px;
  background: var(--bg-light, #f8fafc);
  border-radius: var(--radius-sm, 6px);
  overflow: hidden;
}
.horizon-builder .horizon-actions {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px;
}
.horizon-builder .horizon-actions .btn { flex: 0 1 auto; }
.horizon-builder .horizon-hint {
  font-size: 0.72rem; color: var(--text-muted);
  margin-top: 6px; font-style: italic;
}

.horizon-row {
  display: grid;
  grid-template-columns: 56px 56px 1fr 1fr 1fr 1fr 28px;
  gap: 4px;
  margin-bottom: 6px;
  font-size: 0.82rem;
  align-items: center;
}
.horizon-row input,
.horizon-row select {
  width: 100%; padding: 4px 6px; min-width: 0;
  border: 1px solid var(--border, #d1d5db); border-radius: 4px;
  background: var(--bg-white, #fff);
  font-size: 0.8rem;
}
.horizon-row .horizon-del {
  background: transparent; border: none; cursor: pointer;
  color: #c0392b; padding: 2px; font-size: 1rem;
}

/* Mobile : layout en grille 2 colonnes, dropdowns sur leurs propres lignes */
@media (max-width: 640px) {
  .horizon-row {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 8px;
    background: var(--bg-white, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    margin-bottom: 8px;
  }
  .horizon-row input[data-horizon="de"],
  .horizon-row input[data-horizon="a"] {
    /* De / À sur la 1re rangée */
  }
  .horizon-row select { grid-column: 1 / -1; }
  .horizon-row .horizon-del {
    grid-column: 1 / -1;
    justify-self: end;
    margin-top: 4px;
  }
}

/* GPS bouton */
.gps-card {
  background: var(--bg-light); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px; margin-top: 12px;
}
.gps-card .gps-result { font-family: 'SF Mono', Monaco, monospace; font-size: 0.86rem; margin-top: 8px; }

/* =============================================================
   PHOTOS TERRAIN
   ============================================================= */
.photo-upload-zone {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-bottom: 14px;
}

.photo-upload-status {
  font-size: 0.82rem; padding: 6px 10px;
  background: var(--blue-pale); border-radius: var(--radius-sm);
  color: var(--blue); margin-bottom: 10px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 4px;
}
@media (min-width: 480px) { .photo-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); } }
@media (min-width: 768px) { .photo-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }

.photo-card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: box-shadow 0.15s;
}
.photo-card:hover { box-shadow: var(--shadow-md); }

.photo-img-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--bg-light);
  overflow: hidden;
}
.photo-img-wrap img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
  transition: transform 0.2s;
}
.photo-img-wrap img:hover { transform: scale(1.04); }
.photo-err {
  display: flex; align-items: center; justify-content: center;
  height: 100%; font-size: 1.8rem; color: var(--text-faint);
}

.photo-meta {
  padding: 6px 8px;
  display: flex; flex-direction: column; gap: 5px;
  border-top: 1px solid var(--border-soft);
}
.photo-meta .item-delete {
  align-self: flex-end;
  font-size: 0.9rem; padding: 2px 7px;
}

/* Lightbox plein écran */
.photo-lightbox {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0, 0, 0, 0.93);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  animation: lb-in 0.15s ease;
}
@keyframes lb-in { from { opacity: 0; } to { opacity: 1; } }
.photo-lightbox img {
  max-width: 95vw; max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  cursor: default;
  box-shadow: 0 8px 48px rgba(0,0,0,0.6);
}
.photo-lightbox-close {
  position: absolute; top: 16px; right: 20px;
  color: rgba(255,255,255,0.8); font-size: 1.6rem; font-weight: 700;
  cursor: pointer; background: none; border: none; line-height: 1;
  transition: color 0.15s;
}
.photo-lightbox-close:hover { color: #fff; }

/* =============================================================
 * Modale générique (Nouveau client, v0.9.9)
 * ============================================================= */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(15, 30, 45, 0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  animation: modal-fade 0.15s ease;
}
.modal-backdrop[hidden] { display: none !important; }

/* Note reverse-geocoding GPS (modale nouveau client) */
.gps-reverse-note {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.84rem;
  line-height: 1.4;
  display: flex; gap: 8px; align-items: flex-start;
}
.gps-reverse-note.ok      { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }
.gps-reverse-note.warn    { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.gps-reverse-note.error   { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.gps-reverse-note.loading { background: #f3f4f6; border: 1px solid #e5e7eb; color: #475569; }
.gps-reverse-note strong { font-weight: 600; }

/* Grille cartes IGN (détail client) */
.cartes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.carte-card {
  margin: 0;
  background: #fff;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 6px;
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: box-shadow 0.15s, transform 0.15s;
}
.carte-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.08); transform: translateY(-1px); }
.carte-card img {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover;
  display: block; cursor: zoom-in; background: #f3f4f6;
}
/* Wrapper image + pin (carré, ratio 1:1). Le pin pointe exactement au centre
   géographique (GPS du client) puisque l'image WMS est centrée sur ces coords. */
.carte-img-wrap {
  position: relative; width: 100%; aspect-ratio: 1 / 1; line-height: 0;
}
.carte-img-wrap > img:not(.carte-pin) {
  width: 100%; height: 100%; object-fit: cover; display: block;
  cursor: zoom-in; background: #f3f4f6;
}
/* Couche de fond optionnelle (Plan IGN) sous l'overlay transparent (PPRI, REMNAPPE).
   Quand un fond est présent, on bascule le wrap en CSS Grid stacking : tous les
   children (base + overlay) sont placés dans la même cellule `stack` et se
   superposent. Évite les pièges de aspect-ratio + flex sans contenu en flow.
   Scopé `.carte-card` pour ne pas impacter la lightbox. */
.carte-card .carte-img-wrap:has(> img.carte-base) {
  display: grid;
  grid-template-areas: "stack";
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}
.carte-card .carte-img-wrap > img.carte-base,
.carte-card .carte-img-wrap > img.carte-base ~ img:not(.carte-pin) {
  grid-area: stack;
  position: static; /* annule l'éventuel position: absolute hérité */
}
.carte-card .carte-img-wrap > img.carte-base { cursor: default; pointer-events: none; }
/* L'overlay PPRI/REMNAPPE est un PNG transparent : si on garde le background gris
   hérité de `.carte-card img`, il opacifie le rectangle et masque entièrement le
   PlanIGN dessous (cas typique d'une zone inland sans PPRI = retour WMS vide). */
.carte-card .carte-img-wrap > img.carte-base ~ img:not(.carte-pin) {
  z-index: 1;
  background: transparent;
}
/* Le pin : pointe (bas-centre du PNG 25x41) ancrée au centre de l'image */
.carte-card img.carte-pin,
.carte-img-wrap img.carte-pin {
  position: absolute; left: 50%; top: 50%;
  width: 20px; height: 33px; /* léger downscale pour ne pas saturer */
  aspect-ratio: auto; object-fit: contain;
  transform: translate(-50%, -100%);
  pointer-events: none; cursor: default; background: transparent;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.45));
}
/* Lightbox : image plus grande, pin un peu plus gros */
.carte-img-wrap-lightbox {
  max-width: 90vw; max-height: 80vh; aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
}
.carte-img-wrap-lightbox > img:not(.carte-pin) {
  max-width: 100%; max-height: 100%; width: auto; height: auto; cursor: default;
}
/* Base + overlay s'alignent : mêmes contraintes, centrage absolu, l'overlay au-dessus */
.carte-img-wrap-lightbox > img.carte-base {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  max-width: 100%; max-height: 100%; width: auto; height: auto;
  cursor: default; pointer-events: none;
}
.carte-img-wrap-lightbox > img.carte-base + img:not(.carte-pin) {
  position: relative; z-index: 1;
}
.carte-img-wrap-lightbox img.carte-pin {
  width: 28px; height: 46px;
  max-width: none; max-height: none;
  border-radius: 0; box-shadow: none;
}
.carte-card figcaption {
  padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px;
  font-size: 0.78rem;
}
.carte-title { font-weight: 600; color: var(--text-main, #3D3733); }
.carte-source { color: var(--text-muted, #6e6360); font-size: 0.72rem; font-style: italic; }
.carte-link {
  margin-top: 4px; color: var(--blue, #019CDE); text-decoration: none;
  font-size: 0.74rem; font-weight: 600;
}
.carte-link:hover { text-decoration: underline; }
/* Sélecteur d'échelle d'impression (figures du rapport) sous chaque carte */
.carte-echelle {
  margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--border, #e5e7eb);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 0.72rem; color: var(--text-muted, #6e6360);
}
.carte-echelle-select {
  width: auto; min-width: 84px; padding: 2px 6px; font-size: 0.76rem;
}
.carte-echelle-fig { font-style: italic; }
.carte-error-msg {
  aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
  background: #f9fafb; color: var(--text-muted, #6e6360);
  font-size: 0.82rem; font-style: italic; text-align: center; padding: 12px;
}
.carte-lightbox-title {
  position: absolute; top: 16px; left: 20px; right: 60px;
  color: #fff; font-weight: 600; font-size: 0.92rem;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

@media (max-width: 640px) {
  .cartes-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .carte-card figcaption { padding: 6px 8px 8px; font-size: 0.72rem; }
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: #fff;
  border-radius: var(--radius-md, 10px);
  width: 100%; max-width: 640px;
  box-shadow: 0 12px 56px rgba(0,0,0,0.25);
  padding: 22px 26px 20px;
  animation: modal-slide 0.18s ease;
}
@keyframes modal-slide { from { transform: translateY(-12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.modal-title { margin: 0; font-size: 1.15rem; color: var(--blue, #019CDE); font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.1rem; color: var(--text-muted, #6e6360);
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.modal-close:hover { background: #f1f5f9; color: var(--text-main, #3D3733); }
.modal-subtitle { font-size: 0.84rem; color: var(--text-muted, #6e6360); margin: 0 0 14px; }
.modal-body { display: flex; flex-direction: column; gap: 14px; }
.modal-fieldset {
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 6px;
  padding: 10px 14px 12px;
  margin: 0;
}
.modal-fieldset legend {
  padding: 0 6px;
  font-size: 0.78rem; font-weight: 700; color: var(--blue-dark, #01679B);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.modal-row { display: flex; gap: 10px; flex-wrap: wrap; }
.modal-row .field { flex: 1; min-width: 120px; }
.modal-fieldset .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.modal-fieldset .field:last-child { margin-bottom: 0; }
.modal-fieldset .field span {
  font-size: 0.8rem; color: var(--text-main, #3D3733); font-weight: 500;
}
.modal-fieldset .field .req { color: #c0392b; font-weight: 700; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 4px; padding-top: 12px;
  border-top: 1px solid var(--border, #e5e7eb);
}
.modal-actions .btn { min-width: 110px; }

/* === Champs de prose extensibles + bibliothèque d'extraits === */
.field-label-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 4px;
}
.field-label-row label { margin: 0; }
/* Repère « § du rapport » : indique où le champ / la section atterrit dans le
   document généré (texte + tooltip recalculés selon la présence de sondages). */
.rapport-ref {
  flex: none; white-space: nowrap; cursor: help;
  display: inline-block;
  font-size: 0.68rem; font-weight: 600; line-height: 1.6;
  color: var(--blue-dark, #01679B);
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 10px;
  padding: 0 8px;
}
/* Colle le badge au titre (header de section et label-row sont en
   justify-content:space-between : la marge auto absorbe l'espace libre). */
.fiche-section > header .rapport-ref { margin-right: auto; font-weight: 500; }
.field-label-row .rapport-ref { margin-right: auto; }
.btn-extraits {
  flex: none; cursor: pointer;
  background: #f1f5f9; color: var(--blue-dark, #01679B);
  border: 1px solid var(--border, #e5e7eb); border-radius: 6px;
  font-size: 0.78rem; font-weight: 600; padding: 3px 9px;
  transition: background 0.15s, border-color 0.15s;
}
.btn-extraits:hover { background: #e2e8f0; border-color: #cbd5e1; }
textarea.textarea-auto { resize: vertical; overflow: hidden; min-height: 2.6em; }

.extraits-list { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; }
.extrait-item {
  display: flex; align-items: flex-start; gap: 10px;
  border: 1px solid var(--border, #e5e7eb); border-radius: 6px;
  padding: 8px 10px; background: #fff;
}
.extrait-main { flex: 1; min-width: 0; }
.extrait-label { font-weight: 700; font-size: 0.86rem; color: var(--text-main, #3D3733); }
.extrait-preview {
  font-size: 0.8rem; color: var(--text-muted, #6e6360); line-height: 1.4; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.extrait-actions { flex: none; display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.extrait-del {
  background: none; border: none; cursor: pointer; font-size: 0.95rem;
  color: var(--text-muted, #6e6360); border-radius: 6px; padding: 2px 6px;
  transition: background 0.15s, color 0.15s;
}
.extrait-del:hover { background: #fef2f2; color: #c0392b; }
/* Rendu du balisage léger dans l'aperçu des modèles */
.extrait-preview strong { font-weight: 700; color: inherit; }
.extrait-preview em { font-style: italic; }
.extrait-preview u { text-decoration: underline; }

/* Éditeur enrichi (création / modification d'un modèle) : barre d'outils + zone */
.rich-toolbar { display: flex; gap: 4px; margin-bottom: 6px; }
.rich-btn {
  min-width: 30px; height: 28px; padding: 0 8px;
  border: 1px solid var(--border, #e5e7eb); border-radius: 5px;
  background: #fff; color: var(--text-main, #3D3733); cursor: pointer;
  font-size: 0.9rem; line-height: 1; transition: background 0.15s, border-color 0.15s;
}
.rich-btn:hover { background: var(--bg-hover, #f3f4f6); border-color: var(--blue, #2b8cc4); }
.rich-btn:active { background: #e5edf5; }
.rich-editor {
  min-height: 90px; max-height: 40vh; overflow-y: auto;
  border: 1px solid var(--border, #e5e7eb); border-radius: 6px;
  padding: 8px 10px; background: #fff;
  font-size: 0.9rem; line-height: 1.5; color: var(--text-main, #3D3733); font-family: inherit;
}
.rich-editor:focus { outline: none; border-color: var(--blue, #2b8cc4); box-shadow: 0 0 0 2px rgba(43,140,196,0.15); }
.rich-editor:empty::before { content: attr(data-placeholder); color: var(--text-muted, #9ca3af); }

@media (max-width: 640px) {
  .modal-backdrop { padding: 12px 8px; }
  .modal-card { padding: 16px 14px; }
  .modal-title { font-size: 1rem; }
  .modal-row { flex-direction: column; gap: 6px; }
  .modal-row .field { min-width: 0; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}

/* Util */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-1 { gap: 6px; }
.gap-2 { gap: 12px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 18px; }
.muted { color: var(--text-muted); }
.small { font-size: 0.78rem; }
.bold { font-weight: 700; }
.tabular { font-variant-numeric: tabular-nums; }
.center { text-align: center; }

/* ── Études voisines (P4) ───────────────────────────────────────────────── */
.btn-small { padding: 4px 10px; font-size: 0.8rem; }
.voisins-box {
  margin: 0 0 16px;
  border: 1px solid var(--border, #cce8f4);
  border-radius: 8px;
  background: var(--blue-pale, #E6F4FB);
}
.voisins-box > summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--blue-dark, #01679B);
  list-style: none;
}
.voisins-box > summary::-webkit-details-marker { display: none; }
.voisins-box > summary::before { content: '▸ '; }
.voisins-box[open] > summary::before { content: '▾ '; }
.voisins-box[open] > summary { border-bottom: 1px solid var(--border, #cce8f4); }
.voisins-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  padding: 12px 14px;
}
.voisin-card {
  background: #fff;
  border: 1px solid var(--border, #cce8f4);
  border-radius: 6px;
  padding: 10px 12px;
}
.voisin-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.voisin-head strong { color: var(--anthracite, #1B1B1B); font-size: 0.92rem; }
.voisin-dist {
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem; font-weight: 700;
  color: #fff; background: var(--blue, #019CDE);
  border-radius: 100px; padding: 1px 8px; white-space: nowrap;
}
.voisin-meta { font-size: 0.78rem; color: var(--text-muted, #6e6360); margin-top: 2px; }
.voisin-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.voisin-tag {
  font-size: 0.72rem;
  background: var(--blue-pale, #E6F4FB);
  color: var(--blue-dark, #01679B);
  border-radius: 4px; padding: 2px 6px;
  cursor: help;
}
.voisin-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
