/* Theme sombre, pense pour le telephone d'abord.
   Les couleurs sont regroupees en variables pour rester coherentes entre les
   trois ecrans. */

:root {
  --bg: #0f1117;        /* fond general de la page */
  --card: #1a1d27;      /* fond des cartes et des listes */
  --card2: #232735;     /* fond secondaire : champs, lignes survolees */
  --text: #e8eaf0;      /* texte principal */
  --muted: #8b90a3;     /* texte secondaire, libelles, dates */
  --accent: #6366f1;    /* couleur d'action (boutons, onglet actif) */
  --danger: #ef4444;    /* suppressions et erreurs */

  --rayon: 12px;
  --hauteur-onglets: 62px;
}

/* --- Remise a zero --------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  /* Reserve la place de la barre d'onglets fixe, plus l'encoche eventuelle. */
  padding-bottom: calc(var(--hauteur-onglets) + env(safe-area-inset-bottom));
}

[hidden] {
  display: none !important;
}

ul,
ol {
  list-style: none;
}

a {
  color: var(--accent);
}

/* --- Structure des ecrans -------------------------------------------- */

.entete {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--card2);
}

.entete h1 {
  font-size: 1.15rem;
  font-weight: 600;
}

.contenu {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Boutons ---------------------------------------------------------- */

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

.bouton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  /* 44px minimum : cible tactile confortable au doigt. */
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--rayon);
  background: var(--card2);
  color: var(--text);
  font-weight: 600;
}

.bouton-principal {
  background: var(--accent);
  color: #fff;
}

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

.bouton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.bouton-large {
  width: 100%;
}

/* --- Champs de saisie -------------------------------------------------- */

label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--card2);
  border-radius: var(--rayon);
  background: var(--card2);
  color: var(--text);
  /* 16px evite le zoom automatique de Safari iOS a la mise au point. */
  font-size: 16px;
  font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

input[type="color"] {
  padding: 4px;
  height: 44px;
}

.champ {
  margin-bottom: 14px;
}

/* --- Listes et cartes -------------------------------------------------- */

.carte {
  padding: 14px;
  border-radius: var(--rayon);
  background: var(--card);
}

.liste {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.liste-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--rayon);
  background: var(--card);
}

.liste-item-corps {
  flex: 1;
  min-width: 0;
}

.liste-item-titre {
  font-weight: 600;
}

.liste-item-detail,
.secondaire {
  color: var(--muted);
  font-size: 0.85rem;
}

.pastille {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.vide {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
}

.sous-titre {
  margin: 8px 0 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.liste-inactifs {
  opacity: 0.6;
}

.liste-item {
  cursor: pointer;
}

.champ-suffixe {
  position: relative;
}

.champ-suffixe input {
  padding-right: 48px;
}

.champ-suffixe-texte {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.85rem;
  pointer-events: none;
}

/* --- Palette de couleurs ------------------------------------------------ */

.palette {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.palette-pastille {
  width: 32px;
  height: 32px;
  min-height: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
}

.palette-pastille.selectionnee {
  border-color: var(--text);
}

/* --- Interrupteur (case Actif) ------------------------------------------ */

.champ-interrupteur {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.champ-interrupteur label:not(.interrupteur) {
  margin-bottom: 0;
}

.interrupteur {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
}

.interrupteur input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.interrupteur-piste {
  position: absolute;
  inset: 0;
  background: var(--card2);
  border-radius: 999px;
  transition: background 0.15s ease;
}

.interrupteur-piste::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s ease, background 0.15s ease;
}

.interrupteur input:checked + .interrupteur-piste {
  background: var(--accent);
}

.interrupteur input:checked + .interrupteur-piste::before {
  transform: translateX(20px);
  background: #fff;
}

.erreur {
  padding: 10px 12px;
  border-radius: var(--rayon);
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger);
  font-size: 0.9rem;
}

/* --- Modales ----------------------------------------------------------- */

.modale {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}

.modale-boite {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: var(--rayon) var(--rayon) 0 0;
  background: var(--card);
}

.modale-entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modale-titre {
  font-size: 1.05rem;
  font-weight: 600;
}

.modale-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.modale-actions .bouton {
  flex: 1;
}

/* Sur ecran large, la modale se centre plutot que de coller en bas. */
@media (min-width: 600px) {
  .modale {
    align-items: center;
  }

  .modale-boite {
    border-radius: var(--rayon);
  }
}

/* --- Ecran de connexion -------------------------------------------------- */

#ecran-connexion {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.connexion-boite {
  width: 100%;
  max-width: 360px;
}

.connexion-boite h1 {
  margin-bottom: 24px;
  font-size: 1.3rem;
  text-align: center;
}

/* --- Barre d'onglets --------------------------------------------------- */

.barre-onglets {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--card2);
  padding-bottom: env(safe-area-inset-bottom);
}

.onglet {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: var(--hauteur-onglets);
  color: var(--muted);
  font-size: 0.72rem;
}

.onglet-icone {
  font-size: 1.25rem;
  line-height: 1;
}

.onglet.actif {
  color: var(--accent);
}

/* --- Calendrier : vue semaine ------------------------------------------- */

:root {
  --largeur-heures: 42px;   /* echelle horaire a gauche de la grille */
  --hauteur-heure: 52px;    /* hauteur d'une heure : 24 x 52 = 1248px */
}

/* L'ecran occupe toute la hauteur disponible : seule la grille defile,
   l'en-tete, la barre de navigation et les noms de jours restent fixes. */
#ecran-calendrier {
  position: relative;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--hauteur-onglets) - env(safe-area-inset-bottom));
}

.contenu-calendrier {
  flex: 1;
  min-height: 0;
  padding: 0;
  gap: 0;
}

.calendrier-barre {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--card2);
}

.calendrier-periode {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
}

.bouton-fleche {
  min-width: 44px;
  padding: 10px 12px;
  font-size: 1.3rem;
  line-height: 1;
}

#calendrier-aujourdhui {
  padding: 10px 12px;
  font-size: 0.85rem;
}

#calendrier-erreur {
  margin: 10px 12px 0;
}

/* En-tete des jours, hors de la zone de defilement pour rester visible. */
.calendrier-jours {
  display: flex;
  border-bottom: 1px solid var(--card2);
}

.calendrier-jours-cale {
  width: var(--largeur-heures);
  flex: 0 0 auto;
}

.calendrier-jour {
  flex: 1 1 0;
  min-width: 0;
  padding: 6px 2px;
  text-align: center;
  line-height: 1.2;
}

.calendrier-jour-nom {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
}

.calendrier-jour-numero {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
}

/* Le jour du jour est mis en avant, colonne comprise. */
.calendrier-jour.aujourdhui .calendrier-jour-nom,
.calendrier-jour.aujourdhui .calendrier-jour-numero {
  color: var(--accent);
}

.calendrier-jour.aujourdhui .calendrier-jour-numero {
  display: inline-block;
  min-width: 24px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
}

.calendrier-defilement {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.calendrier-grille {
  display: flex;
  height: calc(24 * var(--hauteur-heure));
}

/* Echelle horaire : les graduations sont posees en absolu sur la hauteur
   totale, exactement au niveau des lignes de la grille. */
.calendrier-heures {
  position: relative;
  width: var(--largeur-heures);
  flex: 0 0 auto;
}

.calendrier-heure {
  position: absolute;
  right: 6px;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.calendrier-heure-premiere {
  transform: none;
}

.calendrier-heure-derniere {
  transform: translateY(-100%);
}

.calendrier-colonnes {
  position: relative;
  display: flex;
  flex: 1;
  min-width: 0;
  /* Les lignes des heures sont dessinees en fond plutot qu'en 24 elements. */
  background: repeating-linear-gradient(
    to bottom,
    var(--card2) 0,
    var(--card2) 1px,
    transparent 1px,
    transparent var(--hauteur-heure)
  );
}

.calendrier-colonne {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  border-left: 1px solid var(--card2);
}

.calendrier-colonne.aujourdhui {
  background: rgba(99, 102, 241, 0.1);
}

/* Un bloc = un fragment de presence sur une journee. */
.calendrier-bloc {
  position: absolute;
  overflow: hidden;
  /* Un creneau tres court reste tapable meme s'il dure quelques minutes. */
  min-height: 18px;
  padding: 3px 4px;
  border-radius: 6px;
  text-align: left;
  font-size: 0.66rem;
  line-height: 1.15;
}

/* Coins carres du cote ou le creneau se poursuit sur le jour voisin :
   les deux moities d'une nuit se lisent comme un seul creneau coupe. */
.calendrier-bloc.coupe-avant {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.calendrier-bloc.coupe-apres {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.calendrier-bloc-nom {
  display: block;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calendrier-bloc-heures {
  display: block;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Une presence deja payee s'efface : opacite reduite et coche discrete dans
   le coin, visible meme sur un bloc tres court ou coupe par minuit. */
.calendrier-bloc.bloc-paye {
  opacity: 0.45;
}

.calendrier-bloc.bloc-paye::after {
  content: "\2713";
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
}

/* --- Legende et total de la semaine ------------------------------------- */

.calendrier-legende {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  color: var(--muted);
  font-size: 0.78rem;
  border-bottom: 1px solid var(--card2);
}

.calendrier-legende-paye {
  opacity: 0.75;
}

#calendrier-total-impaye {
  font-weight: 600;
  color: var(--text);
}

/* --- Boutons flottants : venue unique, ou saisie d'un rythme regulier --- */

.boutons-flottants {
  position: absolute;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
}

.bouton-flottant {
  width: 56px;
  height: 56px;
  min-height: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}

/* Bouton secondaire (serie) : plus discret que le « + » principal. */
.bouton-flottant-secondaire {
  width: 44px;
  height: 44px;
  background: var(--card2);
  color: var(--text);
  font-size: 1.25rem;
}

/* --- Modale de saisie d'une venue --------------------------------------- */

/* Deux champs (date + heure) cote a cote : gagne de la place en modale. */
.champ-ligne {
  display: flex;
  gap: 10px;
}

.champ-ligne .champ {
  flex: 1;
  min-width: 0;
}

#presence-recapitulatif {
  margin: -4px 0 14px;
}

/* --- Jours de la semaine (saisie en serie) ------------------------------ */

.serie-jours {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.serie-jour {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 40px;
  margin: 0;
  border-radius: var(--rayon);
  background: var(--card2);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.serie-jour input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.serie-jour:has(input:checked) {
  background: var(--accent);
  color: #fff;
}

/* --- Recapitulatif : barre de filtres ----------------------------------- */

.recap-barre {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--card2);
}

.recap-barre .champ {
  margin-bottom: 10px;
}

.recap-raccourcis {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.recap-raccourcis .bouton {
  flex: 1 1 auto;
  padding: 8px 10px;
  font-size: 0.8rem;
  font-weight: 500;
}

/* Le telechargement du PDF est une action a part : bouton pleine largeur,
   detache des raccourcis de periode. */
#recap-pdf {
  margin-top: 4px;
}

/* --- Recapitulatif : cartes par intervenante ---------------------------- */

.recap-carte {
  padding: 14px;
  border-radius: var(--rayon);
  background: var(--card);
}

.recap-carte-entete {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.recap-carte-titre {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.recap-carte-nom {
  font-weight: 600;
}

.recap-carte-cout {
  color: var(--muted);
  font-size: 0.8rem;
}

.recap-totaux {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.recap-total-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: var(--rayon);
  background: var(--card2);
}

.recap-total-valeur {
  font-size: 1.15rem;
  font-weight: 700;
}

.recap-total-du .recap-total-valeur {
  color: var(--accent);
}

.recap-total-libelle {
  color: var(--muted);
  font-size: 0.72rem;
}

.recap-sous-totaux {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* --- Recapitulatif : detail depliable des presences --------------------- */

.recap-detail summary {
  padding: 8px 0;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.recap-detail summary::-webkit-details-marker {
  display: none;
}

.recap-detail summary::before {
  content: "▸ ";
}

.recap-detail[open] summary::before {
  content: "▾ ";
}

.recap-presences {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
}

.recap-presence {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "date paye"
    "horaires horaires"
    "duree montant";
  gap: 2px 8px;
  padding: 10px 12px;
  border-radius: var(--rayon);
  background: var(--card2);
  font-size: 0.85rem;
}

.recap-presence-date {
  grid-area: date;
  font-weight: 600;
}

.recap-presence-paye {
  grid-area: paye;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
}

.recap-presence-horaires {
  grid-area: horaires;
  color: var(--muted);
}

.recap-presence-duree {
  grid-area: duree;
  color: var(--muted);
}

.recap-presence-montant {
  grid-area: montant;
  justify-self: end;
  font-weight: 600;
}

.recap-presence-payee {
  opacity: 0.6;
}

/* --- Recapitulatif : pied de page (totaux toutes intervenantes) --------- */

.recap-pied {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 14px 16px;
  border-radius: var(--rayon);
  background: var(--card2);
  font-weight: 600;
}
