/* Charges & Budgets — sobre, une couleur d'accent, clair/sombre, montants en chiffres tabulaires. */

:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dde1e7;
  --text: #1b1f24;
  --muted: #5f6875;
  --accent: #0f766e;
  --accent-soft: #d8efeb;
  --accent-text: #ffffff;
  --chart: #0d9488; /* marque de graphique, validée (L, chroma, contraste) sur fond clair */
  /* Restant fin de mois (texte, contraste ≥ 4,5:1 sur la carte) */
  --good: #15803d;
  --tight: #256abf;
  /* Jauge variable : ordre catégoriel validé (clair, carte #ffffff) */
  --cat-1: #2a78d6;
  --cat-2: #eb6834;
  --cat-3: #1baf7a;
  --cat-4: #eda100;
  --cat-other: #898781;
  /* Qui est concerné : Pixel, Cha, commun (marques discrètes, jamais la couleur du texte) */
  --who-a: var(--who-a-custom, #4a3aa7); /* --who-*-custom : couleur choisie dans Paramètres (app.js) */
  --who-b: var(--who-b-custom, #e87ba4);
  --who-common: #eda100;
  --neg: #b42318;
  --neg-soft: #fde8e6;
  --warn: #9a4a06;
  --warn-soft: #fdf0cf;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.06);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #222831;
    --border: #2e3540;
    --text: #e7eaef;
    --muted: #9ba5b3;
    --accent: #2dd4bf;
    --accent-soft: #123b37;
    --accent-text: #04201d;
    --chart: #19a998; /* validée sur fond sombre */
    --good: #22c55e;
    --tight: #6da7ec;
    --cat-1: #3987e5;
    --cat-2: #d95926;
    --cat-3: #199e70;
    --cat-4: #c98500;
    --who-a: var(--who-a-custom-dark, #9085e9);
    --who-b: var(--who-b-custom-dark, #d55181);
    --who-common: #c98500;
    --neg: #f97066;
    --neg-soft: #3b1714;
    --warn: #fdb022;
    --warn-soft: #3a2b0b;
    --shadow: none;
  }
}

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

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 1.4rem;
}

h2 {
  font-size: 1rem;
}

.money,
.num,
.amount,
.tile-value,
.kv dd {
  font-variant-numeric: tabular-nums;
}

.neg {
  color: var(--neg);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.8rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding-inline: 16px;
}

/* ---------- en-tête et navigation ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-block: 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

/* Logo aux couleurs de la personne connectée (--who-a : Pixel, seul compte pour l'instant). */
.brand-logo {
  width: 26px;
  height: 26px;
  flex: none;
  font-family: -apple-system, 'Helvetica Neue', Arial, sans-serif;
}

.brand-track {
  stroke: var(--border);
}

.brand-arc {
  stroke: var(--who-a);
}

.brand-euro {
  fill: var(--text);
}

.month-select {
  font: inherit;
  font-weight: 600;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  min-width: 0;
}






main.wrap {
  padding-block: 20px 48px;
}

/* ---------- blocs ---------- */

.view > * + * {
  margin-top: 16px;
}

.view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.card > h2,
.card-head {
  margin-bottom: 12px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.banner {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 600;
}

.empty {
  padding: 32px 0;
  text-align: center;
  color: var(--muted);
}

/* ---------- tuiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.region-contents {
  display: contents;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.tile-label,
.field > span,
.stat small,
.kv-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.tile-value {
  font-size: 1.5rem;
  font-weight: 650;
  white-space: nowrap;
}

.tile-sub {
  font-size: 0.8rem;
  color: var(--muted);
}

.input.tile-input {
  font-size: 1.35rem;
  font-weight: 650;
  text-align: left;
  padding: 2px 8px;
  margin-left: -9px;
  width: calc(100% + 9px);
}

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

.input {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  width: 100%;
  min-width: 0;
}

.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.input:disabled {
  background: transparent;
  border-color: transparent;
  opacity: 1;
}

.input.amount {
  text-align: right;
}

.input.invalid {
  border-color: var(--neg);
  outline-color: var(--neg);
}

.check {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.btn,
.btn-primary {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.btn {
  margin-top: 12px;
  padding: 8px 12px;
  color: var(--accent);
  background: transparent;
  border: 1px dashed var(--border);
}

.btn:hover {
  border-color: var(--accent);
}

.btn-primary {
  padding: 6px 12px;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
}

.icon-btn {
  width: 32px;
  height: 32px;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--neg);
  background: var(--neg-soft);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-2);
}

.segmented button {
  font: inherit;
  font-weight: 600;
  padding: 6px 18px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.segmented button.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.12);
}

.fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 220px));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---------- tableaux éditables ---------- */

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  padding: 6px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 3px 6px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table .num {
  text-align: right;
}

.table .center {
  text-align: center;
}

.table .input {
  background: transparent;
  border-color: transparent;
}

.table .input:hover:not(:disabled) {
  border-color: var(--border);
}

.table .input:focus {
  background: var(--surface);
}

.table tr.is-paid .cell-label .input {
  color: var(--muted);
}

.table tfoot td,
.table tfoot th {
  padding: 10px 6px;
  font-weight: 600;
  border-top: 2px solid var(--border);
}

.col-amount {
  width: 120px;
}

.col-payer {
  width: 150px;
}

.col-due {
  width: 90px;
}

.col-check {
  width: 64px;
}

.col-actions {
  width: 40px;
}

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- barres ---------- */

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-2);
}

.bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.bar.over > span {
  background: var(--neg);
}

.range-track {
  position: relative;
  height: 14px;
  margin: 10px 0;
  border-radius: 99px;
  background: var(--surface-2);
}

.range-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 99px;
  background: var(--accent);
}

.range-fill.neg {
  background: var(--neg);
}

.range-zero {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  transform: translateX(-1px);
  background: var(--muted);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.range-labels > div {
  display: flex;
  flex-direction: column;
}

.range-labels .end {
  align-items: flex-end;
  text-align: right;
}

.range-labels small {
  font-size: 0.75rem;
  color: var(--muted);
}

.range-labels .money {
  font-size: 1.15rem;
  font-weight: 650;
}

.cj-link {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
}

.cj-link .money {
  font-weight: 700;
}

.cj-link:hover span:first-child {
  color: var(--accent);
}

/* ---------- postes variables ---------- */

.var-list {
  display: grid;
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.var-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px;
  align-items: center;
  gap: 6px 16px;
}

.var-main {
  display: grid;
  gap: 5px;
}

.var-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.var-label {
  font-weight: 600;
}

.var-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.quick-add {
  display: flex;
  gap: 6px;
}

/* ---------- synthèses ---------- */

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: start;
  gap: 16px;
}

.kv {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 12px;
  margin: 0;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  text-align: right;
  white-space: nowrap;
}

.kv .strong {
  font-weight: 700;
}

.split-person {
  padding-block: 12px;
  border-top: 1px solid var(--border);
}

.split-title {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge.ok {
  color: var(--accent);
  background: var(--accent-soft);
}

.badge.alert {
  color: var(--warn);
  background: var(--warn-soft);
}

.totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

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

.stat .money {
  font-size: 1.1rem;
  font-weight: 650;
}

.stat-wide {
  grid-column: 1 / -1;
}

.transfer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.transfer-amount {
  margin: 8px 0 0;
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.1;
}

.transfer-amount .money:not(.neg) {
  color: var(--accent);
}

.transfer .kv {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  transform: translateX(-50%);
  color: var(--bg);
  background: var(--text);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.2);
}

/* ---------- responsive ---------- */

@media (hover: none) {
  .table .input:not(:disabled) {
    border-color: var(--border);
  }
}

@media (max-width: 900px) {
  .tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  body {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }

  .input,
  .month-select {
    font-size: 16px; /* évite le zoom automatique d'iOS */
  }

  .brand {
    font-size: 0.95rem;
  }





  main.wrap {
    padding-block: 16px 24px;
  }

  .tile {
    padding: 12px;
  }

  .tile-value {
    font-size: 1.2rem;
  }

  .input.tile-input {
    font-size: 1.15rem;
  }

  .fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .var-row {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Tableaux → cartes empilées */
  .table thead {
    display: none;
  }

  .table,
  .table tbody,
  .table tfoot {
    display: block;
  }

  .table tr {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 10px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }

  .table tbody tr:last-child {
    border-bottom: 0;
  }

  .table td,
  .table tfoot th,
  .table tfoot td {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0;
    text-align: left;
    border: 0;
  }

  /* Cellule sans objet (dépensé d'une charge fixe) : rien à afficher en carte. */
  .table td.cell-na {
    display: none;
  }

  .table td[data-label]::before {
    content: attr(data-label);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .table td.cell-label {
    grid-column: 1 / -1;
    padding-right: 40px;
  }

  .table td.num {
    text-align: left;
  }

  /* Coches sur une ligne : case puis libellé */
  .table td.center {
    flex-direction: row-reverse;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
  }

  .table td.center .check {
    width: 22px;
    height: 22px;
  }

  .table td.actions {
    position: absolute;
    top: 12px;
    right: 0;
  }

  .table .input.amount {
    text-align: left;
  }

  .table tfoot tr {
    border-top: 2px solid var(--border);
  }

  .table tfoot td[colspan] {
    grid-column: 1 / -1;
  }

}

/* ---------- fin de mois ---------- */

.month-end p {
  margin: 0 0 12px;
}

.month-end .btn {
  margin-top: 0;
}

.btn-large {
  padding: 10px 16px;
  font-size: 1rem;
}

/* ---------- statistiques ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.metric-select {
  width: auto;
  font-weight: 600;
}

.view.is-loading .card {
  opacity: 0.6;
  transition: opacity 0.2s;
}

.btn.btn-inline {
  margin-top: 0;
  padding: 4px 10px;
  font-size: 0.85rem;
}

.single-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-block: 4px 8px;
}

.single-stat .hero {
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: proportional-nums;
}

.chart-host {
  position: relative;
  min-height: 240px;
}

.chart svg {
  display: block;
  overflow: visible;
}

.chart .grid line {
  stroke: var(--border);
  stroke-width: 1;
}

.chart .grid line.zero {
  stroke: var(--muted);
}

.chart .tick {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart .bar-mark {
  fill: var(--chart);
  transition: fill-opacity 0.15s;
}

.chart .bar-mark.provisional {
  fill-opacity: 0.4;
}

.chart .bar-mark.is-active {
  fill-opacity: 0.75;
}

.chart .bar-mark.provisional.is-active {
  fill-opacity: 0.6;
}

.chart .value-label {
  fill: var(--text);
  font-size: 12px;
  font-weight: 600;
}

.chart .hit {
  fill: transparent;
  outline: none;
}

.chart .hit:focus-visible {
  fill: var(--accent-soft);
  fill-opacity: 0.35;
}

.chart-tip {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  padding: 6px 10px;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.15);
}

.chart-tip[hidden] {
  display: none; /* sinon display: flex l'emporte sur l'attribut hidden */
}

.chart-tip strong {
  font-size: 0.95rem;
}

.chart-tip span {
  font-size: 0.75rem;
  color: var(--muted);
}

.table-scroll {
  overflow-x: auto;
  margin-inline: -16px;
  padding-inline: 16px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.stats-table th,
.stats-table td {
  padding: 8px 10px;
  text-align: right;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.stats-table thead th {
  min-width: 104px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: normal;
  vertical-align: bottom;
  color: var(--muted);
}

.stats-table th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 120px;
  text-align: left;
  background: var(--surface);
}

.stats-table tbody th {
  font-weight: 600;
}

.stats-table small {
  display: block;
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--muted);
}

@media (max-width: 640px) {

  .single-stat .hero {
    font-size: 2.1rem;
  }
}

/* ---------- accueil ---------- */

.status-good {
  color: var(--good);
}

.status-tight {
  color: var(--tight);
}

.status-bad {
  color: var(--neg);
}

.home-kicker {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.home-hero {
  padding: 20px;
}

.home-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.home-solde {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input.home-solde-input {
  width: 11ch;
  padding: 4px 10px;
  font-size: 1.6rem;
  font-weight: 700;
  text-align: left;
}

.rent-flag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  border: 1.5px solid currentColor;
  border-radius: 99px;
  cursor: pointer;
}

.rent-flag.is-paid {
  color: var(--good);
  background: color-mix(in srgb, var(--good) 10%, var(--surface));
}

.rent-flag.is-due {
  color: var(--warn);
  background: var(--warn-soft);
}

.rent-flag:disabled {
  cursor: default;
}

.rent-mark {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--surface);
  border-radius: 50%;
}

.is-paid .rent-mark {
  background: var(--good);
}

.is-due .rent-mark {
  background: var(--warn);
}

.home-outlook {
  margin-top: 20px;
  padding-top: 20px;
  text-align: center;
  border-top: 1px solid var(--border);
}

.home-outlook::before {
  content: '';
  display: block;
  width: 56px;
  height: 6px;
  margin: 0 auto 14px;
  border-radius: 99px;
  background: var(--tone, var(--muted));
}

.home-outlook.tone-good {
  --tone: var(--good);
}

.home-outlook.tone-tight {
  --tone: var(--tight);
}

.home-outlook.tone-bad {
  --tone: var(--neg);
}

.home-big {
  margin: 6px 0 0;
  font-size: clamp(3rem, 12vw, 4.75rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: proportional-nums;
}

.home-big .cents,
.home-topay-amount .cents {
  font-size: 0.42em;
  font-weight: 700;
  letter-spacing: 0;
}

.home-status {
  margin: 8px 0 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.home-max {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 16px 0 4px;
}

.home-max span {
  font-size: 0.8rem;
  color: var(--muted);
}

.home-max strong {
  font-size: 1.35rem;
  font-weight: 700;
}

.home-envelope-total {
  font-size: 1.25rem;
}

.gauge {
  margin: 4px 0 16px;
}

.gauge-icons {
  display: flex;
  gap: 2px;
  height: 30px;
}

.gauge-icons > span {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-width: 0;
}

.gauge-icon {
  padding-bottom: 4px;
  font-size: 1.25rem;
  line-height: 1;
}

.gauge-bar {
  display: flex;
  gap: 2px;
  height: 30px;
  overflow: hidden;
  border-radius: 99px;
}

.gauge-seg {
  min-width: 0;
}

.gauge-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.gauge-legend li {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 8px;
}

.gauge-legend small {
  grid-column: 3 / -1;
  font-size: 0.75rem;
  color: var(--muted);
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.gauge-legend-icon {
  font-size: 1.05rem;
}

.gauge-legend-label {
  font-weight: 600;
}

.gauge-legend-value .money {
  font-weight: 700;
}

.view > .home-topay {
  margin-top: 28px;
}

.home-topay {
  padding: 22px 20px;
  text-align: center;
  color: var(--bg);
  background: var(--text);
  border-radius: var(--radius);
}

.home-topay .home-kicker {
  color: color-mix(in srgb, var(--bg) 70%, var(--text));
}

.home-topay-amount {
  margin: 6px 0 0;
  font-size: clamp(2.2rem, 8vw, 3rem);
  font-weight: 800;
  line-height: 1.05;
  font-variant-numeric: proportional-nums;
}

.home-topay-split {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 10px 0 0;
  font-size: 0.9rem;
  color: color-mix(in srgb, var(--bg) 80%, var(--text));
}

.home-topay-split strong {
  color: var(--bg);
}

.home-topay-split .sep {
  opacity: 0.5;
}

.home-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.home-links a {
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
}

@media (max-width: 640px) {
  .home-hero {
    padding: 16px;
  }

  .input.home-solde-input {
    font-size: 1.4rem;
  }

  .rent-flag {
    padding: 6px 12px;
    font-size: 0.9rem;
  }

}

/* ---------- application installée ---------- */

/* Barre d'état iOS translucide : la bande du haut reste gris-bleu (#0f1216, comme l'écran de
   lancement) et l'en-tête commence sous l'encoche. */
@media (display-mode: standalone) {
  .topbar {
    padding-top: env(safe-area-inset-top);
    background: linear-gradient(#0f1216 0 env(safe-area-inset-top), var(--surface) env(safe-area-inset-top));
  }
}

/* ---------- épargne ---------- */

.home-flags {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.savings-flag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 99px;
}

.savings-flag:hover {
  border-color: var(--accent);
}

.savings-flag strong {
  font-variant-numeric: tabular-nums;
}

.savings-flag.is-empty {
  color: var(--muted);
  border-style: dashed;
}

.savings-hero {
  padding: 20px;
  text-align: center;
}

.savings-balance {
  margin: 6px 0 0;
  font-size: clamp(2.4rem, 9vw, 3.4rem);
  font-weight: 800;
  line-height: 1.05;
  font-variant-numeric: proportional-nums;
}

.savings-last {
  margin: 10px 0 0;
  font-weight: 600;
}

.savings-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-top: 12px;
}

.savings-form .field {
  flex: 0 1 220px;
}

.savings-history {
  margin: 0;
  padding: 0;
  list-style: none;
}

.savings-history li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.savings-history li:last-child {
  border-bottom: 0;
}

.savings-kind {
  font-weight: 600;
}

.savings-amount,
.savings-after {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.savings-amount {
  font-weight: 700;
}

@media (max-width: 640px) {
  .home-flags {
    align-items: flex-start;
  }

  .savings-flag {
    padding: 6px 12px;
    font-size: 0.9rem;
  }

}

/* ---------- glisser d'un onglet à l'autre ---------- */

@media (prefers-reduced-motion: no-preference) {
  #app.slide-next {
    animation: slide-from-right 0.22s ease-out;
  }

  #app.slide-prev {
    animation: slide-from-left 0.22s ease-out;
  }
}

@keyframes slide-from-right {
  from {
    opacity: 0.4;
    transform: translateX(32px);
  }
}

@keyframes slide-from-left {
  from {
    opacity: 0.4;
    transform: translateX(-32px);
  }
}

/* ---------- épargne : évolution et projection ---------- */

.card-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.segmented.small button {
  padding: 4px 12px;
  font-size: 0.85rem;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.chart-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.line-key {
  display: inline-block;
  width: 16px;
  vertical-align: middle;
  border-top: 2px solid;
  border-radius: 2px;
}

.chart .line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart .end-dot {
  stroke: var(--surface);
  stroke-width: 2;
}

.chart .crosshair {
  stroke: var(--muted);
  stroke-width: 1;
}

.chart-tip .tip-title {
  margin-bottom: 2px;
}

.chart-tip .tip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
}

.chart-tip .tip-row strong {
  color: var(--text);
  font-size: 0.9rem;
}

.projection-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin: 4px 0 14px;
}

.projection-summary .stat .money {
  font-size: 1.35rem;
  font-variant-numeric: proportional-nums;
}

.projection-summary .line-key {
  margin-right: 6px;
}

/* Contrôles compacts : jamais de libellé coupé sur deux lignes, en-tête qui passe à la ligne si besoin. */
.segmented button {
  white-space: nowrap;
}

.card-head {
  flex-wrap: wrap;
}

/* ---------- crédit ---------- */

.credit-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-top: 12px;
}

.credit-form .field {
  flex: 0 1 220px;
}

.payoff-when {
  font-size: 1.2rem;
}

.chart .marker {
  stroke: var(--text);
  stroke-width: 1;
  opacity: 0.45;
}

.chart .marker-label {
  fill: var(--text);
  font-size: 11px;
  font-weight: 600;
}


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




.login-body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px 16px;
}

.login {
  width: 100%;
  max-width: 360px;
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
  font-size: 1.25rem;
  font-weight: 700;
}

.login-brand img {
  border-radius: 10px;
}

.login-form {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.field > .password-wrap {
  position: relative;
  display: block;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: normal;
  text-transform: none;
  color: inherit;
}

.password-wrap .input {
  padding-right: 44px;
}

.eye {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: grid;
  place-items: center;
  width: 44px;
  color: var(--muted);
  cursor: pointer;
  background: transparent;
  border: 0;
}

.eye[aria-pressed='true'] {
  color: var(--accent);
}

.remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.login-error {
  margin: 0;
  font-weight: 600;
  color: var(--neg);
}

/* ---------- courbes : réel en trait plein, projection en pointillés ---------- */

.chart .line.dashed {
  stroke-dasharray: 5 4;
}

.line-key.dashed {
  border-top-style: dashed;
}

/* ---------- barres par période (épargne, crédit) ---------- */

/* « bar-seg » et non « bar » : .bar est la barre de progression (height: 8px), qui s'appliquerait aux <rect>. */
.chart .bar-seg {
  transition: fill-opacity 0.15s;
}

.chart .bar-seg.projected {
  fill-opacity: 0.45;
}

.chart .band-highlight {
  fill: var(--surface-2);
}

.bar-key {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  vertical-align: middle;
  border-radius: 3px;
}

.bar-key.projected {
  opacity: 0.45;
}

.chart-legend .bar-key {
  margin-right: 0;
}

/* ---------- axe des mois et des années ---------- */

.chart .tick.month {
  font-size: 10.5px;
}

.chart .tick.month.now,
.chart .tick.year {
  font-weight: 700;
  fill: var(--text);
}

.chart .year-divider {
  stroke: var(--muted);
  stroke-width: 1;
  opacity: 0.55;
}

/* Montants écrits sur le graphique : contour de la couleur du fond, lisibles même au-dessus d'une barre voisine. */
.chart .value-label {
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 3px;
  stroke-linejoin: round;
}

/* Info-bulle : montant ajouté ce mois-là, sous la valeur. */
.chart-tip .tip-note {
  margin: -2px 0 4px 16px;
  font-size: 0.72rem;
}

/* ---------- code couleur des personnes ---------- */

.who-dot {
  display: inline-block;
  flex: none;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  vertical-align: middle;
  border-radius: 50%;
  background: var(--who-common);
}

.who-dot[data-who='a'] {
  background: var(--who-a);
}

.who-dot[data-who='b'] {
  background: var(--who-b);
}

.who-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
}

.home-kicker .who-chip {
  margin-left: 8px;
  vertical-align: middle;
}

.card[data-who] {
  border-top: 3px solid var(--who-common);
}

.card[data-who='a'] {
  border-top-color: var(--who-a);
}

.card[data-who='b'] {
  border-top-color: var(--who-b);
}

.table tr[data-who] td:first-child {
  box-shadow: inset 3px 0 0 var(--who-common);
}

.table tr[data-who='a'] td:first-child {
  box-shadow: inset 3px 0 0 var(--who-a);
}

.table tr[data-who='b'] td:first-child {
  box-shadow: inset 3px 0 0 var(--who-b);
}

.who-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 12px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  /* Cartes empilées : le liseré passe sur la carte entière. */
  .table tr[data-who] td:first-child,
  .table tr[data-who='a'] td:first-child,
  .table tr[data-who='b'] td:first-child {
    box-shadow: none;
  }

  .table tr[data-who] {
    padding-left: 12px;
    box-shadow: inset 3px 0 0 var(--who-common);
  }

  .table tr[data-who='a'] {
    box-shadow: inset 3px 0 0 var(--who-a);
  }

  .table tr[data-who='b'] {
    box-shadow: inset 3px 0 0 var(--who-b);
  }
}

/* Jauge du reste variable : la partie vive se vide de droite à gauche ; le déjà dépensé reste visible en
   version très pâle de la même couleur. */
.gauge-seg {
  position: relative;
  overflow: hidden;
  background: color-mix(in srgb, var(--seg) 22%, var(--surface));
}

.gauge-fill {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  overflow: hidden;
  background: var(--seg);
  transition: width 0.3s ease;
  container-type: inline-size;
}

.gauge-amount {
  padding: 0 4px;
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgb(0 0 0 / 0.45);
}

/* Partie foncée trop étroite pour le montant : on le retire plutôt que de le couper. */
@container (max-width: 46px) {
  .gauge-amount {
    display: none;
  }
}

.gauge-details > summary {
  width: fit-content;
  padding: 4px 0;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.gauge-details[open] > summary {
  margin-bottom: 12px;
}

/* Thème sombre : le consommé reste la teinte claire, le restant la teinte foncée. */
@media (prefers-color-scheme: dark) {
  .gauge-seg {
    background: color-mix(in srgb, var(--seg) 40%, #ffffff);
  }

  .gauge-fill {
    background: color-mix(in srgb, var(--seg) 72%, #000000);
  }
}

/* ---------- menu en haut à droite (comme Collection) ---------- */

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-left: auto;
}

.menu-btn {
  display: grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.menu-btn[aria-expanded='true'] {
  background: var(--surface-2);
}

.menu-overlay {
  position: fixed;
  inset: var(--topbar-h, 57px) 0 0;
  z-index: 40;
  padding: 0;
  background: rgb(0 0 0 / 0.45);
  border: 0;
}

.menu {
  position: fixed;
  top: var(--topbar-h, 57px);
  right: 0;
  bottom: 0;
  z-index: 50;
  width: 288px;
  max-width: 85vw;
  padding: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgb(0 0 0 / 0.18);
}

.menu-links {
  display: grid;
  gap: 2px;
}

.menu a,
.menu-logout {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border-radius: 10px;
}

.menu a:hover,
.menu-logout:hover {
  color: var(--text);
  background: var(--surface-2);
}

.menu a.active {
  color: var(--text);
  background: var(--accent-soft);
}

.menu-icon {
  width: 1.4em;
  text-align: center;
}

.menu-sep {
  margin: 10px 4px;
  border: 0;
  border-top: 1px solid var(--border);
}

.menu-logout {
  width: 100%;
  cursor: pointer;
  background: transparent;
  border: 0;
}

body.menu-open {
  overflow: hidden;
}

@media (max-width: 640px) {
  /* Plus de barre d'onglets en bas : l'espace qui lui était réservé est rendu à la page. */
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }

  #toast {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }

  /* Le nom reste entier : c'est la liste des mois qui rétrécit. */
  .brand {
    flex: none;
  }

  .topbar-actions {
    flex: 1 1 auto;
    justify-content: flex-end;
  }

  .topbar-actions .month-select {
    min-width: 0;
  }

  .brand-extra {
    display: none;
  }
}

/* ---------- paramètres : postes variables ---------- */

.settings-posts {
  display: grid;
  gap: 10px;
  margin: 12px 0;
  padding: 0;
  list-style: none;
}

.settings-post {
  padding: 10px 12px 8px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: inset 5px 0 0 var(--seg);
}

.settings-post-main {
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 1fr) 8rem auto;
  align-items: center;
  gap: 8px;
}

.settings-post-icon {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  font-size: 1.4rem;
  background: color-mix(in srgb, var(--seg) 18%, var(--surface));
  border-radius: 10px;
}

.settings-budget {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.settings-budget .input {
  min-width: 0;
}

.settings-picker > summary {
  width: fit-content;
  padding: 8px 0 2px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.picker-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}

.emoji-btn {
  width: 40px;
  height: 40px;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.emoji-btn[aria-pressed='true'] {
  background: var(--surface-2);
  border-color: var(--text);
}

.swatch-btn {
  width: 32px;
  height: 32px;
  cursor: pointer;
  background: var(--swatch);
  border: 3px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--border);
}

.swatch-btn[aria-pressed='true'] {
  box-shadow: 0 0 0 2px var(--text);
}

.picker-custom {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

.emoji-input {
  width: 3.4rem;
  font-size: 1.2rem;
  text-align: center;
}

.color-input {
  width: 40px;
  height: 34px;
  padding: 2px;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

@media (max-width: 640px) {
  .settings-post-main {
    grid-template-columns: 2.4rem minmax(0, 1fr) auto;
  }

  .settings-budget {
    grid-column: 2 / 3;
  }

  .settings-post-main .icon-btn {
    grid-row: 1;
    grid-column: 3;
  }
}

.settings-subhead {
  margin: 16px 0 8px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.rent-missing {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.settings-people {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.settings-person {
  padding: 10px 12px 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: inset 5px 0 0 var(--seg);
}

.settings-person .picker-group {
  margin-top: 8px;
}

/* ---------- aide « ? » ---------- */

.help {
  position: relative;
  display: inline-block;
  margin-left: 6px;
  vertical-align: middle;
}

.help-btn {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  color: var(--muted);
  cursor: help;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
}

.help-btn:hover,
.help-btn:focus-visible {
  color: var(--text);
  border-color: var(--text);
}

.help-tip {
  position: absolute;
  top: calc(100% + 6px);
  right: -8px;
  z-index: 20;
  display: none;
  width: min(260px, 75vw);
  padding: 8px 10px;
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: normal;
  text-transform: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
}

/* Survol à la souris ; au toucher, .is-open (components.js) ; au clavier, le focus. */
.help:hover .help-tip,
.help.is-open .help-tip,
.help-btn:focus-visible + .help-tip {
  display: block;
}

/* ---------- saisie rapide ---------- */

.saisie-sub {
  margin: 14px 0 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.saisie-checks {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.saisie-checks li + li {
  border-top: 1px solid var(--border);
}

.saisie-check {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 6px 2px;
  cursor: pointer;
}

.saisie-check .check {
  flex: none;
  width: 22px;
  height: 22px;
}

.saisie-label {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  font-weight: 600;
}

.saisie-label small {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
}

.saisie-amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.saisie-check.is-paid .saisie-label,
.saisie-check.is-paid .saisie-amount {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

/* Rupture entre perso, commun avancé et compte joint. */
.saisie-break {
  width: 40%;
  margin: 8px auto;
  border: 0;
  border-top: 3px dotted var(--border);
}

@media (max-width: 640px) {
  /* Accueil : le seul raccourci restant prend toute la largeur. */
  .home-links .home-month-end {
    flex: 1;
    justify-content: center;
    text-align: center;
  }
}

/* ---------- couleurs en duo clair / sombre ---------- */

/* Postes variables : --seg prend la teinte du thème. */
.seg-duo {
  --seg: var(--seg-light);
}

.swatch.seg-duo {
  background: var(--seg);
}

@media (prefers-color-scheme: dark) {
  .seg-duo {
    --seg: var(--seg-dark, var(--seg-light));
  }
}

/* Pastille coupée en deux : clair en haut à gauche, sombre en bas à droite. */
.swatch-btn.swatch-duo {
  background: linear-gradient(135deg, var(--swatch) 50%, var(--swatch-dark) 50%);
}

.picker-colors .picker-group + .picker-group {
  margin-top: 8px;
}

.picker-colors .picker-custom:first-child {
  margin-left: 0;
}

