/* ==========================================================================
   SMPT — « Courrier par avion » : papier chaud, encre bleu nuit,
   serif éditorial pour les titres, liseré tricolore en signature.
   ========================================================================== */

:root {
  /* Papier & encre (mode clair) */
  --bg: #f5f1e8;
  --bg-texture: radial-gradient(circle at 15% 10%, rgba(31, 79, 191, 0.04), transparent 42%),
                radial-gradient(circle at 85% 90%, rgba(198, 71, 47, 0.035), transparent 45%);
  --surface: #fffdf7;
  --surface-2: #efe9db;
  --text: #1c2437;
  --text-2: #565e70;
  --muted: #8a8d97;
  --border: #e2dac7;
  --border-strong: #cfc5ac;
  --shadow: 0 1px 2px rgba(28, 36, 55, 0.05), 0 8px 24px -18px rgba(28, 36, 55, 0.35);
  --shadow-pop: 0 12px 40px -12px rgba(28, 36, 55, 0.35);

  --accent: #1f4fbf;
  --accent-strong: #16389c;
  --accent-soft: #e3eafb;
  --accent-ink: #ffffff;
  --airmail-red: #c6472f;

  /* Statuts (icône + libellé, jamais la couleur seule) */
  --good: #116329;      --good-bg: #ddefe1;
  --warning: #7a4f01;   --warning-bg: #f7ecc8;
  --serious: #93381a;   --serious-bg: #f8e2d5;
  --critical: #a12622;  --critical-bg: #f8dbda;
  --info: #1f4fbf;      --info-bg: #e0e9fb;

  /* Graphique (palette validée) */
  --series-1: #2a78d6;
  --series-2: #1baf7a;
  --grid: #e6dfcd;
  --baseline: #c9bfa6;

  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-body: Seravek, "Gill Sans Nova", Ubuntu, Calibri, "DejaVu Sans", source-sans-pro, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --radius: 14px;
  --radius-sm: 9px;
  --airmail: repeating-linear-gradient(-45deg,
      var(--airmail-red) 0 14px, var(--surface) 14px 26px,
      var(--accent) 26px 40px, var(--surface) 40px 52px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101420;
    --bg-texture: radial-gradient(circle at 15% 10%, rgba(125, 162, 245, 0.05), transparent 45%),
                  radial-gradient(circle at 85% 90%, rgba(198, 71, 47, 0.05), transparent 45%);
    --surface: #171c2b;
    --surface-2: #1f2536;
    --text: #edeff5;
    --text-2: #b4bac8;
    --muted: #858b9b;
    --border: #2a3146;
    --border-strong: #3a4158;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -18px rgba(0, 0, 0, 0.7);
    --shadow-pop: 0 12px 40px -12px rgba(0, 0, 0, 0.7);

    --accent: #7da2f5;
    --accent-strong: #a5bff8;
    --accent-soft: #223052;
    --accent-ink: #0d1322;
    --airmail-red: #d96a52;

    --good: #6fd189;      --good-bg: #14311d;
    --warning: #f1c366;   --warning-bg: #3a2e12;
    --serious: #f0956d;   --serious-bg: #3c2317;
    --critical: #f08a86;  --critical-bg: #3f1c1b;
    --info: #8cb0f7;      --info-bg: #1e2c4d;

    --series-1: #3987e5;
    --series-2: #199e70;
    --grid: #262d40;
    --baseline: #3a4158;
    --airmail: repeating-linear-gradient(-45deg,
        var(--airmail-red) 0 14px, var(--surface) 14px 26px,
        var(--accent) 26px 40px, var(--surface) 40px 52px);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg-texture), var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand-name { font-family: var(--font-display); letter-spacing: 0.01em; }

::selection { background: var(--accent-soft); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- animations ---------- */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: none; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
.stagger > * { animation: fadeUp 0.45s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.stagger > *:nth-child(1) { animation-delay: 0.02s; }
.stagger > *:nth-child(2) { animation-delay: 0.07s; }
.stagger > *:nth-child(3) { animation-delay: 0.12s; }
.stagger > *:nth-child(4) { animation-delay: 0.17s; }
.stagger > *:nth-child(5) { animation-delay: 0.22s; }
.stagger > *:nth-child(6) { animation-delay: 0.27s; }
.stagger > *:nth-child(n+7) { animation-delay: 0.32s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- structure ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  padding: 22px 16px 16px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--airmail);
  background-size: auto 74px;
  opacity: 0.9;
}

.brand { padding: 2px 10px 18px; }
.brand-name {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text);
}
.brand-name .postmark { color: var(--accent); }
.brand small {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-top: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-link .ico { width: 20px; text-align: center; font-style: normal; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}

.compose-cta { padding: 14px 4px 4px; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 10px 4px;
  border-top: 1px dashed var(--border-strong);
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}
.sidebar-footer .host { font-family: var(--font-mono); font-size: 11.5px; }
.sidebar-footer a { color: var(--muted); }
.sidebar-footer a:hover { color: var(--text-2); }

.main {
  flex: 1;
  min-width: 0;
  padding: 34px 40px 70px;
  max-width: 1120px;
}

.page-head { margin-bottom: 24px; }
.page-head .head-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.page-head h1 { font-size: 30px; font-weight: 700; margin: 0; }
.page-head .lede { margin: 6px 0 0; color: var(--text-2); max-width: 62ch; }
.page-head .crumb { font-size: 13.5px; margin-bottom: 10px; }
.page-head .crumb a { color: var(--accent); text-decoration: none; }
.page-head .crumb a:hover { text-decoration: underline; }

/* ---------- composants ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card h2 { font-size: 18px; margin: 0 0 14px; }
.card h2 small { color: var(--muted); font-weight: 400; font-family: var(--font-body); font-size: 13px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.card-head h2 { margin: 0; }
.card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.grid { display: grid; gap: 14px; }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); margin-bottom: 18px; }

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px 14px;
  box-shadow: var(--shadow);
}
.tile .tile-label {
  font-size: 11.5px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}
.tile .tile-value {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.15;
  margin-top: 4px;
}
.tile .tile-sub { font-size: 12.5px; color: var(--muted); }
.tile.alert .tile-value { color: var(--critical); }

/* Boutons */
button, .btn {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: transform 0.12s, box-shadow 0.15s, background 0.15s, border-color 0.15s;
}
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent-strong); }
button:active, .btn:active { transform: translateY(1px); }
button.primary, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 16px -8px var(--accent);
}
button.primary:hover, .btn.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--accent-ink);
}
button.danger { color: var(--critical); }
button.danger:hover { border-color: var(--critical); }
button.small, .btn.small { padding: 4px 11px; font-size: 12.5px; font-weight: 500; }
button.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button:disabled { opacity: 0.45; cursor: default; pointer-events: none; }
.wide { width: 100%; justify-content: center; }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-btn:hover { color: var(--accent-strong); border: none; }

/* Formulaires */
input, select, textarea {
  font: inherit;
  font-size: 14.5px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 130px; resize: vertical; line-height: 1.5; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
label .opt { font-weight: 400; color: var(--muted); }
.field { margin-bottom: 14px; }
form.inline { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
form.inline .field { margin-bottom: 0; }
.hint { color: var(--muted); font-size: 12.5px; }
.error-text { color: var(--critical); font-size: 13px; }

/* Tableaux */
.table-wrap { overflow-x: auto; margin: 0 -8px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 700;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; transition: background 0.12s; }
tr.clickable:hover td { background: var(--surface-2); }
tr.clickable:hover td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono, code { font-family: var(--font-mono); font-size: 0.92em; }
.addr { font-family: var(--font-mono); font-size: 12.5px; }
td.addr { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Badges de statut (toujours avec libellé) */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.sent { background: var(--good-bg); color: var(--good); }
.badge.received { background: var(--info-bg); color: var(--info); }
.badge.queued, .badge.sending { background: var(--warning-bg); color: var(--warning); }
.badge.sending::before { animation: pulse 1.2s ease-in-out infinite; }
.badge.partial { background: var(--serious-bg); color: var(--serious); }
.badge.failed { background: var(--critical-bg); color: var(--critical); }
.badge.neutral { background: var(--surface-2); color: var(--text-2); }
.badge.ok { background: var(--good-bg); color: var(--good); }
.badge.ko { background: var(--critical-bg); color: var(--critical); }

.live-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.live-dot::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--good);
  animation: pulse 2.4s ease-in-out infinite;
}

/* Guide de démarrage */
.onboarding .steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.onboarding .step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.onboarding .step.done { opacity: 0.65; }
.onboarding .step .mark {
  width: 26px; height: 26px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  border: 2px solid var(--border-strong);
  color: var(--muted);
}
.onboarding .step.done .mark { background: var(--good); border-color: var(--good); color: #fff; }
.onboarding .step.next .mark { border-color: var(--accent); color: var(--accent); }
.onboarding .step .step-body { flex: 1; min-width: 0; }
.onboarding .step .step-title { font-weight: 600; }
.onboarding .step .step-hint { font-size: 12.5px; color: var(--muted); }
.onboarding .progress {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 16px;
}
.onboarding .progress > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--series-2));
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* DNS */
.dns-record {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  margin-bottom: 10px;
  background: var(--surface);
}
.dns-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.dns-type {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--accent-strong);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 5px;
}
.dns-name { font-family: var(--font-mono); font-size: 12.5px; color: var(--text-2); }
.dns-purpose { color: var(--muted); font-size: 12.5px; margin-top: 7px; }
.copy-row { display: flex; gap: 8px; align-items: flex-start; }
.copy-row .val {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  word-break: break-all;
  white-space: pre-wrap;
  max-height: 88px;
  overflow-y: auto;
}

/* Graphique */
.chart-svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); }
.legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.chart-tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  box-shadow: var(--shadow-pop);
  padding: 9px 12px;
  font-size: 12.5px;
  z-index: 60;
  display: none;
}
.chart-tooltip .tt-title { font-weight: 700; margin-bottom: 3px; }
.chart-tooltip .tt-row { color: var(--text-2); }

/* Messages */
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.filters select { width: auto; min-width: 130px; }
.filters .search { flex: 1; min-width: 200px; position: relative; }
.filters .search input { padding-left: 34px; }
.filters .search::before {
  content: "⌕";
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-58%);
  font-size: 17px;
  color: var(--muted);
  pointer-events: none;
}
.pagination {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 14px;
  color: var(--text-2);
  font-size: 13px;
}
.subject-cell .subj { font-weight: 600; }
.subject-cell { max-width: 300px; }
.subject-cell .subj, .subject-cell .snippet {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subject-cell .snippet { color: var(--muted); font-size: 12.5px; }
.dir-ico { font-size: 15px; opacity: 0.85; }

/* Détail de message */
.meta-grid { display: grid; grid-template-columns: 130px 1fr; gap: 8px 16px; font-size: 14px; }
.meta-grid dt { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.07em; padding-top: 2px; }
.meta-grid dd { margin: 0; word-break: break-word; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 9px 0 9px 24px; border-left: 2px solid var(--border-strong); position: relative; margin-left: 8px; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -7px; top: 15px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--baseline);
  border: 2px solid var(--surface);
}
.timeline li.ok::before { background: var(--good); }
.timeline li.ko::before { background: var(--critical); }
.timeline .tl-when { font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tabs button {
  border: none;
  background: none;
  border-radius: 8px 8px 0 0;
  padding: 9px 16px;
  color: var(--text-2);
  font-weight: 500;
  margin-bottom: -2px;
}
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button.active {
  color: var(--accent-strong);
  font-weight: 700;
  border-bottom: 2px solid var(--accent);
  background: none;
}
.body-view { white-space: pre-wrap; word-break: break-word; font-size: 14.5px; line-height: 1.6; }
.html-frame { width: 100%; min-height: 400px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }

/* États vides */
.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted);
}
.empty .empty-ico { font-size: 34px; display: block; margin-bottom: 10px; opacity: 0.7; }
.empty .empty-title { font-family: var(--font-display); font-size: 18px; color: var(--text-2); margin-bottom: 4px; }
.empty .btn, .empty button { margin-top: 14px; }

/* Modales & connexion */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 20, 32, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  border-top: 4px solid transparent;
  border-image: var(--airmail) 1;
  border-image-width: 4px 0 0 0;
  padding: 26px 28px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-pop);
  animation: fadeUp 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.modal h2 { margin: 0 0 18px; font-size: 21px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-box {
  width: 100%;
  max-width: 380px;
  position: relative;
  overflow: hidden;
  padding-top: 30px;
}
.login-box::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 6px;
  background: var(--airmail);
  background-size: auto 74px;
}
.login-box .brand { text-align: center; padding-bottom: 14px; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  box-shadow: var(--shadow-pop);
  animation: slideIn 0.25s cubic-bezier(0.2, 0.7, 0.2, 1);
  max-width: min(420px, calc(100vw - 48px));
}

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 12px 14px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar::before { inset: 0 0 auto 0; width: auto; height: 4px; background-size: 74px auto; }
  .brand { padding: 0 8px 0 0; }
  .brand-name { font-size: 20px; }
  .brand small { display: none; }
  .nav-link { padding: 7px 10px; font-size: 14px; }
  .nav-link .ico { width: auto; }
  .compose-cta { padding: 0; margin-left: auto; }
  .compose-cta .label-full { display: none; }
  .sidebar-footer { display: none; }
  .main { padding: 20px 16px 60px; }
  .page-head h1 { font-size: 24px; }
  .meta-grid { grid-template-columns: 1fr; gap: 2px 0; }
  .meta-grid dt { margin-top: 8px; }
  .filters .search { min-width: 100%; order: -1; }
}
