/* ==========================================================================
   Socle — polices, jetons de design, remise à zéro, structure de l'application.
   --------------------------------------------------------------------------
   Parti pris : « Lumière ». Papier crème, cartes blanches posées sur une ombre
   douce, formes franchement arrondies. Outfit porte les titres et les montants,
   Manrope sert à lire. La couleur ne décore pas, elle informe : sapin = ce sur
   quoi on clique et l'argent qui entre, or = l'argent mis de côté, terre cuite
   = l'argent qui sort.
   ========================================================================== */

/* --- Polices, servies depuis notre propre domaine (aucun appel tiers) ------
   Deux familles seulement. Outfit porte les titres et tous les montants —
   ses chiffres sont déjà de largeur constante, donc les colonnes s'alignent
   sans police à chasse fixe supplémentaire. Manrope porte le texte courant. */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/polices/outfit-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/polices/outfit-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('/polices/manrope-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('/polices/manrope-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* --- Jetons : thème « clair » (par défaut) --------------------------------
   Parti pris « Lumière » : papier crème et cartes blanches, vert sapin pour
   l'interactif, or pour l'argent mis de côté. Le relief remplace le filet —
   les surfaces sont arrondies et posées sur une ombre douce. */
:root {
  color-scheme: light;

  /* Surfaces, du fond de page au plus élevé */
  --fond: #f4f0e6;
  --fond-2: #fbf8f1;
  --surface: #ffffff;
  --surface-2: #faf7f0;
  --surface-3: #f1ebdf;
  --surface-4: #e6dfcf;
  --survol: rgba(22, 33, 28, 0.035);
  --actif: rgba(13, 90, 68, 0.09);

  /* Trait : filets discrets */
  --trait: #e6dfcf;
  --trait-fort: #d5cbb4;
  --trait-laiton: rgba(185, 139, 46, 0.35);

  /* Encre */
  --encre: #16211c;
  --encre-2: #4a5850;
  /* Mesuré : #61706a tient 5,2:1 sur la surface la plus claire (#fff). */
  --encre-3: #61706a;
  --encre-4: #61706acc;
  --encre-sur-accent: #ffffff;

  /* Accent : le vert sapin — l'attention, l'interactif, jamais le montant */
  --accent: #0d5a44;
  --accent-fort: #128062;
  --accent-sombre: #093f30;
  --accent-voile: rgba(13, 90, 68, 0.09);

  /* Or : la matière de l'argent mis de côté. « --or » sert aux aplats et aux
     filets, « --epargne » aux textes — #b98b2e ne tient que 3,8:1 sur blanc. */
  --or: #b98b2e;
  --or-clair: #d9b863;

  /* Sens comptables */
  --entree: #0d7a57;
  --entree-voile: rgba(13, 122, 87, 0.11);
  --sortie: #c0392b;
  --sortie-voile: rgba(192, 57, 43, 0.1);
  --epargne: #8a6414;
  --epargne-voile: rgba(185, 139, 46, 0.13);
  --attention: #9a6410;
  --attention-voile: rgba(154, 100, 16, 0.12);
  /* Part « non affectée » d'une jauge : neutre mais lisible (>= 3:1). */
  --neutre: #8a8578;

  /* Voile des fenêtres modales */
  --voile: rgba(38, 30, 14, 0.42);

  /* Typographie */
  --f-titre: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    sans-serif;
  --f-texte: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
  --chiffres: 'tnum' 1, 'lnum' 1;

  --t-micro: 0.6875rem; /* 11 — capitales, interlettrage */
  --t-petit: 0.8125rem; /* 13 */
  --t-corps: 0.9375rem; /* 15 */
  --t-moyen: 1.0625rem; /* 17 */
  --t-grand: 1.3125rem; /* 21 */
  --t-titre: 1.75rem; /* 28 */
  --t-surtitre: 2.25rem; /* 36 */
  --t-heros: clamp(2.5rem, 6vw, 3.5rem);

  /* Rythme vertical, base 4 */
  --e-1: 4px;
  --e-2: 8px;
  --e-3: 12px;
  --e-4: 16px;
  --e-5: 20px;
  --e-6: 24px;
  --e-7: 32px;
  --e-8: 40px;
  --e-9: 56px;
  --e-10: 72px;

  /* Angles : franchement arrondis, jamais bulleux */
  --r-1: 10px;
  --r-2: 16px;
  --r-3: 22px;
  --r-4: 30px;
  --r-plein: 999px;

  --ombre-1: 0 1px 2px rgba(22, 33, 28, 0.05);
  --ombre-2: 0 10px 28px -18px rgba(22, 33, 28, 0.3);
  --ombre-3: 0 26px 56px -24px rgba(22, 33, 28, 0.36);

  --largeur-rail: 250px;
  --largeur-contenu: 1320px;
  --duree: 170ms;
  --courbe: cubic-bezier(0.32, 0.72, 0, 1);
}

/* --- Thème « encre » (variante de nuit) -----------------------------------
   Même langue visuelle, l'encre à la place du papier : vert profond, or plein.
   L'interactif passe à l'or ; l'argent qui entre, au vert d'eau. */
:root[data-theme='encre'] {
  color-scheme: dark;
  --fond: #05130f;
  --fond-2: #081b15;
  --surface: #0c231c;
  --surface-2: #113026;
  --surface-3: #163c31;
  --surface-4: #1e4c3e;
  --survol: rgba(255, 255, 255, 0.04);
  --actif: rgba(231, 201, 121, 0.12);

  --trait: rgba(231, 201, 121, 0.14);
  --trait-fort: rgba(231, 201, 121, 0.28);
  --trait-laiton: rgba(231, 201, 121, 0.32);

  --encre: #eff6f2;
  --encre-2: #b2c9bf;
  --encre-3: #93afa4;
  --encre-4: #93afa499;
  --encre-sur-accent: #06140f;

  --accent: #e7c979;
  --accent-fort: #f6de9e;
  --accent-sombre: #a98c4c;
  --accent-voile: rgba(231, 201, 121, 0.13);

  --or: #e7c979;
  --or-clair: #f6de9e;

  --entree: #52d3a6;
  --entree-voile: rgba(82, 211, 166, 0.13);
  --sortie: #ff7e6b;
  --sortie-voile: rgba(255, 126, 107, 0.14);
  --epargne: #e7c979;
  --epargne-voile: rgba(231, 201, 121, 0.13);
  --attention: #f0b95e;
  --attention-voile: rgba(240, 185, 94, 0.14);
  --neutre: #6e8a80;

  --voile: rgba(4, 12, 9, 0.72);

  --ombre-1: 0 1px 2px rgba(0, 0, 0, 0.5);
  --ombre-2: 0 10px 30px -18px rgba(0, 0, 0, 0.75);
  --ombre-3: 0 26px 60px -24px rgba(0, 0, 0, 0.85);
}

/* ==========================  Remise à zéro  ============================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}
* {
  margin: 0;
  padding: 0;
}
/* Piege connu : n'importe quel display d'auteur ecrase l'attribut hidden. */
[hidden] {
  display: none !important;
}

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

body {
  min-height: 100dvh;
  background: var(--fond);
  color: var(--encre);
  font-family: var(--f-texte);
  font-size: var(--t-corps);
  line-height: 1.55;
  font-feature-settings: var(--chiffres);
  font-variant-numeric: tabular-nums lining-nums;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Halo très discret : le fond n'est pas plat, il a une source de lumiere. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(
      70rem 40rem at 12% -10%,
      color-mix(in oklab, var(--accent) 9%, transparent),
      transparent 60%
    ),
    radial-gradient(
      50rem 30rem at 100% 0%,
      color-mix(in oklab, var(--epargne) 7%, transparent),
      transparent 55%
    );
}

img,
svg,
video {
  display: block;
  max-width: 100%;
}
a {
  color: inherit;
  text-decoration: none;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
}
button {
  cursor: pointer;
}
table {
  border-collapse: collapse;
  width: 100%;
}
ul,
ol {
  list-style: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-1);
}

::selection {
  background: var(--accent-voile);
}

/* Barre de défilement discrète */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-4) transparent;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-thumb {
  background: var(--surface-4);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--r-plein);
}

/* ==========================  Typographie  =============================== */
.titre {
  font-family: var(--f-titre);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.024em;
  color: var(--encre);
}
.titre-surtitre {
  font-size: var(--t-surtitre);
}
.titre-page {
  font-size: var(--t-titre);
}
.titre-carte {
  font-family: var(--f-titre);
  font-size: var(--t-corps);
  font-weight: 600;
  letter-spacing: -0.014em;
}

/* Capitales interlettrées : les étiquettes, partout les mêmes */
.maj {
  font-size: var(--t-micro);
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--encre-3);
}

.muette {
  color: var(--encre-3);
}
.muette-2 {
  color: var(--encre-2);
}
.italique {
  font-family: var(--f-titre);
  font-weight: 500;
}

/* Les chiffres : toujours tabulaires pour que les colonnes s'alignent */
.chiffre {
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: var(--chiffres);
}
.serif {
  font-family: var(--f-titre);
}
.fin {
  font-weight: 300;
}
.demi {
  font-weight: 500;
}
.gras {
  font-weight: 600;
}
.negatif {
  color: var(--sortie);
}
.positif {
  color: var(--entree);
}
.epargne-c {
  color: var(--epargne);
}
.attention-c {
  color: var(--attention);
}
.centrer {
  text-align: center;
}
.droite {
  text-align: right;
}
.tronque {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.flex {
  display: flex;
  align-items: center;
  gap: var(--e-3);
}
.entre {
  justify-content: space-between;
}
.colonne {
  display: flex;
  flex-direction: column;
}
.enveloppe-flex {
  flex-wrap: wrap;
}
.pousse {
  margin-left: auto;
}
.petit {
  font-size: var(--t-petit);
}

/* ==========================  Structure  ================================= */
.app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
}

/* Écrans plein cadre : chargement, installation, connexion */
.plein {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--e-5);
}

/* --- Barre latérale (bureau) --- */
/* Nommée « rail » et non « barre » : « barre » est déjà pris par les colonnes
   d'un graphique, et la collision transformait chaque barre en barre latérale
   de 244 px — invisible sous 1000 px, où le rail est masqué. */
.rail {
  position: fixed;
  top: var(--e-5);
  bottom: var(--e-5);
  left: var(--e-5);
  width: calc(var(--largeur-rail) - var(--e-5));
  display: flex;
  flex-direction: column;
  gap: var(--e-6);
  padding: var(--e-5) var(--e-4);
  background: var(--surface);
  border: 1px solid var(--trait);
  border-radius: var(--r-4);
  box-shadow: var(--ombre-2);
  overflow-y: auto;
  z-index: 20;
}

.marque {
  display: flex;
  align-items: center;
  gap: var(--e-3);
  padding: 0 var(--e-2);
}
.marque-sceau {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--r-2);
  background: linear-gradient(150deg, var(--accent-fort), var(--accent));
  box-shadow: 0 8px 18px -10px color-mix(in oklab, var(--accent) 75%, transparent);
  display: grid;
  place-items: center;
  font-family: var(--f-titre);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--encre-sur-accent);
}
.marque-nom {
  font-family: var(--f-titre);
  font-weight: 600;
  font-size: 1.35rem;
  letter-spacing: -0.028em;
  line-height: 1;
}
.marque-sous {
  font-size: var(--t-micro);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--encre-3);
  margin-top: 3px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-section {
  padding: var(--e-4) var(--e-2) var(--e-2);
}
.nav-lien {
  display: flex;
  align-items: center;
  gap: var(--e-3);
  padding: 9px var(--e-3);
  border-radius: var(--r-2);
  color: var(--encre-2);
  font-size: var(--t-corps);
  font-weight: 500;
  transition: background var(--duree) var(--courbe),
    color var(--duree) var(--courbe);
}
.nav-lien:hover {
  background: var(--survol);
  color: var(--encre);
}
.nav-lien[aria-current='page'] {
  background: var(--actif);
  color: var(--accent);
  font-weight: 600;
}
.nav-lien svg {
  flex: none;
  opacity: 0.85;
}
.nav-lien[aria-current='page'] svg {
  color: var(--accent);
  opacity: 1;
}
.nav-pastille {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-plein);
  background: var(--accent);
  color: var(--encre-sur-accent);
  font-size: var(--t-micro);
  font-weight: 700;
  display: grid;
  place-items: center;
}

.rail-pied {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--e-2);
  padding-top: var(--e-4);
  border-top: 1px solid var(--trait);
}

/* --- Zone principale --- */
.principal {
  margin-left: var(--largeur-rail);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.entete {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: var(--e-4);
  padding: var(--e-4) var(--e-6);
  background: color-mix(in oklab, var(--fond) 82%, transparent);
  backdrop-filter: blur(14px) saturate(150%);
  border-bottom: 1px solid var(--trait);
}
.entete-titres {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
/* Deux écritures du même intitulé, et deux écritures du mois : le CSS en montre
   une seule selon la largeur, sans JavaScript de redimensionnement. La règle de
   base et sa variante mobile vivent ici, dans la même feuille — un doublon dans
   composants.css (chargé après) rendait le mois vide sur téléphone. */
.titre-court,
.mois-bref {
  display: none;
}
.entete-outils {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--e-2);
}

.contenu {
  flex: 1;
  width: 100%;
  max-width: var(--largeur-contenu);
  margin: 0 auto;
  padding: var(--e-6);
  display: flex;
  flex-direction: column;
  gap: var(--e-6);
}

/* --- Barre d'onglets (téléphone) --- */
.onglets {
  display: none;
}

/* --- Adaptation --- */
@media (max-width: 1000px) {
  .rail {
    display: none;
  }
  .principal {
    margin-left: 0;
  }
  .onglets {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: var(--e-2) var(--e-2) calc(var(--e-2) + env(safe-area-inset-bottom));
    background: color-mix(in oklab, var(--fond-2) 92%, transparent);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--trait);
  }
  .onglet {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: var(--e-2) 2px;
    border-radius: var(--r-2);
    color: var(--encre-3);
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.02em;
  }
  .onglet[aria-current='page'] {
    color: var(--accent);
  }
  .contenu {
    padding: var(--e-4);
    padding-bottom: calc(var(--e-9) + env(safe-area-inset-bottom));
    gap: var(--e-5);
  }
  .entete {
    padding: var(--e-3) var(--e-4);
  }
}

/* Téléphone : le titre et le sélecteur de mois se partagent une largeur de 390 px.
   Sans ça, « Tableau de bord » se cassait un mot par ligne et le sous-titre
   s'étalait sur huit lignes. */
@media (max-width: 720px) {
  .entete {
    gap: var(--e-2);
  }
  .entete-titres {
    min-width: 0;
  }
  .entete-titres .titre-page {
    font-size: 21px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* Le sous-titre est décoratif : il ne consomme pas la hauteur de l'écran. */
  .entete-titres .maj {
    display: none;
  }
  .mois-long,
  .titre-long {
    display: none;
  }
  .mois-bref,
  .titre-court {
    display: inline;
  }
  .mois-nav .mois-courant {
    min-width: 58px;
  }
  .mois-nav .mois-aujourdhui {
    display: none;
  }
}

/* Sur téléphone, la barre latérale bascule en tiroir */
.tiroir {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
}
.tiroir.ouvert {
  display: block;
}
.tiroir-voile {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}
.tiroir-panneau {
  position: absolute;
  inset: 0 25% 0 0;
  max-width: 330px;
  background: var(--fond-2);
  border-right: 1px solid var(--trait);
  padding: var(--e-6) var(--e-4);
  display: flex;
  flex-direction: column;
  gap: var(--e-6);
  overflow-y: auto;
}

/* Écran de chargement */
.chargement {
  display: grid;
  place-items: center;
  gap: var(--e-4);
  color: var(--encre-3);
}
.chargement-anneau {
  width: 30px;
  height: 30px;
  border-radius: var(--r-plein);
  border: 2px solid var(--trait-fort);
  border-top-color: var(--accent);
  animation: tourner 0.75s linear infinite;
}
@keyframes tourner {
  to {
    transform: rotate(360deg);
  }
}

/* Squelettes de chargement */
.squelette {
  border-radius: var(--r-2);
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    var(--surface-3) 37%,
    var(--surface-2) 63%
  );
  background-size: 400% 100%;
  animation: miroiter 1.4s ease-in-out infinite;
}
@keyframes miroiter {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

/* Ligne de vie : ce qui apparaît ne saute pas */
.apparait {
  animation: apparaitre 300ms var(--courbe) both;
}
@keyframes apparaitre {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Pour lecteurs d'écran uniquement */
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
