/** =========================================================================
 * STYLES DE LA BOÎTE AUX LETTRES CONNECTÉE
 * =========================================================================
 */

/* 1. RESET & BASES */
*,
::before,
::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Définition des zones sûres (pour iPhone X+) */
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --primary-color: #073b4c;
  --accent-color: #06d6a0;
  --bg-light: #f8fafc;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  /* Ajoute ceci pour remplir le fond derrière les zones safe */
  background-color: var(--primary-color);
}
body {
  font-family: "Jersey 25", sans-serif;
  background-color: var(--bg-light);
  color: white;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  /* Espacement pour le header et footer fixes */
  padding-top: calc(140px + var(--safe-top));
  padding-bottom: calc(80px + var(--safe-bottom));
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.body-historique {
  font-family: "Jersey 25", sans-serif;
  font-weight: 400;
  font-style: normal;
  width: 100%;
  background-color: var(--primary-color); /* Fond bleu foncé */

  /* On utilise 160px pour pousser le contenu sous le header fixed */
  padding-top: calc(130px + var(--safe-top));
  padding-bottom: calc(80px + var(--safe-bottom));
  /* ------------------------- */

  /* UX Tactile */
  -webkit-tap-highlight-color: transparent;
  overflow-y: auto; /* Active le scroll vertical si le contenu dépasse */
}

/* 2. HEADER & NAVIGATION */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background: white;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* On garde juste le safe-area pour les iPhones */
  padding-top: var(--safe-top);
}

h1 {
  margin: 1rem 0;
  text-align: center;
  font-size: 2.2rem;
}

.multicolor-text span:nth-child(1) {
  color: #ef476f;
}
.multicolor-text span:nth-child(2) {
  color: #ffd166;
}
.multicolor-text span:nth-child(3) {
  color: #06d6a0;
}
.multicolor-text span:nth-child(4) {
  color: var(--primary-color);
}
.multicolor-text span:nth-child(5) {
  color: var(--primary-color);
}
.multicolor-text span:nth-child(6) {
  color: var(--primary-color);
}

.offline-banner {
  background: #ef4444;
  color: white;
  text-align: center;
  padding: 5px;
  width: 100%;
  font-size: 0.9rem;
}

.arduino-banner {
  background: grey;
  color: white;
  text-align: center;
  padding: 5px;
  width: 100%;
  font-size: 0.9rem;
}

/* 3. CONTENU PRINCIPAL (MAIN) */
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 0 5%;
  /* On empêche le scroll ici */
  overflow: hidden;
  /* On lui donne une hauteur fixe pour occuper l'espace restant */
  height: calc(100vh - (160px + var(--safe-top)) - (80px + var(--safe-bottom)));
}

/* Le main prend tout l'espace restant */
.container-historique.container {
  /* On retire flex: 1 car la hauteur est déjà calculée par calc() dans .container */
  display: flex;
  flex-direction: column;
  align-items: center; /* Centre le contenu horizontalement */

  /* --- DIMINUTION DE LA LARGEUR --- */
  width: 85%; /* Prend 85% de l'écran sur mobile */
  max-width: 400px; /* Ne dépasse jamais 400px sur ordinateur/tablette */
  margin: 0 auto; /* Centre le bloc sur la page */
  /* -------------------------------- */

  padding: 0; /* On gère le padding dans la box interne */
  overflow: hidden; /* Le container parent ne scrolle pas */
}

#content {
  margin: 1rem 0;
  width: 100%;
  text-align: center;
}

/* 4. BLOCS DE STATUT (BOX & STATE) */
#state {
  display: flex;
  justify-content: space-between;
  width: 100%; /* Utilise toute la largeur du container (90% réel) */
  max-width: 500px;
  gap: 15px;
}

#box,
#state-box {
  flex: 1; /* Les deux boîtes prennent la même largeur */
  height: 10vh;
  min-height: 70px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: white;
  background-color: var(--primary-color);
  border: 2px solid black;
  border-radius: 15px;
  text-align: center;
}

#box span,
#state-box span {
  font-weight: bold;
  font-size: 1.1rem;
}

/* 5. BLOC DE REMPLISSAGE (FILLING BOX) */
#filling-box {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 500px;

  /* --- CONFIGURATION DU SCROLL --- */
  flex: 1; /* Il prend tout l'espace disponible vers le bas */

  -webkit-overflow-scrolling: touch; /* Fluidité iPhone */

  /* Ton style visuel */
  margin-top: 1.5rem;
  color: white;
  background-color: #073b4c;
  border: 2px solid black;
  border-radius: 15px;
  padding: 1rem;
}

/* Style spécifique réduit pour l'historique */
.container-historique {
  flex: 1;
  width: 85%; /* Plus étroit */
  max-width: 380px; /* Largeur max contenue */
  height: calc(100dvh - 200px); /* Ajustement selon header/footer */
  margin: 0 auto;
}

/* 5. BLOCS DE CONTENU */

.infos-historique {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid #cbd5e1;
}

.infos {
  display: flex;
  flex-direction: column; /* Stack sur mobile */
  align-items: center;
  gap: 10px;
  text-align: center;
}

/* 6. BOUTONS & INTERACTIONS */
#install-btn {
  display: block;
  margin: 0.5rem auto;
  padding: 0.6rem 1.2rem;
  background-color: var(--accent-color);
  border: 2px solid black;
  border-radius: 12px;
  cursor: pointer;
  font-family: "Jersey 25", sans-serif;
}

.hidden {
  display: none;
}

/* 7. FOOTER (TAB BAR) */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: calc(65px + var(--safe-bottom));
  background: white;
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-top: 2px solid #e2e8f0;
  padding-bottom: var(--safe-bottom);
  z-index: 1000;
  user-select: none;
}

.tab-bar a {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  text-decoration: none;
  min-width: 50px;
  min-height: 50px;
  color: red;
}

.tab-bar svg {
  pointer-events: none;
}

/* 8. RESPONSIVE */

/* --- Tablettes et écrans intermédiaires --- */
@media screen and (min-width: 768px) {
  body {
    /* Ajuste l'espacement haut en cumulant une valeur fixe et la zone sécurisée */
    padding-top: calc(140px + var(--safe-top, 0px));
  }

  .container-historique {
    max-width: 400px;
    margin-left: auto;
    margin-right: auto; /* Centre le conteneur si besoin */
  }
}

/* --- Desktops (Laptops et grands écrans) --- */
@media screen and (min-width: 1200px) {
  .container {
    max-width: 800px;
    margin-left: auto;
    margin-right: auto; /* Centre le contenu principal */
  }
}

/* #region historique  */
/* 9. HISTORIQUE (notif-historique) */
#notif-historique {
  font-family: "Jersey 25", sans-serif;
  border-radius: 12px;
  background: transparent;
  overflow: hidden;
  width: 100%;
}

.evt-header {
  background: var(--primary-color);
  color: white;
  padding: 10px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1rem;
  letter-spacing: 0.05em;
}

.evt-compteur {
  background: rgba(255, 255, 255, 0.15);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--accent-color);
}

.evt-liste {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.evt-ligne {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.04);
  transition: background 0.2s;
}

.evt-ligne:last-child {
  border-bottom: none;
}

.evt-icone-label {
  font-size: 0.95rem;
  color: white;
}

.evt-date {
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.8rem;
}

/* Liserés de couleur par type d'événement */
.evt-porte-ouverte {
  border-left: 4px solid #ff5f1f;
}
.evt-porte-fermee {
  border-left: 4px solid #06d6a0;
}
.evt-lettre {
  border-left: 4px solid #118ab2;
}
.evt-colis {
  border-left: 4px solid #ffd166;
}
.evt-boite-videe {
  border-left: 4px solid #ef476f;
}
/* #endregion */
