:root {
  --rouge: #ff4d4c; --rouge-fonce: #e04342; --rouge-profond: #c9382b; --rouge-nuit: #a52e23; --orange: #ff874a; --jaune: #ffca4a;
  --encre: #1a1a1a; --corps: #4d4d4d; --discret: #6b6b6b;
  --page: #f4f4f4; --blanc: #fff; --rosee: #fff6f6; --creme: #fffdf7; --filet: #e6e6e6;
  --vert: #2e7d32; --vert-fond: #e8f5e9;
  --rayon: 12px;
  font-family: 'Montserrat', Arial, sans-serif;
  color: var(--encre);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); font-size: 14px; line-height: 1.5; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }

.bandeau-demo { background: var(--encre); color: var(--jaune); text-align: center; font-weight: 700; font-size: 12px; padding: 6px 12px; letter-spacing: .3px; }

/* Boutons */
.btn { background: var(--rouge-profond); color: #fff; border: 0; border-bottom: 3px solid var(--rouge-nuit); border-radius: 8px; padding: 10px 16px; font-weight: 700; font-size: 12px; letter-spacing: .6px; text-transform: uppercase; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--rouge-nuit); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondaire { background: var(--blanc); color: var(--encre); border: 1.5px solid var(--encre); border-bottom-width: 3px; }
.btn-secondaire:hover { background: var(--rosee); }
.btn-vert { background: var(--vert); border-bottom-color: #1b5e20; }
.lien { background: none; border: 0; color: var(--rouge-nuit); font-weight: 700; cursor: pointer; padding: 4px; text-decoration: underline; }
.mini { font-size: 11px; padding: 6px 10px; }

/* Rails (motif du site) */
.rail { position: relative; height: 26px; }
.rail::before, .rail::after { content: ''; position: absolute; left: 0; right: 0; }
.rail::before { top: 9px; height: 7px; background: var(--rouge); }
.rail::after { top: 19px; height: 3px; background: var(--jaune); }
.rail span { position: absolute; left: 50%; top: 1px; width: 24px; height: 24px; margin-left: -12px; border-radius: 50%; background: #fff; border: 5px solid var(--rouge); z-index: 1; }
.rail-plein { margin: 0; }

/* Connexion */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.carte-connexion { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 28px 24px; box-shadow: 0 6px 24px rgba(0,0,0,.08); text-align: center; }
.carte-connexion .logo { width: 150px; height: auto; margin: 0 auto 10px; display: block; }
.carte-connexion .rail { margin: 0 -24px 16px; }
.accroche { font-family: 'Caveat', cursive; font-size: 22px; color: var(--rouge-profond); margin: 0; }
.carte-connexion h1 { font-size: 22px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 20px; }
.pile { display: flex; flex-direction: column; gap: 8px; text-align: left; }
label { font-weight: 700; font-size: 12px; }
input[type=text], input[type=tel], input[type=url], input:not([type]), textarea, select { width: 100%; border: 1.5px solid #cfcfcf; border-radius: 8px; padding: 10px 12px; background: #fff; }
input:focus, textarea:focus, select:focus { border-color: var(--orange); outline: none; box-shadow: 0 0 0 3px rgba(255,135,74,.25); }
#code { font-size: 22px; letter-spacing: 8px; text-align: center; font-weight: 700; }
.separateur { display: flex; align-items: center; gap: 10px; color: var(--discret); margin: 16px 0; font-size: 12px; }
.separateur::before, .separateur::after { content: ''; flex: 1; height: 1px; background: var(--filet); }
.message { min-height: 20px; color: var(--rouge-nuit); font-weight: 600; margin: 12px 0 0; }
.message.ok { color: var(--vert); }

/* Builder : en-tête */
.entete { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: #fff; padding: 10px 16px; }
.entete-gauche, .entete-droite { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.logo-mini { width: 54px; height: auto; }
.surtitre { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--orange); }
#choix-mois { border: 0; padding: 0 22px 0 0; font-weight: 800; font-size: 18px; background: transparent; width: auto; cursor: pointer; }
.statut { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; padding: 4px 10px; border-radius: 20px; background: var(--page); }
.statut.brouillon { background: #fff3e0; color: #b45309; }
.statut.pret { background: var(--vert-fond); color: var(--vert); }
.statut.envoye { background: var(--encre); color: #fff; }
.etat { font-size: 12px; color: var(--discret); min-width: 90px; text-align: right; }

/* Mise en page deux volets */
.espace { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.05fr); gap: 0; height: calc(100vh - 92px); }
.edition { overflow-y: auto; padding: 16px 20px 60px; }
.apercu { background: #e9e9e9; display: flex; flex-direction: column; min-height: 0; }
.barre-apercu { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 14px; background: #ddd; }
.bascule { display: inline-flex; background: #fff; border-radius: 8px; padding: 3px; }
.bascule button, .onglets button, .onglets-mobile button { border: 0; background: none; padding: 6px 12px; border-radius: 6px; font-weight: 700; font-size: 12px; cursor: pointer; }
.bascule .actif, .onglets .actif, .onglets-mobile .actif { background: var(--encre); color: #fff; }
.info { font-size: 12px; color: var(--discret); margin: 0; }
.cadre-apercu { flex: 1; overflow: auto; display: flex; justify-content: center; padding: 14px; min-height: 0; }
#iframe-apercu { width: 375px; height: 100%; min-height: 600px; border: 0; background: var(--page); box-shadow: 0 4px 20px rgba(0,0,0,.12); border-radius: 10px; transition: width .2s; }
.onglets-mobile { display: none; }

/* Calendrier et manques */
.calendrier { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.jalon { background: #fff; border-radius: 10px; padding: 8px 12px; border: 1px solid var(--filet); font-size: 12px; }
.jalon b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--discret); }
.manques { margin-bottom: 14px; }
.manques .boite { background: #fff8f0; border: 1px solid #ffd9bf; border-radius: 10px; padding: 10px 14px; }
.manques .boite.ok { background: var(--vert-fond); border-color: #b9dcbb; color: var(--vert); font-weight: 700; }
.manques ul { margin: 6px 0 0; padding-left: 18px; }
.manques a { color: var(--rouge-nuit); font-weight: 600; }

/* Cartes de section */
.section { background: #fff; border-radius: var(--rayon); margin-bottom: 12px; border: 1px solid var(--filet); }
.section > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 14px 16px; cursor: pointer; }
.section > summary::-webkit-details-marker { display: none; }
.section > summary::after { content: '▾'; margin-left: auto; color: var(--discret); transition: transform .15s; }
.section[open] > summary::after { transform: rotate(180deg); }
.section h2 { font-size: 15px; font-weight: 800; }
.pastille { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; padding: 3px 8px; border-radius: 20px; }
.pastille.humain { background: var(--rosee); color: var(--rouge-nuit); }
.pastille.api { background: #e8f1f8; color: #24597a; }
.pastille.alerte { background: #fff3e0; color: #b45309; }
.pastille.masque { background: var(--page); color: var(--discret); }
.corps-section { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.champ { display: flex; flex-direction: column; gap: 5px; }
.champ small { color: var(--discret); font-size: 12px; }
textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
.deux { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.interrupteur { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 12px; cursor: pointer; }
.interrupteur input { width: 16px; height: 16px; accent-color: var(--rouge); }
.titre-requis input { font-weight: 700; font-size: 16px; }

/* Image choisie */
.image-choisie { display: flex; gap: 12px; align-items: center; background: var(--page); border-radius: 10px; padding: 8px; }
.image-choisie img { width: 120px; height: 72px; object-fit: cover; border-radius: 6px; background: #ddd; }
.image-choisie .vide { width: 120px; height: 72px; border-radius: 6px; border: 2px dashed #ccc; display: grid; place-items: center; color: var(--discret); font-size: 11px; }

/* Listes d'événements */
.recherche { margin-bottom: 4px; }
.liste-ev { max-height: 340px; overflow-y: auto; border: 1px solid var(--filet); border-radius: 10px; }
.ev { display: grid; grid-template-columns: 22px 64px 1fr; gap: 10px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--filet); cursor: pointer; }
.ev:last-child { border-bottom: 0; }
.ev:hover { background: var(--creme); }
.ev input { width: 16px; height: 16px; accent-color: var(--rouge); }
.ev img, .ev .sans-image { width: 64px; height: 30px; object-fit: cover; border-radius: 4px; background: #eee; }
.ev .t { font-weight: 700; font-size: 13px; line-height: 1.3; }
.ev .d { font-size: 11px; color: var(--discret); }
.ev .etoile { color: var(--orange); font-weight: 700; }
.ev.inactif { opacity: .45; cursor: not-allowed; }
.compteur { font-size: 12px; font-weight: 700; color: var(--discret); }

/* Ordre des catégories */
.cats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cat { display: flex; align-items: center; gap: 10px; background: var(--page); border-radius: 8px; padding: 8px 10px; }
.cat .nom { font-weight: 700; flex: 1; }
.cat .nb { font-size: 11px; color: var(--discret); }
.cat button { border: 1px solid #ccc; background: #fff; border-radius: 6px; width: 30px; height: 28px; cursor: pointer; font-weight: 700; }
.cat button:disabled { opacity: .3; cursor: default; }
.cat.vide { opacity: .5; }

/* Journal */
.journal { margin-top: 18px; font-size: 12px; color: var(--discret); }
.journal summary { cursor: pointer; font-weight: 700; }
.journal ol { padding-left: 18px; }

/* Dialogues */
.dialogue { border: 0; border-radius: 16px; padding: 0; width: min(860px, 94vw); max-height: 86vh; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialogue.petit { width: min(440px, 94vw); padding: 20px; }
.dialogue::backdrop { background: rgba(26,26,26,.5); }
.dialogue-tete { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--filet); }
.dialogue h2 { font-size: 16px; }
.onglets { display: flex; gap: 6px; padding: 10px 18px; }
.grille-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 0 18px 18px; overflow-y: auto; max-height: 60vh; }
.vignette { border: 2px solid transparent; border-radius: 10px; padding: 0; background: var(--page); cursor: pointer; text-align: left; overflow: hidden; }
.vignette:hover, .vignette:focus-visible { border-color: var(--rouge); }
.vignette img { width: 100%; height: 90px; object-fit: cover; display: block; }
.vignette span { display: block; font-size: 11px; padding: 5px 7px; line-height: 1.3; }
#zone-url { padding: 0 18px 18px; }
.rangee { display: flex; justify-content: flex-end; gap: 10px; align-items: center; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--encre); color: #fff; padding: 10px 18px; border-radius: 10px; font-weight: 600; z-index: 10; max-width: 92vw; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.erreur { background: var(--rouge-nuit); }

/* Mobile : une vue à la fois */
@media (max-width: 900px) {
  .espace { grid-template-columns: 1fr; height: auto; }
  .onglets-mobile { display: flex; gap: 6px; padding: 8px 16px; background: #fff; position: sticky; top: 0; z-index: 2; }
  .builder[data-vue=edition] .apercu { display: none; }
  .builder[data-vue=apercu] .edition { display: none; }
  .apercu { min-height: calc(100vh - 160px); }
  .edition { padding: 12px 12px 60px; }
  .entete { padding: 8px 12px; gap: 8px; }
  .entete-droite { flex-wrap: nowrap; overflow-x: auto; width: 100%; gap: 6px; padding-bottom: 2px; }
  .entete-droite .btn { padding: 7px 10px; font-size: 11px; }
  .etat { display: none; }
  #choix-mois { font-size: 16px; }
  .logo-mini { width: 40px; }
  .cadre-apercu { padding: 8px 0; }
  #iframe-apercu { max-width: 100%; border-radius: 0; }
  .deux { grid-template-columns: 1fr; }
}
