/* Studio e-mail · Arthur Villecourt. Outil de travail : ivoire et encre, un seul rouge « timbre » pour l'action.
   Signature : la barre d'acheminement envoyés → ouverts → cliqués, la même partout. */
@font-face { font-family: 'Plex'; src: url('/fonts/plex-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Plex'; src: url('/fonts/plex-400-italic.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: 'Plex'; src: url('/fonts/plex-500.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Plex'; src: url('/fonts/plex-600.woff2') format('woff2'); font-weight: 600; font-display: swap; }

:root {
  color-scheme: light;
  --ground: #f7f4ee;
  --surface: #ffffff;
  --rail: #efe9df;
  --sunk: #f2eee7;
  --ink: #1c1a17;
  --ink-2: #5b554c;
  --ink-3: #6f685e;
  --line: #e3ddd2;
  --line-strong: #cfc7b9;
  --accent: #c8402a;
  --accent-hover: #a93420;
  --accent-soft: #f6e3de;
  --on-accent: #ffffff;
  --sent: #d8d0c2;
  --opened: #2f5e8c;
  --clicked: #c8402a;
  --ok: #2f7a4b;   --ok-soft: #e3f0e7;
  --warn: #8a5a0c; --warn-soft: #f6ecd9;
  --bad: #b3261e;  --bad-soft: #f8e1df;
  --info: #2f5e8c; --info-soft: #e2eaf3;
  --focus: #2f5e8c;
  --shadow: 0 1px 2px rgba(40, 30, 15, .06), 0 6px 18px rgba(40, 30, 15, .07);
  --radius: 6px;
  --rail-w: 220px;
  font-family: 'Plex', ui-sans-serif, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--ground);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ground: #171512; --surface: #1f1c18; --rail: #13110f; --sunk: #1b1915;
    --ink: #eee8de; --ink-2: #b8afa2; --ink-3: #a39a8c; --line: #322e28; --line-strong: #4a443b;
    --accent: #e0573f; --accent-hover: #ee6c55; --accent-soft: #3a211b; --on-accent: #1a0d09;
    --sent: #4a443b; --opened: #6f9fcf; --clicked: #e0573f;
    --ok: #6fbf8b; --ok-soft: #1d2e23; --warn: #e0b060; --warn-soft: #33281a; --bad: #ef7a70; --bad-soft: #3a1f1c;
    --info: #8db5dc; --info-soft: #1c2733; --focus: #8db5dc;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--ground); color: var(--ink); -webkit-font-smoothing: antialiased; }
::selection { background: var(--accent-soft); color: var(--ink); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
a { color: inherit; text-underline-offset: 3px; }
.link { color: var(--accent); font-weight: 500; text-decoration: none; }
.link:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: 1.6rem; font-weight: 600; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: .87rem; }
.num { font-variant-numeric: tabular-nums; }
* { scrollbar-color: var(--line-strong) transparent; scrollbar-width: thin; }
::placeholder { color: var(--ink-3); }

/* ---------- coque ---------- */
.app { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100vh; }
.rail { background: var(--rail); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand-mark { font-weight: 600; font-size: .98rem; padding: 2px 10px 18px; margin: 0; }
.brand-mark span { display: block; font-weight: 400; color: var(--ink-2); font-size: .84rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius); text-decoration: none; color: var(--ink-2); font-weight: 500; transition: background .15s, color .15s; }
.nav a:hover { background: var(--sunk); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(40,30,15,.06); }
.nav a[aria-current="page"] svg { color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.rail-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: .85rem; }
.rail-foot .who { font-weight: 500; }
.rail-foot button { margin-top: 8px; }
.main { min-width: 0; padding: 28px 36px 64px; max-width: 1240px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { margin-top: 4px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); text-decoration: none; font-size: .88rem; margin-bottom: 10px; }
.back:hover { color: var(--ink); }
.back svg { width: 16px; height: 16px; }

/* ---------- boutons & formulaires ---------- */
.btn { font: inherit; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; transition: background .15s, border-color .15s, color .15s; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--sunk); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--bad); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); padding: 6px 8px; }
.btn-ghost:hover { background: var(--sunk); color: var(--ink); }
.btn svg { width: 16px; height: 16px; }
.btn[aria-busy="true"] { position: relative; color: transparent; }
.btn[aria-busy="true"]::after { content: ''; position: absolute; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-color: var(--ink-2) transparent var(--ink-2) transparent; animation: spin .7s linear infinite; }
.btn-primary[aria-busy="true"]::after { border-color: var(--on-accent) transparent var(--on-accent) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: .88rem; font-weight: 500; color: var(--ink-2); }
input[type=text], input[type=email], input[type=search], input[type=date], input[type=time], input[type=url], select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 8px 10px; width: 100%; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
input[aria-invalid="true"] { border-color: var(--bad); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .92rem; color: var(--ink); font-weight: 400; }
.check input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; }
.alert { padding: 10px 12px; border-radius: var(--radius); background: var(--bad-soft); color: var(--bad); font-size: .92rem; }
.note { padding: 10px 12px; border-radius: var(--radius); background: var(--info-soft); color: var(--info); font-size: .92rem; }
.note.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- panneaux & tableaux ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-body { padding: 18px; }
.section { margin-top: 28px; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th { text-align: left; font-weight: 500; color: var(--ink-2); font-size: .82rem; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface); }
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr.clickable { cursor: pointer; transition: background .12s; }
table.data tbody tr.clickable:hover { background: var(--sunk); }
table.data td.r, table.data th.r { text-align: right; font-variant-numeric: tabular-nums; }
.cell-title { font-weight: 500; }
.cell-sub { color: var(--ink-2); font-size: .85rem; margin-top: 2px; }
.empty { padding: 36px 18px; text-align: center; color: var(--ink-2); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.load-more { display: flex; justify-content: center; padding: 14px; border-top: 1px solid var(--line); }

/* statut */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: .8rem; font-weight: 500; background: var(--sunk); color: var(--ink-2); white-space: nowrap; }
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.DRAFT { color: var(--ink-2); }
.chip.SCHEDULED { background: var(--warn-soft); color: var(--warn); }
.chip.SENDING { background: var(--info-soft); color: var(--info); }
.chip.SENT { background: var(--ok-soft); color: var(--ok); }
.chip.FAILED { background: var(--bad-soft); color: var(--bad); }
.chip.ARCHIVED { color: var(--ink-3); }
.chip.SUBSCRIBED { background: var(--ok-soft); color: var(--ok); }
.chip.UNSUBSCRIBED, .chip.BOUNCED, .chip.COMPLAINED, .chip.BANNED { background: var(--bad-soft); color: var(--bad); }
.chip.PENDING_CONFIRMATION { background: var(--warn-soft); color: var(--warn); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 4px; background: var(--sunk); border: 1px solid var(--line); font-size: .8rem; color: var(--ink-2); margin: 2px 4px 2px 0; }

/* chiffres */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.figure { padding: 16px 18px; border-right: 1px solid var(--line); }
.figure:last-child { border-right: 0; }
.figure .label { font-size: .82rem; color: var(--ink-2); font-weight: 500; }
.figure .value { font-size: 1.5rem; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.figure .hint { font-size: .82rem; color: var(--ink-2); margin-top: 2px; font-variant-numeric: tabular-nums; }

/* signature : barre d'acheminement */
.route { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.route-bar { position: relative; height: 6px; border-radius: 3px; background: var(--sent); overflow: hidden; }
.route-bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; }
.route-bar i.o { background: var(--opened); }
.route-bar i.c { background: var(--clicked); }
.route-legend { display: flex; gap: 12px; font-size: .8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.route-legend b { font-weight: 600; color: var(--ink); }
.route-legend .o::before, .route-legend .c::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }
.route-legend .o::before { background: var(--opened); }
.route-legend .c::before { background: var(--clicked); }
.route.big .route-bar { height: 12px; border-radius: 6px; }
.route.big .route-legend { font-size: .9rem; gap: 18px; }

/* onglets */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { font: inherit; font-weight: 500; font-size: .9rem; background: none; border: 0; padding: 10px 14px; color: var(--ink-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs .count { color: var(--ink-3); font-variant-numeric: tabular-nums; margin-left: 4px; }
.toolbar-line { display: flex; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.toolbar-line input[type=search] { max-width: 300px; }
.skeleton { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--sunk), var(--line), var(--sunk)); background-size: 200% 100%; animation: shimmer 1.2s ease-in-out infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- éditeur ---------- */
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.editor-meta { display: grid; gap: 12px; margin-bottom: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0; background: var(--surface); position: sticky; top: 0; z-index: 5; }
.toolbar button { font: inherit; font-size: .88rem; min-width: 32px; height: 32px; padding: 0 8px; border: 0; background: none; border-radius: 4px; color: var(--ink-2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.toolbar button:hover { background: var(--sunk); color: var(--ink); }
.toolbar button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.toolbar svg { width: 16px; height: 16px; }
.toolbar .sep { width: 1px; background: var(--line); margin: 4px 4px; }
.canvas-wrap { background: var(--sunk); border: 1px solid var(--line); border-radius: 0 0 8px 8px; padding: 28px 16px; }
.mail-canvas { background: #fff; color: #1c1a17; max-width: 600px; margin: 0 auto; padding: 32px 36px; border-radius: 4px; box-shadow: var(--shadow); min-height: 420px; font-size: 16px; line-height: 1.6; }
.mail-canvas .ProseMirror { outline: none; min-height: 360px; }
.mail-canvas .ProseMirror > * + * { margin-top: .8em; }
.mail-canvas h2 { font-size: 1.45rem; } .mail-canvas h3 { font-size: 1.15rem; }
.mail-canvas a { color: #2f5e8c; }
.mail-canvas blockquote { margin: 0; padding-left: 14px; border-left: 1px solid #cfc7b9; color: #5b554c; }
.mail-canvas hr { border: 0; border-top: 1px solid #e3ddd2; margin: 1.2em 0; }
.mail-canvas img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.mail-canvas img.ProseMirror-selectednode, .mail-canvas .ProseMirror-selectednode { outline: 2px solid #2f5e8c; outline-offset: 2px; }
.mail-canvas p.is-editor-empty:first-child::before { content: attr(data-placeholder); color: #8b8478; float: left; height: 0; pointer-events: none; }
.mail-canvas .ms-variable { background: #e2eaf3; color: #2f5e8c; border-radius: 3px; padding: 0 4px; font-size: .92em; white-space: nowrap; }
.mail-canvas .ms-button { text-align: center; padding: 6px 0; }
.mail-canvas .ms-button span { display: inline-block; padding: 10px 32px; border-radius: 6px; font-weight: 600; color: #fff; }
.mail-canvas .ms-spacer { background: repeating-linear-gradient(90deg, #e3ddd2 0 6px, transparent 6px 12px); background-size: 100% 1px; background-repeat: no-repeat; background-position: center; }
.mail-canvas .ms-footer { margin-top: 2em; padding-top: 1em; border-top: 1px solid #e3ddd2; font-size: 13px; color: #6f685e; }
.mail-canvas .ms-footer::before { content: 'Pied de page (obligatoire, modifiable)'; display: block; font-size: 11px; color: #a39a8c; margin-bottom: 4px; }
.editor-side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 16px; }
.step-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.saved { font-size: .82rem; color: var(--ink-2); }
.saved.err { color: var(--bad); }
.tag-pick { max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; }
.tag-pick label { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 4px; font-size: .88rem; }
.tag-pick label > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-pick label:hover { background: var(--sunk); }
.tag-pick select { padding: 2px 4px; font-size: .8rem; width: auto; }
.big-count { font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.preview-frame { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.inline-pop { position: fixed; z-index: 50; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 14px; width: min(360px, calc(100vw - 32px)); }
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 22px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(28, 26, 23, .35); }

/* chronologie */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 150px 1fr; gap: 14px; padding: 9px 18px; border-bottom: 1px solid var(--line); font-size: .9rem; }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 16px; font-size: .92rem; }
.kv dt { color: var(--ink-2); } .kv dd { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* ---------- connexion ---------- */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 28px; box-shadow: var(--shadow); }
.auth-card .brand-mark { padding: 0 0 22px; }
.auth-card h1 { font-size: 1.35rem; margin-bottom: 8px; }
.auth-card .muted { margin-bottom: 20px; }
.auth-card .btn { width: 100%; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(12px); opacity: 0; background: var(--ink); color: var(--ground); padding: 10px 16px; border-radius: 8px; font-size: .92rem; transition: opacity .2s, transform .2s cubic-bezier(.16,1,.3,1); z-index: 100; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--bad); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .editor-layout { grid-template-columns: 1fr; }
  .editor-side { position: static; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: sticky; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; gap: 8px; z-index: 20; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .brand-mark { display: none; }
  .nav { flex-direction: row; }
  .nav a { padding: 7px 10px; }
  .nav a span { display: none; }
  .rail-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
  .rail-foot .who { display: none; }
  .rail-foot button { margin: 0; }
  .main { padding: 20px 16px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
  .figure { border-right: 0; border-bottom: 1px solid var(--line); }
  .mail-canvas { padding: 22px 18px; }
  .canvas-wrap { padding: 12px 6px; }
  .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 8px; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
  table.data .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
