/*
 * Dashboard — noir épuré.
 *
 * Une seule feuille, sans framework : fond noir, surfaces à peine plus claires,
 * bordures fines, aucune ombre. Mobile d'abord : la navigation passe en barre
 * basse sous 1024 px et les tableaux deviennent des cartes sous 760 px. Toute
 * cible tactile fait au moins 44 px de haut.
 *
 * Les couleurs d'état sont fixées une fois ici (--st-*) et reprises partout :
 * un « Échec » est du même rouge dans un badge, une barre ou un compteur.
 */

:root {
    --bg: #000;
    --surface: #0D0D0F;
    --surface-2: #16161A;
    --surface-3: #1E1E23;
    --border: #26262B;
    --border-strong: #3A3A40;
    --text: #F5F5F7;
    --muted: #8E8E93;
    --faint: #5A5A60;
    --accent: #F5F5F7;
    --accent-ink: #000;
    --green: #30D158;
    --orange: #FF9F0A;
    --red: #FF453A;
    --blue: #0A84FF;
    --cyan: #64D2FF;
    --purple: #BF5AF2;

    /* États d'un message */
    --st-queued: #A1A1A6;
    --st-dispatched: var(--cyan);
    --st-sending: var(--blue);
    --st-sent: #7EE2A0;
    --st-delivered: var(--green);
    --st-undelivered: var(--orange);
    --st-unknown: var(--purple);
    --st-failed: var(--red);
    --st-canceled: #48484D;

    --radius: 22px;
    --radius-sm: 14px;
    --radius-xs: 10px;
    --tap: 44px;
    --sidebar: 256px;
    --font: 'Archivo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    --ease: cubic-bezier(.2, .7, .2, 1);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --bottom-nav: 64px;

    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 400 15px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }
a:hover { color: #fff; }
.link { text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
.link:hover { text-decoration-color: var(--text); }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; line-height: 1.25; }
p { margin: 0 0 .75em; }
p:last-child { margin-bottom: 0; }
code, pre, .mono { font-family: var(--mono); font-size: .88em; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; }
pre {
    margin: 0; padding: 14px 16px; overflow-x: auto; white-space: pre-wrap; word-break: break-all;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
img, svg, video { max-width: 100%; }
strong { font-weight: 600; }
small, .small { font-size: 13px; }

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

.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;
}

/* Utilitaires de texte */
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.text-ok { color: var(--green); }
.text-warn { color: var(--orange); }
.text-err { color: var(--red); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.break { overflow-wrap: anywhere; word-break: break-word; }
.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.mt { margin-top: 16px; }
.mt-sm { margin-top: 8px; }
.mb-0 { margin-bottom: 0; }

/* ==========================================================================
   Structure : barre latérale (bureau), barre haute et barre basse (mobile)
   ========================================================================== */

.shell { min-height: 100vh; min-height: 100dvh; }

.sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30;
    width: var(--sidebar);
    padding: calc(20px + var(--safe-top)) 14px 16px calc(14px + var(--safe-left));
    display: none; flex-direction: column; gap: 4px;
    background: var(--bg); border-right: 1px solid var(--border);
    overflow-y: auto; scrollbar-width: thin;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 18px; min-height: var(--tap); }
.brand img { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border); }
.brand-name { font-weight: 600; font-size: 17px; letter-spacing: -.01em; }
.brand-sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }

.nav-group { margin-top: 14px; }
.nav-label {
    padding: 0 12px 6px; font-size: 11px; font-weight: 600; letter-spacing: .08em;
    text-transform: uppercase; color: var(--faint);
}
.nav-link {
    display: flex; align-items: center; gap: 12px;
    min-height: var(--tap); padding: 0 12px; border-radius: 12px;
    color: var(--muted); font-weight: 500;
    transition: background .2s var(--ease), color .2s var(--ease);
}
.nav-link:hover { background: var(--surface); color: var(--text); }
.nav-link.is-active { background: var(--surface-2); color: var(--text); }
.nav-link .icon { flex: none; }
.nav-link .nav-text { flex: 1 1 auto; }
.nav-count {
    min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--orange); color: #000; font: 600 12px/1 var(--font);
}

.sidebar-foot { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--border); }
.who { padding: 6px 12px 10px; font-size: 13px; color: var(--muted); }
.who strong { display: block; color: var(--text); font-size: 14px; }

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 12px;
    min-height: calc(56px + var(--safe-top));
    padding: var(--safe-top) calc(16px + var(--safe-right)) 0 calc(16px + var(--safe-left));
    background: rgba(0, 0, 0, .82);
    -webkit-backdrop-filter: saturate(160%) blur(18px); backdrop-filter: saturate(160%) blur(18px);
    border-bottom: 1px solid var(--border);
}
/* Le logo de la barre du haut ramène à l'accueil : zone tactile pleine hauteur. */
.topbar .brand { padding: 0; min-height: var(--tap); flex: 1 1 auto; min-width: 0; }
.topbar .brand img { width: 30px; height: 30px; border-radius: 9px; }
.topbar .brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main {
    padding: 22px calc(16px + var(--safe-right)) calc(var(--bottom-nav) + var(--safe-bottom) + 32px) calc(16px + var(--safe-left));
    max-width: 1280px; margin: 0 auto;
}

.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    display: grid; grid-template-columns: repeat(5, 1fr);
    height: calc(var(--bottom-nav) + var(--safe-bottom));
    padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    background: rgba(0, 0, 0, .88);
    -webkit-backdrop-filter: saturate(160%) blur(18px); backdrop-filter: saturate(160%) blur(18px);
    border-top: 1px solid var(--border);
}
.bottom-nav a, .bottom-nav button {
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: var(--tap); padding: 0; border: 0; background: none;
    color: var(--muted); font: 500 11px/1.1 var(--font); cursor: pointer;
    transition: color .2s var(--ease);
}
.bottom-nav .is-active { color: var(--text); }
.bottom-nav .compose-tab .tab-bubble {
    width: 44px; height: 32px; border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent); color: var(--accent-ink);
}
.bottom-nav .tab-dot {
    position: absolute; top: 8px; left: calc(50% + 6px);
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    background: var(--orange); color: #000; font: 600 11px/18px var(--font); text-align: center;
}

@media (min-width: 1024px) {
    .sidebar { display: flex; }
    .topbar, .bottom-nav { display: none; }
    .shell { padding-left: var(--sidebar); }
    .main { padding: 36px 40px 64px; }
}

/* Feuille « Plus » (mobile) */
.sheet {
    width: 100%; max-width: 560px; max-height: 88vh; max-height: 88dvh;
    margin: auto auto 0; padding: 0; border: 1px solid var(--border); border-bottom: 0;
    border-radius: 24px 24px 0 0; background: var(--surface); color: var(--text);
    overflow: hidden;
}
.sheet[open] { display: flex; flex-direction: column; animation: sheet-in .28s var(--ease); }
.sheet::backdrop { background: rgba(0, 0, 0, .6); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 22px; }
.sheet-body { overflow-y: auto; padding: 0 12px calc(20px + var(--safe-bottom)); }
.sheet .nav-link { min-height: 48px; }
.sheet .nav-group { margin-top: 10px; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ==========================================================================
   En-tête de page
   ========================================================================== */

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .grow { min-width: 220px; }
.page-title { font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.page-sub { margin-top: 6px; color: var(--muted); max-width: 72ch; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.back { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; margin-bottom: 6px; color: var(--muted); font-size: 14px; }
.back:hover { color: var(--text); }
@media (pointer: coarse) { .back { min-height: var(--tap); } }
@media (min-width: 1024px) { .page-title { font-size: 30px; } }

/* ==========================================================================
   Cartes et grilles
   ========================================================================== */

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    min-width: 0;
}
.card + .card { margin-top: 16px; }
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 18px 20px 0;
}
.card-title { font-size: 16px; font-weight: 600; }
.card-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-body { padding: 18px 20px 20px; }
.card-foot { padding: 16px 20px; border-top: 1px solid var(--border); }
.card-flush { padding: 12px 0 4px; }
.card.is-ok { border-color: rgba(48, 209, 88, .45); }
.card.is-warn { border-color: rgba(255, 159, 10, .45); }

.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.grid > .card + .card { margin-top: 0; }
@media (min-width: 760px) {
    .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .grid-side { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (min-width: 1100px) {
    .grid-side { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); }
    .grid-main { grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); }
}
.col-stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.col-stack > .card + .card { margin-top: 0; }

.section-title { margin: 30px 0 12px; font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.section-title:first-child { margin-top: 0; }

/* Tuiles de chiffres */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat {
    position: relative; display: flex; flex-direction: column; gap: 4px;
    min-height: 104px; padding: 16px 18px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border);
    transition: border-color .2s var(--ease), background .2s var(--ease);
}
a.stat:hover { border-color: var(--border-strong); background: var(--surface-2); }
.stat-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-value { font: 600 30px/1.1 var(--font); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 16px; color: var(--muted); font-weight: 500; }
.stat-hint { margin-top: auto; color: var(--faint); font-size: 12px; }
.stat .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--muted)); flex: none; }

/* ==========================================================================
   Boutons
   ========================================================================== */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--tap); padding: 0 18px; border-radius: 999px;
    border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
    font: 500 14px/1 var(--font); white-space: nowrap; cursor: pointer;
    transition: background .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease), transform .15s var(--ease);
    text-decoration: none; -webkit-appearance: none; appearance: none;
}
.btn:hover { background: var(--surface-3); border-color: #4A4A50; color: var(--text); }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: #fff; border-color: #fff; color: #000; }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: rgba(255, 69, 58, .45); color: var(--red); }
.btn-danger:hover { background: rgba(255, 69, 58, .12); border-color: var(--red); color: var(--red); }
.btn-success { background: var(--green); border-color: var(--green); color: #000; font-weight: 600; }
.btn-success:hover { background: #4ADE74; border-color: #4ADE74; color: #000; }
.btn-warn { background: transparent; border-color: rgba(255, 159, 10, .5); color: var(--orange); }
.btn-warn:hover { background: rgba(255, 159, 10, .12); color: var(--orange); }
.btn-block { display: flex; width: 100%; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 13px; }
.btn-icon { width: var(--tap); padding: 0; }
.btn-icon.btn-sm { width: 36px; }
.btn-lg { min-height: 54px; padding: 0 26px; font-size: 16px; }
/* Au doigt, même un petit bouton garde 44 px de cible. */
@media (pointer: coarse) {
    .btn-sm { min-height: var(--tap); }
    .btn-icon.btn-sm { width: var(--tap); }
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions form { margin: 0; }
.actions-end { justify-content: flex-end; }

/* ==========================================================================
   Formulaires
   ========================================================================== */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field + .field, .field + .fields, .fields + .field, .fields + .fields { margin-top: 16px; }
.fields { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) {
    .fields-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .fields-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.label, .field > label { font-size: 13px; font-weight: 600; color: var(--text); }
.label-opt { color: var(--muted); font-weight: 400; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; }
.hint + .hint { margin-top: 6px; }

.input, .select, .textarea {
    width: 100%; min-height: var(--tap); padding: 10px 14px;
    background: var(--bg); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font: 400 15px/1.4 var(--font);
    transition: border-color .2s var(--ease), background .2s var(--ease);
    -webkit-appearance: none; appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--text); background: #050506; }
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.textarea.mono, .input.mono { font-family: var(--mono); font-size: 14px; }
.select {
    padding-right: 40px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 15px center;
}
.select option { background: var(--surface-2); color: var(--text); }
.input-sm, .select-sm { min-height: 38px; padding-top: 6px; padding-bottom: 6px; font-size: 14px; border-radius: 12px; }
@media (pointer: coarse) { .input-sm, .select-sm { min-height: var(--tap); font-size: 16px; } }
/* iOS agrandit la page sur un champ en dessous de 16 px. */
@media (max-width: 760px) { .input, .select, .textarea { font-size: 16px; } }
input[type="file"].input { padding: 9px 12px; }
input[type="file"]::file-selector-button {
    margin-right: 12px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border-strong);
    background: var(--surface-2); color: var(--text); font: 500 13px var(--font); cursor: pointer;
}
input[type="datetime-local"].input, input[type="time"].input { color-scheme: dark; }

.input-group { display: flex; align-items: stretch; }
.input-group > .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group > .addon {
    display: flex; align-items: center; padding: 0 14px; color: var(--muted);
    border: 1px solid var(--border); border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--surface-2); font-size: 14px;
}
.input-pair { display: flex; align-items: center; gap: 8px; }
.input-pair .sep { color: var(--muted); font-size: 14px; }

.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.inline-form .input, .inline-form .select { width: auto; flex: 1 1 160px; min-width: 0; }

/* Cases à cocher et options sous forme de lignes cliquables */
.check { display: flex; align-items: flex-start; gap: 12px; min-height: var(--tap); padding: 10px 0; cursor: pointer; }
.check input { flex: none; }
input[type="checkbox"], input[type="radio"] {
    width: 22px; height: 22px; margin: 0; accent-color: var(--text); cursor: pointer;
}
.check-row {
    display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 14px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); cursor: pointer;
    transition: border-color .2s var(--ease), background .2s var(--ease);
}
.check-row + .check-row { margin-top: 8px; }
.check-row:hover { border-color: var(--border-strong); }
.check-row:has(input:checked) { border-color: var(--text); background: var(--surface-2); }
.check-row .grow { display: flex; flex-direction: column; gap: 2px; }
.check-row .sub { color: var(--muted); font-size: 13px; }
.checks-inline { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.checks-inline .check { padding: 6px 0; }

/* Puces (délais, variables, filtres) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 38px; min-width: 52px; padding: 0 14px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--bg); color: var(--text);
    font: 500 14px/1 var(--font); cursor: pointer; white-space: nowrap;
    transition: background .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease);
}
.chip:hover { border-color: var(--border-strong); }
.chip.is-on, .chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.mono { font-family: var(--mono); font-size: 13px; }
@media (pointer: coarse) { .chip { min-height: var(--tap); } }
.chip .count { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.chip.is-on .count { color: rgba(0, 0, 0, .6); }

/* ==========================================================================
   Badges d'état
   ========================================================================== */

.badge {
    --c: var(--muted);
    display: inline-flex; align-items: center; gap: 6px;
    height: 24px; padding: 0 10px; border-radius: 999px;
    background: color-mix(in srgb, var(--c) 14%, transparent);
    color: var(--c); font: 500 12px/1 var(--font); white-space: nowrap; vertical-align: middle;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge.no-dot::before { display: none; }
.badge-ok { --c: var(--green); }
.badge-warn { --c: var(--orange); }
.badge-err { --c: var(--red); }
.badge-info { --c: var(--blue); }
.badge-cyan { --c: var(--cyan); }
.badge-purple { --c: var(--purple); }
.badge-muted { --c: var(--muted); }
.badge-white { --c: var(--text); }
.st-queued { --c: var(--st-queued); }
.st-dispatched { --c: var(--st-dispatched); }
.st-sending { --c: var(--st-sending); }
.st-sent { --c: var(--st-sent); }
.st-delivered { --c: var(--st-delivered); }
.st-undelivered { --c: var(--st-undelivered); }
.st-unknown { --c: var(--st-unknown); }
.st-failed { --c: var(--st-failed); }
.st-canceled { --c: #8E8E93; }

/* ==========================================================================
   Tableaux — en cartes sous 760 px
   ========================================================================== */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
    padding: 10px 16px; text-align: left; white-space: nowrap;
    color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}
.table td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table th:first-child, .table td:first-child { padding-left: 20px; }
.table th:last-child, .table td:last-child { padding-right: 20px; }
.table .right, .table th.right { text-align: right; }
.table tr.is-link { cursor: pointer; transition: background .15s var(--ease); }
.table tr.is-link:hover td { background: var(--surface-2); }
.table .cell-sub { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.table-kv th { width: 40%; text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 500; vertical-align: top; padding-top: 14px; }

@media (max-width: 759.98px) {
    .table-cards thead { display: none; }
    .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
    .table-cards tr {
        margin: 0 12px 10px; width: auto; padding: 12px 16px;
        border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg);
    }
    .table-cards tbody tr:last-child { margin-bottom: 12px; }
    .table-cards td {
        display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
        padding: 7px 0 !important; border: 0; text-align: right;
    }
    .table-cards td::before {
        content: attr(data-label); flex: none; max-width: 45%; font-family: var(--font); font-variant-numeric: normal;
        color: var(--muted); font-size: 13px; text-align: left;
    }
    .table-cards td[data-label=""]::before, .table-cards td:not([data-label])::before { display: none; }
    .table-cards td.cell-main { display: block; text-align: left; padding-bottom: 8px !important; font-size: 15px; }
    .table-cards td.cell-main::before { display: none; }
    .table-cards td.cell-actions { justify-content: flex-start; padding-top: 10px !important; }
    .table-cards td.cell-actions::before { display: none; }
    .table-cards td > .actions { justify-content: flex-start; }
    .table-cards td .cell-sub { text-align: inherit; }
    .table-cards tr.is-link:hover td { background: none; }
    .card-flush { padding: 12px 0 2px; }
}

/* Paires clé / valeur (fiches de détail) */
.kv { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.kv > div { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.kv > div:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); font-size: 14px; flex: none; max-width: 50%; }
.kv dd { margin: 0; text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* ==========================================================================
   Messages, encarts, état vide
   ========================================================================== */

.flash {
    display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px; padding: 14px 16px;
    border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface);
    animation: fade-in .3s var(--ease);
}
.flash .icon { flex: none; margin-top: 1px; }
.flash-body { flex: 1 1 auto; min-width: 0; }
.flash-close { margin: -8px -8px -8px 0; }
.flash-ok { border-color: rgba(48, 209, 88, .4); }
.flash-ok .icon { color: var(--green); }
.flash-err { border-color: rgba(255, 69, 58, .45); }
.flash-err .icon { color: var(--red); }
@keyframes fade-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.callout { padding: 14px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); }
.callout-err { border-color: rgba(255, 69, 58, .45); background: rgba(255, 69, 58, .07); }
.callout-warn { border-color: rgba(255, 159, 10, .45); background: rgba(255, 159, 10, .07); }
.callout-ok { border-color: rgba(48, 209, 88, .4); background: rgba(48, 209, 88, .06); }
.callout-title { font-weight: 600; margin-bottom: 4px; }

.empty { padding: 28px 20px; text-align: center; color: var(--muted); }
.empty .icon { color: var(--faint); margin-bottom: 8px; }

/* Repli (Lignes supprimées, réglages avancés) */
.fold { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.fold + .fold, .card + .fold, .fold + .card { margin-top: 16px; }
.fold > summary {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    min-height: 60px; padding: 0 20px; cursor: pointer; list-style: none; font-weight: 600;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary .icon { color: var(--muted); transition: transform .25s var(--ease); }
.fold[open] > summary .icon { transform: rotate(180deg); }
.fold-body { padding: 0 20px 20px; }
.fold-flush { padding: 0 0 4px; }
.fold.inner { background: var(--bg); border-radius: var(--radius-sm); }
.fold.inner > summary { min-height: 52px; font-size: 14px; }

/* ==========================================================================
   Progression d'une campagne
   ========================================================================== */

.progress { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surface-2); gap: 2px; }
.progress > span { display: block; height: 100%; min-width: 3px; background: var(--c, var(--muted)); transition: width .6s var(--ease); }
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.counts { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .counts { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .counts { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.count {
    display: flex; flex-direction: column; gap: 2px; min-height: 72px; padding: 12px 14px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg);
    transition: border-color .2s var(--ease), background .2s var(--ease);
}
a.count:hover { border-color: var(--border-strong); background: var(--surface-2); }
.count.is-on { border-color: var(--c, var(--text)); }
.count-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.count-label::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--text)); flex: none; }
.count-value { font: 600 22px/1.2 var(--font); font-variant-numeric: tabular-nums; }
.count.is-total .count-label::before { display: none; }

.live-dot { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.live-dot::before {
    content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--green);
    animation: pulse 1.8s ease-in-out infinite;
}
.live-dot.is-idle::before { background: var(--faint); animation: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* ==========================================================================
   Conversation, frise, vignettes, QR
   ========================================================================== */

.thread { display: flex; flex-direction: column; gap: 12px; }
.bubble-row { display: flex; flex-direction: column; align-items: flex-start; max-width: 82%; }
.bubble-row.is-out { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 10px 14px; border-radius: 18px 18px 18px 6px; background: var(--surface-2); border: 1px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-row.is-out .bubble { border-radius: 18px 18px 6px 18px; background: var(--text); color: #000; border-color: var(--text); }
.bubble-meta { margin-top: 4px; font-size: 12px; color: var(--muted); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 26px; }
.timeline li::before { content: ''; position: absolute; left: 5px; top: 18px; bottom: -2px; width: 1px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline .tl-dot { position: absolute; left: 0; top: 6px; width: 11px; height: 11px; border-radius: 50%; background: var(--c, var(--muted)); }
.timeline .tl-time { color: var(--muted); font-size: 13px; font-family: var(--mono); }

.thumbs { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 760px) { .thumbs { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.thumb { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg); }
.thumb img, .thumb video { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.thumb audio { display: block; width: 100%; margin: 12px 0 0; }
.thumb .caption { padding: 8px 12px; color: var(--muted); font-size: 13px; }

.qr { display: inline-block; padding: 14px; background: #fff; border-radius: var(--radius-sm); line-height: 0; }
.qr svg { display: block; width: 220px; max-width: 100%; height: auto; }
.code-big { font: 600 30px/1.2 var(--mono); letter-spacing: .2em; }

/* Pagination */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pager .actions { gap: 6px; }

/* Bannière d'installation (PWA) */
.install-banner {
    position: fixed; z-index: 40; left: 12px; right: 12px;
    bottom: calc(var(--bottom-nav) + var(--safe-bottom) + 12px);
    display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 16px;
    border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface-2);
    animation: fade-in .3s var(--ease);
}
.install-banner[hidden] { display: none; }
.install-banner img { width: 40px; height: 40px; border-radius: 11px; flex: none; }
.install-banner .grow { font-size: 14px; }
.install-banner .grow strong { display: block; }
.install-banner .muted { font-size: 13px; }
@media (min-width: 1024px) {
    .install-banner { left: auto; right: 24px; bottom: 24px; width: 380px; }
}
.ios-share { display: inline-flex; vertical-align: -4px; }

/* ==========================================================================
   Page de connexion et page hors ligne
   ========================================================================== */

.auth {
    min-height: 100vh; min-height: 100dvh;
    display: flex; align-items: center; justify-content: center;
    padding: calc(24px + var(--safe-top)) calc(20px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(20px + var(--safe-left));
}
.auth-box { width: 100%; max-width: 400px; }
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 28px; text-align: center; }
.auth-logo img { width: 64px; height: 64px; border-radius: 18px; border: 1px solid var(--border); }
.auth-logo h1 { font-size: 24px; }
.auth-logo p { color: var(--muted); margin: 0; }
.auth .card-body { padding: 24px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Bouton présenté comme un lien du menu (installer, se déconnecter). */
.nav-button { width: 100%; background: none; border: 0; cursor: pointer; font: inherit; text-align: left; }
.workspace { padding: 0 2px 6px; }
.sheet-workspace { padding: 0 10px; }
.sheet-foot { margin-top: 16px; }
.st-inbound { --c: var(--text); }
.st-ok { --c: var(--green); }
.st-warn { --c: var(--orange); }
.st-err { --c: var(--red); }
@media (min-width: 760px) { .hide-desktop { display: none; } }
@media (max-width: 759.98px) { .hide-mobile { display: none; } }
.divided { padding-top: 18px; border-top: 1px solid var(--border); }
.line-list { list-style: none; margin: 6px 0 0; padding: 0; }
.line-list li { color: var(--muted); font-size: 13px; }

/* Changement de mot de passe d'un accès : replié sous son bouton. */
.password-fold { position: relative; }
.password-fold > summary { list-style: none; }
.password-fold > summary::-webkit-details-marker { display: none; }
.password-form {
    margin-top: 8px; padding: 12px; min-width: 240px; text-align: left;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
@media (min-width: 760px) {
    .password-form { position: absolute; right: 0; z-index: 5; }
}
.check-row input { flex: none; }
.line-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.line-tags:empty { display: none; }
.fields > .field { margin-top: 0; }
/* Cellule au contenu riche (téléphone et lignes, texte) : sur téléphone, le
   libellé passe au-dessus et la valeur reprend toute la largeur. */
@media (max-width: 759.98px) {
    .table-cards td.cell-block { display: block; text-align: left; }
    .table-cards td.cell-block::before { display: block; max-width: none; margin-bottom: 4px; }
    .table-cards td.cell-block .row { justify-content: flex-start !important; }
}
.callout-link { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.callout-link:hover { border-color: var(--orange); }
