:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e0e5ee;
  --border-strong: #c9d1e0;
  --text: #16202e;
  --text-2: #5c6b81;
  --text-3: #8b98ac;
  --accent: #2f6df6;
  --accent-soft: #e8f0ff;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --ok: #1f9d63;
  --warn: #b7791f;
  --warn-soft: #fdf6e3;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(20, 32, 51, .05), 0 4px 14px rgba(20, 32, 51, .06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0 0 10px; }
a { color: var(--accent); }

.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.row--wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ------------------------------------------------------------------ shell */

.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px; height: 56px; flex: none;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.015em; }
.brand__dot { width: 24px; height: 24px; border-radius: 7px; background: linear-gradient(135deg, #2f6df6, #6f4df6); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.brand small { font-weight: 500; color: var(--text-3); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }

.nav { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 9px; border: 1px solid var(--border); }
.nav button {
  border: 0; background: transparent; font: inherit; font-weight: 550; color: var(--text-2);
  padding: 6px 13px; border-radius: 6px; cursor: pointer;
}
.nav button:hover { color: var(--text); }
.nav button.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(20,32,51,.08); }

.view { flex: 1; min-height: 0; overflow: auto; }
.view--flush { overflow: hidden; display: flex; flex-direction: column; }
.page { max-width: 1080px; margin: 0 auto; padding: 26px 22px 60px; }
.page__head { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 18px; }
.page__head h1 { font-size: 21px; }

/* --------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; padding: 7px 13px; border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(.5px); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: #245bd4; }
.btn--danger { background: var(--surface); border-color: #eab8b8; color: var(--danger); }
.btn--danger:hover { background: var(--danger-soft); }
.btn--sm { padding: 4px 9px; font-size: 12.5px; }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.icon-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--text-2);
  width: 26px; height: 26px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; line-height: 1; flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn--danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn svg { display: block; pointer-events: none; }
.btn svg { display: block; flex: none; }

.input, .select, .textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 7px 10px;
}
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.textarea { resize: vertical; min-height: 76px; }
.textarea--code { font-family: var(--mono); font-size: 12.5px; line-height: 1.55; white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%235c6b81'/></svg>"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field__label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field__help { font-size: 11.5px; color: var(--text-3); }
.field__label .req { color: var(--danger); }

.switch { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; }

.badge {
  display: inline-block; padding: 2px 7px; border-radius: 20px; font-size: 11px; font-weight: 600;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.badge--accent { background: var(--accent-soft); color: #1c4bb8; border-color: #cfe0ff; }

/* ------------------------------------------------------------------ cards */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card__body { padding: 16px; }
.card__head { padding: 13px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card__head h3 { font-size: 14px; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
/* Les cartes Modules portent six actions sur une rangée plus large que la colonne :
   sans retour à la ligne, ↑ ↓ 🗑 sortaient de la carte. L'espaceur prend toute une ligne
   pour que ces trois icônes passent ensemble dessous, calées à droite, quelle que soit la
   largeur (un simple retour à la ligne les séparait). */
.grid > .card { min-width: 0; }
.grid .card__body .row { flex-wrap: wrap; row-gap: 4px; }  /* × 2 autour de l'espaceur = 8 px */
.grid .card__body .row > .spacer { flex-basis: 100%; height: 0; }
.grid .card__body .row > .spacer + .icon-btn { margin-left: auto; }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list__row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.list__row:last-child { border-bottom: 0; }
.list__row:hover { background: var(--surface-2); }
.list__row h4 { font-size: 14px; }
.list__link {
  flex: 1; min-width: 0; display: block; text-align: left;
  border: 0; background: none; font: inherit; color: inherit; cursor: pointer;
  padding: 2px 4px; margin: -2px -4px; border-radius: var(--radius-sm);
}
.list__link:hover h4 { color: var(--accent); text-decoration: underline; }
.list__link:focus-visible { outline: 2px solid var(--accent); }
/* Rappel du dossier, sous le nom de l'e-mail, devant la ligne d'informations. */
.list__meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 3px; }
.list__meta .badge { flex: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { text-align: center; padding: 46px 20px; color: var(--text-2); }
.empty h3 { margin-bottom: 6px; font-size: 15px; color: var(--text); }

/* -------------------------------------------------------------- dossiers */

/* Colonne calibrée pour afficher en entier un nom de dossier long
   (« Welcome journey - Boost ouvertures magasins » ≈ 295 px en 13 px gras). */
.mails { display: grid; grid-template-columns: 420px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1040px) { .mails { grid-template-columns: 1fr; } }

.folders {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 8px; display: flex; flex-direction: column; gap: 1px;
  position: sticky; top: 16px;
}
.folders__sep { height: 1px; background: var(--border); margin: 7px 2px; }
.folders__title { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); padding: 4px 8px 3px; }

.folder {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  border: 1px solid transparent; border-radius: var(--radius-sm); color: var(--text-2);
}
.folder:hover { background: var(--surface-2); color: var(--text); }
.folder.is-active { background: var(--accent-soft); border-color: #cfe0ff; color: #1c4bb8; font-weight: 600; }
.folder.is-drag-over { border-color: var(--accent); border-style: dashed; background: var(--accent-soft); }
.folder__btn {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px;
  border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left;
}
.folder__btn svg { flex: none; color: var(--text-3); }
.folder.is-active .folder__btn svg { color: currentColor; }
.folder__name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Le compteur et les actions partagent la même case : la largeur du nom ne bouge pas au survol. */
.folder__side { flex: none; width: 52px; display: flex; align-items: center; justify-content: flex-end; gap: 1px; }
.folder__count { font-size: 11.5px; color: var(--text-3); }
/* `display:none` et non `opacity:0` : des boutons invisibles décaleraient le compteur
   vers la gauche, et les totaux des dossiers ne seraient plus alignés entre eux. */
.folder__actions { display: none; gap: 1px; }
.folder--editable:hover .folder__actions, .folder--editable.is-active .folder__actions { display: flex; }
.folder--editable:hover .folder__count, .folder--editable.is-active .folder__count { display: none; }

/* -------------------------------------------------------- éditeur e-mail */

.editor { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.editor__bar {
  display: flex; align-items: center; gap: 10px; padding: 9px 16px; flex: none;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.editor__title { font-weight: 650; font-size: 15px; border: 1px solid transparent; background: transparent; padding: 4px 7px; border-radius: 6px; flex: 0 1 360px; min-width: 150px; font-family: inherit; }
.editor__title:hover { border-color: var(--border); }
.editor__title:focus { border-color: var(--accent); background: var(--surface); outline: none; }

.editor__body { flex: 1; min-height: 0; display: grid; grid-template-columns: 288px minmax(0, 1fr) 360px; }
.editor__body.is-collapsed { grid-template-columns: 288px minmax(0, 1fr) 0; }
.pane { min-height: 0; overflow: auto; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.pane--right { border-right: 0; border-left: 1px solid var(--border); }
.pane__head { padding: 11px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.pane__head h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.pane__content { padding: 12px; }

.blocks { display: flex; flex-direction: column; gap: 6px; padding: 10px; }
.block {
  display: flex; align-items: center; gap: 8px; padding: 8px 9px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.block:hover { border-color: var(--border-strong); }
.block.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.block.is-disabled { opacity: .5; }
.block.is-drag-over { border-top: 2px solid var(--accent); }
.block__grip { cursor: grab; color: var(--text-3); line-height: 0; flex: none; display: inline-flex; }
.block__grip svg { display: block; }
.block__main { min-width: 0; flex: 1; }
.block__name { font-size: 12px; color: var(--text-3); font-weight: 600; }
.block__label { font-size: 13px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.block__actions { display: flex; gap: 1px; opacity: 0; flex: none; }
/* Point d'insertion entre deux blocs : invisible au repos, révélé au survol. */
.insert {
  position: relative; height: 14px; margin: -5px 0; flex: none;
  display: flex; align-items: center; justify-content: center; cursor: copy;
}
.insert::before {
  content: ''; position: absolute; left: 4px; right: 4px; height: 2px; border-radius: 2px;
  background: var(--accent); opacity: 0; transition: opacity .12s;
}
.insert__btn {
  position: relative; z-index: 1;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 700; line-height: 17px; text-align: center;
  opacity: 0; transform: scale(.6); transition: opacity .12s, transform .12s;
}
.insert:hover::before, .insert.is-drag-over::before { opacity: 1; }
.insert:hover .insert__btn, .insert.is-drag-over .insert__btn { opacity: 1; transform: scale(1); }
.block:hover .block__actions, .block.is-selected .block__actions { opacity: 1; }

.preview { background: #e9edf4; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.preview__bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); flex: none; }
.preview__stage { flex: 1; min-height: 0; overflow: auto; display: flex; justify-content: center; padding: 18px; }
.preview__holder { flex: none; }
.preview__frame { border: 0; background: #fff; box-shadow: var(--shadow); width: 660px; height: 100%; transform-origin: top left; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); font: inherit; font-size: 12.5px; padding: 4px 11px; cursor: pointer; color: var(--text-2); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.is-active { background: var(--accent-soft); color: #1c4bb8; font-weight: 600; }

.warnings { border-top: 1px solid #f0e2c0; background: var(--warn-soft); color: var(--warn); padding: 8px 12px; font-size: 12.5px; flex: none; max-height: 108px; overflow: auto; }
.warnings ul { margin: 0; padding-left: 18px; }

/* ------------------------------------------------------------ picker */

.picker { display: flex; flex-direction: column; gap: 7px; }
.picker__item { text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; font: inherit; }
.picker__item:hover { border-color: var(--accent); background: var(--accent-soft); }
.picker__item strong { display: block; font-size: 13.5px; }
.picker__item span { font-size: 12px; color: var(--text-2); }

/* ------------------------------------------------------------ champs */

.colorfield { display: flex; align-items: center; gap: 7px; }
.colorfield input[type=color] { width: 34px; height: 32px; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; flex: none; }
.swatches { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.swatch { width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgba(0,0,0,.15); cursor: pointer; padding: 0; }

.thumb { margin-top: 6px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: repeating-conic-gradient(#f0f2f6 0 25%, #fff 0 50%) 50%/12px 12px; padding: 5px; display: block; }
.thumb img { display: block; max-width: 100%; max-height: 110px; margin: 0 auto; }

.htmlbar { display: flex; gap: 3px; margin-bottom: 4px; flex-wrap: wrap; }
.htmlbar button { border: 1px solid var(--border); background: var(--surface); border-radius: 5px; font-size: 11.5px; padding: 2px 7px; cursor: pointer; color: var(--text-2); font-family: inherit; }
.htmlbar button:hover { background: var(--surface-2); color: var(--text); }

.repeater { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px; background: var(--surface-2); display: flex; flex-direction: column; gap: 9px; }
.repeater__item { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); padding: 9px; display: flex; flex-direction: column; gap: 8px; }
.repeater__head { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); }

/* --------------------------------------------------------- éditeur module */

.modedit { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 16px; align-items: start; }
@media (max-width: 1180px) { .modedit { grid-template-columns: 1fr; } }

.fieldrow { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.fieldrow__head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; }
.fieldrow__head:hover { background: var(--surface-2); }
.fieldrow__key { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.fieldrow__body { padding: 10px; border-top: 1px solid var(--border); display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fieldrow__body .field--full { grid-column: 1 / -1; }
.fieldrow.is-drag-over { border-top: 2px solid var(--accent); }

.tplcheck { font-size: 12.5px; padding: 8px 10px; border-radius: var(--radius-sm); }
.tplcheck--ok { background: #eaf7f0; color: var(--ok); }
.tplcheck--warn { background: var(--warn-soft); color: var(--warn); }
.tplcheck--err { background: var(--danger-soft); color: var(--danger); }

/* --------------------------------------------------------------- overlays */

.overlay { position: fixed; inset: 0; background: rgba(22, 32, 46, .38); display: flex; align-items: flex-start; justify-content: center; padding: 7vh 20px 20px; z-index: 50; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border-radius: 12px; box-shadow: 0 18px 50px rgba(16,26,42,.28); width: 100%; display: flex; flex-direction: column; max-height: 84vh; }
.modal__head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal__head h2 { font-size: 15px; flex: 1; }
.modal__body { padding: 16px; overflow: auto; }
.modal__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }

.toast-host { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 7px; z-index: 90; align-items: center; }
.toast { background: #16202e; color: #fff; padding: 8px 15px; border-radius: 20px; font-size: 13px; box-shadow: 0 6px 20px rgba(16,26,42,.25); transition: opacity .3s, transform .3s; }
.toast--err { background: var(--danger); }
.toast--warn { background: var(--warn); }
.toast.is-out { opacity: 0; transform: translateY(6px); }

.savestate { font-size: 12px; color: var(--text-3); min-width: 92px; }

/* ------------------------------------------------------------ pied de page */

/* Posé sur le fond gris de l'application, sans filet ni bandeau blanc. */
.appfoot { flex: none; text-align: center; padding: 5px 0 7px; background: var(--bg); }
.appfoot__btn { border: 0; background: none; font: inherit; font-size: 11px; color: var(--text-3); cursor: pointer; padding: 1px 6px; border-radius: 5px; }
.appfoot__btn:hover { color: var(--text-2); background: var(--surface); }

.changelog { display: flex; flex-direction: column; gap: 16px; }
.changelog h4 { font-size: 13px; }
.changelog ul { margin: 5px 0 0; padding-left: 18px; color: var(--text-2); font-size: 13px; }
.changelog li { margin-bottom: 3px; }

/* Lecteur : pas d'actions de modification sur la liste des blocs */
.is-readonly .block__actions, .is-readonly .insert, .is-readonly .blocks > .btn--primary { display: none !important; }
.is-readonly .block { cursor: pointer; }
#userbox { gap: 10px; margin-left: 12px; align-items: center; }
