:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --text: #1d1b18;
  --muted: #6b665e;
  --line: #e4e1da;
  --accent: #1f5f4a;
  --accent-text: #ffffff;
  --ok: #1f7a4d;
  --warn: #a16207;
  --fail: #b42318;
  --ok-bg: #e6f4ec;
  --warn-bg: #fdf3d7;
  --fail-bg: #fde8e6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --card: #201f1c;
    --text: #ece9e3;
    --muted: #a39e94;
    --line: #34322d;
    --accent: #4fb592;
    --accent-text: #10201a;
    --ok: #5ccf95;
    --warn: #e5b94a;
    --fail: #f2796d;
    --ok-bg: #173325;
    --warn-bg: #3a2f10;
    --fail-bg: #3d1a16;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: -0.01em; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button {
  background: none;
  color: var(--muted);
  border: 0;
  padding: 8px 12px;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
nav button:hover { color: var(--text); }
nav button.active { background: var(--bg); color: var(--text); font-weight: 600; }

main { max-width: 1040px; margin: 0 auto; padding: 24px 16px 64px; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.label { color: var(--muted); font-size: 13px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
p { margin: 0 0 12px; }
.note { border-left: 3px solid var(--warn); padding: 8px 12px; background: var(--warn-bg); border-radius: 0 8px 8px 0; }

button {
  font: inherit;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--text); border-color: var(--line); }
button.danger { background: transparent; color: var(--fail); border-color: var(--line); }
button.small { padding: 4px 10px; font-size: 13px; font-weight: 500; }
button:disabled { opacity: 0.5; cursor: default; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
textarea { resize: vertical; font-family: inherit; }
input[type="checkbox"] { width: auto; }
input[type="file"] { padding: 6px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input, label select, label textarea { margin-top: 4px; font-size: 15px; }
.hint { display: block; margin-top: 4px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row input, .row select { width: auto; flex: 1 1 200px; }
.row select { flex: 0 0 auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.grid .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
.check input { margin: 0; }
.days { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; }
.days label { display: flex; gap: 5px; align-items: center; margin: 0; color: var(--text); font-size: 14px; }
.days input { margin: 0; }
.sticky { margin-bottom: 16px; }

/* Tableau de bord */
.queue { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.queue-status { font-size: 18px; font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { margin: 0; padding: 16px; }
.num { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.sub { font-size: 13px; color: var(--muted); }
.banner { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.fail { background: var(--fail-bg); color: var(--fail); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bar { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-n { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-d { font-size: 11px; color: var(--muted); margin-top: 4px; white-space: nowrap; }

/* Tables */
.table-wrap { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td:last-child { text-align: right; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.fail { background: var(--fail-bg); color: var(--fail); }
.badge.neutral { background: var(--bg); color: var(--muted); }

/* Campagnes */
.campaign { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: center; }
.campaign h3 { margin: 0 0 4px; font-size: 16px; }
.campaign .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.progress { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; margin-top: 12px; }
.progress > div { height: 100%; background: var(--accent); }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); max-width: 640px; width: calc(100% - 32px); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.preview-subject { font-weight: 700; margin: 8px 0; }
pre { white-space: pre-wrap; word-break: break-word; background: var(--bg); padding: 12px; border-radius: 8px; font: 14px/1.5 system-ui, sans-serif; max-height: 50vh; overflow: auto; }

/* Statistiques */
.rates { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.rate { background: var(--bg); border-radius: 10px; padding: 12px; }
.rate .pct { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.rate .pct.warn { color: var(--warn); }
.rate .pct.fail { color: var(--fail); }
.rate .count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.small-note { font-size: 13px; margin: 12px 0 0; }
.campaign-stats { display: flex; gap: 6px 18px; flex-wrap: wrap; margin-top: 12px; font-size: 14px; font-variant-numeric: tabular-nums; }
.campaign-stats b { font-weight: 600; }
dialog.wide-dialog { max-width: 860px; }
dialog h3 { font-size: 14px; margin: 20px 0 8px; }
.table-wrap.tall { max-height: 38vh; overflow-y: auto; }
.table-wrap.tall td:last-child { text-align: left; }
.link-row { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; border-bottom: 1px solid var(--line); color: var(--text); font-size: 14px; }
.link-row span:first-child { word-break: break-all; }
.link-row span:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
a.button { display: inline-block; text-decoration: none; font-weight: 600; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); color: var(--text); }

/* Listes */
.pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 99px; padding: 6px 14px; font-weight: 500; }
.pill .n { color: var(--muted); font-weight: 400; margin-left: 4px; font-variant-numeric: tabular-nums; }
.pill.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.pill.active .n { color: inherit; opacity: 0.8; }
.bulk { background: var(--bg); border-radius: 8px; padding: 8px 12px; margin-top: 12px; }
.tag { display: inline-block; background: var(--bg); border-radius: 6px; padding: 1px 7px; font-size: 12px; margin-right: 4px; }
#contacts td:first-child, #contacts th:first-child { width: 1%; }
[hidden] { display: none !important; }
.options { display: grid; gap: 6px; margin-bottom: 12px; max-height: 40vh; overflow-y: auto; }
.options label { display: flex; align-items: center; gap: 10px; margin: 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); font-size: 15px; cursor: pointer; }
.options label .n { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.options input { margin: 0; }
.options hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
.launch-count { font-weight: 600; }
.reply { padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--text); font-size: 14px; }
.reply .who { font-weight: 600; }

/* Relances */
.section-title { font-size: 15px; margin: 20px 0 6px; }
.followup { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.followup-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; font-size: 14px; }
.followup-head input { width: 70px; }
.followup-head button { margin-left: auto; }
#preview-followups h3 { color: var(--muted); font-weight: 500; }
#stats-steps td:last-child, #stats-steps th:last-child { text-align: left; }

/* Format d'envoi et connexion Google */
.format-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.format-row .muted { flex: 1 1 260px; font-size: 13px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; background: transparent; color: var(--muted); font-weight: 500; padding: 6px 14px; }
.segmented button.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }
ol.steps { margin: 0 0 12px; padding-left: 20px; }
ol.steps li { margin-bottom: 6px; }
ol.steps code { word-break: break-all; }
input[readonly] { opacity: 0.7; }

/* Pro : import, A/B, réponses, placement */
.opts { gap: 4px 24px; }
.opts .check { margin: 0; font-size: 14px; }
details.ab { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 12px 0; }
details.ab summary { cursor: pointer; font-weight: 600; font-size: 14px; }
details.ab[open] summary { margin-bottom: 10px; }
.reply-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.reply-card.done { opacity: 0.6; }
.reply-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.reply-head .who { font-weight: 600; }
.reply-text { margin: 8px 0; white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.reply-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.reply-actions button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.reply-answer { margin-top: 10px; }
.reply-answer textarea { margin-bottom: 8px; }
.winner { color: var(--ok); font-weight: 600; }

/* Compte */
.whoami { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
body:not(.is-admin) .admin-only { display: none; }
.actions-col button { margin-left: 4px; }

/* Délivrabilité */
.check-row { display: grid; grid-template-columns: 96px 1fr; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.check-row:last-child { border-bottom: 0; }
.check-row .name { font-weight: 600; }
.check-row .detail { word-break: break-word; font-size: 14px; }
.check-row .fix { margin-top: 6px; font-size: 14px; color: var(--muted); word-break: break-word; }
ul.plain { margin: 0; padding-left: 18px; }
ul.plain li { margin-bottom: 8px; }

/* Boîtes d'envoi */
.mb-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.mb-head h3 { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
.mb-head .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.mb-section { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.mb-section h4 { margin: 0 0 8px; font-size: 14px; }
.mb-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 16px; }
.mb-grid label { margin-bottom: 8px; }
.mb-stats { font-size: 14px; font-variant-numeric: tabular-nums; margin: 8px 0 0; }
.mb-out { margin-top: 10px; font-size: 14px; }
.mb-out ul { margin: 6px 0 0; padding-left: 18px; }
