/* ==========================================================================
   Sama Cours — application installable (assets/js/pwa.js)
   ========================================================================== */

/* -------------------- Bouton « Installer » (en-tête) -------------------- */
.pwa-install-btn {
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-family: inherit;
  cursor: pointer;
}

/* Le menu garde sa largeur (3 entrées avec « Installer ») ; c'est la recherche qui se resserre.
   Sur grand écran, style.css centre le menu en position absolue : avec trois entrées il passait
   sous la barre de recherche. Il reprend ici sa place dans le flux, entre le logo et la recherche. */
.header-nav {
  flex-shrink: 0;
}

@media (min-width: 1000px) {
  .header-nav {
    position: static;
    left: auto;
    transform: none;
    margin: 0 auto;
  }
}

.header-search {
  min-width: 0;
}

.pwa-install-btn[hidden] {
  display: none !important;
}

/* -------------------- Messages brefs -------------------- */
.pwa-toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  width: max-content;            /* sans cela, left: 50 % ne laisse que la moitié de l'écran : le texte s'écrasait en colonne étroite */
  max-width: min(calc(100vw - 1.5rem), 480px);
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: #16233a;
  color: #fff;
  font-size: 0.9rem;
  line-height: 1.35;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.35);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

.pwa-toast.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

.pwa-toast button {
  flex-shrink: 0;
  padding: 0.4rem 0.8rem;
  border: 0;
  border-radius: 999px;
  background: #d9a43a;
  color: #16233a;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.pwa-toast button.is-secondary {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  font-weight: 600;
}

/* Téléphone : le message occupe toute la largeur, au-dessus de la barre d'onglets ; le texte d'abord, puis deux boutons de même largeur */
@media (max-width: 860px) {
  .pwa-toast {
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(70px + env(safe-area-inset-bottom));
    width: auto;
    max-width: none;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0.75rem;
    padding: 1rem;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.4;
    transform: translateY(12px);
  }
  .pwa-toast.is-visible { transform: none; }
  .pwa-toast span { flex: 1 1 100%; }
  .pwa-toast button { flex: 1 1 0; min-width: 0; min-height: 46px; padding: 0.6rem 0.9rem; font-size: 0.95rem; }
}

/* -------------------- Pastille « téléchargement de tout le contenu » -------------------- */
.offline-pill {
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 190;
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.8rem;
  width: min(calc(100vw - 2rem), 360px);
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  background: #16233a;
  color: #fff;
  font-size: 0.82rem;
  line-height: 1.35;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.35);
}

.offline-pill.is-visible {
  display: flex;
}

.offline-pill-text {
  flex: 1 1 200px;
}

.offline-pill-bar {
  order: 3;
  flex: 1 1 100%;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

.offline-pill-bar i {
  display: block;
  width: 0;
  height: 100%;
  background: #d9a43a;
  transition: width 0.3s ease;
}

.offline-pill.is-done .offline-pill-bar i {
  background: #3fbf7f;
}

/* Repliée (appui sur le texte) : ne garde que la barre d'avancement. */
.offline-pill.is-mini {
  width: 150px;
  padding: 0.5rem 0.7rem;
}

.offline-pill.is-mini .offline-pill-text {
  flex: 1 1 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.offline-pill.is-mini .offline-pill-btn {
  display: none;
}

.offline-pill-text {
  cursor: pointer;
}

.offline-pill-btn {
  flex-shrink: 0;
  padding: 0.3rem 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.offline-pill-hide {
  border-color: transparent;
  opacity: 0.85;
}

/* Mise à jour lancée par l'élève : le bouton « Masquer » ressort (doré, plein, léger battement) pour qu'il puisse cacher la fenêtre et continuer. */
.offline-pill.is-update .offline-pill-hide {
  order: 3;
  flex: 1 1 100%;
  padding: 0.55rem 0.9rem;
  border: 2px solid #f5c542;
  background: #f5c542;
  color: #16233a;
  font-size: 0.9rem;
  font-weight: 800;
  opacity: 1;
  box-shadow: 0 0 0 0 rgba(245, 197, 66, 0.7);
  animation: offline-hide-pulse 1.6s ease-out infinite;
}
.offline-pill.is-update .offline-pill-hide:hover { filter: brightness(1.06); }
@keyframes offline-hide-pulse {
  0% { box-shadow: 0 0 0 0 rgba(245, 197, 66, 0.7); }
  70% { box-shadow: 0 0 0 10px rgba(245, 197, 66, 0); }
  100% { box-shadow: 0 0 0 0 rgba(245, 197, 66, 0); }
}
@media (prefers-reduced-motion: reduce) { .offline-pill.is-update .offline-pill-hide { animation: none; } }

/* -------------------- Hors connexion -------------------- */
body.is-offline .site-header::after {
  content: "Hors connexion";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.15rem 0.8rem;
  border-radius: 0 0 10px 10px;
  background: #b45309;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  z-index: 60;
}

/* -------------------- Bouton « Hors ligne » du lecteur -------------------- */
.offline-save-btn {
  gap: 0.35rem;
  padding: 0 0.8rem;
}

.offline-save-btn.is-saved {
  background: #e7f8ee;
  border-color: #128c4a;
  color: #128c4a;
}

.offline-save-btn.is-busy {
  opacity: 0.7;
  cursor: progress;
}

.manual-viewer:fullscreen .offline-save-btn.is-saved,
.manual-viewer:-webkit-full-screen .offline-save-btn.is-saved {
  background: rgba(18, 140, 74, 0.25);
  color: #8be2b0;
}

/* Lien « Accès hors ligne » de l'accueil */
.hero-stats a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (max-width: 640px) {
  .offline-save-btn span { display: none; }
  .offline-save-btn { width: 40px; padding: 0; }
}

/* Mise à jour en cours (assets/js/pwa.js, SamaUpdate.run) : voile plein écran avec un message clair */
.pwa-updating { position: fixed; inset: 0; z-index: 2000; display: none; align-items: center; justify-content: center; padding: 1.5rem; background: rgba(16, 28, 48, .82); }
.pwa-updating.is-visible { display: flex; }
.pwa-updating-box { width: min(340px, 100%); padding: 1.6rem 1.4rem; border-radius: 16px; background: var(--color-surface, #fbf7ee); color: var(--color-text, #1c2b42); text-align: center; box-shadow: 0 16px 40px rgba(0, 0, 0, .35); }
.pwa-updating-box p { margin: .9rem 0 0; font-weight: 700; line-height: 1.4; }
.pwa-updating-spin { width: 38px; height: 38px; margin: 0 auto; border: 4px solid var(--color-border, #e6dcc7); border-top-color: var(--color-primary, #b8872b); border-radius: 50%; animation: pwa-spin .8s linear infinite; }
@keyframes pwa-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .pwa-updating-spin { animation-duration: 3s; } }
