/*
 * Feuille de style de l'application.
 * Un seul fichier, sans framework : variables en tête, puis composants.
 */

@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans-latin-400-normal.64d7b23d069a.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans-latin-500-normal.6a6919c7a327.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans-latin-600-normal.244d3ce7dfd5.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

:root {
  --fond: #f5f7fa;
  --surface: #ffffff;
  --encre: #1b2b48;
  --encre-douce: #4a5872;
  --prevu: #6b7a90;
  --filet: #d9dfe8;
  --sortie: #a4402e;
  --action: #16697a;
  --action-fonce: #0f4f5c;
  --cloture: #4f7a5a;
  --alerte: #8a5a00;
  --rayon: 6px;
  --texte: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

body {
  margin: 0;
  background: var(--fond);
  color: var(--encre);
  font-family: var(--texte);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--action); }
a:hover { color: var(--action-fonce); }

:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }

.montant, .tabulaire {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.negatif { color: var(--sortie); }

/* --- Barre de navigation ---------------------------------------------------------- */

.barre {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--encre);
  color: #fff;
}
.barre a { color: #dbe4f0; text-decoration: none; }
.barre a:hover, .barre a[aria-current="page"] { color: #fff; }
.barre .marque { font-weight: 600; color: #fff; margin-right: auto; }
.barre form { margin: 0; }
.barre button {
  background: none; border: 0; color: #dbe4f0; font: inherit; cursor: pointer; padding: 0;
}
.barre button:hover { color: #fff; text-decoration: underline; }

main {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 4rem;
}

/* --- Messages ----------------------------------------------------------------------- */

.messages { list-style: none; padding: 0; margin: 0 0 1.25rem; }
.messages li {
  padding: 0.6rem 0.9rem;
  border-left: 3px solid var(--action);
  background: var(--surface);
  margin-bottom: 0.5rem;
}
.messages .error { border-color: var(--sortie); }

/* --- En-tête de période et frise ---------------------------------------------------- */

.periode-entete {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.periode-entete h1 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.1;
  text-align: center;
}
.periode-entete .voisine {
  color: var(--encre-douce);
  text-decoration: none;
  font-size: 0.9rem;
}
.periode-entete .voisine:hover { color: var(--action); }
.statut {
  display: block;
  text-align: center;
  font-size: 0.95rem;
  color: var(--encre-douce);
  margin-top: 0.35rem;
}
.statut-cloturee { color: var(--cloture); font-weight: 500; }

/* La frise : la période du 11 au 10, avec aujourd'hui et les échéances. */
.frise {
  position: relative;
  height: 3.25rem;
  margin: 1.25rem 0 2rem;
}
.frise .axe {
  position: absolute; left: 0; right: 0; top: 1.25rem;
  height: 4px; border-radius: 2px;
  background: var(--filet);
}
.frise .ecoule {
  position: absolute; left: 0; top: 1.25rem;
  height: 4px; border-radius: 2px;
  background: var(--encre);
}
.frise.cloturee .axe, .frise.cloturee .ecoule { background: var(--cloture); }
.frise .borne {
  position: absolute; top: 2rem;
  font-size: 0.8rem; color: var(--encre-douce);
}
.frise .borne.fin { right: 0; }
.frise .echeance {
  position: absolute; top: 0.95rem;
  width: 2px; height: 0.8rem;
  background: var(--prevu);
  transform: translateX(-1px);
}
.frise .echeance.realise { background: var(--encre); }
.frise .aujourdhui {
  position: absolute; top: 0;
  transform: translateX(-50%);
  font-size: 0.75rem; font-weight: 600;
  color: var(--encre);
}
.frise .aujourdhui.droite { transform: translateX(-100%); }
.frise .aujourdhui.droite::after { left: 100%; }
.frise .aujourdhui.gauche { transform: none; }
.frise .aujourdhui.gauche::after { left: 0; }
.frise .aujourdhui::after {
  content: ""; position: absolute; left: 50%; top: 1.1rem;
  width: 2px; height: 1.1rem; margin-left: -1px;
  background: var(--encre);
}

/* --- Comptes courants ----------------------------------------------------------------- */

.comptes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
  border-top: 2px solid var(--encre);
}
.compte { padding: 1rem 0 1.5rem; }
.compte + .compte { border-left: 1px solid var(--filet); padding-left: 1.5rem; }
.compte:first-child { padding-right: 1.5rem; }

.compte h2 { margin: 0 0 0.75rem; font-size: 1.15rem; font-weight: 600; }

.bilan { display: grid; grid-template-columns: 1fr auto; row-gap: 0.15rem; margin: 0 0 1.25rem; }
.bilan dt { color: var(--encre-douce); }
.bilan dd { margin: 0; text-align: right; }
.bilan .fin dt, .bilan .fin dd {
  border-top: 1px solid var(--filet);
  padding-top: 0.4rem; margin-top: 0.3rem;
  color: var(--encre); font-weight: 600; font-size: 1.35rem;
}

.operations { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.operations td { padding: 0.45rem 0.25rem; border-bottom: 1px solid var(--filet); vertical-align: top; }
.operations td.date { color: var(--encre-douce); width: 3.5rem; }
.operations td.montant { text-align: right; width: 7.5rem; }
.operations .libelle small { display: block; color: var(--prevu); font-size: 0.8rem; }
.operations tr.prevu td { color: var(--prevu); }
.operations tr.prevu td.libelle { border-left: 2px dashed var(--prevu); padding-left: 0.5rem; }
.operations tr.prevu td.montant.negatif { color: #b7776b; }
.operations tr.groupe td {
  padding-top: 1rem; border-bottom: 0;
  font-size: 0.85rem; font-weight: 600; color: var(--encre-douce);
}
.operations .actions { text-align: right; white-space: nowrap; width: 1%; }

/* Formulaire de confirmation dans une ligne */
.confirmation {
  display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; justify-content: flex-end;
}
.confirmation input { width: 6.5rem; }
.confirmation input[type="date"] { width: 8.5rem; }

/* --- Formulaires et boutons ------------------------------------------------------------ */

input, select, textarea {
  font: inherit; color: var(--encre);
  border: 1px solid #b8c2d1; border-radius: var(--rayon);
  padding: 0.35rem 0.5rem; background: var(--surface);
}
textarea { width: 100%; min-height: 4rem; }

.bouton {
  display: inline-block;
  font: inherit; font-weight: 500; font-size: 0.9rem;
  padding: 0.35rem 0.8rem;
  border-radius: var(--rayon);
  border: 1px solid var(--action);
  background: var(--action); color: #fff;
  cursor: pointer; text-decoration: none;
}
.bouton:hover { background: var(--action-fonce); border-color: var(--action-fonce); color: #fff; }
.bouton.discret { background: transparent; color: var(--action); }
.bouton.discret:hover { background: #e6f0f2; color: var(--action-fonce); }
.bouton.danger { background: transparent; color: var(--sortie); border-color: #d9b2aa; }
.bouton.danger:hover { background: #f7ebe8; }
.bouton[disabled] { opacity: 0.45; cursor: not-allowed; }
.lien-bouton {
  background: none; border: 0; padding: 0; font: inherit; font-size: 0.85rem;
  color: var(--prevu); cursor: pointer; text-decoration: underline;
}
.lien-bouton:hover { color: var(--sortie); }

details.ajout { margin-top: 0.75rem; }
details.ajout summary { cursor: pointer; color: var(--action); font-size: 0.95rem; }
.formulaire-ligne { display: grid; gap: 0.6rem; margin-top: 0.75rem; }
.formulaire-ligne label { display: grid; gap: 0.2rem; font-size: 0.85rem; color: var(--encre-douce); }
.formulaire-ligne .rangee { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.formulaire-ligne label > * { min-width: 0; width: 100%; }
.erreurs { color: var(--sortie); font-size: 0.85rem; margin: 0; }

/* --- Épargne --------------------------------------------------------------------------- */

.section-titre { font-size: 1.15rem; font-weight: 600; margin: 2.5rem 0 0.75rem; }
.epargne { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.epargne th, .epargne td { padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--filet); }
.epargne th { text-align: left; font-weight: 500; color: var(--encre-douce); font-size: 0.85rem; }
.epargne th.nombre, .epargne td.montant { text-align: right; }
.epargne tr.bloquee td:first-child::after {
  content: " · enfants"; color: var(--prevu); font-size: 0.85rem;
}
.epargne tfoot td { font-weight: 600; border-bottom: 0; }
.tableau-defilant { overflow-x: auto; }

/* --- Clôture ----------------------------------------------------------------------------- */

.cloture {
  margin-top: 2.5rem;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--filet);
  border-left: 4px solid var(--alerte);
  border-radius: var(--rayon);
}
.cloture.prete { border-left-color: var(--action); }
.cloture.faite { border-left-color: var(--cloture); }
.cloture h2 { margin: 0 0 0.5rem; font-size: 1.15rem; }
.cloture ul { margin: 0.5rem 0 1rem; padding-left: 1.2rem; }
.cloture li { margin-bottom: 0.4rem; }
.cloture details { margin-top: 1rem; }
.cloture summary { cursor: pointer; color: var(--encre-douce); }

/* --- Connexion ---------------------------------------------------------------------------- */

.connexion { max-width: 22rem; margin: 12vh auto 0; }
.connexion h1 { font-size: 1.6rem; margin: 0 0 1.5rem; }
.connexion label { display: grid; gap: 0.25rem; margin-bottom: 1rem; color: var(--encre-douce); }
.connexion input { width: 100%; padding: 0.55rem 0.65rem; }
.connexion .bouton { width: 100%; padding: 0.6rem; font-size: 1rem; }

/* --- Mobile ----------------------------------------------------------------------------------- */

@media (max-width: 42rem) {
  .barre { gap: 0.9rem; padding: 0.75rem 1rem; font-size: 0.9rem; }
  .barre .admin { display: none; }

  /* Chaque opération sur deux lignes : date, libellé, montant, puis les actions. */
  .operations, .operations tbody { display: block; }
  .operations tr {
    display: grid;
    grid-template-columns: 3.2rem 1fr auto;
    column-gap: 0.4rem;
    border-bottom: 1px solid var(--filet);
    padding: 0.45rem 0;
  }
  .operations td { border-bottom: 0; padding: 0; }
  .operations tr.groupe { border-bottom: 0; padding-top: 1rem; }
  .operations tr.groupe td { grid-column: 1 / -1; padding: 0; }
  .operations td.actions { grid-column: 2 / -1; text-align: left; width: auto; }
  .operations td.actions:empty { display: none; }
  .operations td.actions details[open] { margin-top: 0.4rem; }
  .operations tr.prevu td.libelle { padding-left: 0.4rem; }
  .operations td.actions summary.bouton { padding: 0.1rem 0; border: 0; font-size: 0.85rem; text-decoration: underline; }

  .epargne .optionnel { display: none; }
  .formulaire-ligne .rangee { grid-template-columns: 1fr; }
  .epargne { font-size: 0.9rem; }
  .epargne th, .epargne td { padding: 0.45rem 0.2rem; }
  main { padding: 1rem 1rem 3rem; }
  .periode-entete { grid-template-columns: 1fr 1fr; }
  .periode-entete > div { grid-column: 1 / -1; grid-row: 1; }
  .periode-entete .voisine.suivante { text-align: right; }
  .compte + .compte { border-left: 0; padding-left: 0; border-top: 1px solid var(--filet); }
  .compte:first-child { padding-right: 0; }
  .operations td.date { width: 2.8rem; }
  .operations td.montant { width: auto; }
  .confirmation { justify-content: flex-start; }
}

@media (prefers-reduced-motion: no-preference) {
  .htmx-swapping { opacity: 0; transition: opacity 120ms ease-out; }
}

/* --- Ponctuelles regroupées ------------------------------------------------------------- */

.operations tr.ponctuelles summary { cursor: pointer; }
.detail-ponctuelles {
  list-style: none; margin: 0.5rem 0 0.25rem; padding: 0 0 0 0.75rem;
  border-left: 2px solid var(--filet);
  font-size: 0.875rem; color: var(--encre-douce);
}
.detail-ponctuelles li { display: grid; grid-template-columns: 3.2rem 1fr auto; gap: 0.4rem; padding: 0.15rem 0; }

.detail-ponctuelles li > details { grid-column: 1 / -1; }
.detail-ponctuelles summary { cursor: pointer; font-size: 0.8rem; color: var(--action); width: max-content; }
.detail-ponctuelles li:not(:hover):not(:focus-within) details:not([open]) summary { opacity: 0.55; }
.detail-ponctuelles .formulaire-ligne { margin: 0.4rem 0 0.6rem; max-width: 26rem; }
.boutons { display: flex; flex-wrap: wrap; gap: 0.9rem; align-items: center; }

/* Solde validé : sous la fin de période, discret */
.bilan dt.valide, .bilan dd.valide { font-size: 0.9rem; color: var(--encre-douce); padding-top: 0.25rem; }
.bilan dt.valide { cursor: help; text-decoration: underline dotted var(--filet); text-underline-offset: 3px; }

/* Actions sous une opération prévue */
.liens-operation { display: flex; flex-wrap: wrap; gap: 0.9rem; justify-content: flex-end; margin-top: 0.4rem; font-size: 0.85rem; }
.liens-operation form { margin: 0; }

/* --- Récurrents ------------------------------------------------------------------------ */

.page-titre { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.75rem; }
.page-titre h1 { margin: 0; font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 600; }
.intro { color: var(--encre-douce); max-width: 46rem; }
.recurrents { width: 100%; border-collapse: collapse; font-size: 0.95rem; margin-bottom: 1rem; }
.recurrents th, .recurrents td { padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--filet); text-align: left; vertical-align: top; }
.recurrents th { font-weight: 500; color: var(--encre-douce); font-size: 0.85rem; }
.recurrents td.montant, .recurrents th.nombre { text-align: right; }
.recurrents td small { display: block; color: var(--prevu); font-size: 0.8rem; }
.recurrents tr.sans-prevision td { color: var(--prevu); }
.recurrents a { text-decoration: none; font-weight: 500; }
.recurrents a:hover { text-decoration: underline; }
.formulaire-recurrent { max-width: 38rem; }
.formulaire-recurrent .aide { font-size: 0.8rem; color: var(--prevu); }
.formulaire-recurrent .case { display: flex; gap: 0.5rem; align-items: center; color: var(--encre); font-size: 0.95rem; }
.formulaire-recurrent .case input { width: auto; }
.encadre {
  margin-top: 2rem; padding: 1rem 1.25rem; background: var(--surface);
  border: 1px solid var(--filet); border-radius: var(--rayon);
}
.encadre h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.historique { list-style: none; padding: 0; margin: 0; font-size: 0.9rem; }
.historique li { display: grid; grid-template-columns: 9rem 1fr auto; gap: 0.5rem; padding: 0.25rem 0; border-bottom: 1px solid var(--filet); }

@media (max-width: 42rem) {
  .recurrents .optionnel { display: none; }
  .recurrents th, .recurrents td { padding: 0.5rem 0.2rem; }
  .liens-operation { justify-content: flex-start; }
  .historique li { grid-template-columns: 1fr auto; }
  .historique li .tabulaire:first-child { grid-column: 1 / -1; color: var(--prevu); font-size: 0.8rem; }
}

/* Découvert prévu : signalé, jamais corrigé automatiquement */
.bilan .alerte-decouvert {
  grid-column: 1 / -1; text-align: left; margin: 0.4rem 0 0;
  padding: 0.45rem 0.7rem; border-left: 3px solid var(--sortie); background: #f7ebe8;
  font-size: 0.875rem; color: var(--encre);
}
.formulaire-ligne .aide { font-size: 0.8rem; color: var(--prevu); }
/* Formulaire d'ajout : « Vers le compte » seulement pour un virement, le sens sinon */
.seulement-virement { display: none !important; }
form:has(select[name="type"] option[value="virement"]:checked) .seulement-virement { display: grid !important; }
form:has(select[name="type"] option[value="virement"]:checked) .sauf-virement { display: none; }

/* --- Pages d'erreur ------------------------------------------------------------------- */
.page-erreur { max-width: 36rem; margin: 10vh auto 0; }
.page-erreur h1 { font-size: 1.6rem; margin: 0 0 1rem; }

/* --- Second facteur -------------------------------------------------------------------- */
.connexion.large { max-width: 30rem; margin-top: 8vh; }
.connexion .intro { margin: 0 0 1.25rem; }
.connexion form.sortie { margin-top: 1.5rem; text-align: center; }
.etapes { padding-left: 1.2rem; margin: 0 0 1rem; }
.etapes li { margin-bottom: 0.9rem; }
.qr { width: 13rem; margin: 0.75rem 0; background: #fff; padding: 0.5rem; border: 1px solid var(--filet); border-radius: var(--rayon); }
.qr svg { display: block; width: 100%; height: auto; }
.cle { font-size: 1.05rem; letter-spacing: 0.05em; word-break: break-all; background: var(--surface); padding: 0.4rem 0.6rem; border-radius: var(--rayon); }
.codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.4rem 1.5rem; font-size: 1.15rem; margin: 0 0 1.25rem; }
@media print { .barre, .bouton { display: none !important; } }
