/* ============================================================
   COMPOSANTS
   ============================================================ */

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--tap); padding: 0 var(--s-5);
  border: 1px solid var(--line-fort); border-radius: var(--r-m);
  background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast), transform var(--dur-fast);
  -webkit-user-select: none; user-select: none;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn--primaire { background: var(--primaire); border-color: var(--primaire); color: var(--primaire-texte); box-shadow: 0 6px 22px rgba(5, 17, 242, 0.35); }
.btn--primaire:hover { background: var(--primaire-hover); border-color: var(--primaire-hover); }
.btn--danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger-doux); border-color: var(--danger); }
.btn--ok { background: transparent; border-color: var(--ok); color: var(--ok); }
.btn--ok:hover { background: var(--ok-doux); border-color: var(--ok); }
.btn--fantome { background: transparent; border-color: transparent; color: var(--accent); }
.btn--fantome:hover { background: var(--accent-doux); border-color: transparent; }
.btn--grand { min-height: var(--tap-lg); font-size: 17px; width: 100%; }
.btn--plein { width: 100%; }
.btn--icone { width: var(--tap); padding: 0; }
.btn--petit { min-height: 36px; padding: 0 var(--s-3); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.actions--fin { justify-content: flex-end; }
.actions--pile { flex-direction: column; }
.actions--pile .btn { width: 100%; }

/* ---------- Cartes ---------- */
.carte {
  position: relative;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: var(--s-5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .carte { background: var(--surface); }
}
.carte--edge::after {
  content: ""; position: absolute; left: 18px; right: 18px; top: -1px; height: 1px; background: var(--edge);
}
.carte + .carte, .carte + .section, .section + .carte, .section + .section { margin-top: var(--s-4); }

/* Pile verticale d'une vue : un seul espacement regulier entre blocs,
   quelles que soient les marges propres des composants. */
.pile { display: flex; flex-direction: column; gap: var(--s-4); }
.pile > * { margin-top: 0 !important; margin-bottom: 0 !important; }
.pile > .titre-page, .pile > .periode, .pile > .jour-tete { margin-bottom: var(--s-1) !important; }
.pile > .bandeau { margin-bottom: 0; }
.carte__titre { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-3); }
.carte__titre h2 { font-size: 16px; }
.carte--lien { display: block; text-decoration: none; color: inherit; transition: border-color var(--dur-fast), transform var(--dur-fast); }
.carte--lien:hover { border-color: var(--line-fort); transform: translateY(-1px); }

.grille { display: grid; gap: var(--s-3); }
.grille--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grille--3 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grille--4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

.titre-page { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; margin-bottom: var(--s-5); }
.titre-page p { color: var(--text-2); margin-top: var(--s-1); }
.surtitre {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: 4px 12px; border-radius: var(--r-pill);
  background: var(--accent-doux); border: 1px solid var(--line);
  color: var(--accent); font: 700 11px/1.4 var(--font); letter-spacing: 0.1em; text-transform: uppercase;
  margin-bottom: var(--s-2);
  white-space: nowrap;
}
.surtitre svg { width: 14px; height: 14px; }
.grille > .carte { margin-top: 0; }

/* ---------- Statistiques ---------- */
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat__lib { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); }
.stat__val { font: 700 24px/1.15 var(--font); white-space: nowrap; }
.stat__val--xl { font-size: var(--t-xxl); letter-spacing: -0.01em; }
.stat__sous { font-size: 13px; color: var(--text-2); }
.stat--accent .stat__val { color: var(--accent); }
.stat--ok .stat__val { color: var(--ok); }
.stat--alerte .stat__val { color: var(--alerte); }

/* ---------- Pastilles de statut (jamais la couleur seule) ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px; border-radius: var(--r-pill);
  font: 700 12px/1.4 var(--font); white-space: nowrap;
  background: var(--neutre-doux); color: var(--text-2); border: 1px solid transparent;
}
.pill svg { width: 14px; height: 14px; flex: none; }
.pill--ok { background: var(--ok-doux); color: var(--ok); }
.pill--alerte { background: var(--alerte-doux); color: var(--alerte); }
.pill--danger { background: var(--danger-doux); color: var(--danger); }
.pill--info { background: var(--accent-doux); color: var(--accent); }
.pill--contour { background: transparent; border-color: var(--line-fort); }

/* ---------- Bandeaux ---------- */
.bandeau {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-m);
  border: 1px solid var(--line); background: var(--surface-2);
  font-size: 14px; margin-bottom: var(--s-4);
}
.bandeau svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.bandeau--alerte { border-color: color-mix(in srgb, var(--alerte) 45%, transparent); background: var(--alerte-doux); }
.bandeau--alerte svg { color: var(--alerte); }
.bandeau--danger { border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: var(--danger-doux); }
.bandeau--danger svg { color: var(--danger); }
.bandeau--ok { border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: var(--ok-doux); }
.bandeau--ok svg { color: var(--ok); }
.bandeau--info svg { color: var(--accent); }
.bandeau strong { display: block; margin-bottom: 2px; }
.bandeau .actions { margin-top: var(--s-2); }

/* ---------- Champs ---------- */
.champ { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.champ + .champ, .champ + .ligne-champs, .ligne-champs + .champ, .ligne-champs + .ligne-champs { margin-top: var(--s-4); }
.champ > label, .champ__lib { font-size: 14px; font-weight: 600; color: var(--text-2); }
.champ__aide { font-size: 13px; color: var(--text-3); }
.champ__erreur { font-size: 13px; color: var(--danger); font-weight: 600; }
.ligne-champs { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s-4) var(--s-3); align-items: end; }
/* Champs cote a cote : aucune marge propre, c'est la grille qui espace.
   (Sans cette regle, tous les champs sauf le premier etaient decales.) */
.ligne-champs > .champ { margin-top: 0 !important; }
/* Alignement par le bas : si un libelle passe sur deux lignes, les
   champs de la rangee restent alignes entre eux. */

.saisie {
  width: 100%; min-height: var(--tap-lg); padding: 0 var(--s-4);
  border: 1px solid var(--line-fort); border-radius: var(--r-m);
  background: var(--bg); color: var(--text);
  font-size: 17px; font-weight: 600;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
textarea.saisie { padding: var(--s-3) var(--s-4); min-height: 88px; resize: vertical; font-weight: 500; font-size: 16px; }
select.saisie { appearance: none; -webkit-appearance: none; padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }
.saisie:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-doux); }
.saisie[aria-invalid="true"] { border-color: var(--danger); }
.saisie--heure { text-align: center; font-family: var(--font); font-size: 22px; letter-spacing: 0.04em; padding: 0 var(--s-2); }
.saisie::placeholder { color: var(--text-3); font-weight: 500; }

.interrupteur { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); min-height: var(--tap); cursor: pointer; }
.interrupteur input { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 15px; background: var(--surface-3); border: 1px solid var(--line-fort); position: relative; flex: none; cursor: pointer; transition: background var(--dur); }
.interrupteur input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--text); transition: transform var(--dur) var(--ease); }
.interrupteur input:checked { background: var(--primaire); border-color: var(--primaire); }
.interrupteur input:checked::after { transform: translateX(20px); background: #fff; }

.puces { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.puce {
  min-height: 40px; padding: 0 var(--s-4); border-radius: var(--r-pill);
  border: 1px solid var(--line-fort); background: transparent; color: var(--text-2);
  font-weight: 600; font-size: 14px; cursor: pointer;
}
.puce[aria-pressed="true"] { background: var(--primaire); border-color: var(--primaire); color: #fff; }

.segment { display: inline-flex; padding: 3px; border-radius: var(--r-m); background: var(--surface-2); border: 1px solid var(--line); }
.segment button { min-height: 38px; padding: 0 var(--s-4); border: 0; border-radius: 9px; background: transparent; color: var(--text-2); font-weight: 600; cursor: pointer; }
.segment button[aria-pressed="true"] { background: var(--primaire); color: #fff; }

/* ---------- Listes ---------- */
.liste { list-style: none; margin: 0; padding: 0; }
.liste > li + li { border-top: 1px solid var(--line); }
.ligne {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 60px; padding: var(--s-3) 0;
  color: inherit; text-decoration: none; width: 100%;
  background: none; border: 0; text-align: left; cursor: pointer;
}
a.ligne:hover .ligne__titre, button.ligne:hover .ligne__titre { color: var(--accent); }
.ligne__corps { flex: 1; min-width: 0; }
.ligne__titre { font-weight: 700; display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.ligne__sous { font-size: 13px; color: var(--text-2); margin-top: 2px; overflow-wrap: anywhere; }
.ligne__val { font-weight: 700; white-space: nowrap; text-align: right; }
.ligne__val small { display: block; font-size: 12px; font-weight: 600; color: var(--text-3); }
.ligne__chevron { width: 18px; height: 18px; color: var(--text-3); flex: none; }
.ligne--vide .ligne__titre { color: var(--text-3); font-weight: 600; }

.vide { text-align: center; padding: var(--s-8) var(--s-4); color: var(--text-2); }
.vide svg { width: 40px; height: 40px; margin: 0 auto var(--s-3); color: var(--text-3); }

/* ---------- Tableaux (ordinateur) ---------- */
.tableau-conteneur { overflow-x: auto; margin: 0 calc(var(--s-5) * -1); padding: 0 var(--s-5); }
table.tableau { width: 100%; border-collapse: collapse; font-size: 14px; }
.tableau th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); font-weight: 700; padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--line-fort); white-space: nowrap; }
.tableau td { padding: var(--s-3); border-bottom: 1px solid var(--line); vertical-align: middle; }
.tableau tr:hover td { background: var(--accent-doux); }
.tableau .num { text-align: right; white-space: nowrap; }
.tableau a { font-weight: 700; color: var(--text); text-decoration: none; }
.tableau a:hover { color: var(--accent); }
.tableau input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--mx-primary); }

/* Sur mobile, les tableaux deviennent des listes de cartes */
@media (max-width: 720px) {
  table.tableau--cartes thead { display: none; }
  table.tableau--cartes, .tableau--cartes tbody, .tableau--cartes tr, .tableau--cartes td { display: block; width: 100%; }
  .tableau--cartes tr { border: 1px solid var(--line); border-radius: var(--r-m); padding: var(--s-3); margin-bottom: var(--s-3); }
  .tableau--cartes td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: var(--s-3); text-align: right; }
  .tableau--cartes td::before { content: attr(data-lib); color: var(--text-3); font-size: 12px; font-weight: 700; text-transform: uppercase; text-align: left; }
  .tableau--cartes td.td-titre { font-size: 16px; text-align: left; }
  .tableau--cartes td.td-titre::before { display: none; }
  .tableau-conteneur { margin: 0; padding: 0; overflow: visible; }
}

/* ---------- Feuilles modales (dialog) ---------- */
dialog.feuille {
  width: 100%; max-width: 560px; max-height: calc(100dvh - var(--safe-top) - 24px);
  margin: auto auto 0; padding: 0; border: 1px solid var(--line-fort); border-bottom: 0;
  border-radius: 22px 22px 0 0; background: var(--surface); color: var(--text);
  box-shadow: var(--ombre-sheet); overflow: hidden;
}
dialog.feuille[open] { display: flex; flex-direction: column; animation: monter var(--dur) var(--ease); }
dialog.feuille::backdrop { background: var(--scrim); }
.feuille__tete { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); position: relative; }
.feuille__tete::after { content: ""; position: absolute; left: 20px; right: 20px; bottom: -1px; height: 1px; background: var(--edge); opacity: 0.6; }
.feuille__tete h2 { flex: 1; font-size: 18px; }
.feuille__corps { padding: var(--s-5); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.feuille__pied { padding: var(--s-4) var(--s-5) calc(var(--s-4) + var(--safe-bottom)); border-top: 1px solid var(--line); }
@media (min-width: 720px) {
  dialog.feuille { margin: auto; border-radius: 22px; border-bottom: 1px solid var(--line-fort); }
  dialog.feuille[open] { animation: apparaitre var(--dur) var(--ease); }
}
@keyframes monter { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes apparaitre { from { transform: scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Notifications ---------- */
.toasts {
  position: fixed; z-index: var(--z-toast);
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--s-3));
  width: min(520px, calc(100% - 32px));
  display: flex; flex-direction: column; gap: var(--s-2);
  pointer-events: none;
}
@media (min-width: 960px) { .toasts { bottom: var(--s-6); } }
.toast {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4); border-radius: var(--r-m);
  background: var(--surface-3); border: 1px solid var(--line-fort); color: var(--text);
  box-shadow: var(--ombre); font-weight: 600; font-size: 15px;
  animation: monter var(--dur) var(--ease);
  pointer-events: auto;
}
.toast svg { width: 20px; height: 20px; flex: none; }
.toast--ok svg { color: var(--ok); }
.toast--erreur svg { color: var(--danger); }
.toast--attente svg { color: var(--alerte); }

/* ---------- Indicateur de synchronisation ---------- */
.sync {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 0 10px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--surface-2);
  font: 600 12px/1 var(--font); color: var(--text-2); cursor: pointer;
}
.sync__point { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.sync[data-etat="attente"] .sync__point, .sync[data-etat="hors_ligne"] .sync__point { background: var(--alerte); }
.sync[data-etat="erreur"] .sync__point, .sync[data-etat="conflit"] .sync__point { background: var(--danger); }
.sync[data-etat="encours"] .sync__point { background: var(--accent); animation: pulser 1s infinite; }
@keyframes pulser { 50% { opacity: 0.3; } }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--mx-primary), var(--mx-blue-bright));
  color: #fff; font: 700 13px/1 var(--font); text-decoration: none;
}

/* ---------- Barre de periode ---------- */
.periode { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-4); }
.periode__lib { flex: 1; text-align: center; font-weight: 700; font-size: 17px; }
.periode__lib small { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); }

/* ---------- Chargement ---------- */
.chargement { display: grid; place-items: center; padding: var(--s-10); color: var(--text-3); }
.chargement::before { content: ""; width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-fort); border-top-color: var(--accent); animation: tourner 0.8s linear infinite; }
@keyframes tourner { to { transform: rotate(360deg); } }

/* ---------- Divers ---------- */
.sep { height: 1px; background: var(--line); border: 0; margin: var(--s-4) 0; }
.barre-prog { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.barre-prog > span { display: block; height: 100%; background: linear-gradient(90deg, var(--mx-primary), var(--mx-blue-bright)); border-radius: 4px; }
.lien-copie { display: block; padding: var(--s-3); border-radius: var(--r-m); border: 1px dashed var(--accent); background: var(--bg); font-family: var(--font-mono); font-size: 13px; word-break: break-all; user-select: all; -webkit-user-select: all; }
.diff { font-family: var(--font-mono); font-size: 12px; background: var(--bg); border-radius: var(--r-s); padding: var(--s-2) var(--s-3); white-space: pre-wrap; word-break: break-word; margin-top: var(--s-2); border: 1px solid var(--line); }
details.plier > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; list-style: none; }
details.plier > summary::-webkit-details-marker { display: none; }
