:root {
  color-scheme: light;
  --fond: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --bord: #e3e1da;
  --texte: #161614;
  --texte-2: #5b5a55;
  --texte-3: #8a8983;
  --accent: #2a78d6;
  --accent-doux: #e3eefb;
  --accent-texte: #ffffff;
  --bulle-lui: #ecebe6;
  --bulle-toi: #2a78d6;
  --bulle-ia: #dbe8f8;
  --bulle-ia-texte: #12345c;
  --serie-1: #2a78d6;
  --grille: #e7e5df;
  --vert: #1d7a3a;   --vert-fond: #e3f3e7;
  --jaune: #8a5a00;  --jaune-fond: #fbf0d6;
  --orange: #a1430d; --orange-fond: #fde5d6;
  --rouge: #b42323;  --rouge-fond: #fbe2e2;
  --gris: #5b5a55;   --gris-fond: #ecebe6;
  --ombre: 0 1px 2px rgba(20, 20, 18, .06), 0 4px 16px rgba(20, 20, 18, .05);
  --rayon: 16px;
  --haut: env(safe-area-inset-top, 0px);
  --bas: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --fond: #151514;
    --surface: #1f1f1d;
    --surface-2: #292927;
    --bord: #33332f;
    --texte: #f0efec;
    --texte-2: #c3c2b7;
    --texte-3: #8f8e86;
    --accent: #3987e5;
    --accent-doux: #1d2c40;
    --bulle-lui: #2a2a27;
    --bulle-toi: #3987e5;
    --bulle-ia: #1d2c40;
    --bulle-ia-texte: #cfe1f8;
    --serie-1: #3987e5;
    --grille: #2c2c29;
    --vert: #6fd08c;   --vert-fond: #173322;
    --jaune: #f0c45a;  --jaune-fond: #3a2f12;
    --orange: #f5a070; --orange-fond: #3d2416;
    --rouge: #f08a8a;  --rouge-fond: #3d1b1b;
    --gris: #c3c2b7;   --gris-fond: #2a2a27;
    --ombre: 0 1px 2px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --fond: #151514; --surface: #1f1f1d; --surface-2: #292927; --bord: #33332f;
  --texte: #f0efec; --texte-2: #c3c2b7; --texte-3: #8f8e86;
  --accent: #3987e5; --accent-doux: #1d2c40; --bulle-lui: #2a2a27; --bulle-toi: #3987e5;
  --bulle-ia: #1d2c40; --bulle-ia-texte: #cfe1f8; --serie-1: #3987e5; --grille: #2c2c29;
  --vert: #6fd08c; --vert-fond: #173322; --jaune: #f0c45a; --jaune-fond: #3a2f12;
  --orange: #f5a070; --orange-fond: #3d2416; --rouge: #f08a8a; --rouge-fond: #3d1b1b;
  --gris: #c3c2b7; --gris-fond: #2a2a27; --ombre: 0 1px 2px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.visuellement-cache { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Connexion ---------- */
.connexion { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.carte-connexion { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.carte-connexion h1 { font-size: 22px; margin: 4px 0 12px; }
.logo { align-self: center; border-radius: 15px; }
input[type="password"], input[type="search"], textarea {
  width: 100%; border: 1px solid var(--bord); background: var(--surface); border-radius: 12px;
  padding: 12px 14px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
.erreur { color: var(--rouge); min-height: 1.4em; margin: 0; font-size: 14px; }

/* ---------- Boutons ---------- */
.bouton {
  border: 1px solid var(--bord); background: var(--surface); border-radius: 12px; padding: 10px 14px;
  font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; transition: transform .08s ease, opacity .15s;
}
.bouton:active { transform: scale(.97); }
.bouton:disabled { opacity: .5; }
.bouton.principal { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); }
.bouton.vert { background: var(--vert-fond); border-color: transparent; color: var(--vert); }
.bouton.rouge { background: var(--rouge-fond); border-color: transparent; color: var(--rouge); }
.bouton.discret { background: transparent; border-color: transparent; color: var(--texte-2); font-weight: 500; }
.bouton.petit { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.bouton.large { width: 100%; }

/* ---------- Structure ---------- */
#app { min-height: 100%; }
.entete {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--haut)) 16px 10px; background: color-mix(in srgb, var(--fond) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
}
.entete h1 { font-size: 28px; letter-spacing: -.02em; margin: 0; }
.contenu { padding: 4px 16px calc(96px + var(--bas)); max-width: 720px; margin: 0 auto; }

.interrupteur {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--bord); background: var(--surface);
  border-radius: 999px; padding: 6px 12px 6px 8px; font-size: 14px; font-weight: 600; min-height: 36px;
}
.interrupteur .pastille { width: 10px; height: 10px; border-radius: 50%; background: var(--vert); box-shadow: 0 0 0 3px var(--vert-fond); }
.interrupteur[aria-checked="false"] .pastille { background: var(--texte-3); box-shadow: 0 0 0 3px var(--gris-fond); }

.onglets {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(6px + var(--bas)); background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-top: 1px solid var(--bord);
}
.onglet {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px;
  text-decoration: none; color: var(--texte-3); font-size: 11px; font-weight: 600; border-radius: 10px;
}
.onglet .icone { font-size: 21px; line-height: 1; filter: grayscale(1); opacity: .7; }
.onglet.actif { color: var(--accent); }
.onglet.actif .icone { filter: none; opacity: 1; }
.badge {
  position: absolute; top: 2px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--rouge); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* ---------- Listes ---------- */
.liste { display: flex; flex-direction: column; gap: 10px; }
.carte {
  background: var(--surface); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.carte-tete { display: flex; align-items: flex-start; gap: 12px; text-decoration: none; color: inherit; }
.avatar {
  flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 17px; background: var(--surface-2); color: var(--texte-2);
}
.carte-infos { flex: 1; min-width: 0; }
.ligne-nom { display: flex; align-items: baseline; gap: 8px; }
.nom { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quand { margin-left: auto; flex: none; font-size: 13px; color: var(--texte-3); }
.raison { margin: 3px 0 0; font-size: 14px; color: var(--texte-2); }
.details { margin: 2px 0 0; font-size: 13px; color: var(--texte-3); }
.montant { font-weight: 700; color: var(--texte); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .bouton { flex: 1 1 auto; }
.vide { text-align: center; color: var(--texte-2); padding: 48px 16px; }
.vide .grand { font-size: 40px; display: block; margin-bottom: 8px; }

.etat {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 650; border-radius: 999px;
  padding: 2px 8px; background: var(--gris-fond); color: var(--gris); white-space: nowrap;
}
.etat.actif { background: var(--vert-fond); color: var(--vert); }
.etat.pause, .etat.relais { background: var(--jaune-fond); color: var(--jaune); }
.etat.paiement { background: var(--orange-fond); color: var(--orange); }
.etat.mineur { background: var(--rouge-fond); color: var(--rouge); }

.outils { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.filtres { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.filtres::-webkit-scrollbar { display: none; }
.filtre {
  flex: none; border: 1px solid var(--bord); background: var(--surface); border-radius: 999px; padding: 6px 12px;
  font-size: 14px; font-weight: 600; color: var(--texte-2);
}
.filtre[aria-selected="true"] { background: var(--texte); color: var(--fond); border-color: var(--texte); }
.filtre .nb { font-weight: 500; opacity: .7; margin-left: 2px; }

/* ---------- Conversation ---------- */
.panneau {
  position: fixed; inset: 0; z-index: 20; background: var(--fond); display: flex; flex-direction: column;
  animation: entree .22s ease;
}
@keyframes entree { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.entete-conv { border-bottom: 1px solid var(--bord); padding-left: 6px; }
.retour { border: 0; background: none; font-size: 36px; line-height: 1; padding: 0 10px 4px; color: var(--accent); min-height: 44px; }
.titre-conv { flex: 1; min-width: 0; }
.titre-conv h2 { margin: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titre-conv p { margin: 0; font-size: 13px; color: var(--texte-3); }
.lien-telegram { font-size: 14px; font-weight: 600; color: var(--accent); text-decoration: none; white-space: nowrap; }
.conv-defile { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px 16px; }
.fiche { max-width: 720px; margin: 0 auto 16px; display: flex; flex-direction: column; gap: 10px; }
.puces { display: flex; flex-wrap: wrap; gap: 6px; }
.puce { font-size: 13px; background: var(--surface-2); color: var(--texte-2); border-radius: 8px; padding: 3px 8px; }
.bloc { background: var(--surface); border-radius: var(--rayon); padding: 12px 14px; box-shadow: var(--ombre); }
.bloc h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--texte-3); }
.bloc p { margin: 2px 0; font-size: 15px; }
.bloc .total { font-weight: 700; font-size: 17px; margin-top: 6px; }
.envois { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--texte-3); }

.messages { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 4px; }
.jour { align-self: center; font-size: 12px; color: var(--texte-3); background: var(--surface-2); border-radius: 999px; padding: 2px 10px; margin: 10px 0 6px; }
.bulle {
  max-width: 82%; padding: 8px 12px; border-radius: 18px; font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere;
  position: relative;
}
.bulle.lui { align-self: flex-start; background: var(--bulle-lui); border-bottom-left-radius: 6px; }
.bulle.toi { align-self: flex-end; background: var(--bulle-toi); color: #fff; border-bottom-right-radius: 6px; }
.bulle.ia { align-self: flex-end; background: var(--bulle-ia); color: var(--bulle-ia-texte); border-bottom-right-radius: 6px; }
.bulle .meta { display: block; font-size: 11px; opacity: .7; margin-top: 2px; text-align: right; }
.bulle .etiquette { display: block; font-size: 12px; font-weight: 650; opacity: .85; margin-bottom: 2px; }
.bulle img { display: block; max-width: 220px; max-height: 280px; border-radius: 12px; margin: 2px 0; background: var(--surface-2); cursor: zoom-in; }
.bulle.photo { padding: 4px; }
.bulle.photo .meta, .bulle.photo .etiquette { padding: 0 6px; }

.composer {
  display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px calc(8px + var(--bas));
  border-top: 1px solid var(--bord); background: var(--surface);
}
.composer textarea { resize: none; max-height: 140px; border-radius: 20px; padding: 10px 14px; }
.composer .bouton { border-radius: 20px; }

.visionneuse { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .92); display: grid; place-items: center; padding: 16px; }
.visionneuse img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + var(--bas)); transform: translateX(-50%); z-index: 50;
  max-width: calc(100% - 32px); background: var(--texte); color: var(--fond); padding: 10px 16px; border-radius: 14px;
  font-size: 14px; box-shadow: var(--ombre); animation: monte .2s ease;
}
@keyframes monte { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------- Stats ---------- */
.segments { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.segments button { border: 0; background: none; border-radius: 9px; padding: 7px 0; font-size: 14px; font-weight: 600; color: var(--texte-2); }
.segments button.actif { background: var(--surface); color: var(--texte); box-shadow: var(--ombre); }
.stats { display: flex; flex-direction: column; gap: 12px; }
.tuiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tuile { background: var(--surface); border-radius: var(--rayon); padding: 12px 14px; box-shadow: var(--ombre); }
.tuile .valeur { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tuile .libelle { font-size: 13px; color: var(--texte-2); }
.graphique { background: var(--surface); border-radius: var(--rayon); padding: 14px; box-shadow: var(--ombre); position: relative; }
.graphique h3, .entonnoir h3 { margin: 0 0 2px; font-size: 15px; }
.graphique .sous { margin: 0 0 8px; font-size: 13px; color: var(--texte-3); }
.graphique svg { display: block; width: 100%; height: auto; overflow: visible; }
.graphique .axe { font-size: 10px; fill: var(--texte-3); }
.graphique .grille { stroke: var(--grille); stroke-width: 1; }
.graphique .barre { fill: var(--serie-1); }
.graphique .barre.survol { opacity: .75; }
.infobulle {
  position: absolute; pointer-events: none; background: var(--texte); color: var(--fond); font-size: 12px;
  padding: 5px 8px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -100%); z-index: 2;
}
.entonnoir { background: var(--surface); border-radius: var(--rayon); padding: 14px; box-shadow: var(--ombre); }
.etape { margin-top: 10px; }
.etape-tete { display: flex; justify-content: space-between; font-size: 14px; gap: 8px; }
.etape-tete .n { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.etape-tete .pct { color: var(--texte-3); font-weight: 500; }
.piste { height: 8px; background: var(--surface-2); border-radius: 4px; margin-top: 4px; overflow: hidden; }
.piste span { display: block; height: 100%; background: var(--serie-1); border-radius: 4px; }
.conseil { background: var(--accent-doux); border-radius: var(--rayon); padding: 12px 14px; font-size: 15px; }
details.tableau-chiffres { font-size: 14px; color: var(--texte-2); margin-top: 8px; }
details.tableau-chiffres summary { cursor: pointer; }
details.tableau-chiffres table { width: 100%; border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
details.tableau-chiffres td, details.tableau-chiffres th { padding: 4px 2px; border-bottom: 1px solid var(--bord); text-align: right; }
details.tableau-chiffres td:first-child, details.tableau-chiffres th:first-child { text-align: left; }

@media (min-width: 720px) {
  .tuiles { grid-template-columns: repeat(4, 1fr); }
  .panneau { left: auto; width: min(560px, 100%); border-left: 1px solid var(--bord); box-shadow: -8px 0 32px rgba(0, 0, 0, .08); }
}
