/* Thème clair/sombre (EF-UX-06) via variables CSS.
   Par défaut : suit la préférence système ; surchargé par [data-theme="clair|sombre"]. */
:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #5a5a5a;
  --accent: #1e5aa8;
  --card-bg: #f4f6f9;
  --border: #d8dee6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --fg: #e9edf2;
    --muted: #a7b0bb;
    --accent: #6fa8e6;
    --card-bg: #1d222a;
    --border: #2c333d;
  }
}
html[data-theme="clair"] {
  --bg: #ffffff; --fg: #1a1a1a; --muted: #5a5a5a;
  --accent: #1e5aa8; --card-bg: #f4f6f9; --border: #d8dee6;
}
html[data-theme="sombre"] {
  --bg: #14171c; --fg: #e9edf2; --muted: #a7b0bb;
  --accent: #6fa8e6; --card-bg: #1d222a; --border: #2c333d;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  background: var(--bg);
  color: var(--fg);
}

/* Accessibilité (RGAA) : focus visible + lien d'évitement */
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff;
  padding: .6rem 1rem; z-index: 100;
}
.skip-link:focus { left: 0; }

.site-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .8rem 1rem; border-bottom: 1px solid var(--border);
}
.brand a { font-weight: 700; text-decoration: none; color: var(--fg); }
.header-tools { display: flex; align-items: center; gap: .75rem; }
.theme-toggle {
  font-size: 1.1rem; background: var(--card-bg); color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px; padding: .35rem .6rem; cursor: pointer;
}
select { padding: .35rem .5rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card-bg); color: var(--fg); }

.site-main { max-width: 960px; margin: 0 auto; padding: 1.5rem 1rem; }
.hero h1 { margin-top: 0; }
.cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; }
.card h2 { margin-top: 0; font-size: 1.1rem; }
.muted { color: var(--muted); font-size: .95rem; }

.site-footer { border-top: 1px solid var(--border); padding: 1rem; text-align: center; }
.site-footer nav { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

/* --- Honeypot anti-spam (ES-14) : hors écran, hors tabulation --- */
.hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* --- Formulaires --- */
.contact-form, .auth-form, .traitement-form, .quartier-select-form { max-width: 640px; }
.field { display: flex; flex-direction: column; gap: .3rem; margin: 0 0 1rem; }
.field label { font-weight: 600; }
.consent-field label { font-weight: 400; display: flex; gap: .5rem; align-items: flex-start; }
.field input, .field select, .field textarea {
  padding: .55rem .6rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--fg); font: inherit; width: 100%;
}
.field .help { color: var(--muted); font-size: .9rem; }
.field-error, .form-errors { color: #b00020; font-size: .95rem; }
html[data-theme="sombre"] .field-error, html[data-theme="sombre"] .form-errors { color: #ff8a9b; }
.has-error input, .has-error select, .has-error textarea { border-color: #b00020; }
.req { color: #b00020; }
.rgpd-mention {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: .8rem 1rem; margin: 1rem 0; font-size: .92rem;
}
button, .button {
  display: inline-block; background: var(--accent); color: #fff; border: 0;
  border-radius: 8px; padding: .6rem 1.1rem; font: inherit; cursor: pointer; text-decoration: none;
}
button:hover, .button:hover { filter: brightness(1.07); }

/* --- Messages flash --- */
.flash-messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.flash { padding: .6rem .9rem; border-radius: 8px; border: 1px solid var(--border); margin-bottom: .5rem; }
.flash.success { border-color: #2e7d32; }
.flash.error { border-color: #b00020; }

/* --- Tables back-office (ENF-01 : optimisé desktop) --- */
.messages-table { width: 100%; border-collapse: collapse; }
.messages-table th, .messages-table td {
  text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border);
}
.message-detail dt { font-weight: 600; margin-top: .6rem; }
.message-detail dd { margin: 0 0 .3rem; }

/* --- Référents sur la page de quartier --- */
.referents { list-style: none; padding: 0; display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.referent-card { background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem; }
.referent-photo { max-width: 96px; border-radius: 50%; }
.cta { margin: 1rem 0; }

/* --- Éditeur Markdown (barre d'outils maison) --- */
.md-toolbar { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .4rem; }
.md-btn { background: var(--card-bg); color: var(--fg); border: 1px solid var(--border);
  border-radius: 6px; padding: .25rem .6rem; font-size: .9rem; cursor: pointer; }

/* --- Formsets (pièces jointes, liens) --- */
.formset { border: 1px solid var(--border); border-radius: 10px; padding: .8rem 1rem; margin: 1rem 0; }
.formset legend { font-weight: 600; padding: 0 .4rem; }
.formset-row { display: flex; flex-wrap: wrap; gap: .8rem; align-items: end;
  padding: .4rem 0; border-bottom: 1px dashed var(--border); }

/* --- Actualités (affichage public) --- */
.actualite { border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1rem; }
.actu-meta { color: var(--muted); font-size: .9rem; }
.actu-pj, .actu-liens { margin: .4rem 0; }
.pagination { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }

/* --- Navigation principale (en-tête) + fil d'Ariane --- */
.site-header { flex-wrap: wrap; }
.site-nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.site-nav a { text-decoration: none; color: var(--fg); font-weight: 500; }
.site-nav a:hover { color: var(--accent); }

.breadcrumb { max-width: 960px; margin: 0 auto; padding: .5rem 1rem 0; font-size: .9rem; }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem; padding: 0; margin: 0; }
.breadcrumb li + li::before { content: "\203A"; margin-right: .4rem; color: var(--muted); }
.breadcrumb a { text-decoration: none; }
.breadcrumb [aria-current="page"] { color: var(--muted); }

/* --- Sondages (vote + résultats) --- */
.vote-form .question { border: 1px solid var(--border); border-radius: 10px; padding: .6rem 1rem; margin: 1rem 0; }
.vote-form .option { display: block; padding: .25rem 0; cursor: pointer; }
.question-row { flex-direction: column; align-items: stretch; }
.resultats-liste { list-style: none; padding: 0; }
.resultats-liste li { display: grid; grid-template-columns: 1fr 2fr auto; gap: .6rem; align-items: center; margin: .35rem 0; }
.resultats-liste meter { width: 100%; height: 1rem; }
.res-valeur { color: var(--muted); font-variant-numeric: tabular-nums; }
.sondages-liste { line-height: 1.9; }

/* --- Bannière d'accueil --- */
.accueil-banniere { width: 100%; height: auto; border-radius: 12px; margin-bottom: 1rem; }
