/* ===== COULEURS ET TAILLES COMMUNES =====
   On les définit une seule fois ici : pour changer une couleur
   dans toute l'appli, il suffit de la modifier à cet endroit. */
:root {
  --fond: #0c0c0e;          /* fond presque noir */
  --surface: #17171b;       /* fond des cases */
  --bordure: #2a2a30;       /* contours discrets */
  --texte: #f4f4f5;         /* texte principal */
  --texte-doux: #9a9aa3;    /* texte secondaire */
  --accent: #f4f4f5;        /* blanc : ce qui est actif dans l'interface */
  --valide: #a78bfa;        /* violet : tout ce qui est validé */
  --valide-fond: #1e1733;   /* violet très sombre, fond d'une case cochée */
  --valide-bord: #4c3a80;   /* violet moyen, contour d'une case cochée */
  --retard: #ff6b6b;        /* rouge : une tâche non faite */
  --retard-fond: #2a1416;   /* rouge très sombre, fond d'une tâche non faite */
  --retard-bord: #6e2c30;   /* rouge moyen, contour d'une tâche non faite */
  --vert: #34d17c;          /* vert vif du calendrier : le jour complet */
  --vert-3: #17784a;        /* vert soutenu : la plupart des habitudes faites */
  --vert-2: #115a38;        /* vert moyen : environ la moitié */
  --vert-1: #0f3f29;        /* vert sombre : une petite partie */
  --hauteur-barre: 64px;    /* hauteur de la barre du bas */
}

/* Les tailles incluent les marges intérieures : ça simplifie les calculs */
* {
  box-sizing: border-box;
}

/* Un élément marqué "hidden" reste toujours caché, quel que soit son style */
[hidden] {
  display: none !important;
}

/* ===== BASE DE LA PAGE ===== */
body {
  margin: 0;
  min-height: 100vh;
  background: var(--fond);
  color: var(--texte);
  /* Police native de l'iPhone, rien à télécharger */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  /* Évite le flash gris quand on touche un élément sur iPhone */
  -webkit-tap-highlight-color: transparent;
}

/* ===== CHANGEMENT DE PAGE ===== */
/* Les boutons qui retiennent la page affichée restent invisibles */
.choix-page {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* Toutes les pages sont cachées par défaut... */
.page {
  display: none;
  /* Centre le contenu si l'écran est large, avec des marges sur les côtés.
     max() tient compte de l'encoche de l'iPhone. */
  max-width: 560px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px
    calc(var(--hauteur-barre) + env(safe-area-inset-bottom) + 24px);
}

/* ... et on affiche seulement celle qui correspond au bouton actif */
#choix-jour:checked ~ .page-jour,
#choix-calendrier:checked ~ .page-calendrier {
  display: block;
}

/* ===== EN-TÊTE ===== */
.entete {
  margin-bottom: 24px;
}

.surtitre {
  margin: 0 0 4px;
  color: var(--texte-doux);
  font-size: 15px;
}

h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

/* ===== ACCUEIL : L'HEURE ET LA DATE ===== */
.accueil {
  margin-bottom: 32px;
}

/* L'heure est le plus grand élément de l'écran */
.heure {
  margin: 0;
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.date {
  margin: 8px 0 0;
  color: var(--texte-doux);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0;
}

/* ===== LES DEUX SECTIONS ===== */
.section {
  margin-bottom: 32px;
}

/* Le titre à gauche, le compteur à droite */
.section-titre {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.compteur {
  margin: 0;
  color: var(--texte-doux);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.compteur strong {
  color: var(--valide);
  font-weight: 700;
}

/* ===== BARRE DE PROGRESSION DES HABITUDES ===== */
.progression-barre {
  height: 6px;
  margin-bottom: 12px;
  border-radius: 3px;
  background: var(--bordure);
  overflow: hidden;
}

/* La partie remplie : 50 % correspond à l'exemple 2 cases sur 4 */
.progression-barre span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--valide);
  transition: width 0.2s;
}

/* ===== LISTE DES CASES ===== */
.liste-cases {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

/* Une ligne : la coche, le nom, puis la série à droite */
.case {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px; /* assez haut pour le pouce */
  padding: 0 6px 0 0;
  border: 1px solid var(--bordure);
  border-radius: 14px;
  background: var(--surface);
}

/* La zone qu'on touche pour cocher : toute la ligne, sauf le bouton ⋯ */
.case-zone {
  display: flex;
  flex: 1;
  align-items: center;
  align-self: stretch;
  gap: 14px;
  min-width: 0;
  padding: 12px 0 12px 16px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

/* Le bouton ⋯ pour renommer ou supprimer */
.bouton-plus {
  flex: none;
  width: 44px;
  height: 44px;
  margin-left: -8px;
  border: 0;
  background: transparent;
  color: var(--texte-doux);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}

/* Message quand une liste est vide */
.liste-vide {
  padding: 4px 2px;
  color: var(--texte-doux);
  font-size: 15px;
}

/* Les habitudes pas prévues aujourd'hui, repliées sous le bouton d'ajout */
.autres {
  margin-top: 12px;
}

.autres summary {
  min-height: 44px;
  padding: 12px 2px;
  color: var(--texte-doux);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.autres .liste-cases {
  margin-bottom: 0;
}

.autres .case {
  min-height: 52px;
  padding-left: 16px;
}

/* Les jours prévus, affichés sous le nom d'une habitude repliée */
.autres-jours {
  display: block;
  color: var(--texte-doux);
  font-size: 13px;
  font-weight: 500;
}

/* Le carré à cocher */
.case-coche {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 2px solid #4a4a52;
  border-radius: 9px;
  color: var(--fond);
  font-size: 18px;
  font-weight: 900;
}

/* Le nom prend toute la place disponible et peut passer à la ligne */
.case-nom {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.case-serie {
  flex: none;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums; /* chiffres de même largeur */
}

/* Une série à zéro reste discrète */
.case-serie-vide {
  opacity: 0.4;
}

/* Apparence d'une case cochée */
.case.cochee {
  border-color: var(--valide-bord);
  background: var(--valide-fond);
}

.case.cochee .case-coche {
  border-color: var(--valide);
  background: var(--valide);
}

/* Une tâche du jour : coche ronde et ligne plus fine, pour la distinguer d'une habitude */
.case.tache {
  min-height: 52px;
}

.case.tache .case-coche {
  border-radius: 50%;
}

/* Une tâche faite passe au second plan */
.case.tache.cochee .case-nom {
  color: var(--texte-doux);
  text-decoration: line-through;
}

/* ===== TÂCHES NON FAITES (ZONE ROUGE) ===== */
.non-faites {
  margin-top: 24px;
}

h3 {
  margin: 0 0 10px;
  color: var(--retard);
  font-size: 15px;
  font-weight: 700;
}

.case.non-faite {
  gap: 8px;
  padding: 10px 8px 10px 16px;
  border-color: var(--retard-bord);
  background: var(--retard-fond);
}

/* Le nom de la tâche, avec le jour où elle était prévue juste en dessous */
.non-faite-texte {
  flex: 1;
  min-width: 0;
}

.non-faite-texte .case-nom {
  display: block;
}

.non-faite-jour {
  color: var(--retard);
  font-size: 13px;
  font-weight: 600;
}

/* Les deux petits boutons : remettre à aujourd'hui, ou retirer */
.bouton-icone {
  flex: none;
  width: 44px;
  height: 44px;
  border: 1px solid var(--retard-bord);
  border-radius: 12px;
  background: transparent;
  color: var(--texte);
  font-size: 18px;
  cursor: pointer;
}

/* Le bouton ✕ après un premier toucher : il demande confirmation */
.bouton-icone.a-confirmer {
  width: auto;
  padding: 0 10px;
  border-color: var(--retard);
  background: var(--retard);
  color: var(--fond);
  font-size: 13px;
  font-weight: 700;
}

/* ===== BOUTONS D'AJOUT ===== */
.bouton-ajouter {
  width: 100%;
  min-height: 48px;
  border: 1px dashed #4a4a52;
  border-radius: 14px;
  background: transparent;
  color: var(--texte-doux);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
}

/* ===== PANNEAU DE CRÉATION ET DE MODIFICATION ===== */
/* Il monte depuis le bas de l'écran, à portée de pouce */
.panneau {
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  border: 1px solid var(--bordure);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--texte);
}

/* Le reste de l'écran s'assombrit derrière le panneau */
.panneau::backdrop {
  background: rgb(0 0 0 / 0.65);
}

.panneau h2 {
  margin-bottom: 16px;
}

.champ-titre {
  display: block;
  margin-bottom: 8px;
  padding: 0;
  color: var(--texte-doux);
  font-size: 14px;
  font-weight: 600;
}

/* 16 px minimum : en dessous, l'iPhone zoome tout seul sur le champ */
.champ {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid #4a4a52;
  border-radius: 12px;
  background: var(--fond);
  color: var(--texte);
  font: inherit;
  font-size: 16px;
}

/* Le contour du champ actif reprend le violet de l'appli */
.champ:focus {
  outline: 2px solid var(--valide);
  outline-offset: 0;
}

.choix-jours {
  margin: 18px 0 0;
  padding: 0;
  border: 0;
}

/* La vraie case à cocher est invisible : on affiche la lettre à la place */
.choix-jours input {
  position: absolute;
  opacity: 0;
}

.choix-jours span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid #4a4a52;
  border-radius: 12px;
  color: var(--texte-doux);
  font-weight: 700;
  cursor: pointer;
}

.choix-jours input:checked + span {
  border-color: var(--valide);
  background: var(--valide);
  color: var(--fond);
}

/* Contour visible au clavier, pour rester utilisable sans le doigt */
.choix-jours input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.panneau-erreur {
  margin: 12px 0 0;
  color: var(--retard);
  font-size: 14px;
  font-weight: 600;
}

.bouton-principal,
.bouton-secondaire,
.bouton-supprimer {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.bouton-principal {
  margin-top: 20px;
  border: 0;
  background: var(--accent);
  color: var(--fond);
}

.bouton-secondaire {
  border: 1px solid var(--bordure);
  background: transparent;
  color: var(--texte);
}

.bouton-supprimer {
  border: 0;
  background: transparent;
  color: var(--retard);
}

/* Deuxième étape de la suppression : le bouton devient bien visible */
.bouton-supprimer.a-confirmer {
  background: var(--retard);
  color: var(--fond);
}

/* Le choix du rythme et de l'objectif dans le panneau */
.choix-rythme {
  margin: 18px 0 0;
  padding: 0;
  border: 0;
}

/* Deux choix côte à côte. Le vrai bouton est invisible : on affiche le texte. */
.segments {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segments input {
  position: absolute;
  opacity: 0;
}

.segments span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid #4a4a52;
  border-radius: 12px;
  color: var(--texte-doux);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.segments input:checked + span {
  border-color: var(--valide);
  background: var(--valide);
  color: var(--fond);
}

.segments input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Le compteur − 4 + de l'objectif */
.compteur-objectif {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.bouton-nombre {
  width: 44px;
  height: 44px;
  border: 1px solid #4a4a52;
  border-radius: 12px;
  background: transparent;
  color: var(--texte);
  font-size: 22px;
  cursor: pointer;
}

.objectif-nombre {
  min-width: 32px;
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.objectif-texte {
  color: var(--texte-doux);
  font-size: 15px;
}

.panneau-note {
  margin: 12px 0 0;
  color: var(--texte-doux);
  font-size: 14px;
}

/* Le texte sous le nom d'une habitude : par exemple 2 / 4 cette semaine */
.case-sous {
  display: block;
  color: var(--texte-doux);
  font-size: 13px;
  font-weight: 500;
}

/* ===== RAPPEL ROUGE EN HAUT DE L'ÉCRAN ===== */
.rappel {
  display: inline-block;
  margin-top: 12px;
  padding: 7px 12px;
  border: 1px solid var(--retard-bord);
  border-radius: 999px;
  background: var(--retard-fond);
  color: var(--retard);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

/* ===== CALENDRIER : LE VERT REMPLACE LE VIOLET =====
   Sur cette page uniquement, tout ce qui est validé passe en vert :
   les jours, les compteurs, les frises et les barres de palier. */
.page-calendrier {
  --valide: var(--vert);
  --valide-fond: var(--vert-1);
  --valide-bord: var(--vert-3);
}

/* ===== CALENDRIER : LE MOIS ET SON BILAN ===== */
.mois {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mois-fleche {
  width: 44px;
  height: 44px;
  border: 1px solid var(--bordure);
  border-radius: 12px;
  background: var(--surface);
  color: var(--texte);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

/* Une flèche sans mois à afficher devient discrète */
.mois-fleche:disabled {
  opacity: 0.3;
  cursor: default;
}

.trophees {
  margin: 12px 0 20px;
  color: var(--texte-doux);
  font-size: 15px;
  text-align: center;
}

.trophees strong {
  color: var(--valide);
  font-weight: 700;
}

/* ===== CALENDRIER : LA GRILLE DES JOURS ===== */
/* Sept colonnes de même largeur, une par jour de la semaine */
.grille {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.grille-titres {
  margin-bottom: 8px;
  color: var(--texte-doux);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

/* Chaque jour est un carré tactile */
.jour {
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--texte);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

/* Les quatre états d'un jour : ils servent aussi aux pastilles de la légende.
   Le jour complet est le plus lumineux : c'est le trophée. */
.complet {
  background: var(--valide);
  color: var(--fond);
}

.partiel {
  border-color: var(--valide-bord);
  background: var(--valide-fond);
}

.rate {
  border-color: var(--retard-bord);
  background: var(--retard-fond);
  color: var(--retard);
}

.libre {
  background: var(--surface);
  color: var(--texte-doux);
}

/* Le dégradé des jours partiels : plus il y a d'habitudes faites, plus le vert est vif */
.jour.vert-1 {
  border-color: var(--vert-2);
  background: var(--vert-1);
}

.jour.vert-2 {
  border-color: var(--vert-3);
  background: var(--vert-2);
}

.jour.vert-3 {
  border-color: var(--vert-3);
  background: var(--vert-3);
}

/* Dans la légende, la pastille Partiel montre tout le dégradé */
.pastille.partiel {
  border: 0;
  background: linear-gradient(90deg, var(--vert-1), var(--vert-3));
}

/* Un jour à venir n'a pas encore de couleur et ne se touche pas */
.jour.futur {
  background: transparent;
  color: var(--texte-doux);
  opacity: 0.4;
  cursor: default;
}

/* Le jour d'aujourd'hui a un fin contour blanc */
.jour.aujourdhui {
  border-color: var(--accent);
}

/* Le jour touché est entouré de blanc */
.jour.choisi {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== CALENDRIER : LA LÉGENDE ===== */
.legende {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  margin: 18px 0 28px;
  padding: 0;
  color: var(--texte-doux);
  font-size: 13px;
  list-style: none;
}

.legende li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pastille {
  width: 12px;
  height: 12px;
  border: 1px solid transparent;
  border-radius: 4px;
}

/* ===== CALENDRIER : LE DÉTAIL D'UN JOUR ===== */
.detail-liste {
  margin: 0;
  padding: 0;
  list-style: none;
}

.detail-liste li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  border-bottom: 1px solid var(--bordure);
  font-size: 16px;
}

.detail-fait,
.detail-rate,
.detail-attente {
  width: 20px;
  font-weight: 800;
  text-align: center;
}

/* Une habitude d'aujourd'hui pas encore cochée : ni réussie, ni ratée */
.detail-attente {
  color: var(--texte-doux);
}

.detail-fait {
  color: var(--valide);
}

.detail-rate {
  color: var(--retard);
}

/* ===== STATISTIQUES PAR HABITUDE ===== */
.stats {
  margin-top: 32px;
}

.stats-liste {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.fiche {
  padding: 14px;
  border: 1px solid var(--bordure);
  border-radius: 14px;
  background: var(--surface);
}

/* Le nom à gauche, la flamme à droite */
.fiche-haut {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
}

/* On annule ici la couleur rouge des titres de la zone Non faites */
.fiche-nom {
  margin: 0;
  color: var(--texte);
  font-size: 17px;
  overflow-wrap: anywhere;
}

.fiche-serie {
  flex: none;
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* La flamme grandit à chaque palier : 1, 7, 30 puis 100 d'affilée */
.fiche-serie span {
  line-height: 1;
  vertical-align: middle;
}

.flamme-0 {
  color: var(--texte-doux);
}

.flamme-0 span {
  font-size: 18px;
  opacity: 0.35; /* flamme éteinte */
}

.flamme-1 span {
  font-size: 20px;
}

.flamme-2 span {
  font-size: 28px;
}

.flamme-3 span {
  font-size: 36px;
}

.flamme-4 span {
  font-size: 44px;
}

/* La barre qui se remplit jusqu'au prochain palier */
.palier {
  height: 6px;
  margin-top: 10px;
  border-radius: 3px;
  background: var(--bordure);
  overflow: hidden;
}

.palier span {
  display: block;
  height: 100%;
  background: var(--valide);
}

.fiche-info,
.fiche-mois {
  margin: 8px 0 0;
  color: var(--texte-doux);
  font-size: 13px;
}

.fiche-mois strong {
  color: var(--valide);
}

/* La frise du mois : un petit carré par jour, du 1er au dernier */
.frise {
  display: grid;
  grid-template-columns: repeat(31, 1fr);
  gap: 2px;
  margin-top: 12px;
}

.frise span {
  height: 16px;
  border-radius: 2px;
  background: var(--bordure); /* gris : pas prévu ce jour-là */
}

.frise .fait {
  background: var(--valide);
}

.frise .pas-fait {
  background: var(--retard);
}

/* Le numéro de version, discret, tout en bas du calendrier */
.version {
  margin: 24px 0 0;
  color: var(--texte-doux);
  font-size: 12px;
  text-align: center;
}

/* ===== BARRE DU BAS ===== */
/* Elle reste fixée en bas de l'écran, au-dessus de la zone d'accueil de l'iPhone */
.barre-bas {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  height: calc(var(--hauteur-barre) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--bordure);
  background: var(--fond);
}

.onglet {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--texte-doux);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.onglet-icone {
  font-size: 20px;
  line-height: 1;
}

/* L'onglet de la page affichée passe en orange */
#choix-jour:checked ~ .barre-bas .onglet-jour,
#choix-calendrier:checked ~ .barre-bas .onglet-calendrier {
  color: var(--accent);
}
