:root {
  --bg: #0b1220;
  --card: #141d31;
  --card2: #1b2742;
  --line: #24304d;
  --text: #e6edf7;
  --muted: #8fa0bd;
  --accent: #22d3a7;
  --accent-rgb: 34,211,167;   /* teinte accent en rgb, pour les fonds translucides re-skinnables */
  --on-accent: #04281e;       /* couleur de texte lisible posée sur l'accent (re-skinnable) */
  --accent-dark: #0e9f7a;
  --danger: #f0616d;
  --warn: #eab308;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100%;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

/* ---------- layout ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: rgba(11, 18, 32, .92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .3px; }
.badge {
  background: var(--accent); color: #04281e; font-size: 12px; font-weight: 700;
  padding: 3px 9px; border-radius: 99px;
}

.topbar-right { display: flex; align-items: center; gap: 8px; }
/* bouton « ? » discret : ouvre la fiche d'aide liée à l'écran courant (géré par render()) */
#topbar-aide {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: var(--card2); border: 1px solid var(--line); color: var(--muted);
  font-size: 15px; font-weight: 800; cursor: pointer; line-height: 1;
}
#topbar-aide:active { color: var(--accent); border-color: var(--accent); }

#view { padding: 16px 16px calc(84px + var(--safe-b)); max-width: 640px; margin: 0 auto; }

/* ---------- centre d'aide (fiches pas à pas) ---------- */
.aide-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-top: 1px solid var(--line); cursor: pointer; font-size: 15px; font-weight: 600; }
.aide-item:first-of-type { border-top: none; }
.aide-item .aide-ico { font-size: 20px; width: 28px; text-align: center; flex: none; }
.aide-item .aide-t { flex: 1; min-width: 0; }
.aide-item .aide-chev { color: var(--muted); font-size: 13px; flex: none; }
.aide-steps { list-style: none; display: flex; flex-direction: column; gap: 12px; margin: 4px 0 14px; }
.aide-steps li { display: flex; gap: 12px; align-items: flex-start; font-size: 14.5px; line-height: 1.5; }
.aide-steps .aide-num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: rgba(var(--accent-rgb), .14); color: var(--accent); font-weight: 800; font-size: 13px; display: flex; align-items: center; justify-content: center; margin-top: 1px; }
.aide-steps .aide-ico { flex: none; font-size: 18px; width: 24px; text-align: center; margin-top: 1px; }
.aide-note { font-size: 12.5px; color: var(--muted); line-height: 1.5; border-left: 2px solid var(--line); padding-left: 10px; margin-bottom: 14px; }

#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + var(--safe-b));
  background: rgba(15, 23, 41, .96);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; color: var(--muted); font-size: 10.5px; font-weight: 600;
  padding: 6px 0; cursor: pointer;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }

/* ---------- composants ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 15px; margin-bottom: 12px; color: var(--text); }
.card .hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

.btn {
  display: block; width: 100%; text-align: center;
  background: var(--accent); color: var(--on-accent);
  border: none; border-radius: 12px;
  padding: 15px; font-size: 16px; font-weight: 700; cursor: pointer;
  transition: transform .05s;
}
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--card2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.small { padding: 10px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
input[type="text"], input[type="tel"], input[type="email"], input[type="url"], input[type="password"], input[type="date"], textarea, select {
  width: 100%; background: var(--card2); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; color: var(--text); font-size: 16px;
  font-family: inherit;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 72px; resize: vertical; }

.checkline { display: flex; align-items: center; gap: 10px; padding: 10px 2px; font-size: 15px; cursor: pointer; }
.checkline input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- écran scan ---------- */
.scan-hero { text-align: center; padding: 30px 10px 10px; }
.scan-hero .pulse-ring {
  width: 130px; height: 130px; margin: 0 auto 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle, rgba(var(--accent-rgb),.16), transparent 70%);
  border: 2px solid var(--accent);
}
.scan-hero .pulse-ring svg { width: 56px; height: 56px; }
.scan-hero h1 { font-size: 21px; margin-bottom: 8px; }
.scan-hero p { color: var(--muted); font-size: 14px; margin-bottom: 26px; line-height: 1.5; }

.spinner {
  width: 42px; height: 42px; margin: 30px auto; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.photo-preview { width: 100%; border-radius: 12px; margin-bottom: 14px; max-height: 240px; object-fit: contain; background: #000; }

/* ---------- carnet ---------- */
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar input { flex: 1; }
.searchbar select { width: auto; max-width: 45%; }

.contact-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
}
.contact-item .avatar {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  background: var(--card2); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; overflow: hidden;
}
.contact-item .avatar img { width: 100%; height: 100%; object-fit: cover; }
.contact-item .info { flex: 1; min-width: 0; }
.contact-item .info .name { font-weight: 600; font-size: 15px; }
.contact-item .info .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-item .meta { text-align: right; font-size: 11px; color: var(--muted); flex-shrink: 0; }
.contact-item .meta .tag { display: inline-block; background: var(--card2); border-radius: 6px; padding: 2px 7px; margin-top: 3px; }
.contact-item .meta .due { color: var(--warn); font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 44px 20px; font-size: 14px; line-height: 1.6; }

/* ---------- détail / actions ---------- */
.action-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.action-grid .btn { padding: 12px 4px; font-size: 12.5px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); flex-shrink: 0; }
.kv .v { text-align: right; word-break: break-word; }
.kv .v a { color: var(--accent); text-decoration: none; }

/* ---------- divers ---------- */
#maj-banner {
  position: fixed; bottom: calc(96px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  background: var(--card2); border: 1px solid var(--accent);
  color: var(--text); padding: 10px 12px 10px 16px; border-radius: 99px;
  font-size: 14px; font-weight: 600; z-index: 60; white-space: nowrap; max-width: 94vw;
}
#maj-banner .btn.small { padding: 8px 14px; width: auto; }

/* Bandeau d'installation (discret, refermable). Même ancrage que #maj-banner. */
#install-banner {
  position: fixed; bottom: calc(96px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: var(--card2); border: 1px solid var(--accent);
  color: var(--text); padding: 8px 10px 8px 14px; border-radius: 99px;
  font-size: 13.5px; font-weight: 600; z-index: 55; max-width: 94vw;
}
#install-banner .ib-txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#install-banner .btn.small { padding: 8px 14px; width: auto; flex-shrink: 0; }
#install-banner .ib-close {
  background: none; border: none; color: var(--muted); font-size: 20px; line-height: 1;
  padding: 0 2px; cursor: pointer; flex-shrink: 0;
}
/* Bannière « Débloquer le réseau » (Android : veille profonde constructeur qui prive le
   navigateur de réseau). Même ancrage que #install-banner ; une fois par session, refermable. */
#deblocage-banner {
  position: fixed; bottom: calc(96px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: var(--card2); border: 1px solid var(--warn);
  color: var(--text); padding: 8px 10px 8px 14px; border-radius: 99px;
  font-size: 13.5px; font-weight: 600; z-index: 56; max-width: 94vw;
}
#deblocage-banner .ib-txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#deblocage-banner .btn.small { padding: 8px 14px; width: auto; flex-shrink: 0; }

/* Le bandeau flotte AU-DESSUS de la barre d'onglets (bottom ~96px, hauteur ~44px) : sans reserve,
   il recouvre le bas du contenu (Scanner, Club). Quand il est present, on empile sa hauteur
   par-dessus l'espace deja reserve pour #tabbar (84px). La classe est posee/retiree par le JS. */
body.with-install-banner #view { padding-bottom: calc(150px + var(--safe-b)); }

/* Aides visuelles iOS (dans .sheet) */
.ib-steps { margin: 0 0 4px; padding-left: 20px; font-size: 14px; line-height: 1.7; }
.ib-steps li { margin-bottom: 4px; }
.ib-steps b { color: var(--text); }
.ib-share {
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: middle; color: var(--accent);
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 4px; background: var(--card2);
}
.ib-arrow { text-align: center; font-size: 30px; line-height: 1; margin-top: 4px; }
.ib-link {
  background: var(--card2); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; font-size: 13px; word-break: break-all; margin: 4px 0 12px; color: var(--text);
}

#toast {
  position: fixed; bottom: calc(96px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--accent);
  color: var(--text); padding: 11px 20px; border-radius: 99px;
  font-size: 14px; font-weight: 600; z-index: 50; white-space: nowrap;
  max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}

.back { background: none; border: none; color: var(--accent); font-size: 15px; font-weight: 600; padding: 0 0 14px; cursor: pointer; }

.mic-btn {
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--accent); padding: 0 14px; font-size: 18px; cursor: pointer;
}
.mic-btn.rec { border-color: var(--danger); color: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .4; } }

.note-row { display: flex; gap: 8px; }
.note-row textarea { flex: 1; }

.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  background: var(--card2); border: 1px solid var(--line); color: var(--text);
  border-radius: 99px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.pill.on { background: var(--accent); color: #04281e; border-color: var(--accent); }

details.section { margin-bottom: 14px; }
details.section summary {
  cursor: pointer; font-weight: 600; font-size: 14px; padding: 10px 0; color: var(--text);
  list-style: none;
}
details.section summary::before { content: "▸ "; color: var(--accent); }
details.section[open] summary::before { content: "▾ "; }

.notice { font-size: 12px; color: var(--muted); line-height: 1.6; }
.notice strong { color: var(--text); }

/* ---------- vue Suivi (colonnes) ---------- */
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; background: none; border: none; color: var(--muted); font-weight: 700; font-size: 13px; padding: 8px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #04281e; }
.kanban { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 12px; scroll-snap-type: x proximity; }
.kcol { min-width: 232px; max-width: 232px; scroll-snap-align: start; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; align-self: flex-start; }
.kcol h3 { font-size: 12.5px; margin-bottom: 8px; display: flex; justify-content: space-between; color: var(--text); }
.kcol h3 .n { color: var(--muted); font-weight: 600; }
.kcard { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; margin-bottom: 7px; cursor: pointer; }
.kcard .kn { font-weight: 700; font-size: 13.5px; }
.kcard .ks { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kcard .kd { font-size: 10.5px; color: var(--warn); font-weight: 700; margin-top: 2px; }
.kempty { font-size: 11.5px; color: var(--muted); text-align: center; padding: 10px 0; }

/* ---------- journal (timeline) ---------- */
.timeline { border-left: 2px solid var(--line); margin: 4px 0 0 6px; padding-left: 14px; display: flex; flex-direction: column; gap: 10px; }
.tl-item { font-size: 13px; position: relative; line-height: 1.4; }
.tl-item::before { content: ""; position: absolute; left: -19px; top: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.tl-item.note::before { background: var(--accent); }
.tl-item .tl-date { color: var(--muted); font-size: 10.5px; display: block; }

/* ---------- panneau de sélection (envoi multi-cartes) ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(4, 8, 16, .72);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + var(--safe-b));
  width: 100%; max-width: 640px;
  animation: slideup .18s ease-out;
}
.sheet h2 { font-size: 16px; }
@keyframes slideup { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }

/* ---------- calendrier agenda (vue mois, multi-club superposé) ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head .m { font-weight: 700; font-size: 14px; text-transform: capitalize; }
.cal-nav { background: var(--card2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; width: 30px; height: 30px; font-size: 16px; cursor: pointer; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; width: 100%; }
.cal-dow { text-align: center; font-size: 10px; color: var(--muted); font-weight: 700; padding: 2px 0; min-width: 0; }
.cal-cell { height: 46px; min-width: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--card2); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12.5px; cursor: pointer; position: relative; gap: 3px; }
/* classe dediee : ".empty" global (etats vides) applique un padding 44px qui etirait la ligne */
.cal-cell.cal-empty { background: transparent; border-color: transparent; cursor: default; padding: 0; }
.cal-cell.today { border-color: var(--accent); }
.cal-cell.sel { background: var(--accent); color: #04281e; font-weight: 800; }
.cal-cell.has { font-weight: 700; }
.cal-dots { display: flex; gap: 2px; height: 5px; }
.cal-dots i { width: 5px; height: 5px; border-radius: 50%; display: inline-block; }
.cal-day-events { margin-top: 12px; }
.club-chip { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 7px; border-radius: 99px; color: #fff; vertical-align: 1px; }

/* ---------- signature de marque : le pouls bat ---------- */
@media (prefers-reduced-motion: no-preference) {
  .pulse-ring { animation: pouls 2.4s ease-in-out infinite; }
  @keyframes pouls {
    0%, 100% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), .28); }
    50% { box-shadow: 0 0 0 16px rgba(var(--accent-rgb), 0); }
  }
}

/* ---------- Relanso Pro : pastille verrouillée + statistiques ---------- */
.pill.pill-pro { opacity: .62; border-style: dashed; }

.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat-kpi {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 8px; text-align: center; min-width: 0;
}
.stat-kpi b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat-kpi span { display: block; font-size: 11px; color: var(--muted); line-height: 1.25; margin-top: 2px; }
.stat-kpi.alerte b { color: var(--warn); }

/* Histogramme : hauteur fixe, les barres poussent depuis le bas.
   Le nombre vit AU-DESSUS de la barre (une valeur posee dedans serait vert sur vert). */
.stat-chart { display: flex; align-items: flex-end; gap: 6px; height: 110px; margin-top: 6px; }
.stat-bar { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; height: 100%; }
.stat-zone { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.stat-fill { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 3px; }
.stat-n { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1.4; }
.stat-m { font-size: 10px; color: var(--muted); margin-top: 4px; }

.stat-list { list-style: none; padding: 0; margin: 6px 0 0; }
.stat-list li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.stat-list li:last-child { border-bottom: 0; }

/* Cle de restauration : lisible, selectionnable, jamais tronquee silencieusement. */
.cle-box {
  background: #0b1220; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; overflow-x: auto;
}
.cle-box code {
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  font-size: 12.5px; letter-spacing: .04em; color: var(--text);
  white-space: nowrap; user-select: all;
}

/* Bac a sable : un rappel discret et FIXE (ne scrolle pas, n'entoure rien, ne coupe
   aucune section). Le 🎬 dans le titre porte le reste du signal. */
body.demo::before {
  content: "MODE DÉMONSTRATION";
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: #a855f7; color: #fff;
  font-size: 9px; font-weight: 700; letter-spacing: .18em; text-align: center;
  padding: 2px 0; pointer-events: none;
}
body.demo #topbar { top: 15px; }   /* laisse la place au bandeau fixe */

/* Classements du president : la valeur est alignee a droite, tabulaire. */
.stat-list li b { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Suggestions de ville (geocodage data.gouv.fr) sous le champ ville. */
.sug-list { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.sug-list .sug {
  text-align: left; background: var(--card2, #1b2742); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 9px 12px; font-size: 14px; cursor: pointer;
}
.sug-list .sug:hover { border-color: var(--accent); }
