/* ------------------------------------------------------------------ jetons
   Palette validée : un seul accent (bleu) + gris de mise en retrait.
   Les barres de catégories sont une série unique → une seule couleur ;
   colorier chaque catégorie différemment doublerait l'encodage de la longueur.
   Les couleurs d'état (hausse/baisse) sont toujours accompagnées d'une flèche
   et d'un texte : jamais la couleur seule.                                  */

.viz-root {
  color-scheme: light;
  --plane:          #f9f9f7;
  --surface-1:      #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --series-1:       #2a78d6;      /* accent : la donnée mise en avant */
  --series-mute:    #898781;      /* gris de mise en retrait (contexte) */
  --good:           #006300;
  --critical:       #d03b3b;
  --shadow:         0 2px 12px rgba(11, 11, 11, 0.10);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --plane:          #0d0d0d;
    --surface-1:      #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --series-1:       #3987e5;
    --series-mute:    #898781;
    --good:           #0ca30c;
    --critical:       #d03b3b;
    --shadow:         0 2px 12px rgba(0, 0, 0, 0.50);
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --plane:          #0d0d0d;
  --surface-1:      #1a1a19;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --series-1:       #3987e5;
  --series-mute:    #898781;
  --good:           #0ca30c;
  --critical:       #d03b3b;
  --shadow:         0 2px 12px rgba(0, 0, 0, 0.50);
}

/* -------------------------------------------------------------------- base */

* { box-sizing: border-box; }

/* L'attribut `hidden` doit gagner, toujours.
   Sans cette règle, la `display` d'un sélecteur de classe (.lock est en grid,
   .sheet en flex) l'emporte sur le `[hidden] { display: none }` de la feuille
   du navigateur, moins spécifique : l'élément reste affiché alors que le code
   le croit masqué. C'est exactement ce qui laissait le verrou par-dessus
   l'appli après une authentification réussie. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--plane);
  color: var(--text-primary);
  padding: 0 16px calc(96px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin-inline: auto;
}

h1, h2 { font-weight: 600; }

/* ------------------------------------------------------------------ verrou */

.lock {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--plane);
  z-index: 40;
}
.lock__card {
  width: 100%;
  max-width: 320px;
  background: var(--surface-1);
  border: 0.5px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.lock__title { margin: 0 0 20px; font-size: 20px; text-align: center; }
.lock__error {
  margin: 12px 0 0;
  color: var(--critical);
  font-size: 14px;
}

/* ------------------------------------------------------- navigation du mois */

.monthnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 0 4px;
}
.monthnav__label {
  margin: 0;
  font-size: 19px;
  text-align: center;
  flex: 1;
}
.monthnav__today { margin: 0 0 12px; text-align: center; min-height: 20px; }

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

.btn {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  min-height: 44px;
  padding: 0 14px;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn--icon {
  width: 44px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  color: var(--text-secondary);
  flex: 0 0 auto;
}
.btn--primary {
  background: var(--series-1);
  border-color: transparent;
  color: #ffffff;
  font-weight: 600;
}
.btn--block { width: 100%; margin-top: 20px; }
.btn--small { min-height: 36px; padding: 0 10px; font-size: 13px; }
.btn--link {
  background: none;
  border: none;
  color: var(--series-1);
  padding: 0;
  min-height: 32px;
  text-decoration: none;
  font-size: 14px;
}

/* ------------------------------------------------------------------- KPIs */

.kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--surface-1);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.kpi--hero { grid-column: 1 / -1; }
.kpi__label {
  margin: 0 0 2px;
  font-size: 13px;
  color: var(--text-secondary);
}
/* Chiffres proportionnels sur les grands nombres : tabular-nums fait « flotter »
   les valeurs à cette taille. */
.kpi__value { margin: 0; font-size: 34px; font-weight: 600; letter-spacing: -0.5px; }
.kpi__value--sm { font-size: 20px; }

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

.card {
  background: var(--surface-1);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.card__title { margin: 0; font-size: 16px; }
.card__hint {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-muted);
}
.empty { margin: 4px 0 0; font-size: 14px; color: var(--text-muted); }

/* ------------------------------------- barres horizontales par catégorie
   Marques fines, extrémité arrondie à 4px, ancrées sur la ligne de base.
   Chaque valeur est étiquetée directement : la donnée est lisible sans
   survol, ce qui est indispensable au doigt.                              */

.bars { display: flex; flex-direction: column; gap: 14px; }

.bar {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 4px 0;
  cursor: pointer;
  min-height: 44px;
  color: inherit;
  font: inherit;
}
.bar__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.bar__label { font-size: 14px; }
.bar__value { font-size: 14px; font-weight: 600; white-space: nowrap; }
/* display:block indispensable : ce sont des <span> (enfants légitimes d'un
   <button>), donc inline par défaut, et une hauteur ne s'applique pas à un
   élément inline. */
.bar__track {
  display: block;
  height: 10px;
  background: var(--gridline);
  border-radius: 5px;
  overflow: hidden;
}
.bar__fill {
  display: block;
  height: 100%;
  background: var(--series-1);
  border-radius: 0 4px 4px 0;
  min-width: 3px;
}
.bar__delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 6px;
  white-space: nowrap;
}
.bar__delta--up { color: var(--critical); }
.bar__delta--down { color: var(--good); }

/* ------------------------------------------- historique 12 mois (colonnes)
   La hauteur du conteneur inclut la bande de libellés : pas de scroll
   imbriqué qui rogne l'axe.                                              */

/* La marge haute laisse la place à l'étiquette directe de la colonne courante,
   qui déborde volontairement au-dessus du tracé. Le tracé n'a NI marge NI
   remplissage internes : les hauteurs en % des colonnes et la position de la
   ligne de moyenne se réfèrent ainsi exactement à la même boîte. */
.history { margin: 22px 0 14px; }
.history__plot {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 104px;
  border-bottom: 1px solid var(--baseline);
}
.col {
  flex: 1 1 0;
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.col__fill {
  background: var(--series-mute);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
}
.col--current .col__fill { background: var(--series-1); }
.col__peak {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
}
/* Bande d'axe hors du tracé : la carte n'a pas de hauteur fixe qui rognerait
   les libellés de mois. */
.history__axis { display: flex; gap: 4px; margin-top: 5px; }
.tick {
  flex: 1 1 0;
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
}
.tick--current { color: var(--text-primary); font-weight: 600; }
.avg {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid var(--baseline);
  pointer-events: none;
}
.avg__label {
  position: absolute;
  right: 0;
  top: -15px;
  font-size: 10px;
  color: var(--text-muted);
  background: var(--surface-1);
  padding: 0 3px;
}

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

.tableview { font-size: 14px; }
.tableview summary {
  cursor: pointer;
  color: var(--series-1);
  min-height: 32px;
}
.tbl { width: 100%; border-collapse: collapse; margin-top: 8px; }
.tbl th, .tbl td {
  text-align: left;
  padding: 6px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.tbl th { color: var(--text-secondary); font-weight: 500; }
.tbl td:last-child, .tbl th:last-child { text-align: right; }

/* --------------------------------------------------------- opérations */

.ops { display: flex; flex-direction: column; }
.op {
  display: grid;
  grid-template-columns: 46px 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
}
.op:last-child { border-bottom: none; }
.op__date {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.op__main { min-width: 0; }
.op__cat { font-size: 14px; }
.op__note {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.op__amount { font-size: 14px; font-weight: 600; white-space: nowrap; }
.op__amount--rev { color: var(--good); }
.op__del {
  width: 36px;
  min-height: 36px;
  padding: 0;
  font-size: 15px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
}

/* ------------------------------------------------------------- pied, FAB */

.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 4px 4px 0;
}

.fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--series-1);
  color: #ffffff;
  font-size: 30px;
  line-height: 1;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 20;
}

/* -------------------------------------------------------------- feuilles */

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 11, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 30;
}
.sheet__card {
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface-1);
  border-radius: 16px 16px 0 0;
  padding: 18px 18px calc(24px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin-inline: auto;
}
.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

/* --------------------------------------------------------- formulaires */

.field { display: block; margin-bottom: 14px; }
.field__label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.field__opt { color: var(--text-muted); }

input[type="text"], input[type="password"], input[type="date"] {
  font: inherit;
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  color: var(--text-primary);
  background: var(--plane);
  border: 0.5px solid var(--border);
  border-radius: 10px;
}
input:focus-visible, .btn:focus-visible, .bar:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}
.input--amount {
  font-size: 26px;
  font-weight: 600;
  min-height: 56px;
}

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  background: var(--plane);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 16px;
}
.seg__btn {
  font: inherit;
  min-height: 40px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
}
.seg__btn.is-active {
  background: var(--surface-1);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.chips { border: none; margin: 0 0 14px; padding: 0; }
.chips__list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip {
  font: inherit;
  font-size: 14px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 20px;
  border: 0.5px solid var(--border);
  background: var(--plane);
  color: var(--text-secondary);
  cursor: pointer;
}
.chip.is-active {
  background: var(--series-1);
  border-color: transparent;
  color: #ffffff;
  font-weight: 600;
}

.duplist { display: flex; flex-direction: column; }
.dup {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 14px;
}
.dup input[type="checkbox"] { width: 22px; height: 22px; flex: 0 0 auto; accent-color: var(--series-1); }
.dup__main { flex: 1; min-width: 0; }
.dup__note { font-size: 12px; color: var(--text-muted); }
.dup__amount { font-weight: 600; white-space: nowrap; }

.dup--off { opacity: 0.55; }

/* ------------------------------------------------ gestion des catégories */

.chips__manage { margin-top: 10px; }

.catadd {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.catadd__field { flex: 1; margin-bottom: 0; }

.catlist { display: flex; flex-direction: column; margin-top: 10px; }
.cat {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 0.5px solid var(--border);
}
.cat__label { min-height: 40px; }
.cat__actions { display: flex; align-items: center; gap: 6px; }
.cat__fixe {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  font-size: 12px;
  color: var(--text-secondary);
}
.cat__fixe input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--series-1);
}
/* Une catégorie archivée reste lisible mais visiblement mise de côté. */
.cat--archived .cat__label { color: var(--text-muted); font-style: italic; }
.catlist__help { margin: 14px 0 0; }

/* Sur écran étroit, la ligne passe sur deux niveaux plutôt que de déborder. */
@media (max-width: 420px) {
  .cat { grid-template-columns: 1fr; }
  .cat__actions { justify-content: flex-end; }
}

.is-busy { opacity: 0.6; pointer-events: none; }

@media (min-width: 560px) {
  .kpis { grid-template-columns: 2fr 1fr 1fr; }
  .kpi--hero { grid-column: auto; }
}
