:root {
  --fond: #f4f5f8;
  --carte: #ffffff;
  --texte: #1c2030;
  --texte-doux: #646b7d;
  --bord: #e2e5ec;
  --accent: #ff7a1a;
  --accent-fonce: #e3650a;
  --accent-clair: #fff1e6;
  --vert: #1f9d55;
  --rouge: #d64545;
  --led-on: #ff8a2a;
  --led-off: #2a2422;
  --badge: #14161d;
  --rayon: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--texte);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--fond);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
input, select, textarea { user-select: text; -webkit-user-select: text; font: inherit; }
h2 { font-size: 16px; margin: 0; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

/* ---------- Barre du haut ---------- */
.barre {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 20px; background: var(--carte); border-bottom: 1px solid var(--bord);
}
.marque { display: flex; align-items: center; gap: 10px; min-width: 250px; }
.marque img { border-radius: 8px; }
.marque-nom { font-weight: 700; font-size: 16px; }
.marque-sous { color: var(--texte-doux); font-size: 12px; }

.programmes { display: flex; align-items: center; gap: 6px; flex: 1; position: relative; }
.programmes label { color: var(--texte-doux); font-size: 13px; margin-right: 2px; }
.programmes select { min-width: 160px; max-width: 220px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--bord); background: #fff; }

.btn {
  padding: 6px 12px; border-radius: 8px; border: 1px solid var(--bord); background: #fff; color: var(--texte);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #c8ccd6; background: #fafbfc; }
.btn-icone { padding: 6px 10px; font-weight: 700; }

.menu {
  position: absolute; top: 38px; right: 0; z-index: 20; background: #fff; border: 1px solid var(--bord);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(20, 24, 40, .14); padding: 6px; min-width: 230px;
}
.menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px; }
.menu button:hover { background: var(--fond); }
.menu hr { border: 0; border-top: 1px solid var(--bord); margin: 4px 0; }

.etat {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
  font-weight: 600; white-space: nowrap; background: #fdecec; color: var(--rouge);
}
.etat .point { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; }
.etat[data-etat="connecte"] { background: #e6f6ec; color: var(--vert); }
.etat[data-etat="connecte"] .point { background: currentColor; }
.etat[data-etat="plusieurs"] { background: #fff4e0; color: #b26a00; }

.bandeau-debug { background: #312e81; color: #fff; text-align: center; padding: 6px; font-size: 12px; font-weight: 600; }

/* ---------- Zone principale ---------- */
.principal { display: grid; grid-template-columns: 340px 1fr; gap: 18px; padding: 18px 20px; overflow: hidden; min-height: 0; }
.colonne-messages { display: flex; flex-direction: column; min-height: 0; }
.aide { color: var(--texte-doux); margin: 4px 0 10px; }
.petit { font-size: 12px; }

.liste-messages { list-style: none; margin: 0; padding: 0 4px 0 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.message-item {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center;
  padding: 7px 10px; background: var(--carte); border: 2px solid transparent; border-radius: var(--rayon);
  box-shadow: 0 1px 2px rgba(20, 24, 40, .06); cursor: pointer;
}
.message-item:hover { border-color: #f2d3bb; }
.message-item.selection { border-color: var(--accent); background: var(--accent-clair); }
.message-item.inactif .mini { opacity: .35; }
.numero {
  grid-row: span 2; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--fond); font-weight: 700; color: var(--texte-doux);
}
.message-item.selection .numero { background: var(--accent); color: #fff; }
.mini { width: 136px; height: 34px; background: var(--badge); border-radius: 6px; display: block; image-rendering: pixelated; }
.resume { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12px; color: var(--texte-doux); }
.resume .coche { display: flex; align-items: center; gap: 4px; color: var(--texte); }
.resume .coche input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.resume .vide { font-style: italic; }

.editeur { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; min-height: 0; padding-right: 4px; }
.carte { background: var(--carte); border-radius: var(--rayon); padding: 16px; box-shadow: 0 1px 2px rgba(20, 24, 40, .06); }
.carte-titre { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.lecture { display: flex; gap: 6px; }

.badge-cadre {
  background: linear-gradient(180deg, #23262f, #101218); border-radius: 18px; padding: 12px;
  display: flex; justify-content: center; box-shadow: inset 0 0 0 2px #2d313c;
}
#apercu { width: 100%; max-width: 620px; height: auto; aspect-ratio: 4 / 1; display: block; }

.onglets { display: flex; gap: 4px; margin-bottom: 14px; background: var(--fond); padding: 4px; border-radius: 10px; width: fit-content; }
.onglet { border: 0; background: none; padding: 7px 16px; border-radius: 7px; color: var(--texte-doux); font-weight: 600; }
.onglet.actif { background: #fff; color: var(--texte); box-shadow: 0 1px 3px rgba(20, 24, 40, .12); }

.etiquette { display: block; font-weight: 600; margin-bottom: 6px; }
.etiquette-inline { font-weight: 600; color: var(--texte-doux); margin-right: 6px; font-size: 13px; }
#saisie {
  width: 100%; font-size: 20px; padding: 12px 14px; border-radius: 10px; border: 2px solid var(--bord); outline: none;
}
#saisie:focus { border-color: var(--accent); }

.ligne-options { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 12px; }
.choix { display: flex; align-items: center; gap: 4px; }
.choix button { border: 1px solid var(--bord); background: #fff; padding: 6px 12px; border-radius: 8px; }
.choix button.actif { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.symboles { display: flex; flex-wrap: wrap; gap: 4px; }
.symboles button { width: 32px; height: 32px; border: 1px solid var(--bord); background: #fff; border-radius: 8px; font-size: 16px; padding: 0; }
.symboles button:hover { background: var(--accent-clair); }

#largeur-image { padding: 5px; border-radius: 8px; border: 1px solid var(--bord); }
.grille-defil { overflow-x: auto; margin-top: 12px; background: var(--badge); border-radius: 10px; padding: 10px; }
#grille { display: block; cursor: crosshair; touch-action: none; }

.reglages { display: flex; flex-direction: column; gap: 16px; }
.effets { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.effet {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 6px; border-radius: 10px;
  border: 2px solid var(--bord); background: #fff; color: var(--texte);
}
.effet .ico { font-size: 20px; line-height: 1.1; }
.effet .nom { font-size: 11px; font-weight: 600; text-align: center; line-height: 1.15; }
.effet:hover { border-color: #f2d3bb; }
.effet.actif { border-color: var(--accent); background: var(--accent-clair); }

.reglage-ligne { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.reglage-ligne .etiquette { margin: 0; min-width: 120px; }
.curseur { display: flex; align-items: center; gap: 10px; flex: 1; color: var(--texte-doux); font-size: 12px; }
.curseur input { flex: 1; accent-color: var(--accent); max-width: 380px; }

.interrupteurs { gap: 26px; }
.interrupteur { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.interrupteur input { display: none; }
.interrupteur span {
  width: 40px; height: 22px; border-radius: 999px; background: #cfd3dc; position: relative; transition: background .15s;
}
.interrupteur span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff;
  transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
}
.interrupteur input:checked + span { background: var(--accent); }
.interrupteur input:checked + span::after { transform: translateX(18px); }

/* ---------- Pied ---------- */
.pied {
  display: grid; grid-template-columns: 330px 1fr auto; align-items: center; gap: 20px;
  padding: 14px 20px; background: var(--carte); border-top: 1px solid var(--bord);
}
.memoire { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--texte-doux); }
.jauge { flex: 1; height: 8px; background: var(--fond); border-radius: 99px; overflow: hidden; }
.jauge div { height: 100%; width: 0; background: var(--vert); transition: width .2s; }
.jauge div.plein { background: var(--rouge); }
.statut { min-width: 0; }
.statut-texte { font-weight: 600; }
.statut-texte.ok { color: var(--vert); }
.statut-texte.erreur { color: var(--rouge); }
.progression { height: 8px; background: var(--fond); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progression div { height: 100%; width: 0; background: var(--accent); transition: width .08s; }

.btn-envoyer {
  border: 0; border-radius: 12px; padding: 16px 34px; font-size: 17px; font-weight: 800; letter-spacing: .04em;
  background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(255, 122, 26, .35);
}
.btn-envoyer:hover:not(:disabled) { background: var(--accent-fonce); }

/* ---------- Modale ---------- */
.voile { position: fixed; inset: 0; background: rgba(15, 18, 28, .45); display: grid; place-items: center; z-index: 50; }
.voile[hidden] { display: none; }
.modale { background: #fff; border-radius: 14px; padding: 22px; width: min(620px, 92vw); max-height: 86vh; overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modale h3 { margin: 0 0 12px; font-size: 18px; }
.modale p, .modale li { line-height: 1.5; }
.modale input[type=text] { width: 100%; padding: 10px 12px; border-radius: 8px; border: 2px solid var(--bord); font-size: 15px; }
.modale pre { font-size: 11px; background: var(--fond); padding: 10px; border-radius: 8px; max-height: 50vh; overflow: auto; user-select: text; -webkit-user-select: text; }
.modale-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.btn-principal { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.btn-principal:hover:not(:disabled) { background: var(--accent-fonce) !important; }

.alerte { color: #b26a00; font-weight: 600; }
.etat.cliquable { cursor: pointer; background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(255, 122, 26, .35); }
.etat.cliquable .point { border-color: #fff; }
.bandeau-navigateur { background: #fff4e0; color: #7a4a00; text-align: center; padding: 10px 16px; font-weight: 600; }
.bandeau-navigateur a { color: inherit; }

/* ---------- Outil intégré dans une page du site (iframe) ---------- */
html.integre, html.integre body { height: auto; overflow: visible; }
html.integre body { display: block; }
html.integre .principal, html.integre .editeur, html.integre .liste-messages { overflow: visible; }
html.integre .barre { border-radius: 14px 14px 0 0; }
html.integre .pied { border-radius: 0 0 14px 14px; }

/* ---------- Largeurs réduites ---------- */
@media (max-width: 1080px) {
  .barre { flex-wrap: wrap; gap: 10px 16px; }
  .marque { min-width: 0; }
  .programmes { order: 3; flex-basis: 100%; flex-wrap: wrap; }
  .etat { margin-left: auto; }
  .principal { grid-template-columns: 1fr; }
  .liste-messages { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); overflow: visible; }
  .colonne-messages { min-height: auto; }
  .pied { grid-template-columns: 1fr; gap: 10px; }
  .btn-envoyer { width: 100%; }
  .effets { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 560px) {
  .effets { grid-template-columns: repeat(2, 1fr); }
  .liste-messages { grid-template-columns: 1fr; }
}
