/* Mode sombre automatique (Karim, 17 oct. 2026).
   S'applique seulement quand l'appareil est regle en mode sombre, et jamais a
   l'impression (@media screen) : les feuilles imprimees restent claires et
   contrastees. Charge EN DERNIER sur chaque page, pour passer devant les
   couleurs ecrites en dur dans les autres feuilles.
   Un meme jeton servait a la fois de fond (en-tete, pied) et de couleur de
   texte (liens du menu, etiquettes) : en sombre, le jeton devient la couleur
   du texte (vert clair) et les fonds concernes sont repris un par un. */

@media screen and (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --fond: #0E1613;
    --surface: #17211D;
    --surface-muted: #1D2A25;
    --text-main: #E3ECE7;
    --border: #2E3D36;
    --vert-teinte: #1D352D;
    --vert-fonce: #9ED9C3;      /* texte : titres, liens du menu */
    --brand-black: #9ED9C3;
    --brand-gold: #1D352D;
    --brand-gold-soft: #17211D;
    --vert: #23866B;
    --vert-survol: #2A9C7D;
    --brand-orange: #23866B;
    --brand-orange-deep: #2A9C7D;
    --texte-doux: #B4C2BB;
    --ok: #86D39F;
    --erreur: #FF9C94;
  }

  body { background: var(--fond); color: var(--text-main); }
  a { color: #8CC8FF; }
  a:visited { color: #C3A8FF; }

  /* Bandeaux du haut et du bas : restent vert sapin fonce */
  header, footer { background: #0A2A22; color: #F2F7F4; }
  header h1, header h3, footer, footer a { color: #F2F7F4; }
  nav { background: var(--surface); }
  nav a { color: var(--brand-black); }
  nav a:hover { color: #C8F0E1; }
  main { background: var(--surface); border-color: var(--border); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45); }

  /* Champs */
  input, textarea, select, .status-select, .fiche input, .fiche select,
  .question-edition select, .affectation select, .form-remplacant input, .form-remplacant select {
    background: #0F1916;
    color: var(--text-main);
    border-color: #3A4B44;
  }
  input::placeholder, textarea::placeholder { color: #7F8F88; }

  /* Tout ce qui etait sur fond blanc */
  .reservation-panel, .reservations-panel, .period-option, .reservation-card, .boite-adresses,
  .sondage-carte, .question-edition, .textes-libres li, .tuile-chiffre, .filtre, .table-operateurs,
  .fiche, .onglets-page button, .form-remplacant, .fiche-remplacant, .admin-tuile, .apercu-courriel,
  .suivi-carte, .onglet-membre, .entete-membre, .carte-resa, .info-carte, .publiees,
  .confirmation-non, dialog.confirmation, .sondages-liste, table.car-list td {
    background: var(--surface);
    color: var(--text-main);
  }
  /* Pages Administrateurs et Conseil : leurs cartes et leur liste de
     recherche gardaient un fond blanc ecrit en dur, sur lequel le texte
     clair du mode sombre devenait invisible (signale par Karim,
     18 oct. 2026). */
  .fiche-admin, #liste-recherche, #liste-recherche button,
  .ca-table, .ca-table td, .ca-table th, .message-lu, .courrier, .paiement {
    background: var(--surface);
    color: var(--text-main);
  }
  #liste-recherche button:hover { background: var(--vert-teinte); }
  #liste-recherche { border-color: var(--border); }
  #liste-recherche button { border-bottom-color: var(--border); }
  .fiche-admin { border-color: var(--border); }
  /* Le code QR du Coffre-fort doit rester sur fond blanc : c'est ce qui le
     rend lisible par l'appareil photo. */
  .qr .image { background: #fff; }

  .period-fieldset, .sondage-question, .coordonnees { background: rgba(255, 255, 255, 0.04); }
  .tuile-chiffre:hover { background: #20302A; }
  .table-operateurs tbody tr:nth-child(even) { background: #1B2722; }
  .fiche-avis { background: #33291A; }
  .dispo-jour.non { background: #222; color: #A3AAA6; border-color: #3A403D; }
  .barre-resultat .jauge, .suivi-carte .jauge { background: #0F1916; border-color: #6E7C76; }
  .barre-resultat .jauge span, .suivi-carte .jauge span { background: #9ED9C3; }

  /* Textes gris fonce devenus illisibles */
  .section-intro, .reservation-card__label, .coordonnees span, .stat-detail, .sondage-intro,
  .sondage-question .facultatif, .pastille.brouillon, .courriel-operateur, .berline-type,
  .fiche-factures .etat, .numero-membre, .titre-groupe, .affectation label, .badge-statut.canceled,
  .info-pied, .info-vide, .etat-retiree, .admin-chiffre, .apercu-corps, .table-operateurs a,
  .tuile-chiffre {
    color: var(--texte-doux);
  }
  .tuile-chiffre { border-left-color: #6E7C76; }
  .table-operateurs th { border-bottom-color: #6E7C76; }
  .table-operateurs td, .sondages-liste th, .sondages-liste td, .sondages-liste tr,
  .table-operateurs tr, .fiche-berlines, .fiche input, .fiche select, .apercu-courriel, .apercu-corps {
    border-color: #3A4B44;
  }

  /* Etats : vert et rouge eclaircis pour rester lisibles sur fond sombre */
  .sondage-merci, .sondage-message.ok, .pastille.ouvert, .pastille-paiement.paye, .message-remplacants.ok,
  .dossier-etat.complet, .message-resa.ok, .badge-statut.confirmed { color: var(--ok); }
  .sondage-message.erreur, .pastille.ferme, .telephone-manquant, .pastille-paiement.impaye, .requis,
  .fiche-message, .fiche-factures .etat.echec, .message-remres.err, .message-remplacants.err,
  .dossier-etat.incomplet, .message-resa.err, .manquant, .bandeau-simulation { color: var(--erreur); }
  .bandeau-simulation { border-color: var(--erreur); }
  .pastille-paiement.exempte, .badge-statut.pending { color: #E8C36A; }
  .reservation-badge--pending { background: #3A3214; color: #F2D98A; }
  .reservation-badge--confirmed { background: #183A22; color: #9BE0AE; }
  .reservation-badge--canceled { background: #3D1A1D; color: #F4A9AF; }
  .tuile-paye { border-left-color: #4FA866; }
  .tuile-impaye { border-left-color: #E06A60; }

  /* Administration : l'onglet et les tuiles gardent leur rouge, eclairci */
  .admin-tuile h2 { color: #FF8A80; }

  /* Babillard */
  .detour .info-type { background: #4A3410; color: #FFD9A8; }
  .important .info-type { background: #4A1C1C; color: #FFC2BD; }
  .info-titre { color: #C8F0E1; }

  /* Fenetre de confirmation */
  dialog.confirmation::backdrop { background: rgba(0, 0, 0, 0.65); }
  .confirmation-non { color: #C8F0E1; border-color: #6E9C8C; }

  /* Ombres : sur fond sombre, une ombre noire plus franche */
  .reservation-card, .sondage-carte, .admin-tuile, .fiche { box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5); }
}
