/* Coquille de l'application : conteneur plein écran, contenu scrollable,
   barre d'onglets fixe en bas (avec réserve pour la zone de sécurité Android/iOS). */
#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  /* Fond bleu foncé = seul visible derrière la barre d'état (mode edge-to-edge) :
     l'appli s'ouvre TOUJOURS sur un en-tête bleu, la barre d'état s'y fond. */
  background: var(--primary-dark);
  box-shadow: 0 0 40px rgba(24, 29, 58, .08);
  /* Décale tout le contenu sous la barre d'état / l'encoche — une seule fois,
     pour tous les écrans (avec ou sans en-tête coloré). */
  padding-top: var(--safe-top);
}

/* ── Bannière globale (ex: réinscription requise) — persiste au-dessus du
   contenu quel que soit l'écran affiché, tant que la situation n'est pas résolue. ── */
#global-banner {
  display: none;
  flex-shrink: 0;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 14px;
  background: #FEF3C7;
  color: #92400E;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.4;
  border-bottom: 1px solid #FDE68A;
}
#global-banner.visible { display: flex; }
#global-banner svg { flex-shrink: 0; margin-top: 1px; }

/* ── Bannière "mise à jour disponible" (APK) — insérée en tête de #app,
   au-dessus de tout le reste. Rejetable pour la session. ── */
#update-banner {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px 9px 14px;
  background: var(--primary, #3D5CE0);
  color: #fff;
}
#update-banner .update-banner-body {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
}
#update-banner .update-banner-body > svg { flex-shrink: 0; }
#update-banner .update-banner-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
#update-banner .update-banner-text strong { font-size: 12.5px; font-weight: 700; }
#update-banner .update-banner-text span { font-size: 11px; opacity: .85; }
#update-banner .update-banner-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
#update-banner #update-banner-get {
  background: #fff;
  color: var(--primary, #3D5CE0);
  border: 0;
  border-radius: 8px;
  padding: 7px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
#update-banner #update-banner-close {
  background: transparent;
  border: 0;
  color: #fff;
  opacity: .8;
  padding: 4px;
  display: flex;
  cursor: pointer;
}
#update-banner #update-banner-close:hover { opacity: 1; }

/* MAJ obligatoire : bannière en rouge (l'app reste utilisable jusqu'à ce que la
   feuille bloquante prenne le relais). */
#update-banner[data-severity="mandatory"] { background: var(--danger, #EF4444); }
#update-banner[data-severity="mandatory"] #update-banner-get { color: var(--danger, #EF4444); }

/* ── Feuille de mise à jour (téléchargement + install in-app) ── */
.update-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: rgba(16, 20, 38, .55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.update-sheet {
  width: 100%;
  max-width: 460px;
  background: var(--surface, #fff);
  color: var(--text, #1A2233);
  border-radius: var(--radius-lg, 22px) var(--radius-lg, 22px) 0 0;
  padding: 20px 18px calc(18px + var(--safe-bottom, 0px));
  box-shadow: 0 -10px 40px rgba(16, 20, 38, .22);
}
@media (min-width: 520px) {
  .update-sheet-overlay { align-items: center; }
  .update-sheet { border-radius: var(--radius-lg, 22px); }
}
.update-sheet .us-head {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--primary, #3D5CE0);
}
.update-sheet .us-head > svg { flex-shrink: 0; }
.update-sheet .us-head strong { display: block; font-size: 15px; color: var(--text); }
.update-sheet .us-head span { font-size: 12.5px; color: var(--text-light, #6B7280); }
.update-sheet .us-notes {
  margin: 12px 0 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-light, #6B7280);
}
.update-sheet .us-body { margin-top: 16px; }
.update-sheet .us-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--border, #E7EAF3);
  overflow: hidden;
}
.update-sheet .us-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary, #3D5CE0);
  transition: width .25s ease;
}
.update-sheet .us-bar-indef { animation: us-indef 1.1s ease-in-out infinite alternate; }
@keyframes us-indef { from { margin-left: 0; width: 30%; } to { margin-left: 70%; width: 30%; } }
.update-sheet .us-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-light, #6B7280);
}
.update-sheet .us-pct { font-weight: 700; color: var(--text); }
.update-sheet .us-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 12px 0 0;
  font-size: 12.5px;
  color: var(--text-light, #6B7280);
}
.update-sheet .us-status.us-error { color: var(--danger, #EF4444); }
.update-sheet .us-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.update-sheet .us-btn {
  border: 0;
  border-radius: var(--radius-sm, 14px);
  padding: 10px 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.update-sheet .us-btn-primary { background: var(--primary, #3D5CE0); color: #fff; }
.update-sheet .us-btn-ghost { background: transparent; color: var(--text-light, #6B7280); }
@media (prefers-reduced-motion: reduce) {
  .update-sheet .us-bar-fill { transition: none; }
  .update-sheet .us-bar-indef { animation: none; }
}

#app-content {
  position: relative; /* ancre les écrans en position:absolute;inset:0 (ex: chat.js) */
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  background: var(--bg); /* #app est bleu foncé (barre d'état) — le contenu reste clair */
  /* Pas de barre de défilement visible : elle chevauchait l'en-tête sticky (style app). */
  scrollbar-width: none;
  -ms-overflow-style: none;
  /* Réserve pour la barre de navigation système (mode edge-to-edge, Android 15+)
     sur les écrans SANS barre d'onglets — surchargé par .with-tabs ci-dessous. */
  padding-bottom: var(--safe-bottom);
}

#app-content::-webkit-scrollbar { width: 0; height: 0; display: none; }

#app-content.with-tabs {
  padding-bottom: calc(var(--tab-bar-h) + var(--safe-bottom));
}

/* ── Barre d'onglets ── */
#bottom-tabs {
  display: none;
  flex-shrink: 0;
  background: rgba(255, 255, 255, .94);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + var(--safe-bottom));
  box-shadow: 0 -4px 20px rgba(24, 29, 58, .06);
  z-index: 20;
}
#bottom-tabs.visible { display: flex; }

.tab-row {
  display: flex;
  width: 100%;
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 2px 5px;
  background: none;
  border: none;
  border-radius: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s;
}
.tab-item.active { color: var(--primary); }
.tab-icon-wrap {
  position: relative;
  width: 44px;
  height: 28px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tab-item.active .tab-icon-wrap { background: var(--surface3); }
.tab-label { font-size: 10px; font-weight: 600; margin-top: 1px; letter-spacing: .01em; }

/* Pastille "nouvelles actualités" sur l'onglet du bas */
.tab-badge {
  position: absolute;
  top: -3px;
  right: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .94);
}

/* ── Utilitaires ── */
.stack { display: flex; flex-direction: column; }
.row { display: flex; flex-direction: row; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.flex-1 { flex: 1; min-width: 0; }
.gap-4 { gap: 4px; }
.gap-5 { gap: 5px; }
.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-10 { gap: 10px; }
.gap-12 { gap: 12px; }
.gap-14 { gap: 14px; }

/* Repli pour le flexbox `gap` — non supporté par le WebView système sur les appareils
   Android < 11 pas mis à jour depuis le Play Store (Chromium < 84, mi-2020). Sans ce
   repli, tous les `.row`/`.stack` gap-X (utilisés dans quasi tout l'écran) s'affichent
   collés les uns aux autres → la mise en page casse sur ces appareils. On simule le
   gap avec une marge sur chaque enfant sauf le premier. */
@supports not (gap: 1px) {
  .row.gap-4  > * + * { margin-left: 4px; }
  .row.gap-5  > * + * { margin-left: 5px; }
  .row.gap-6  > * + * { margin-left: 6px; }
  .row.gap-8  > * + * { margin-left: 8px; }
  .row.gap-10 > * + * { margin-left: 10px; }
  .row.gap-12 > * + * { margin-left: 12px; }
  .row.gap-14 > * + * { margin-left: 14px; }
  .stack.gap-4  > * + * { margin-top: 4px; }
  .stack.gap-5  > * + * { margin-top: 5px; }
  .stack.gap-6  > * + * { margin-top: 6px; }
  .stack.gap-8  > * + * { margin-top: 8px; }
  .stack.gap-10 > * + * { margin-top: 10px; }
  .stack.gap-12 > * + * { margin-top: 12px; }
  .stack.gap-14 > * + * { margin-top: 14px; }
}
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-14 { margin-top: 14px; }
.p-16 { padding: 16px; }
.center { display: flex; align-items: center; justify-content: center; }
.text-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scroll-x {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.scroll-x::-webkit-scrollbar { display: none; }

.screen-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}
