/* Mailetter design system.
   Single served stylesheet (CSP style-src 'self', no 'unsafe-inline'): every
   style lives here — templates carry no inline style= or <style> blocks.
   Brand: Hesias — teal #046a6e (primary), orange #f29104 (accent). */

/* ========================================================================
   1. TOKENS
   ======================================================================== */
:root {
  color-scheme: light;

  /* Teal scale (brand primary) */
  --teal-50:  #e6f2f2;
  --teal-100: #c2dedf;
  --teal-200: #9bcacb;
  --teal-300: #6fb1b3;
  --teal-400: #3d9094;
  --teal-500: #167479;
  --teal-600: #0a6c70;
  --teal-700: #046a6e; /* primary */
  --teal-800: #04565a;
  --teal-900: #033b3e;

  /* Orange scale (brand accent) */
  --orange-50:  #fff4e2;
  --orange-100: #ffe4ba;
  --orange-200: #ffd08a;
  --orange-300: #ffba56;
  --orange-400: #faa326;
  --orange-500: #f29104; /* accent */
  --orange-600: #d67e02;
  --orange-700: #b96f00;
  --orange-800: #9a5c00; /* orange-as-text: 5.38:1 on white (AA normal) */

  /* Slate neutral scale */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  /* Semantic */
  --success: #16a34a;
  --danger:  #dc2626;
  --warning: #f59e0b;
  --info:    #0a7d82;
  --success-bg: #dcfce7;
  --danger-bg:  #fee2e2;
  --warning-bg: #fef3c7;
  --info-bg:    #e6f2f2;

  /* Role aliases */
  --primary: var(--teal-700);
  --primary-hover: var(--teal-800);
  --accent: var(--orange-500);
  --accent-hover: var(--orange-600);

  /* Surfaces / text — teal-tinted neutrals (Console Hesias) */
  --bg:        #f3f6f6;
  --surface:   #ffffff;
  --surface-2: #f7fafa;
  --border:    #e2e9e9;
  --border-strong: #c8d4d5;
  --text:      var(--slate-800);
  --text-muted: var(--slate-600); /* slate-600 ~6:1 on all light surfaces incl. --bg (slate-500 fails 4.5:1 on --bg) */
  --text-inverse: #ffffff;

  /* Sidebar */
  --sidebar-bg: var(--teal-900);
  --sidebar-text: #cfe3e3;
  --sidebar-muted: #7fa6a8;
  --sidebar-hover: rgba(255, 255, 255, 0.07);
  --sidebar-active-bg: rgba(242, 145, 4, 0.12);

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;

  /* Radius */
  --r-sm: 4px;
  --r:    8px;
  --r-lg: 12px;
  --r-full: 999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow:    0 4px 12px rgba(15, 23, 42, 0.10), 0 2px 4px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.16);

  /* Elevation (teal-tinted) — card = flat 1px ring; raised is hover-only */
  --elev-card:    0 0 0 1px var(--border);
  --elev-raised:  0 2px 8px rgba(3, 59, 62, 0.08);
  --elev-overlay: 0 8px 24px rgba(3, 59, 62, 0.16);
  --elev-modal:   0 20px 48px rgba(3, 59, 62, 0.28);

  /* Typography */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.9375rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;
  --fs-3xl: 2.25rem;

  --sidebar-w: 240px;
  --topbar-h: 56px;
  --content-max: 1280px;
  --focus-ring: 0 0 0 3px rgba(242, 145, 4, 0.45);

  /* Motion */
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
  --dur: 140ms;
}

/* ========================================================================
   2. RESET / BASE
   ======================================================================== */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 var(--sp-3); line-height: 1.25; font-weight: 650; color: var(--slate-900); }
h1 { font-size: 1.5rem; letter-spacing: -0.02em; }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p { margin: 0 0 var(--sp-3); }

a { color: var(--teal-700); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre { font-family: var(--font-mono); font-size: 0.875em; }
pre {
  background: var(--slate-900);
  color: var(--slate-100);
  padding: var(--sp-4);
  border-radius: var(--r);
  overflow: auto;
}

.muted { color: var(--text-muted); }
.spacer { flex: 1 1 auto; }
.danger { color: var(--danger); }

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}

/* Global reduced-motion kill-switch: collapses every animation/transition. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========================================================================
   3. APP SHELL
   ======================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
/* Bare pages (login/error) render with no sidebar: drop the grid entirely so
   the content is never auto-placed into a sidebar column. */
.app--bare { display: block; min-height: 100vh; }
.app--bare > .content { min-height: 100vh; }
.app--bare main { max-width: none; margin: 0; padding: 0; }

.content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

main {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-6) var(--sp-8);
}
/* Narrow reading/form pages (settings, single-entity forms). */
main.main--narrow { max-width: 760px; }

/* ---- Sidebar ---- */
.sidebar {
  grid-row: 1 / -1;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #043e42 0%, var(--teal-900) 100%);
  color: var(--sidebar-text);
  border-right: 1px solid var(--teal-900);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-5);
  height: var(--topbar-h);
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex: 0 0 auto;
}
.sidebar .brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex;
  width: 26px;
  height: 26px;
  border-radius: var(--r-sm);
  background: var(--orange-500);
  color: #fff;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: var(--fs-sm);
}
.brand-mark--accent { background: var(--orange-500); }

.sidebar-nav {
  flex: 1 1 auto;
  padding: var(--sp-4) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section {
  margin-top: var(--sp-4);
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-muted);
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r);
  color: var(--sidebar-text);
  font-size: var(--fs-base);
  font-weight: 500;
  white-space: nowrap;
  position: relative;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item .nav-icon {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  display: inline-flex;
  color: var(--sidebar-muted);
}
.nav-item:hover .nav-icon { color: var(--orange-300); }
.nav-item .nav-icon svg { width: 100%; height: 100%; }

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: #fff;
  font-weight: 600;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: var(--r-full);
  background: var(--orange-500);
}
.nav-item.active .nav-icon { color: var(--orange-400); }

.sidebar-footer {
  flex: 0 0 auto;
  padding: var(--sp-4);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
}
/* The identity block links to the self-service account page. */
a.sidebar-user {
  text-decoration: none;
  border-radius: var(--r);
  padding: var(--sp-1);
  margin: calc(var(--sp-1) * -1);
  transition: background var(--dur) var(--ease);
}
a.sidebar-user:hover,
a.sidebar-user.active { background: rgba(255, 255, 255, 0.08); }
.avatar {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: var(--r-full);
  background: var(--teal-600);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--fs-sm);
  text-transform: uppercase;
}
.sidebar-user-meta { min-width: 0; line-height: 1.2; }
.sidebar-user-email {
  font-size: var(--fs-sm);
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}
.sidebar-user-role { font-size: var(--fs-xs); color: var(--sidebar-muted); }

/* ---- Topbar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--sp-6);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .page-title { font-size: var(--fs-lg); font-weight: 650; color: var(--slate-900); margin: 0; }

.hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.hamburger svg { width: 20px; height: 20px; }
.topbar .who { font-size: var(--fs-sm); color: var(--text-muted); }

/* Backdrop for off-canvas sidebar on mobile */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(3, 59, 62, 0.5);
}

/* ========================================================================
   4. BUTTONS
   ======================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: 600;
  line-height: 1.2;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), color var(--dur) var(--ease);
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: var(--slate-50); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn[aria-busy="true"] { opacity: 0.7; cursor: progress; pointer-events: none; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text-inverse);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

/* Accent — the single per-page "commit" action (orange, dark text ≥7:1). */
.btn-accent {
  background: var(--orange-500);
  border-color: var(--orange-500);
  color: var(--slate-900);
}
.btn-accent:hover { background: var(--orange-400); border-color: var(--orange-400); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--text-inverse);
}
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--teal-700);
}
.btn-ghost:hover { background: var(--teal-50); }

.btn-sm { padding: var(--sp-1) var(--sp-3); font-size: var(--fs-sm); }
.btn-block { width: 100%; }
.btn-icon svg { width: 16px; height: 16px; }

/* ========================================================================
   5. FORMS
   ======================================================================== */
form.inline { display: inline; }

label {
  display: inline-block;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--slate-700);
  margin-bottom: var(--sp-1);
}
.required { color: var(--danger); margin-left: 2px; }

input, select, textarea {
  font-family: inherit;
  font-size: var(--fs-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  padding: var(--sp-2) var(--sp-3);
  width: 100%;
  max-width: 100%;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input[type="checkbox"], input[type="radio"] { width: auto; }
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--orange-400);
  box-shadow: var(--focus-ring);
}
input::placeholder, textarea::placeholder { color: var(--slate-500); } /* 4.76:1 on white; slate-400 was 2.56:1 */
input:disabled, select:disabled, textarea:disabled { background: var(--slate-100); color: var(--text-muted); }

.field { display: flex; flex-direction: column; margin-bottom: var(--sp-4); }
.field > label { margin-bottom: var(--sp-1); }
.field .help { font-size: var(--fs-sm); color: var(--text-muted); margin-top: var(--sp-1); }
.field .error { font-size: var(--fs-sm); color: var(--danger); margin-top: var(--sp-1); }
.field--error input,
.field--error select,
.field--error textarea { border-color: var(--danger); }
.field--error input:focus-visible,
.field--error textarea:focus-visible { box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.35); }

.field-row { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.field-row > .field { flex: 1 1 200px; }

.checkbox-field { display: flex; align-items: center; gap: var(--sp-2); }
.checkbox-field label { margin: 0; font-weight: 500; }

/* ========================================================================
   6. CARDS & KPI
   ======================================================================== */
.card {
  background: var(--surface);
  border: none;
  border-radius: var(--r-lg);
  box-shadow: var(--elev-card); /* flat 1px ring — raised only on interaction */
  overflow: hidden;
  transition: box-shadow var(--dur) var(--ease);
}
a.card:hover, .card--interactive:hover { box-shadow: var(--elev-card), var(--elev-raised); text-decoration: none; }
.card-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card-header h2, .card-header h3 { margin: 0; }
.card-body { padding: var(--sp-5); }

.cards, .grid {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* Template gallery — wide cards with a scaled, legible full-email thumbnail.
   The preview iframe is laid out at 2x the card width then scaled to 0.5 so a
   ~600px email renders in full instead of showing a cropped top-left corner. */
.gallery-grid {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.gallery-card { display: flex; flex-direction: column; }
.gallery-card .card-body { flex: 1 1 auto; }
.preview-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #fff;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.preview-frame .preview {
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;
  height: 200%;
  border: 0;
  transform: scale(0.5);
  transform-origin: top left;
  pointer-events: none;
}

.kpi {
  background: var(--surface);
  border: none;
  border-radius: var(--r-lg);
  box-shadow: var(--elev-card);
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  transition: box-shadow var(--dur) var(--ease);
}
a.kpi:hover, .kpi--interactive:hover { box-shadow: var(--elev-card), var(--elev-raised); text-decoration: none; }
.kpi-label { font-size: var(--fs-sm); color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: var(--fs-3xl); font-weight: 700; color: var(--slate-900); line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-trend { font-size: var(--fs-sm); font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.kpi-trend--flat { color: var(--text-muted); }

/* ========================================================================
   7. TABLES
   ======================================================================== */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  text-align: left;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 700;
  padding: 10px var(--sp-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: 10px var(--sp-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--teal-50); }
.table.zebra tbody tr:nth-child(even) { background: var(--slate-50); }
.table.zebra tbody tr:nth-child(even):hover { background: var(--teal-50); }
.table .num, .table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table.compact thead th { padding: var(--sp-2) var(--sp-3); }
.table.compact tbody td { padding: var(--sp-2) var(--sp-3); }
/* Relaxed variant restores the pre-S1 roomier cell padding. */
.table--relaxed thead th { padding: var(--sp-3) var(--sp-4); }
.table--relaxed tbody td { padding: var(--sp-3) var(--sp-4); }

/* Sortable column header — link inside <th>; caret follows th[aria-sort]. */
.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
}
.th-sort:hover { color: var(--text); text-decoration: none; }
.th-sort::after {
  content: "↕";
  font-size: 0.9em;
  line-height: 1;
  opacity: 0.45;
}
th[aria-sort] .th-sort { color: var(--text); }
th[aria-sort="ascending"] .th-sort::after { content: "▲"; opacity: 1; color: var(--orange-600); }
th[aria-sort="descending"] .th-sort::after { content: "▼"; opacity: 1; color: var(--orange-600); }

/* ========================================================================
   8. BADGES
   ======================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--sp-2);
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  background: var(--slate-100);
  color: var(--slate-600);
  border: 1px solid transparent;
}
.badge--success { background: var(--success-bg); color: #166534; }
.badge--danger  { background: var(--danger-bg);  color: #991b1b; }
.badge--warning { background: var(--warning-bg); color: #92400e; }
.badge--info    { background: var(--info-bg);    color: var(--teal-800); }
.badge--neutral { background: var(--slate-100);  color: var(--slate-600); }
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: var(--r-full);
  background: currentColor;
  opacity: 0.85;
}

/* Domain status mappings — campaign status */
.status-draft     { background: var(--slate-100);  color: var(--slate-600); }
.status-scheduled { background: var(--info-bg);    color: var(--teal-800); }
.status-sending   { background: var(--warning-bg); color: #92400e; }
.status-sent      { background: var(--success-bg); color: #166534; }
.status-paused    { background: var(--warning-bg); color: #92400e; }
.status-cancelled { background: var(--danger-bg);  color: #991b1b; }
.status-failed    { background: var(--danger-bg);  color: #991b1b; }

/* Subscription state */
.sub-pending     { background: var(--warning-bg); color: #92400e; }
.sub-subscribed  { background: var(--success-bg); color: #166534; }
.sub-confirmed   { background: var(--success-bg); color: #166534; }
.sub-unsubscribed{ background: var(--slate-100);  color: var(--slate-600); }
.sub-bounced     { background: var(--danger-bg);  color: #991b1b; }

/* Suppression reason — class names match the stored reason values
   (hard_bounce / global_unsub / rgpd / complaint), see domain.SuppressionReason. */
.supp-hard_bounce  { background: var(--danger-bg);  color: #991b1b; }
.supp-complaint    { background: var(--danger-bg);  color: #991b1b; }
.supp-global_unsub { background: var(--slate-100);  color: var(--slate-600); }
.supp-rgpd         { background: var(--warning-bg); color: #92400e; }

/* ========================================================================
   9. TOASTS / FLASH
   ======================================================================== */
.toast {
  position: fixed;
  top: calc(var(--topbar-h) + var(--sp-3));
  right: var(--sp-5);
  z-index: 60;
  max-width: 380px;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--elev-overlay);
  border-left: 4px solid var(--teal-600);
  font-size: var(--fs-base);
  animation: toast-in var(--dur) var(--ease);
}
.toast--success { border-left-color: var(--success); }
.toast--error   { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* Stacked toasts (toast.js): fixed container; toasts inside flow statically. */
.toast-stack {
  position: fixed;
  top: calc(var(--topbar-h) + var(--sp-3));
  right: var(--sp-5);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: min(380px, calc(100vw - 2 * var(--sp-3)));
}
.toast-stack .toast { position: static; max-width: none; }
.toast-close {
  float: right;
  margin-left: var(--sp-3);
  padding: 0 2px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text-muted);
  font-size: var(--fs-md);
  line-height: 1;
  cursor: pointer;
}
.toast-close:hover { color: var(--text); }
.toast--hide {
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

/* Legacy flash hook kept for compatibility. */
.flash {
  padding: var(--sp-3) var(--sp-4);
  margin: 0 0 var(--sp-4);
  border-radius: var(--r);
  background: var(--success-bg);
  color: #166534;
  border: 1px solid #bbf7d0;
}

/* ========================================================================
   10. EMPTY STATE / TOOLBAR / BREADCRUMB / PAGINATION
   ======================================================================== */
.empty-state {
  text-align: center;
  padding: var(--sp-8) var(--sp-5);
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface);
}
.empty-state .empty-icon { width: 48px; height: 48px; margin: 0 auto var(--sp-3); color: var(--slate-300); }
.empty-state .empty-icon svg { width: 100%; height: 100%; }
.empty-state h3 { color: var(--slate-700); }
.empty-state p { margin-bottom: var(--sp-4); }

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}
.toolbar .toolbar-search { flex: 1 1 220px; max-width: 360px; }
.toolbar .toolbar-spacer { flex: 1 1 auto; }

/* Search + filters on one flat inline row (matches the design comp): the
   search input flexes to fill, the filter selects size to their content, no
   visible submit button (search is live/HTMX or submits on Enter). */
.toolbar--filters { gap: var(--sp-2); }
.toolbar--filters .toolbar-search { flex: 1 1 260px; max-width: 360px; width: auto; }
.toolbar--filters select { width: auto; min-width: 160px; }

/* Contextual bulk-action bar — hidden until at least one row is selected, then
   revealed by tables.js with a live count. Teal-tinted so it reads as an
   active selection context. */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: var(--teal-50);
  border: 1px solid var(--teal-100);
  border-radius: var(--r);
}
.bulk-bar[hidden] { display: none; }
.bulk-bar .bulk-count { font-size: var(--fs-sm); color: var(--teal-800); }
.bulk-bar .bulk-count strong { color: var(--teal-900); font-variant-numeric: tabular-nums; }
.bulk-bar .bulk-sep { flex: 1 1 0; }
.bulk-bar select { width: auto; min-width: 150px; }

/* Merge-variable pill — a teal-tinted monospace token for {{field}} keys shown
   in tables (custom fields, template variable lists). */
/* Detail two-column layout (contact detail): identity/info on the left,
   subscriptions/activity on the right, matching the design comp's single-screen
   layout. Collapses to one column on narrow viewports. */
.detail-cols {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: var(--sp-4);
  align-items: start;
}
.detail-cols > .stack { min-width: 0; }
@media (max-width: 900px) {
  .detail-cols { grid-template-columns: 1fr; }
}

.var-pill {
  display: inline-block;
  background: var(--info-bg);
  color: var(--teal-800);
  padding: 2px 7px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  white-space: nowrap;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  list-style: none;
  margin: 0;
  padding: 0;
}
.breadcrumb li { display: flex; align-items: center; gap: var(--sp-2); }
.breadcrumb li:not(:last-child)::after { content: "/"; color: var(--slate-300); }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb li:last-child { color: var(--slate-700); font-weight: 600; }

/* Page header pattern */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; }
.page-head .subtitle { color: var(--text-muted); margin: var(--sp-1) 0 0; }
.actions { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }

.stack > * + * { margin-top: var(--sp-4); }

/* Pager (Précédent / page indicator / Suivant) — shared by every paginated
   list. Prev sits left, the page indicator centres, next sits right; an absent
   direction renders as an aria-disabled span (greyed via the .btn rule). */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}
.pager .btn { min-width: 104px; justify-content: center; }
.pager a.btn:hover { border-color: var(--primary); color: var(--primary); }
.pager .muted { font-size: var(--fs-sm); }
/* Range indicator « x–y sur z » between the two direction buttons. */
.pager-info { font-size: var(--fs-sm); color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ========================================================================
   11. CHART HELPERS (SVG styled by class — no inline style)
   ======================================================================== */
.chart { display: block; max-width: 100%; height: auto; }
.chart-axis { stroke: var(--border-strong); stroke-width: 1; }
.chart-bar  { fill: var(--teal-600); }
.chart-line { fill: none; stroke: var(--teal-600); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--teal-100); opacity: 0.6; }
.chart-dot  { fill: var(--teal-700); }
.chart-label { fill: var(--text-muted); font-size: 10px; font-family: var(--font); }

.hbar { display: block; }
.hbar-track { fill: var(--slate-100); }
.hbar-fill  { fill: var(--teal-600); }

.donut { display: block; }
.donut-track { fill: none; stroke: var(--slate-100); }
.donut-seg-0 { stroke: var(--teal-600); fill: none; }
.donut-seg-1 { stroke: var(--orange-500); fill: none; }
.donut-seg-2 { stroke: var(--teal-300); fill: none; }
.donut-seg-3 { stroke: var(--slate-400); fill: none; }
.donut-seg-4 { stroke: var(--orange-300); fill: none; }
.donut-center { fill: var(--slate-900); font-weight: 700; font-family: var(--font); }

/* S1 chart additions: gridlines, second series (lineChart2), legend, hovers. */
.chart-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 3; fill: none; }
.chart-line--alt { stroke: var(--orange-500); }
.chart-dot--alt  { fill: var(--orange-500); }
.chart-swatch      { fill: var(--teal-600); }
.chart-swatch--alt { fill: var(--orange-500); }
.chart-legend text { fill: var(--text-muted); font-size: 11px; font-family: var(--font); }
.chart-bar, .chart-dot { transition: fill var(--dur) var(--ease); }
.chart-bar:hover { fill: var(--orange-500); }
.chart-dot:hover { fill: var(--orange-500); }
.donut [class^="donut-seg"] { transition: opacity var(--dur) var(--ease); }
.donut [class^="donut-seg"]:hover { opacity: 0.8; }
.hbar-label { fill: var(--text-muted); font-size: 10px; font-family: var(--font); }

/* ========================================================================
   12. RESPONSIVE — off-canvas sidebar
   ======================================================================== */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.sidebar--open { transform: translateX(0); }
  body.sidebar--open .sidebar-backdrop { display: block; }
  .hamburger { display: inline-flex; }
  main { padding: var(--sp-4); }
  .topbar { padding: 0 var(--sp-4); }
}

@media (max-width: 560px) {
  .page-head { flex-direction: column; }
  .toast { left: var(--sp-3); right: var(--sp-3); max-width: none; }
  .toast-stack { left: var(--sp-3); right: var(--sp-3); width: auto; }
  .toast-stack .toast { left: auto; right: auto; }
  .kpi-value { font-size: var(--fs-2xl); }
}

/* ========================================================================
   13. S1 UI FOUNDATION — menus, tabs, dialog, tooltip, editor, misc
   ======================================================================== */

/* ---- Row-actions dropdown (details/summary — opens without JS) ---- */
.menu { position: relative; display: inline-block; }
.menu > summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r);
  color: var(--text-muted);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary:hover, .menu[open] > summary { background: var(--surface-2); color: var(--text); }
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + var(--sp-1));
  z-index: 30;
  min-width: 180px;
  padding: var(--sp-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--elev-overlay);
}
.menu-panel form { margin: 0; }
.menu-panel a, .menu-panel button {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text);
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
}
.menu-panel a:hover, .menu-panel button:hover { background: var(--surface-2); text-decoration: none; }
.menu-panel .danger:hover { background: var(--danger-bg); }
/* An open row-action menu must escape its clipping ancestors: the panel is
   absolutely positioned and opens downward from its row, but .table-region
   (overflow-x:auto forces overflow-y to auto) and .card (overflow:hidden) would
   clip it for the last row. While a .menu is open, drop the clip on those
   ancestors so every item stays reachable; closed, they clip as before. */
.card:has(.menu[open]),
.table-region:has(.menu[open]) { overflow: visible; }

/* ---- Tabs (server-rendered; active tab carries aria-current="page") ---- */
.tabs {
  display: flex;
  gap: var(--sp-1);
  margin-bottom: var(--sp-5);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tab:hover { color: var(--text); border-bottom-color: var(--border-strong); text-decoration: none; }
.tab[aria-current="page"] { color: var(--slate-900); border-bottom-color: var(--orange-500); }

/* ---- Confirm dialog (base.html <dialog id="confirm-dialog">) ---- */
dialog#confirm-dialog {
  margin: auto;
  width: min(420px, calc(100vw - var(--sp-6)));
  padding: var(--sp-5);
  border: none;
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--elev-modal);
}
dialog#confirm-dialog::backdrop { background: rgba(3, 59, 62, 0.5); }
dialog#confirm-dialog h2 { font-size: var(--fs-lg); margin-bottom: var(--sp-2); }
dialog#confirm-dialog p { color: var(--text-muted); margin-bottom: var(--sp-5); overflow-wrap: break-word; }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); }

/* ---- CSS-only tooltip: [data-tip] on :hover and :focus-visible ---- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 7px);
  transform: translate(-50%, 2px);
  z-index: 70;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-sm);
  background: var(--slate-900);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1.35;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
[data-tip]::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 2px);
  transform: translate(-50%, 2px);
  z-index: 70;
  border: 5px solid transparent;
  border-top-color: var(--slate-900);
  border-bottom: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
[data-tip]:hover::after, [data-tip]:hover::before,
[data-tip]:focus-visible::after, [data-tip]:focus-visible::before {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---- Spinner (16px, currentColor — drop inside .htmx-indicator) ---- */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: var(--r-full);
  vertical-align: -2px;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Skip link (first focusable in <body>; visible only on focus) ---- */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--sp-3);
  z-index: 100;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--teal-700);
  font-weight: 600;
  box-shadow: var(--elev-overlay);
}
.skip-link:focus { top: var(--sp-3); }

/* ---- Chip (small pill button — variable insertion in the editor) ---- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--sp-3);
  border: 1px solid var(--teal-100);
  border-radius: var(--r-full);
  background: var(--teal-50);
  color: var(--teal-800);
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.chip:hover { background: var(--teal-100); border-color: var(--teal-200); }

/* ---- Template editor: source/preview side by side ≥1100px ---- */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
  align-items: start;
}
@media (min-width: 1100px) {
  .editor-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
.editor-textarea {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: 1.6;
  min-height: 420px;
  tab-size: 2;
  resize: vertical;
}

/* ========================================================================
   14. DARK THEME
   ======================================================================== */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    /* Teal-tinted dark neutrals (Console Hesias) */
    --bg:        #0a1516;
    --surface:   #101d1e;
    --surface-2: #0d1a1b;
    --border:    #1e3234;
    --border-strong: #2b4547;
    --text:      #e2e8f0;
    --text-muted: #94a3b8;
    --slate-900: #f1f5f9;
    --slate-700: #cbd5e1;
    --success-bg: #052e1a;
    --danger-bg:  #3a0d0d;
    --warning-bg: #3a2a06;
    --info-bg:    #04282a;
    --primary: var(--teal-600);
    --primary-hover: var(--teal-500);
    /* Teal-tinted drop shadows read as mud on dark — go black-based.
       --elev-card keeps tracking var(--border) and needs no override. */
    --elev-raised:  0 2px 8px rgba(0, 0, 0, 0.45);
    --elev-overlay: 0 8px 24px rgba(0, 0, 0, 0.55);
    --elev-modal:   0 20px 48px rgba(0, 0, 0, 0.7);
  }
  a { color: var(--teal-300); }
  .topbar { background: rgba(16, 29, 30, 0.85); }
  /* Neutral .btn hover uses the light-only --slate-50 literal; the variant
     colors are restated after it so this later rule cannot flatten them. */
  .btn:hover { background: var(--surface-2); }
  .btn-primary { background: var(--primary); border-color: var(--primary); color: var(--text-inverse); }
  .btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
  .btn-danger { background: var(--danger); border-color: var(--danger); color: var(--text-inverse); }
  .btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
  .btn-ghost { background: transparent; border-color: transparent; color: var(--teal-300); }
  .btn-ghost:hover { background: rgba(4, 106, 110, 0.25); }
  /* --slate-900 flips light in dark: restate the accent's dark-on-orange. */
  .btn-accent { background: var(--orange-500); border-color: var(--orange-500); color: #0f172a; }
  .btn-accent:hover { background: var(--orange-400); border-color: var(--orange-400); }
  .table tbody tr:hover { background: rgba(4, 106, 110, 0.18); }
  .table.zebra tbody tr:nth-child(even) { background: rgba(255,255,255,0.02); }
  .badge--success { color: #4ade80; }
  .badge--danger { color: #f87171; }
  .badge--warning { color: #fbbf24; }
  /* Domain badges (.status-*, .sub-*, .supp-*) reuse the semantic --*-bg
     surfaces, which darken in dark mode; their light-mode dark text (e.g.
     #166534) then sits near-invisibly (~2.3:1). Lift the text to the same
     light tints used for .badge--success/danger/warning above. The neutral
     slate-backed variants are intentionally left as-is, matching .badge--neutral. */
  .status-sent,
  .sub-subscribed,
  .sub-confirmed { color: #4ade80; }
  .status-cancelled,
  .status-failed,
  .sub-bounced,
  .supp-hard_bounce,
  .supp-complaint { color: #f87171; }
  .status-sending,
  .status-paused,
  .sub-pending,
  .supp-rgpd { color: #fbbf24; }
  .status-scheduled { color: var(--teal-300); }
  pre { background: #0a1516; }
  .chart-area { opacity: 0.35; }
  /* Light slate track literals are blinding on dark cards. */
  .hbar-track { fill: rgba(255, 255, 255, 0.08); }
  .donut-track { stroke: rgba(255, 255, 255, 0.08); }
  th[aria-sort="ascending"] .th-sort::after,
  th[aria-sort="descending"] .th-sort::after { color: var(--orange-400); }

  /* ---- S1 UI foundation counterparts ----
     Components built purely on remapped tokens (.menu-panel, .tabs, the
     dialog surface, .editor-*, .spinner, .toast-stack, .pager-info,
     .chart-grid, .btn[aria-busy]) adapt automatically; below are the spots
     where a light-mode literal would otherwise leak through. */
  .menu > summary:hover, .menu[open] > summary { background: rgba(255, 255, 255, 0.08); }
  .menu-panel a:hover, .menu-panel button:hover { background: rgba(255, 255, 255, 0.06); }
  dialog#confirm-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
  /* Tooltip bubble bg (--slate-900) flips light: swap the text to dark. */
  [data-tip]::after { color: #0f172a; }
  /* Extra 1px ring so stacked toasts separate from the dark page. */
  .toast-stack .toast { box-shadow: var(--elev-overlay), 0 0 0 1px var(--border); }
  .chip { background: rgba(4, 106, 110, 0.22); border-color: var(--teal-800); color: var(--teal-200); }
  /* Selection bulk-bar: the light teal-50 fill is blinding on dark — swap to a
     translucent teal tint with light teal text (matches .chip). */
  .bulk-bar { background: rgba(4, 106, 110, 0.22); border-color: var(--teal-800); }
  .bulk-bar .bulk-count { color: var(--teal-200); }
  .bulk-bar .bulk-count strong { color: var(--teal-100); }
  /* var-pill on --info-bg (dark teal) needs a light token, not teal-800. */
  .var-pill { color: var(--teal-200); }
  .chip:hover { background: rgba(4, 106, 110, 0.4); border-color: var(--teal-700); }
  .skip-link { color: var(--teal-300); }
  /* Wins over the later S3 .error-code rule via higher specificity;
     orange-400 keeps the big code ≥AA-large on the dark card. */
  .error-card .error-code { color: var(--orange-400); }
}

/* ========================================================================
   15. HTMX INDICATORS (served, not runtime-injected — keeps CSP 'self')
   ======================================================================== */
.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }

/* ========================================================================
   S3 additions
   ======================================================================== */

/* ---- Public recipient-facing pages (pub_base.html shell) ---- */
body.public {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--sp-5);
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--teal-50), transparent 60%),
    var(--bg);
}

.public-card {
  width: 100%;
  max-width: 460px;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.public-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 700;
  font-size: var(--fs-md);
  letter-spacing: -0.01em;
  color: var(--slate-900);
}

.public-body {
  padding: var(--sp-6) var(--sp-5);
  text-align: center;
}

.public-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--sp-4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-full);
  background: var(--teal-50);
  color: var(--teal-700);
}
.public-icon svg { width: 28px; height: 28px; }
.public-icon--success { background: var(--success-bg); color: var(--success); }
.public-icon--warning { background: var(--warning-bg); color: var(--warning); }

.public-body h1 { font-size: var(--fs-xl); margin-bottom: var(--sp-3); }
.public-body p { color: var(--text-muted); }
.public-body .public-lead { color: var(--text); font-size: var(--fs-md); }

.public-form { margin-top: var(--sp-5); }

.public-footer {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  background: var(--surface-2);
}

/* ---- Contacts / import (S3) ---- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.toolbar-search.field-row {
  align-items: center;
  gap: var(--sp-2);
}
.toolbar-search.field-row input[type="search"] { flex: 1 1 220px; }
.toolbar-search.field-row .btn { flex: 0 0 auto; }

.form-narrow { max-width: 560px; }

.form-alert { position: static; max-width: none; margin-bottom: var(--sp-4); animation: none; }

.def-list { margin: 0; }
.def-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}
.def-row:last-child { border-bottom: 0; }
.def-row dt { margin: 0; font-weight: 600; color: var(--text-muted); }
.def-row dd { margin: 0; color: var(--text); }

.report-details {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2);
}
.report-details > summary { cursor: pointer; font-weight: 600; }
.report-details ul { margin: var(--sp-3) 0 0; padding-left: var(--sp-5); }
.report-details--error { border-color: var(--danger); }
.report-details--error > summary { color: var(--danger); }
.report-details--warning { border-color: var(--warning); }
.report-details--warning > summary { color: #92400e; }

@media (max-width: 560px) {
  .def-row { grid-template-columns: 1fr; gap: var(--sp-1); }
}

/* ---- Auth (login) — full-height branded screen, no sidebar ---- */
.auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--sp-6);
  background: linear-gradient(135deg, var(--teal-700) 0%, var(--teal-900) 100%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: var(--sp-6);
  box-shadow: var(--shadow-lg);
  border: none;
  text-align: center;
}
.auth-head {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
}
.auth-logo { width: 32px; height: 32px; font-size: var(--fs-lg); }
.auth-wordmark { font-weight: 700; font-size: var(--fs-lg); color: var(--slate-900); }
.auth-title { font-size: var(--fs-2xl); margin-bottom: var(--sp-1); }
.auth-sub { color: var(--text-muted); margin-bottom: var(--sp-6); }
.auth-form { text-align: left; }
.auth-form .field { margin-bottom: var(--sp-4); }
.auth-error {
  position: static;
  max-width: none;
  margin-bottom: var(--sp-4);
  box-shadow: none;
  border: 1px solid var(--danger);
  text-align: left;
}

/* ---- Error page card ---- */
.errorpage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}
.error-card {
  width: 100%;
  max-width: 460px;
  text-align: center;
}
.error-card .card-body { padding: var(--sp-7) var(--sp-5); }
.error-code {
  font-size: var(--fs-3xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  /* orange-800 #9a5c00 = 5.38:1 on white — AA even at body size. */
  color: var(--orange-800);
  margin-bottom: var(--sp-2);
}
.error-card .actions { justify-content: center; margin-top: var(--sp-4); }

/* ---- Warning list inside cards ---- */
.warning-list { margin: 0; padding-left: var(--sp-5); }
.warning-list li { margin-bottom: var(--sp-1); }

/* ========================================================================
   S7 REFONTE ADDITIONS
   New component classes the page refonte needs that S1/S3 didn't cover.
   All token-based (dark-mode adapts automatically except the few literals
   restated in the trailing dark block). No existing S1 selector is redefined
   here — these are all new class names or new descendant seams.
   ======================================================================== */

/* ---- Stepper: horizontal 1-2-3 progress header (CSV import) ----
   Markup: <ol class="stepper"><li class="stepper-item stepper-item--done">
     <span class="stepper-num">1</span><span class="stepper-label">…</span></li>…
   Teal for the active/done reach, muted for upcoming steps. */
.stepper {
  display: flex;
  align-items: flex-start;
  margin: 0 0 var(--sp-5);
  padding: 0;
  list-style: none;
}
.stepper-item {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  text-align: center;
  font-size: var(--fs-sm);
}
/* Connector: line from the previous circle centre to this one, behind the
   opaque circles. Vertically centred on the 32px numbered circle (top 15px). */
.stepper-item:not(:first-child)::before {
  content: "";
  position: absolute;
  top: 15px;
  left: -50%;
  right: 50%;
  height: 2px;
  background: var(--border-strong);
  z-index: 0;
}
.stepper-num {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 2px solid var(--border-strong);
  color: var(--text-muted);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stepper-label { font-weight: 600; color: var(--text-muted); }
/* Reached (active or done) — the connector leading into the step turns teal. */
.stepper-item--active::before,
.stepper-item--done::before { background: var(--primary); }
.stepper-item--active .stepper-num { background: var(--primary); border-color: var(--primary); color: var(--text-inverse); }
.stepper-item--active .stepper-label { color: var(--slate-900); }
.stepper-item--done .stepper-num { background: var(--teal-50); border-color: var(--primary); color: var(--primary); }
.stepper-item--done .stepper-label { color: var(--text); }

/* ---- Toolbar filter group (S1 data-autosubmit filter row above a table) ----
   Sits inside the existing .toolbar; groups the filter selects/inputs so they
   stay compact and wrap together on narrow screens. */
.toolbar-filters {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.toolbar-filters select,
.toolbar-filters input { width: auto; min-width: 140px; }

/* ---- Tab panel: content region under .tabs (tabbed detail pages) ----
   Standalone it draws its own top divider; directly after the tab bar it
   defers to the tab bar's own border + 24px gap so the line isn't doubled. */
.tab-panel {
  padding-top: var(--sp-5);
  border-top: 1px solid var(--border);
}
.tabs + .tab-panel { padding-top: 0; border-top: 0; }

/* ---- Page-header quick actions: right-aligned button row ----
   Drop into .page-head next to the title; margin-left:auto keeps it right even
   when it is the only trailing child. (Use the existing .page-head for the
   title-left / actions-right header shell — no separate .page-header needed.) */
.quick-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-left: auto;
}

/* ---- KPI delta captions (dashboard) — directional tint under .kpi-value ----
   .kpi-trend base (flex + gap) is defined in §6; these add the up/down glyphs. */
.kpi-trend--up { color: var(--success); }
.kpi-trend--up::before { content: "▲"; font-size: 0.85em; }
.kpi-trend--down { color: var(--danger); }
.kpi-trend--down::before { content: "▼"; font-size: 0.85em; }

/* ---- Table region: HTMX live-search swap target + overflow scroll ----
   Minimal wrapper — pair with .card or .table-wrap when a border is wanted. */
.table-region { overflow-x: auto; }

/* ---- Visually-hidden aria-live status line (announces live-search results) --- */
.sr-status {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Detail grid: responsive two-column definition layout ----
   Replaces ad-hoc <dl> styling on detail/settings pages; both themes via
   tokens. Collapses to a single stacked column on narrow screens. */
.detail-grid {
  display: grid;
  grid-template-columns: minmax(140px, max-content) 1fr;
  gap: var(--sp-2) var(--sp-5);
  align-items: baseline;
  margin: 0;
}
.detail-grid dt { margin: 0; font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); }
.detail-grid dd { margin: 0; min-width: 0; color: var(--text); overflow-wrap: break-word; }
@media (max-width: 560px) {
  .detail-grid { grid-template-columns: 1fr; gap: var(--sp-1); }
  .detail-grid dd { margin-bottom: var(--sp-3); }
}

/* ---- One-system polish: a .table nested flush inside a .card ----
   The card already draws the 1px ring + radius, so the table runs edge-to-edge
   under the card header, its outer cell padding lined up with the header's. */
.card > .table-region > .table thead th:first-child,
.card > .table-region > .table tbody td:first-child { padding-left: var(--sp-5); }
.card > .table-region > .table thead th:last-child,
.card > .table-region > .table tbody td:last-child { padding-right: var(--sp-5); }

/* ---- S7 dark-theme counterparts (only where a light literal would leak) ---- */
@media (prefers-color-scheme: dark) {
  /* KPI deltas: lift the semantic tints for contrast on the dark card
     (matches the .badge--success/--danger dark treatment). */
  .kpi-trend--up { color: #4ade80; }
  .kpi-trend--down { color: #f87171; }
  /* Done-step circle uses the light --teal-50 literal (not remapped) — swap to
     a translucent teal so it reads as a badge, not a bright dot. */
  .stepper-item--done .stepper-num { background: rgba(4, 106, 110, 0.22); color: var(--teal-300); }
}

/* ========================================================================
   16. REFONTE UI — comp-parity additions (CSP-safe, token-based)
   New component classes for the "Refonte UI" pass. Every rule is class-scoped
   and token-driven; the trailing dark block restates only the spots where a
   light literal would otherwise leak. No existing selector is redefined here.
   ======================================================================== */

/* ---- Callout: filled teal-tinted emphasis box ----
   Used for the campaign recipient estimate and the user-role explainer. */
.callout {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-lg);
  background: var(--info-bg);
  color: var(--teal-800);
  font-size: var(--fs-sm);
}
.callout strong { color: var(--teal-700); font-weight: 700; }
.callout .callout-num {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--teal-700);
  font-variant-numeric: tabular-nums;
}

/* ---- Identity header: large avatar + name/sub (detail pages) ---- */
.identity-head { display: flex; align-items: center; gap: var(--sp-4); }
.identity-head h1 { margin: 0 0 2px; }
.avatar--lg {
  width: 52px;
  height: 52px;
  font-size: var(--fs-xl);
  background: var(--teal-50);
  color: var(--teal-700);
}

/* ---- File dropzone (CSV import) — click-to-browse label, no JS ---- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-7) var(--sp-5);
  border: 2px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--primary); background: var(--teal-50); }
.dropzone .dropzone-icon { width: 44px; height: 44px; color: var(--slate-300); }
.dropzone .dropzone-icon svg { width: 100%; height: 100%; }
.dropzone .dropzone-prompt { font-weight: 600; color: var(--slate-700); word-break: break-word; }
.dropzone .dropzone-hint { font-size: var(--fs-sm); color: var(--text-muted); }
/* A file is chosen: solid teal border + tinted fill so the change is obvious. */
.dropzone.is-selected { border-style: solid; border-color: var(--primary); background: var(--teal-50); }
.dropzone.is-selected .dropzone-icon,
.dropzone.is-selected .dropzone-prompt { color: var(--teal-800); }
/* The real file input is visually hidden; the label (.dropzone) drives it. */
.dropzone-input {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ---- Dashboard: weighted two-chart row (send-volume chart wider) ---- */
.chart-row { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }
@media (min-width: 900px) { .chart-row { grid-template-columns: 1.5fr 1fr; } }

/* ---- Dashed "start from scratch / blank" card (template list + gallery) ---- */
.card--dashed {
  border: 2px dashed var(--border-strong);
  box-shadow: none;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 180px;
  padding: var(--sp-5);
  text-align: center;
  color: var(--text-muted);
  font-weight: 600;
}
.card--dashed:hover { border-color: var(--primary); color: var(--primary); box-shadow: none; text-decoration: none; }
.card--dashed .card-dashed-icon { width: 28px; height: 28px; }
.card--dashed .card-dashed-icon svg { width: 100%; height: 100%; }

/* ---- Template thumbnail card (templates list) — name/meta under a preview --- */
.tpl-meta { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-2); }
.tpl-meta .tpl-name { font-weight: 650; color: var(--slate-900); }
.tpl-meta .tpl-sub { font-size: var(--fs-sm); color: var(--text-muted); margin: 2px 0 0; }

/* ---- Automation flow diagram: vertical node + connector sequence ---- */
.flow {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.flow-node {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
}
.flow-node--trigger { background: var(--teal-50); border-color: var(--teal-100); }
.flow-icon {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r);
  background: var(--slate-100);
  color: var(--slate-600);
}
.flow-icon svg { width: 18px; height: 18px; }
.flow-node--trigger .flow-icon { background: var(--primary); color: #fff; }
.flow-node--email .flow-icon { background: var(--orange-500); color: var(--slate-900); }
.flow-body { flex: 1 1 auto; min-width: 0; }
.flow-title { font-weight: 650; color: var(--slate-900); }
.flow-sub { font-size: var(--fs-sm); color: var(--text-muted); }
.flow-stat { flex: 0 0 auto; font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
.flow-connector { width: 2px; height: 24px; background: var(--border-strong); align-self: center; }
.flow-add { align-self: center; margin-top: var(--sp-2); }

/* ---- Public preferences: bordered option rows + CSS toggle switch ---- */
.public-body--form { text-align: left; }
.prefs-list { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-4); }
.pref-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  margin: 0;
  cursor: pointer;
}
.pref-row .pref-name { font-weight: 600; color: var(--slate-900); }
.switch {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 22px;
}
.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.switch .switch-track {
  position: absolute;
  inset: 0;
  border-radius: var(--r-full);
  background: var(--border-strong);
  transition: background var(--dur) var(--ease);
}
.switch .switch-track::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: var(--r-full);
  background: #fff;
  box-shadow: var(--shadow-xs);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::before { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus-ring); }

/* ---- Fidelity pass: page-specific components from the full comp rebuild ---- */

/* Inline status badge beside a page-head <h1> (automation/webhook/txn detail). */
.page-head h1 .badge--head { vertical-align: middle; margin-left: var(--sp-1); }

/* Soft-teal avatar + identity cell (users table). */
.avatar--soft { background: var(--teal-50); color: var(--teal-700); }
.user-cell { display: inline-flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.user-cell-email { font-weight: 600; color: var(--slate-900); overflow: hidden; text-overflow: ellipsis; }

/* Send-progress meter — native <progress> styled to the system (queue "Lots en cours"). */
.meter-row { display: flex; align-items: center; gap: var(--sp-3); }
.meter-row .num { flex: 0 0 auto; font-size: var(--fs-sm); }

/* Dashboard "Croissance de la liste": label + signed total on a row, and a
   net-balance footer under the two mini-charts. */
.growth-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-1); }
.growth-head .kpi-trend { font-variant-numeric: tabular-nums; }
.growth-net { margin: 0; font-size: var(--fs-sm); color: var(--text-muted); border-top: 1px solid var(--border); padding-top: var(--sp-3); }
.growth-net strong { font-variant-numeric: tabular-nums; }
.growth-net strong.pos { color: var(--success); }
.growth-net strong.neg { color: var(--danger); }
.meter {
  flex: 1 1 auto;
  min-width: 80px;
  height: 7px;
  border: none;
  border-radius: var(--r-full);
  background: var(--slate-100);
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
}
.meter::-webkit-progress-bar { background: var(--slate-100); border-radius: var(--r-full); }
.meter::-webkit-progress-value { background: var(--teal-700); border-radius: var(--r-full); }
.meter::-moz-progress-bar { background: var(--teal-700); border-radius: var(--r-full); }

/* Segment builder: rule box + compact inline controls. */
.sb-panel {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.sb-add-pill { align-self: flex-start; }
.sb-inline { width: auto; align-self: flex-start; }
.rule-summary { color: var(--text-muted); }

/* ---- Refonte dark-theme counterparts (only where a light literal leaks) ---- */
@media (prefers-color-scheme: dark) {
  /* Callout text tints flip too dark on the darkened --info-bg. */
  .callout { color: var(--teal-200); }
  /* Soft avatar + meter track use light literals. */
  .avatar--soft { background: rgba(4, 106, 110, 0.22); color: var(--teal-300); }
  .meter, .meter::-webkit-progress-bar { background: var(--border); }
  .callout strong, .callout .callout-num { color: var(--teal-300); }
  /* Large avatar soft-teal literals. */
  .avatar--lg { background: rgba(4, 106, 110, 0.22); color: var(--teal-300); }
  /* Dropzone hover/selected use --teal-50 literals. */
  .dropzone:hover, .dropzone.is-dragover, .dropzone.is-selected { background: rgba(4, 106, 110, 0.15); }
  .dropzone.is-selected .dropzone-icon,
  .dropzone.is-selected .dropzone-prompt { color: var(--teal-200); }
  /* Flow trigger node soft-teal literals; email icon glyph stays dark on orange. */
  .flow-node--trigger { background: rgba(4, 106, 110, 0.15); border-color: var(--teal-800); }
  .flow-node--email .flow-icon { color: #0f172a; }
}
