/* Les Piscines de l'Olympe - outil central : styles communs.
   Variables reprises de olympe-app/styles.css. Classes documentées dans LISEZ-MOI-technique.md. */

:root {
  --blue: #1D4CA1;
  --blue-dark: #163C84;
  --blue-soft: #EEF3FC;
  --ink: #10213F;
  --muted: #5A6A85;
  --line: #D9E1EC;
  --bg: #F2F5FA;
  --card: #FFFFFF;
  --turq: #2FB8AE;
  --sky: #00A3E0;
  --yellow: #F9B812;
  --danger: #C23B30;
  --danger-soft: #FDF1EF;
  --warn-soft: #FFF6DC;
  --warn-ink: #6B4E00;
  --ok: #1B7F52;
  --ok-soft: #E9F7F0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 33, 63, .05), 0 6px 18px rgba(16, 33, 63, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.verrou { overflow: hidden; }
h1, h2, h3, p, dl, dd, ul { margin: 0; }
ul { padding: 0; list-style: none; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; text-align: inherit; }
button:disabled { cursor: default; }
a { color: var(--blue); }
em, i { font-style: normal; }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 3px solid rgba(0, 163, 224, .55); outline-offset: 2px; }

.ic { display: inline-flex; flex: none; }
.ic svg { display: block; }
.discret { color: var(--muted); }

/* ---------- Boutons : .btn + .primaire | .secondaire | .danger | .discret ; .petit .plein .icone ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  border-radius: 10px;
  font-size: 15px; font-weight: 600;
  transition: background-color .15s, box-shadow .15s, opacity .15s;
  user-select: none; -webkit-user-select: none; white-space: nowrap;
}
a.btn, a.btn:hover, a.btn:focus { text-decoration: none; }
.btn .ic svg { width: 18px; height: 18px; }
.btn.petit { min-height: 32px; padding: 0 10px; font-size: 14px; border-radius: 8px; }
.btn.plein { width: 100%; }
.btn.icone { width: 36px; min-height: 36px; padding: 0; }
.btn.primaire { background: var(--blue); color: #fff; }
.btn.primaire:hover:not(:disabled) { background: var(--blue-dark); }
.btn.primaire:disabled { background: #B9C5DA; }
.btn.secondaire { background: var(--card); color: var(--blue); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.secondaire:hover:not(:disabled) { background: var(--blue-soft); }
.btn.secondaire:disabled { color: #A9B4C6; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #A62F26; }
.btn.discret { color: var(--muted); }
.btn.discret:hover:not(:disabled) { background: rgba(16, 33, 63, .06); }

/* ---------- Mise en page ---------- */

.entete-page { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.titre-page { font-size: 26px; line-height: 1.2; font-weight: 700; letter-spacing: -.015em; }
.sous-titre { font-size: 14px; color: var(--muted); margin-top: 2px; }
.titre-section { font-size: 17px; font-weight: 650; letter-spacing: -.005em; margin: 0 0 10px; }
.barre-outils { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.carte { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.grille { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.vide { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 15px; background: var(--card); border-radius: var(--radius); box-shadow: inset 0 0 0 1.5px var(--line); }

/* ---------- Champs : .champ > label.champ-etiquette + .entree (+ .champ-aide, .champ-erreur) ---------- */

.champ { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.champ-etiquette { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 14px; font-weight: 600; color: var(--ink); }
.champ-option { font-size: 12.5px; font-weight: 500; color: #7A889F; }
.champ-aide { font-size: 13.5px; color: var(--muted); line-height: 1.4; }
.champ-erreur { font-size: 13.5px; font-weight: 500; color: var(--danger); }
.ligne-champs { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }

.entree {
  width: 100%; min-height: 40px; padding: 8px 12px;
  font: inherit; font-size: 15px; color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--line); border-radius: 10px;
  appearance: none; -webkit-appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
select.entree {
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='18' height='18' fill='none' stroke='%235A6A85' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
textarea.entree { resize: vertical; line-height: 1.45; }
.entree::placeholder { color: #9AA7BC; }
.entree:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(29, 76, 161, .12); outline: none; }
.entree:disabled { background: var(--bg); color: var(--muted); }
.en-erreur .entree { border-color: var(--danger); }
.en-erreur .entree:focus { box-shadow: 0 0 0 4px rgba(194, 59, 48, .12); }

.recherche { position: relative; min-width: 220px; }
.recherche .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.recherche .ic svg { width: 18px; height: 18px; }
.recherche .entree { padding-left: 38px; }

/* ---------- Tableau : div.tableau-cadre > table.tableau ---------- */

.tableau-cadre { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.tableau { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.tableau th {
  position: sticky; top: 0; text-align: left; white-space: nowrap;
  padding: 11px 16px; font-size: 12.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted); background: #F8FAFD; border-bottom: 1px solid var(--line);
}
.tableau td { padding: 12px 16px; border-bottom: 1px solid #EAEFF6; vertical-align: middle; }
.tableau tr:last-child td { border-bottom: 0; }
.tableau .num { text-align: right; font-variant-numeric: tabular-nums; }
.tableau tr.cliquable { cursor: pointer; }
.tableau tr.cliquable:hover td { background: #F5F8FD; }
.tableau tr.cliquable:focus-visible { outline-offset: -3px; }
.tableau .principal { font-weight: 600; }
.secondaire-texte { font-size: 13px; font-weight: 400; color: var(--muted); }
.tableau .secondaire-texte { display: block; }

/* ---------- Étiquettes de statut : .etiquette + a_prevoir | planifiee | en_cours | terminee | archivee | ok | alerte | neutre ---------- */

.etiquette {
  display: inline-flex; align-items: center; min-height: 24px; padding: 0 10px;
  border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: #ECEFF5; color: #566580;
}
.etiquette.a_prevoir { background: #FFF3CF; color: #8A5F00; }
.etiquette.planifiee { background: #EAF0FB; color: #1D4CA1; }
.etiquette.en_cours { background: #DFF3FB; color: #0A6F99; }
.etiquette.terminee, .etiquette.ok { background: #E3F5EC; color: #17704A; }
.etiquette.archivee, .etiquette.neutre { background: #ECEFF5; color: #566580; }
.etiquette.alerte { background: var(--danger-soft); color: #8E2A21; }

/* ---------- Fenêtre : .fenetre-fond > .fenetre (.large) > .fenetre-tete, .fenetre-corps, .fenetre-pied ---------- */

.fenetre-fond { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(16, 33, 63, .45); overflow-y: auto; }
.fenetre { width: 100%; max-width: 480px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--card); border-radius: 16px; box-shadow: 0 20px 60px rgba(16, 33, 63, .3); }
.fenetre.large { max-width: 760px; }
.fenetre-tete { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 12px 22px; }
.fenetre-titre { font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.fenetre-corps { padding: 4px 22px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.fenetre-pied { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px 18px; border-top: 1px solid #EAEFF6; }

/* ---------- Messages brefs (.messages > .message) et notes dans la page (.note) ---------- */

.messages { position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 24px); transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.message { opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; background: var(--ink); color: #fff; font-size: 14.5px; font-weight: 500; padding: 11px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(16, 33, 63, .28); }
.message.visible { opacity: 1; transform: none; }
.message.ok { background: var(--ok); }
.message.erreur { background: var(--danger); }

.note { display: block; padding: 12px 16px; border-radius: 10px; background: var(--blue-soft); font-size: 14.5px; line-height: 1.45; }
.note.alerte { background: var(--warn-soft); color: var(--warn-ink); }
.note.erreur { background: var(--danger-soft); color: #7E241C; }
.note.ok { background: var(--ok-soft); color: #0F4D32; }

/* ---------- Indicateur de synchronisation : button.sync (+ .ok | .attente | .hors | .occupe) ---------- */

.sync { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; line-height: 1.3; text-align: left; border-radius: 8px; padding: 4px 6px; margin: -4px -6px; }
.sync-point { flex: none; width: 8px; height: 8px; border-radius: 50%; background: #9AA7BC; }
.sync.ok .sync-point { background: var(--turq); }
.sync.attente .sync-point { background: var(--yellow); }
.sync.hors .sync-point { background: var(--danger); }
.sync.occupe .sync-point { background: var(--sky); animation: clignote 1s ease-in-out infinite; }
@keyframes clignote { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .sync-point, .message { animation: none !important; transition: none !important; } }

/* Graphiques SVG (Central.graphique) */
.graphique { margin: 0; }
.graphique-titre { font-size: 14px; font-weight: 650; color: var(--ink); margin-bottom: 8px; }
.graphique-svg { display: block; max-width: 100%; height: auto; }
.graphique-svg text { fill: var(--muted); font-family: var(--font); font-size: 12px; }
.graphique-svg .axe { stroke: var(--line); stroke-width: 1; }
.graphique-svg .bande-cible { fill: #DEF5F2; }
.graphique-svg .graphique-total { fill: var(--ink); font-size: 18px; font-weight: 700; }
.graphique-legende { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }
.graphique-legende li { display: inline-flex; align-items: center; gap: 6px; }
.graphique-legende.vertical { flex-direction: column; flex-wrap: nowrap; gap: 6px; margin: 0; min-width: 190px; }
.graphique-legende.vertical li { width: 100%; }
.graphique-lib { flex: 1; color: var(--ink); }
.graphique-pastille { flex: none; width: 10px; height: 10px; border-radius: 3px; }
.repartition-corps { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }

/* Impression d'un élément seul (Central.imprimer) */
.zone-impression-bureau { display: none; }
@media print {
  body.impression > *:not(.zone-impression-bureau) { display: none !important; }
  body.impression .zone-impression-bureau { display: block; padding: 0; }
  .titre-impression { font-size: 18px; margin: 0 0 12px; }
}

/* Mention discrète des écrans de facturation (Central.mentionEssai) */
.mention-essai { margin: 0 0 14px; font-size: 12.5px; color: var(--muted); }

/* Listes par tranches (Central.tableau) : pied « N lignes affichées sur M » ; la liste entière sort à l'impression */
.tableau-suite { padding: 14px 16px; font-size: 13.5px; color: var(--muted); text-align: center; border-top: 1px solid #EAEFF6; }
@media print { .tableau-suite { display: none !important; } }

/* Bandeau « Nouvelle version disponible » (service worker) : jamais de rechargement automatique */
.maj-bandeau {
  position: fixed; z-index: 120; left: 12px; right: 12px; top: calc(var(--safe-top) + 10px);
  max-width: 460px; margin: 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 16px; border-radius: 12px; background: var(--ink); color: #fff;
  box-shadow: 0 8px 28px rgba(16, 33, 63, .28); font-size: 14.5px; font-weight: 500;
}
.maj-bandeau .maj-texte { flex: 1; }
.maj-bandeau .maj-bouton { background: #fff; color: var(--blue); min-height: 34px; }
.maj-bandeau .maj-bouton:hover:not(:disabled) { background: var(--blue-soft); }
.maj-bandeau .maj-fermer { color: rgba(255, 255, 255, .8); width: 32px; min-height: 32px; }
.maj-bandeau .maj-fermer:hover { background: rgba(255, 255, 255, .14); }
@media print { .maj-bandeau { display: none !important; } }
.version-app { font-size: 12px; color: var(--muted); }

/* Barre de progression de la synchronisation (première synchronisation ou parcours de plusieurs pages) : l'écran reste utilisable dessous */
.sync-progression {
  position: fixed; z-index: 110; left: 12px; right: 12px; bottom: calc(var(--safe-bottom) + 12px);
  max-width: 420px; margin: 0 auto; padding: 10px 14px 12px; border-radius: 12px; background: var(--ink); color: #fff;
  box-shadow: 0 8px 28px rgba(16, 33, 63, .28); font-size: 13.5px; pointer-events: none;
}
.sync-progression-piste { height: 5px; margin-top: 8px; border-radius: 3px; background: rgba(255, 255, 255, .22); overflow: hidden; }
.sync-progression-remplissage { height: 100%; width: 1%; border-radius: 3px; background: var(--turq); transition: width .25s ease; }
@media print { .sync-progression { display: none !important; } }

/* Images de fichiers chargés à la demande (Central.imageFichier) : état de chargement et d'échec */
img.fichier-attente { background: var(--blue-soft); min-width: 40px; min-height: 40px; animation: fichier-pulse 1.2s ease-in-out infinite; }
@keyframes fichier-pulse { 50% { opacity: .55; } }
.fichier-echec, img.fichier-echec-img {
  display: inline-flex; align-items: center; justify-content: center; text-align: center; padding: 8px 10px; min-width: 64px; min-height: 40px;
  border-radius: 8px; background: var(--bg); border: 1px dashed var(--line); color: var(--muted); font-size: 12.5px; cursor: pointer;
}
img.fichier-echec-img { cursor: default; }

/* Menu discret d'actions rares (fiche client : export et suppression des données personnelles) */
.menu-plus-zone { position: relative; display: inline-flex; }
.menu-plus { position: absolute; z-index: 40; right: 0; top: calc(100% + 4px); min-width: 280px; padding: 6px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.menu-plus[hidden] { display: none; }
.menu-plus-item { display: block; width: 100%; padding: 9px 12px; border-radius: 7px; text-align: left; font-size: 14.5px; color: var(--ink); }
.menu-plus-item:hover { background: var(--blue-soft); }
.menu-plus-item.danger { color: var(--danger); }
.menu-plus-item.danger:hover { background: var(--danger-soft); }

/* Réglages, Comptes : les actions passent à la ligne plutôt que de déborder du tableau */
.actions-cellule .actions-ligne.rg-comptes-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; width: 175px; flex-wrap: wrap; max-width: 100%; white-space: normal; }
.actions-cellule .actions-ligne.rg-comptes-actions .btn { white-space: nowrap; }
