/* ---------------------------------------------------------------------------
   Système visuel — Facturation consultant Québec
   ---------------------------------------------------------------------------
   Reproche du fondateur, 27 septembre 2026 : « graphiquement ça semble encore
   très années 2000 PowerPoint ». Ce fichier est la réponse. Les partis pris :

   - UNE colonne de navigation fixe, un contenu large : on travaille dans une
     liste, pas dans un formulaire qui occupe l'écran.
   - Des chiffres TABULAIRES partout : des montants qui ne s'alignent pas sont
     des montants qu'on relit trois fois.
   - Clair et sombre à parité, choix rangé dans le navigateur (le fondateur
     aime le sombre mais veut pouvoir « se tanner »).
   - Aucune image, aucune police téléchargée : l'app doit s'ouvrir avant que
     l'oeil ait le temps de le remarquer.
   --------------------------------------------------------------------------- */

:root {
  --bg: #F3F6F8;
  --bg-motif: #E9EEF1;
  --surface: #FFFFFF;
  --surface-2: #F7FAFB;
  --surface-3: #EDF2F5;
  --ink: #0F1B22;
  --ink-doux: #40545F;
  --muted: #647985;
  --line: #DFE7EB;
  --line-forte: #C9D6DD;
  --brand: #0D6E80;
  --brand-fort: #0A5766;
  --brand-doux: #E4F1F4;
  --ok: #17794F;
  --ok-doux: #E3F3EB;
  --warn: #A96A12;
  --warn-doux: #FBEFDC;
  --danger: #B3261E;
  --danger-doux: #FBE7E5;
  --ombre: 0 1px 2px rgba(15, 27, 34, .06), 0 8px 24px -12px rgba(15, 27, 34, .18);
  --ombre-forte: 0 2px 6px rgba(15, 27, 34, .08), 0 24px 48px -20px rgba(15, 27, 34, .35);
  --r: 12px;
  --r-s: 8px;
  --rail: 236px;
  --police: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Inter, system-ui, sans-serif;
}

html[data-theme="sombre"] {
  --bg: #0A1115;
  --bg-motif: #0E171C;
  --surface: #121D23;
  --surface-2: #17242B;
  --surface-3: #1D2D35;
  --ink: #E9EFF2;
  --ink-doux: #C2D0D7;
  --muted: #8DA3AE;
  --line: #22333C;
  --line-forte: #2E434E;
  --brand: #3BB3C7;
  --brand-fort: #6ED0E0;
  --brand-doux: #10333B;
  --ok: #4FC08D;
  --ok-doux: #102E22;
  --warn: #E0A64A;
  --warn-doux: #33260F;
  --danger: #F1756B;
  --danger-doux: #381715;
  --ombre: 0 1px 2px rgba(0, 0, 0, .4);
  --ombre-forte: 0 24px 48px -20px rgba(0, 0, 0, .75);
}

* { box-sizing: border-box; }

/* `display: flex` sur une classe bat l'attribut `hidden` : sans cette règle, un
   bandeau d'erreur vide restait visible sous le formulaire de connexion. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--police);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; letter-spacing: -.021em; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.0625rem; }
h3 { font-size: .9375rem; }
p { margin: 0; }
a { color: var(--brand); }

.hors-ecran {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* Les montants. Toute la raison d'être de l'app. */
.nb { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* ---------------------------------------------------------------- squelette */

.app {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 12px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.marque {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 18px;
  font-weight: 750; letter-spacing: -.02em;
}
.marque svg { flex: none; }
.marque small { display: block; font-weight: 500; color: var(--muted); font-size: .75rem; letter-spacing: 0; }

.rail nav { display: flex; flex-direction: column; gap: 2px; }

.rail a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-s);
  color: var(--ink-doux); text-decoration: none;
  font-weight: 550; font-size: .9375rem;
  transition: background .12s ease, color .12s ease;
}
.rail a svg { flex: none; opacity: .85; }
.rail a:hover { background: var(--surface-3); color: var(--ink); }
.rail a[aria-current="page"] { background: var(--brand-doux); color: var(--brand-fort); }
.rail a .compteur {
  margin-left: auto;
  font-size: .75rem; font-weight: 700;
  background: var(--surface-3); color: var(--ink-doux);
  padding: 1px 7px; border-radius: 999px;
}
.rail a[aria-current="page"] .compteur { background: var(--brand); color: #fff; }
.rail a .compteur.alerte { background: var(--danger); color: #fff; }

.rail-bas { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.rail-compte {
  padding: 10px; border-radius: var(--r-s); background: var(--surface-2);
  font-size: .8125rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis;
}
.rail-compte b { display: block; color: var(--ink); font-size: .875rem; }

.zone { padding: 22px 28px 64px; max-width: 1180px; }

.tete {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.tete p { color: var(--muted); font-size: .9375rem; margin-top: 3px; }
.tete .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ boutons */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; min-height: 36px;
  border: 1px solid var(--line-forte); border-radius: var(--r-s);
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; font-size: .9375rem;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primaire { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primaire:hover { background: var(--brand-fort); border-color: var(--brand-fort); }
.btn-danger { color: var(--danger); border-color: var(--line-forte); }
.btn-danger:hover { background: var(--danger-doux); }
.btn-fantome { border-color: transparent; background: transparent; }
.btn-fantome:hover { background: var(--surface-3); }
.btn-min { padding: 5px 10px; min-height: 30px; font-size: .875rem; }
.btn-icone { padding: 5px 7px; }
.btn-icone.deja-envoyee { color: var(--ok); }
/* « envoyée le 15 oct. » sous le statut, dans la liste : pour ne pas renvoyer deux fois. */
.envoi-fait { display: flex; align-items: center; gap: 4px; margin-top: 5px; font-size: .78rem; font-weight: 600; color: var(--ok); white-space: nowrap; }
.envoi-fait svg { width: 13px; height: 13px; flex: none; }

:where(.btn, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}

/* ------------------------------------------------------------------- cartes */

.panneau {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--ombre);
}
.panneau-tete {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.panneau-corps { padding: 16px; }

.grille { display: grid; gap: 14px; }
/* Sans `min-width: 0`, un élément de grille refuse de rétrécir sous la largeur
   de son contenu : un tableau large débordait alors SOUS le panneau voisin. */
.grille > * { min-width: 0; }
.panneau { min-width: 0; }
.grille-kpi { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grille-2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }

.kpi {
  padding: 15px 16px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--ombre);
}
.kpi .etiquette { color: var(--muted); font-size: .8125rem; font-weight: 600; }
.kpi .valeur { font-size: 1.75rem; font-weight: 760; letter-spacing: -.03em; margin-top: 4px; }
.kpi .detail { color: var(--muted); font-size: .8125rem; margin-top: 3px; }
.kpi.alerte { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.kpi.alerte .valeur { color: var(--danger); }
.kpi.bien .valeur { color: var(--ok); }

/* ------------------------------------------------------------------ tableau */

.table-cadre { overflow-x: auto; }
table.liste { width: 100%; border-collapse: collapse; font-size: .9375rem; }
table.liste th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; font-size: .75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); background: var(--surface-2);
  padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.liste th.num, table.liste td.num { text-align: right; }
table.liste th button {
  all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center;
  font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit;
}
table.liste th button:hover { color: var(--ink); }
table.liste td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
/* Un numéro de facture ou une date coupés sur trois lignes rendent un tableau
   illisible : ces colonnes ne se cassent pas, la table défile plutôt. */
table.liste td.nb, table.liste td .nb, table.liste td.date { white-space: nowrap; }
table.liste td.num { white-space: nowrap; }
table.liste tbody tr { transition: background .1s ease; }
table.liste tbody tr:hover { background: var(--surface-2); }
table.liste tbody tr.cliquable { cursor: pointer; }
table.liste .principal { font-weight: 650; }
table.liste .sous { color: var(--muted); font-size: .8125rem; }
table.liste td.actions-ligne { text-align: right; white-space: nowrap; }
table.liste td.actions-ligne .btn { opacity: 0; transition: opacity .12s ease; }
tr:hover td.actions-ligne .btn, td.actions-ligne .btn:focus-visible { opacity: 1; }
@media (hover: none) { table.liste td.actions-ligne .btn { opacity: 1; } }

/* Sélection pour la suppression en lot : une case à gauche des factures que le
   serveur laisse supprimer (brouillon, ou annulée jamais vue par un client). */
table.liste th.selection, table.liste td.selection { width: 40px; padding-right: 0; }
table.liste .case { display: flex; align-items: center; justify-content: center; min-height: 28px; cursor: pointer; }
table.liste .case input { width: 17px; height: 17px; cursor: pointer; }
.barre-selection {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--brand-doux); border-radius: var(--r) var(--r) 0 0;
}
.barre-selection[hidden] { display: none; }

/* Fenêtre d'envoi : ouvrir le courriel dans sa propre boîte */
.choix-envoi { display: grid; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r-s); }
.choix-envoi .boutons { display: flex; gap: 8px; flex-wrap: wrap; }

/* Réglages → Courriel des factures */
.sous-titre { font-size: .9375rem; font-weight: 700; margin: 0; }
.bloc-brancher { display: grid; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r-s); }
.apercu-courriel { display: grid; gap: 8px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--surface-2); }
.apercu-courriel .apercu-titre { font-weight: 700; font-size: .875rem; }
.apercu-courriel #apercu-corps { display: grid; gap: 8px; }
.apercu-courriel .apercu-objet { color: var(--ink); font-size: .9375rem; }
.apercu-courriel .apercu-message { color: var(--ink); font-size: .9375rem; line-height: 1.55; white-space: pre-wrap; }
.barre-selection .espace { flex: 1; }

/* ------------------------------------------------------------- états, puces */

.puce {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; letter-spacing: .01em;
  background: var(--surface-3); color: var(--ink-doux); white-space: nowrap;
}
.puce::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.puce-brouillon { background: var(--surface-3); color: var(--muted); }
.puce-emise { background: var(--brand-doux); color: var(--brand-fort); }
.puce-partielle { background: var(--warn-doux); color: var(--warn); }
.puce-payee { background: var(--ok-doux); color: var(--ok); }
.puce-annulee { background: var(--surface-3); color: var(--muted); }
.puce-retard { background: var(--danger-doux); color: var(--danger); }

.filtres { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filtre {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-forte);
  background: var(--surface); color: var(--ink-doux);
  font: inherit; font-size: .875rem; font-weight: 600; cursor: pointer;
}
.filtre:hover { background: var(--surface-3); }
.filtre[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.filtre .n { opacity: .7; font-weight: 600; }

.recherche { position: relative; flex: 1 1 260px; min-width: 200px; }
.recherche input { padding-left: 34px; }
.recherche svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }

input, select, textarea {
  width: 100%; padding: 9px 11px; min-height: 38px;
  border: 1px solid var(--line-forte); border-radius: var(--r-s);
  background: var(--surface); color: var(--ink);
  font: inherit;
}
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--brand); }
label.champ { display: grid; gap: 5px; font-size: .8125rem; font-weight: 650; color: var(--ink-doux); }
/* Une case à cocher et son texte tiennent sur UNE ligne. Sans cette classe, la
   case héritait de la grille du champ et s'étirait en gros carré. */
label.case { display: flex; align-items: center; gap: 8px; font-size: .875rem; font-weight: 600; color: var(--ink-doux); cursor: pointer; }
label.case input { flex: none; }
label.champ .aide { font-weight: 500; color: var(--muted); }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.trio { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

.vide {
  display: grid; gap: 8px; justify-items: center; text-align: center;
  padding: 44px 20px; color: var(--muted);
}
.vide b { color: var(--ink); font-size: 1rem; }

.squelette {
  border-radius: var(--r-s);
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%;
  animation: glisse 1.4s ease infinite;
  height: 14px;
}
@keyframes glisse { from { background-position: 100% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .squelette { animation: none; } }

/* --------------------------------------------------------- barres et graphe */

.barre-age { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-3); }
.barre-age span { display: block; height: 100%; }
.legende { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: .8125rem; color: var(--muted); }
.legende i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

.colonnes { display: flex; align-items: flex-end; gap: 6px; height: 132px; }
.colonnes .mois { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 3px; height: 100%; }
.colonnes .paire { display: flex; align-items: flex-end; gap: 2px; height: 100%; }
.colonnes .paire span { flex: 1; border-radius: 3px 3px 0 0; min-height: 2px; }
.colonnes .f { background: color-mix(in srgb, var(--brand) 70%, transparent); }
.colonnes .e { background: var(--ok); }
.colonnes .etiq { text-align: center; font-size: .6875rem; color: var(--muted); }

/* ------------------------------------------------------------ chronologie */

.chrono { display: grid; gap: 0; }
.chrono li { display: grid; grid-template-columns: 22px 1fr; gap: 10px; list-style: none; padding-bottom: 14px; position: relative; }
.chrono li::before {
  content: ""; position: absolute; left: 10px; top: 18px; bottom: 0; width: 1px; background: var(--line);
}
.chrono li:last-child { padding-bottom: 0; }
.chrono li:last-child::before { display: none; }
.chrono .point {
  width: 21px; height: 21px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface-3); color: var(--ink-doux);
  font-size: 11px; font-weight: 800;
}
.chrono .point.fait { background: var(--brand-doux); color: var(--brand-fort); }
.chrono .point.ok { background: var(--ok-doux); color: var(--ok); }
.chrono .quand { color: var(--muted); font-size: .8125rem; }

/* ----------------------------------------------------------------- modales */

.voile {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 16, 20, .55); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 18px;
}
.modale {
  width: min(520px, 100%); max-height: 88vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--ombre-forte); padding: 20px;
}
.modale h2 { margin-bottom: 4px; }
.modale .pied { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

.messages { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: grid; gap: 8px; }
.message {
  padding: 11px 14px; border-radius: var(--r-s); box-shadow: var(--ombre-forte);
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: .9375rem;
  max-width: 360px;
}
.message.erreur { background: var(--danger); color: #fff; }
.message.succes { background: var(--ok); color: #fff; }

.avis {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--r-s);
  background: var(--warn-doux); color: var(--warn); font-size: .875rem; font-weight: 600;
}
.avis.danger { background: var(--danger-doux); color: var(--danger); }
.avis.info { background: var(--brand-doux); color: var(--brand-fort); }

/* --------------------------------------------------------------- connexion */

.entree {
  min-height: 100vh; display: grid; place-items: center; padding: 22px;
  background:
    radial-gradient(1100px 520px at 12% -10%, color-mix(in srgb, var(--brand) 16%, transparent), transparent 60%),
    radial-gradient(900px 460px at 110% 110%, color-mix(in srgb, var(--warn) 12%, transparent), transparent 55%),
    var(--bg);
}
.entree .boite { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--ombre-forte); padding: 26px; }
.entree .boite h1 { font-size: 1.375rem; }
.entree .boite p.sous { color: var(--muted); margin: 6px 0 20px; }
.entree form { display: grid; gap: 14px; }
.entree .lien-secours { margin-top: 16px; text-align: center; font-size: .875rem; }
.entree .lien-secours button { all: unset; color: var(--brand); cursor: pointer; font-weight: 600; }
.entree .lien-secours button:hover { text-decoration: underline; }

/* ----------------------------------------------------------- petite largeur */

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .rail {
    position: sticky; top: 0; z-index: 20; height: auto;
    flex-direction: row; align-items: center; gap: 4px;
    padding: 8px 10px; overflow-x: auto;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .marque { padding: 0 10px 0 4px; }
  .marque small { display: none; }
  .rail nav { flex-direction: row; }
  .rail a { padding: 8px 10px; }
  .rail a span.texte { display: none; }
  .rail a[aria-current="page"] span.texte { display: inline; }
  .rail-bas { margin-top: 0; flex-direction: row; }
  .rail-compte { display: none; }
  .zone { padding: 16px 14px 56px; }
  .duo { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------- impression */

/* La FACTURE ne s'imprime pas d'ici : le PDF vient du serveur (/api/v2/.../pdf),
   c'est exactement le document que le client reçoit en piece jointe. Deux
   factures dessinees a deux endroits finissent par ne plus se ressembler.
   Ce qui s'imprime ici, ce sont les ECRANS — le rapport annuel, surtout. */
@media print {
  body { background: #fff; }
  .messages, .voile, .rail { display: none !important; }
  .zone { padding: 0; max-width: none; }
  .btn, select, .actions-ligne, .selection, .barre-selection { display: none !important; }
  .panneau { box-shadow: none; break-inside: avoid; }
  table.liste th { position: static; }
}
