:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #16202e;
  --muted: #6b7a8d;
  --line: #e2e8f0;
  --accent: #2a78d6;
  --accent-soft: #eaf1fb;
  --danger: #c2374a;
  --ok: #1f7a4d;
  --radius: 10px;

  /* Categorical palette, validated slot order */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

h1 { font-size: 1.6rem; margin: 0 0 1.25rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.9rem; }

/* Une hauteur minimale, pas fixe : avec six liens et le menu de bascule, la barre doit pouvoir
   passer sur deux lignes sur un écran étroit au lieu de rogner ce qui dépasse. */
.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  padding: 0.4rem 1.5rem;
  min-height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); }
.topbar nav { display: flex; gap: 0.9rem; flex: 1; flex-wrap: wrap; }
/* L'adresse email est le plus gros élément facultatif de la barre : sous 1400 px elle cède la
   place, le bouton Déconnexion suffit. */
@media (max-width: 1400px) { .topbar .email { display: none; } }
.topbar nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 0.3rem 0;
  border-bottom: 2px solid transparent;
}
.topbar nav a.active, .topbar nav a:hover { color: var(--ink); border-color: var(--accent); }
.logout { display: flex; align-items: center; gap: 0.75rem; }
.email { color: var(--muted); font-size: 0.85rem; }

main { max-width: 1100px; margin: 0 auto; padding: 1.75rem 1.25rem 3rem; }
main.narrow { max-width: 420px; padding-top: 4rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }

.auth h1 { text-align: center; }
.auth form { display: flex; flex-direction: column; gap: 0.9rem; }

label { display: block; font-size: 0.82rem; color: var(--muted); font-weight: 500; }
input, select {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

button { font: inherit; cursor: pointer; }
button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 0.55rem 1.1rem;
  font-weight: 600;
}
button.primary:hover { background: #1c5cab; }
button.link {
  background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline;
}
button.link.danger { color: var(--danger); }

.row-form { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; }
.row-form label { flex: 0 0 auto; min-width: 130px; }
.row-form label.grow { flex: 1 1 180px; }
.stacked-form { display: flex; flex-direction: column; gap: 0.9rem; }
/* Bottom-aligned, as .row-form is: a label that wraps onto two lines must not push its own
   field below the others on the same line. */
.field-row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; }
.field-row label { flex: 1 1 140px; }
.filters { display: flex; gap: 0.5rem; }
.filters select { width: auto; margin-top: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; }
.stat { display: flex; flex-direction: column; gap: 0.25rem; }
.stat-label { font-size: 0.8rem; color: var(--muted); }
.stat-value { font-size: 1.55rem; font-weight: 700; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 1.25rem; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1rem; margin-bottom: 1rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.right { text-align: right; }
tr.phase-retraite td { background: #fbfcfe; }

.tag {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px;
  background: var(--accent-soft); color: #1c5cab; font-size: 0.78rem;
}
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.hint { font-weight: 400; color: var(--muted); }
.error {
  background: #fdecee; color: var(--danger); border: 1px solid #f5c2c9;
  padding: 0.6rem 0.8rem; border-radius: 7px;
}
.verdict { padding: 0.6rem 0.8rem; border-radius: 7px; font-size: 0.9rem; }
.verdict.ok { background: #e9f6ef; color: var(--ok); }
.verdict.ko { background: #fdecee; color: var(--danger); }

.notices { margin-bottom: 0.9rem; }
.notice { margin: 0 0 0.45rem; padding: 0.55rem 0.8rem; border-radius: 7px; font-size: 0.88rem; }
.notice.ok { background: #e9f6ef; color: var(--ok); }
.notice.error { background: #fdecee; color: var(--danger); }
.subhead { font-size: 0.92rem; margin: 1.2rem 0 0.4rem; }
.table-scroll { overflow-x: auto; }

/* ---------- Statement import ---------- */

.dropzone {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.3rem;
  min-height: 130px; padding: 1.25rem; text-align: center;
  border: 2px dashed #cdd6e3; border-radius: var(--radius);
  background: #fafbfd; color: var(--ink); font-size: 0.95rem;
  cursor: pointer; transition: border-color 0.12s, background 0.12s;
}
.dropzone:hover, .dropzone:focus-within, .dropzone.is-over {
  border-color: var(--accent); background: var(--accent-soft);
}
.dropzone.is-busy { opacity: 0.7; pointer-events: none; }
.dropzone-title { font-size: 1.02rem; }
.dropzone-input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer;
}

.inline-form { margin: 0; }
select.tag-select {
  display: inline-block; width: auto; margin: 0;
  padding: 0.12rem 0.4rem; border: 1px solid transparent; border-radius: 999px;
  background: var(--accent-soft); color: #1c5cab; font-size: 0.78rem;
}
select.tag-select:hover { border-color: #b9cdea; }

label.checkbox {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.9rem; color: var(--ink); font-weight: 500;
}
label.checkbox input { display: inline-block; width: auto; margin: 0; }
input[readonly] { background: var(--bg); color: var(--muted); }

/* ---------- Cash-flow sheet (colours of the original spreadsheet) ---------- */

main.wide { max-width: none; }

.cf-card { padding: 1rem 1.25rem 1.25rem; }
.cf-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem 1.5rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.cf-toolbar-group { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
label.cf-inline { display: flex; align-items: center; gap: 0.5rem; }
label.cf-inline select { width: auto; margin: 0; }
.cf-button {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 7px;
  padding: 0.45rem 0.8rem; font-size: 0.88rem;
}
.cf-button:hover:not(:disabled) { border-color: var(--accent); }
.cf-button:disabled { opacity: 0.45; cursor: default; }
.cf-colors { display: inline-flex; align-items: center; gap: 4px; }
.cf-colors-label { font-size: 0.85rem; color: var(--muted); margin-right: 2px; }
.cf-color {
  width: 26px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--ink); font-size: 12px; font-weight: 700; line-height: 1;
}
.cf-color:not([data-color="auto"])::before {
  content: ""; display: block; width: 12px; height: 12px; margin: auto; border-radius: 3px; background: var(--swatch);
}
.cf-color[data-color="black"] { --swatch: #000; }
.cf-color[data-color="red"] { --swatch: #ff0000; }
.cf-color[data-color="green"] { --swatch: #00b050; }
.cf-color[data-color="blue"] { --swatch: #0070c0; }
.cf-color[data-color="orange"] { --swatch: #ed7d31; }
.cf-color:hover:not(:disabled) { border-color: var(--accent); }
.cf-color:disabled { opacity: 0.4; cursor: default; }
.cf-color[aria-pressed="true"] { border: 2px solid var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.cf-status { font-size: 0.85rem; color: var(--muted); }
.cf-status.is-ok { color: var(--ok); }
.cf-status.is-error { color: var(--danger); }

/* Every rule below is scoped by .cf-table so it outranks the generic table styles. */
.cf-table {
  --cf-navy: #1f3864;
  --cf-blue: #2f5597;
  --cf-band: #d9e1f2;
  --cf-total-bg: #b4c6e7;
  --cf-stripe: #f2f5fb;
  --cf-border: #c9d1de;
  --cf-red: #ff0000;
  --cf-green: #00b050;
  --cf-rownum-w: 30px;
  --cf-label-w: 370px;
  --cf-gap-w: 10px;
  --cf-num-w: 94px;
  --cf-total-w: 118px;
  table-layout: fixed;
  width: calc(var(--cf-rownum-w) + var(--cf-label-w) + 2 * var(--cf-gap-w) + 12 * var(--cf-num-w) + var(--cf-total-w));
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
  line-height: 1.2;
  color: #000;
  font-variant-numeric: tabular-nums;
}
.cf-table th, .cf-table td {
  padding: 0; border: 0; text-transform: none; letter-spacing: normal;
  vertical-align: middle; font-size: inherit; font-weight: 400; color: inherit;
  text-align: left; background: transparent;
}
.cf-table .cf-col-rownum { width: var(--cf-rownum-w); }
.cf-table .cf-col-label { width: var(--cf-label-w); }
.cf-table .cf-col-gap { width: var(--cf-gap-w); }
.cf-table .cf-col-num { width: var(--cf-num-w); }
.cf-table .cf-col-total { width: var(--cf-total-w); }

.cf-table .cf-label {
  position: sticky; left: var(--cf-rownum-w); z-index: 2;
  background: #fff; padding: 0 0.3rem; height: 21px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cf-table .cf-gap { background: #fff; }
.cf-table .cf-num { text-align: right; padding: 0 0.35rem; height: 21px; white-space: nowrap; overflow: hidden; }
.cf-table .cf-editable { padding: 0; }

/* Title and month names */
.cf-table .cf-title-row > th { height: 46px; }
.cf-table .cf-title-row > .cf-label { overflow: visible; }
.cf-title { margin: 0; font-size: 1.85rem; font-weight: 700; color: #1f3864; white-space: nowrap; }
.cf-table .cf-month { text-align: center; font-size: 1.45rem; color: var(--cf-navy); }

/* Blue header cells */
.cf-table .cf-head {
  background: var(--cf-blue); color: #fff; font-weight: 700; text-align: right;
  padding: 0 0.3rem; height: 19px; border-right: 1px solid #fff;
}
.cf-table .cf-head-row.is-top .cf-head { border-bottom: 1px solid #8ea9db; }
.cf-table .cf-head-small { font-size: 10px; letter-spacing: -0.01em; }
.cf-table .cf-head-tiny { font-size: 9.5px; }
.cf-table .cf-fiscal { font-weight: 700; color: var(--cf-navy); }
.cf-table .cf-date-cell { padding: 0; overflow: visible; }
.cf-table .cf-date {
  display: block; width: 100%; margin: 0; height: 19px; padding: 0 0.3rem; border-radius: 0;
  border: 1px solid #e6d8a8; background: #fff2cc; color: #000; font-size: 12px; font-weight: 700;
}

/* Spacers */
.cf-table .cf-spacer > td { height: 16px; background: #fff; }
.cf-table .cf-spacer.is-small > td { height: 8px; }
.cf-table .cf-spacer.is-large > td { height: 30px; }

/* Bold summary bands with navy rules */
.cf-table .cf-summary > .cf-label,
.cf-table .cf-summary > .cf-num {
  font-weight: 700; background: var(--cf-band); height: 24px;
  border-top: 2px solid var(--cf-navy); border-bottom: 2px solid var(--cf-navy);
}
.cf-table .cf-summary > .cf-num { border-right: 1px solid #fff; }
.cf-table .cf-summary > .cf-num .cf-input { font-weight: 700; }
.cf-table .cf-opening > .cf-label { font-size: 13.5px; color: var(--cf-navy); }
.cf-table .cf-opening > .cf-num { font-size: 13.5px; }

.cf-table .cf-statement > .cf-label,
.cf-table .cf-statement > .cf-num {
  background: #e7e6e6; color: #595959; font-style: italic; height: 19px;
  border-right: 1px solid #fff;
}
.cf-table .cf-statement .cf-input { font-style: italic; color: #595959; }

.cf-table .cf-section > th,
.cf-table .cf-section > td { background: var(--cf-navy); color: #fff; height: 28px; }
.cf-table .cf-section > .cf-label { font-weight: 700; font-size: 13.5px; }
.cf-table .cf-section > .cf-gap { background: #fff; }
.cf-table .cf-section .cf-add { color: #c9d6ee; margin-left: 1.2rem; font-weight: 400; }
.cf-table .cf-section .cf-add:hover { color: #fff; }

/* Editable lines */
.cf-table .cf-line > .cf-label {
  background: #fff; padding-right: 4.8rem;
  border: 1px solid var(--cf-border); border-top: 0;
}
.cf-table .cf-line:nth-child(even) > .cf-label { background: var(--cf-stripe); }
.cf-table .cf-line > .cf-num {
  background: #fff; border-right: 1px solid var(--cf-border); border-bottom: 1px solid var(--cf-border);
}
.cf-table .cf-line > .cf-gap + .cf-num { border-left: 1px solid var(--cf-border); }
.cf-table .cf-line:hover > .cf-num,
.cf-table .cf-line:hover > .cf-label { background: #eef3fb; }

.cf-input, .cf-label-input {
  display: block; width: 100%; height: 100%; min-height: 20px; margin: 0;
  border: 0; border-radius: 0; background: transparent;
  font: inherit; color: inherit; padding: 0 0.35rem;
}
.cf-input { text-align: right; }
.cf-label-input { padding: 0; text-overflow: ellipsis; }
.cf-input:focus, .cf-label-input:focus {
  outline: 2px solid var(--accent); outline-offset: -2px; background: #fff; border: 0;
}
.cf-label-input:focus { outline-offset: 1px; }
/* A long formula being edited spreads over the neighbouring cells, as in a spreadsheet:
   the cell stops clipping while it has the focus, and the field grows to the right
   (left-hand months) or to the left (right-hand months). */
.cf-table .cf-editable { position: relative; }
.cf-table .cf-editable:focus-within { overflow: visible; }
.cf-table .cf-input.is-long:focus, .cf-square .cf-input.is-long:focus {
  position: absolute; top: 0; left: 0; z-index: 5; min-width: 320px; max-width: 85vw;
  text-align: left; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.cf-table .cf-input.is-long.anchor-right:focus, .cf-square .cf-input.is-long.anchor-right:focus { left: auto; right: 0; }
.cf-table .cf-input.is-custom, .cf-square .cf-input.is-custom { border-left: 3px solid #e0a800; }
.cf-table .is-negative { color: var(--cf-red); }
/* Colours chosen by hand (after the row styles, so they win over them) */
.cf-table .cf-input[data-color="black"], .cf-square .cf-input[data-color="black"] { color: #000; }
.cf-table .cf-input[data-color="red"], .cf-square .cf-input[data-color="red"] { color: var(--cf-red); }
.cf-table .cf-input[data-color="green"], .cf-square .cf-input[data-color="green"] { color: var(--cf-green); }
.cf-table .cf-input[data-color="blue"], .cf-square .cf-input[data-color="blue"] { color: #0070c0; }
.cf-table .cf-input[data-color="orange"], .cf-square .cf-input[data-color="orange"] { color: #ed7d31; }

.cf-row-actions {
  position: absolute; right: 3px; top: 50%; transform: translateY(-50%);
  display: none; gap: 2px;
}
.cf-table .cf-line:hover .cf-row-actions,
.cf-table .cf-line > .cf-label:focus-within .cf-row-actions { display: flex; }
.cf-icon {
  width: 20px; height: 17px; padding: 0; line-height: 1;
  border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--muted); font-size: 12px;
}
.cf-icon:hover:not(:disabled) { color: var(--ink); border-color: var(--accent); }
.cf-icon.is-danger:hover { color: var(--danger); border-color: var(--danger); }
.cf-icon.is-add { font-weight: 700; }
.cf-icon.is-add:hover { color: var(--cf-green); border-color: var(--cf-green); }
.cf-icon:disabled { opacity: 0.35; cursor: default; }

.cf-add { background: none; border: 0; padding: 0; color: var(--accent); font-size: 12px; }
.cf-add:hover { text-decoration: underline; }

.cf-table .cf-section-total > .cf-label,
.cf-table .cf-section-total > .cf-num { background: var(--cf-total-bg); height: 20px; }
.cf-table .cf-section-total + .cf-band > .cf-label,
.cf-table .cf-section-total + .cf-band > .cf-num { border-top: 0; }
.cf-table .cf-band > .cf-label { font-size: 12.5px; }
.cf-table .cf-band > .cf-num { font-size: 13.5px; }

.cf-table .cf-position > .cf-label,
.cf-table .cf-position > .cf-num { background: var(--cf-total-bg); height: 30px; font-size: 14.5px; }
.cf-table .cf-position > .cf-label { font-size: 15px; color: var(--cf-navy); }

/* Several cells selected with the mouse: their sum, in a bar kept in the corner of the window. */
.cf-board.is-picking, .cf-board.is-picking .cf-input { user-select: none; }
.cf-table td.cf-num.is-picked { background: #cfe0f8; }
.cf-sum {
  position: fixed; right: 18px; bottom: 18px; z-index: 30;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(15, 30, 60, 0.18);
  padding: 0.4rem 0.75rem; font-size: 0.88rem; font-variant-numeric: tabular-nums;
}

/* The first row of the table: the drop square in the label cell, then a light-blue square
   above each month, the width of its column, showing the cash on the 1st (both blocks). */
.cf-table { --cf-square: calc(var(--cf-num-w) - 4px); }
.cf-table .cf-cash > th, .cf-table .cf-cash > td {
  height: auto; padding: 0 2px 4px; vertical-align: bottom; border: 0; background: #fff;
  white-space: normal; overflow: visible;
}
.cf-table .cf-cash > .cf-label { padding-left: 0.35rem; }
.cf-cash-head { display: flex; align-items: center; gap: 0.6rem; }
.cf-square {
  position: relative; box-sizing: border-box; width: var(--cf-square); height: var(--cf-square); margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.1rem;
  padding: 0.2rem 0.2rem; border-radius: var(--radius);
  background: #dbeafe; border: 1px solid #93c5fd; color: #1f3864;
}
.cf-square-month { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em; }
.cf-square-row { display: flex; align-items: center; gap: 2px; width: 100%; border-radius: 4px; }
.cf-square-row.is-picked { background: #bcd4f5; }
.cf-square-when { flex: none; width: 1.35rem; font-size: 0.6rem; font-weight: 600; color: #3b5b8a; }
.cf-square .cf-input {
  flex: 1; min-width: 0; height: 22px; min-height: 22px; border-radius: 4px; text-align: right; padding: 0 0.15rem;
  font-weight: 700; font-size: 0.84rem; font-variant-numeric: tabular-nums;
}

/* The square next to the drop square: what the clients and Ronan bring in, both blocks. */
.cf-square-sum { justify-content: center; gap: 0.15rem; cursor: default; }
.cf-square-sum .cf-square-month { font-size: 0.56rem; line-height: 1.1; text-align: center; }
.cf-clients-total { font-size: 0.92rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cf-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 12; display: none;
  min-width: 17rem; max-width: 24rem; max-height: 60vh; overflow: auto;
  padding: 0.5rem 0.6rem; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 22px rgba(15, 30, 60, 0.18);
}
.cf-square-sum:hover > .cf-menu, .cf-square-sum:focus-within > .cf-menu { display: block; }
/* The label cell has a stacking order of its own, so the menu cannot rise above the sticky
   header from inside it: the cell itself is lifted, and only while the square is hovered —
   otherwise it would ride over the frozen month names as the sheet scrolls. */
.cf-table .cf-cash > .cf-label:has(.cf-square-sum:hover),
.cf-table .cf-cash > .cf-label:has(.cf-square-sum:focus-within) { z-index: 20; }
.cf-menu-head { margin: 0.4rem 0 0.25rem; font-size: 0.74rem; font-weight: 700; color: var(--ink); }
.cf-menu-head:first-child { margin-top: 0; }
.cf-menu ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.cf-menu li { display: flex; gap: 0.75rem; font-size: 0.76rem; }
.cf-menu-name { flex: 1 1 auto; color: var(--muted); }
.cf-menu-value { font-variant-numeric: tabular-nums; }

/* The year square next to the clients one: three lines — everything in, everything out, and
   the difference — both blocks together, read from the sheet's own section totals. */
.cf-square-year { gap: 0.05rem; padding-left: 0.1rem; padding-right: 0.1rem; }
.cf-year-row { display: flex; align-items: baseline; justify-content: space-between; gap: 0.1rem; width: 100%; min-width: 0; }
/* The amount always wins the room: the label gives way (and truncates) before the figure can
   overflow the square. Sized so that "entrées" reads in full next to six digits — the usual
   case — and only a seven-digit year shortens it. */
.cf-year-when {
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 0.48rem; font-weight: 600; color: #3b5b8a;
}
.cf-year-value { flex: none; font-size: 0.66rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cf-year-row.is-net { border-top: 1px solid #93c5fd; padding-top: 0.08rem; margin-top: 0.05rem; }
.cf-year-value.is-negative { color: var(--cf-red); }
/* Three squares no longer fit in the narrow label column of a phone: they wrap instead. */
@media (max-width: 640px) { .cf-cash-head { flex-wrap: wrap; } }

/* The months stay in sight: the sheet scrolls inside its own box and the header rows stick to
   its top (their offsets are measured after each render). The squares row scrolls away. */
.cf-scroll { max-height: calc(100vh - 92px); overflow: auto; }
.cf-table thead th { position: sticky; z-index: 6; }
.cf-table .cf-letters > th { background: #f2f2f2; }
.cf-table .cf-title-row > th { background: #fff; }
.cf-table thead .cf-label, .cf-table thead th.cf-rownum { z-index: 8; }
.cf-table .cf-cash > th, .cf-table .cf-cash > td { position: static; }
.cf-table .cf-cash > .cf-label { position: sticky; left: var(--cf-rownum-w); z-index: 4; }

/* The title band of the Brésil block, below the France one. */
.cf-table .cf-block > th, .cf-table .cf-block > td { background: var(--cf-navy); color: #fff; height: 26px; }
.cf-table .cf-block > .cf-label { font-weight: 700; font-size: 13.5px; letter-spacing: 0.02em; }
.cf-table .cf-block > .cf-gap { background: #fff; }

/* The Brésil block wears greens where France wears blues: its rows redefine the palette. */
.cf-table tr.is-br {
  --cf-navy: #14532d;
  --cf-blue: #1e6b45;
  --cf-band: #cfe8d5;
  --cf-total-bg: #a9d7b8;
  --cf-stripe: #f2faf4;
  --cf-border: #9fcaaa;
}
.cf-table tr.is-br.cf-rowgroup > .cf-label,
.cf-table tr.is-br.cf-rowgroup > .cf-num { background: #d8ecdd; border-top-color: #9fcaaa; border-bottom-color: #9fcaaa; }
.cf-table tr.is-br.cf-rowgroup:hover > .cf-label,
.cf-table tr.is-br.cf-rowgroup:hover > .cf-num { background: #c7e3d0; }
.cf-table tr.is-br .cf-rowgroup-name, .cf-table tr.is-br .cf-rowgroup-toggle { color: #14532d; }
.cf-table tr.is-br.cf-line.is-grouped > .cf-label { box-shadow: inset 3px 0 0 #6aa980; }
.cf-table tr.is-br.cf-line:hover > .cf-num,
.cf-table tr.is-br.cf-line:hover > .cf-label { background: #eef8f1; }

/* Group lines ("LOCATIONS"): the sum of their rows, which a click shows or hides. */
.cf-table .cf-rowgroup > .cf-label,
.cf-table .cf-rowgroup > .cf-num {
  background: #dde7f5; height: 22px; border-top: 1px solid #b4c6e7; border-bottom: 1px solid #b4c6e7;
}
.cf-table .cf-rowgroup > .cf-label { padding: 0 3.4rem 0 0.3rem; }
.cf-table .cf-rowgroup > .cf-num .cf-input { font-weight: 700; }
.cf-table .cf-rowgroup:hover > .cf-label,
.cf-table .cf-rowgroup:hover > .cf-num { background: #d0ddf0; }
.cf-rowgroup-name {
  display: flex; align-items: center; gap: 0.4rem; width: 100%; height: 100%; margin: 0; padding: 0;
  border: 0; border-radius: 0; background: none; font: inherit; font-weight: 700; color: var(--cf-navy);
  text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden;
}
.cf-rowgroup-caret { flex: none; width: 0.7rem; }
.cf-rowgroup-count { font-weight: 400; font-size: 11px; color: #595959; }
.cf-rowgroup-toggle {
  display: block; width: 100%; height: 100%; min-height: 20px; margin: 0; padding: 0; border: 0; border-radius: 0;
  background: none; font: inherit; font-size: 13px; font-weight: 700; line-height: 1; color: var(--cf-navy); cursor: pointer;
}
.cf-table .cf-rowgroup:hover .cf-row-actions,
.cf-table .cf-rowgroup > .cf-label:focus-within .cf-row-actions { display: flex; }
/* Rows of an open group: a blue rule and a small indent under their group line. */
.cf-table .cf-line.is-grouped > .cf-label { box-shadow: inset 3px 0 0 #8ea9db; padding-left: 1rem; }

/* Row numbers and column letters, as in the spreadsheet (last, so they win over the row styles) */
.cf-table th.cf-rownum, .cf-table th.cf-letter {
  background: #f2f2f2; color: #595959; font-size: 10.5px; font-weight: 400; font-style: normal;
  text-align: center; padding: 0; height: auto; white-space: nowrap;
  border: 0; border-right: 1px solid #d0d0d0; border-bottom: 1px solid #d0d0d0;
}
.cf-table th.cf-rownum { position: sticky; left: 0; z-index: 3; }
.cf-table .cf-letters > th { height: 16px; }
.cf-table .cf-letters > .cf-corner { z-index: 4; }

@media (max-width: 640px) {
  .cf-card { padding: 0.75rem; }
  .cf-table { --cf-label-w: 180px; --cf-rownum-w: 26px; }
  .cf-title { font-size: 1.15rem; white-space: normal; }
  .cf-table .cf-line > .cf-label { padding-right: 0.3rem; }
  .cf-table .cf-line:hover .cf-row-actions { display: none; }
  .cf-table .cf-line > .cf-label:focus-within .cf-row-actions { display: flex; }
  .cf-row-actions { top: auto; bottom: 100%; transform: none; }
}

@media print {
  .topbar, .cf-toolbar, .cf-add, .cf-row-actions, .cf-bank-lines, .cf-sum, .cf-import { display: none !important; }
  main.wide { padding: 0; }
  .cf-card { border: 0; padding: 0; }
  .table-scroll { overflow: visible; }
  .cf-table { font-size: 9px; }
}

/* ---------- Cash-flow: bank statements ---------- */

/* A small square: the statement is dropped on it, the details are in its tooltip. */
.cf-import { width: var(--cf-square, 90px); flex: none; margin: 0; }
.cf-import .dropzone { box-sizing: border-box; width: 100%; height: var(--cf-square, 90px); min-height: 0; padding: 0.4rem; gap: 0.2rem; text-align: center; }
.cf-import .dropzone-title { font-size: 0.74rem; line-height: 1.2; }
.cf-import .dropzone .muted { display: none; }
.cf-pending {
  margin: 0 0 0.9rem; padding: 0.55rem 0.8rem; border-radius: 7px; font-size: 0.9rem;
  background: #fff7e6; border: 1px solid #f3d19e; color: #7a4b00;
}
.cf-imports { margin-top: 1rem; font-size: 0.9rem; }
.cf-imports summary { cursor: pointer; font-weight: 600; margin-bottom: 0.5rem; }
.cf-imports .inline-form { display: inline; margin-left: 0.75rem; }
/* Amount taken from a bank statement: small green corner, details in the tooltip. */
.cf-table .cf-input.is-imported { background-image: linear-gradient(135deg, #1f7a4d 0 5px, transparent 5px); }

/* Statement lines of the selected expense cell, just below (or above) it. */
.cf-bank-lines {
  position: fixed; z-index: 30; width: min(36rem, calc(100vw - 16px)); max-height: min(24rem, 55vh); overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 30, 60, 0.18); padding: 0.55rem 0.75rem; font-size: 0.85rem; line-height: 1.35;
}
.cf-bank-lines-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; margin-bottom: 0.3rem; }
.cf-bank-lines-head strong { font-size: 0.9rem; }
.cf-bank-lines h4 { margin: 0.55rem 0 0.15rem; font-size: 0.82rem; font-weight: 600; }
.cf-bank-lines h4.is-pending { color: #7a4b00; }
.cf-bank-lines table { width: 100%; border-collapse: collapse; margin: 0; }
.cf-bank-lines td { padding: 0.25rem 0.35rem; border-top: 1px solid var(--line); vertical-align: top; font-size: 0.83rem; }
.cf-bank-lines td.cf-bank-lines-date { white-space: nowrap; color: var(--muted); }
.cf-bank-lines td.cf-bank-lines-amount { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.cf-bank-lines td.cf-bank-lines-file { white-space: nowrap; color: var(--muted); font-size: 0.78rem; }
.cf-bank-lines tr.is-total td { font-weight: 600; }
.cf-bank-lines tr.is-month td { background: var(--bg); font-weight: 600; font-size: 0.8rem; }
.cf-bank-lines-note { margin: 0.35rem 0 0; color: var(--muted); }
.cf-bank-lines-note.is-warning { color: #7a4b00; }

.cf-review .cf-ops th, .cf-review .cf-ops td { padding: 0.4rem 0.5rem; font-size: 0.88rem; vertical-align: middle; }
.cf-review .cf-ops tr.is-unknown td { background: #fff7e6; }
.cf-review .cf-ops select { width: auto; min-width: 16rem; max-width: 100%; margin: 0; padding: 0.3rem 0.4rem; }
.cf-preview-table th, .cf-preview-table td { padding: 0.35rem 0.5rem; font-size: 0.85rem; white-space: nowrap; }
.cf-preview-table .is-real { color: var(--ok); font-weight: 600; }
.cf-preview-table .is-restore { color: #7a4b00; }
.cf-preview-table .is-formula { color: var(--muted); font-style: italic; }
.cf-review .cf-op-amount { white-space: nowrap; font-variant-numeric: tabular-nums; }
.cf-review .cf-ops tr.is-credit .cf-op-amount { color: var(--ok); font-weight: 600; }
#cf-form-error:empty { display: none; }
/* An operation split over several rows: one row and one amount per part. */
.cf-split {
  margin-top: 0.45rem; padding: 0.45rem 0.6rem; background: #f6f8fc;
  border-left: 3px solid #8ea9db; border-radius: 0 6px 6px 0;
}
.cf-split-part { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.35rem; }
.cf-review .cf-split-part select { min-width: 14rem; }
.cf-split-part input { width: 8.5rem; margin: 0; padding: 0.3rem 0.45rem; text-align: right; }
.cf-split-part.is-invalid select, .cf-split-part.is-invalid input { border-color: var(--danger); }
.cf-split-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; font-size: 0.85rem; }
.cf-split-rest.is-ok { color: var(--ok); }
.cf-split-rest.is-error { color: var(--danger); font-weight: 600; }
.cf-review-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-top: 1.2rem;
}

/* ---------- Charts ---------- */

.chart { --plot-h: 180px; }
.chart.is-tall { --plot-h: 240px; }
.chart-body { display: flex; }
.chart-title { font-size: 0.9rem; margin: 1.1rem 0 0.7rem; }

.chart-yaxis { position: relative; width: 52px; height: var(--plot-h); flex: 0 0 52px; }
.chart-yaxis span {
  position: absolute; right: 8px; transform: translateY(50%);
  font-size: 0.7rem; color: var(--muted); white-space: nowrap;
}

.chart-plot { position: relative; flex: 1 1 auto; height: var(--plot-h); min-width: 0; }
.chart-grid { position: absolute; left: 0; right: 0; height: 1px; background: var(--line); }

.chart-cols { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.chart-col {
  position: relative; flex: 1 1 0; height: 100%; min-width: 0;
  display: flex; align-items: flex-end; justify-content: center;
}
.chart-bar {
  width: 100%; max-width: 24px; min-height: 2px;
  background: var(--series-1);
  border-radius: 4px 4px 0 0;
}
.chart-bar.is-current { background: #184f95; }
.chart-col:hover .chart-bar { background: #1c5cab; }
.chart-bar.is-zero { min-height: 0; }

.chart-empty {
  position: absolute; inset: 0; margin: 0; padding: 0 1rem;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 0.85rem; color: var(--muted); pointer-events: none;
}
.chart-empty span { background: var(--card); padding: 0.15rem 0.5rem; border-radius: 4px; }

.chart-xaxis {
  position: relative; display: flex; gap: 2px;
  padding-left: 52px; margin-top: 0.35rem; min-height: 1.1rem;
}
.chart-xaxis span {
  flex: 1 1 0; min-width: 0; text-align: center;
  font-size: 0.7rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chart-xaxis.is-sparse { display: block; height: 1.1rem; }
.chart-xaxis.is-sparse span {
  position: absolute; transform: translateX(-50%); flex: none;
}

.chart-tip {
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 0.72rem; line-height: 1.3;
  padding: 0.3rem 0.5rem; border-radius: 6px; white-space: nowrap;
  /* display, not opacity: a hidden tooltip must not widen the page on small screens. */
  display: none; pointer-events: none; z-index: 5;
}
.chart-tip.tip-start { left: 0; transform: none; }
.chart-tip.tip-end { left: auto; right: 0; transform: none; }
.chart-col:hover > .chart-tip,
.hover-zone:hover > .chart-tip,
.stack-seg:hover > .chart-tip { display: block; }

.chart-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.chart-marker { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--muted); }
.chart-marker span {
  position: absolute; top: 0; left: 4px;
  font-size: 0.68rem; color: var(--muted); white-space: nowrap;
}

.chart-hover { position: absolute; inset: 0; }
.hover-zone { position: absolute; top: 0; bottom: 0; min-width: 6px; transform: translateX(-50%); }
.hover-zone:hover { background: rgba(42, 120, 214, 0.08); }
.hover-dot {
  position: absolute; left: 50%; width: 8px; height: 8px; border-radius: 50%;
  background: var(--series-1); box-shadow: 0 0 0 2px var(--card);
  transform: translate(-50%, 50%); opacity: 0;
}
.hover-zone:hover .hover-dot { opacity: 1; }

.stack-chart { display: flex; flex-direction: column; gap: 0.85rem; }
.stack-track {
  display: flex; gap: 2px; height: 26px; border-radius: 4px; overflow: visible;
}
.stack-track.is-empty { background: var(--line); }
.stack-seg { position: relative; min-width: 2px; }
.stack-seg:first-child { border-radius: 4px 0 0 4px; }
.stack-seg:last-child { border-radius: 0 4px 4px 0; }

.stack-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.stack-legend li { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 10px; }
.legend-name { flex: 1 1 auto; }
.legend-value { font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .topbar { height: auto; padding: 0.75rem 1rem; flex-wrap: wrap; }
  .row-form label, .row-form label.grow { flex: 1 1 100%; }
  .chart-yaxis { width: 42px; flex-basis: 42px; }
  .chart-xaxis { padding-left: 42px; }
  /* Too narrow for a label under every column: keep one in two, untruncated. */
  .chart-xaxis:not(.is-sparse) span { overflow: visible; text-overflow: clip; }
  .chart-xaxis:not(.is-sparse) span:nth-child(even) { visibility: hidden; }
}


/* ---------- Investissements ---------- */
.gain.up { color: var(--ok); }
.gain.down { color: var(--danger); }
/* One line per placement: every amount and every field keeps its column, nothing wraps. */
.inv-top { max-width: 1100px; }
.inv-table th, .inv-table td { white-space: nowrap; vertical-align: middle; padding: 0.45rem 0.5rem; }
.inv-table td.inv-name { white-space: normal; min-width: 13rem; }
.inv-table .inv-when { font-size: 0.75rem; }
.inv-row-form { display: flex; align-items: center; gap: 0.3rem; flex-wrap: nowrap; margin: 0; }
.inv-row-form input { width: 5.6rem; margin: 0; padding: 0.3rem 0.4rem; }
.inv-row-form input[type="date"] { width: 8.4rem; }
.inv-row-form .cf-button { white-space: nowrap; }
.inv-field { width: 5.4rem; margin: 0; padding: 0.3rem 0.4rem; text-align: right; display: inline-block; }
.inv-field.inv-invested { width: 7.2rem; }
.inv-pair { display: flex; gap: 0.25rem; justify-content: flex-end; }
.inv-pair label { font-size: 0.68rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.1rem; align-items: flex-end; }
.inv-tile-form { margin-top: 0.5rem; display: flex; flex-direction: column; gap: 0.2rem; }
.inv-tile-form .inv-row-form input { width: 6.5rem; }
.inv-mini { font-size: 0.84rem; }
.inv-mini th, .inv-mini td { padding: 0.3rem 0.35rem; white-space: nowrap; vertical-align: middle; }
.inv-mini th:first-child, .inv-mini td:first-child { white-space: normal; }
.inv-mini thead th { font-size: 0.7rem; }
.inv-mini tfoot th { border-top: 1px solid var(--line); border-bottom: 0; }
.inv-cat-select { width: auto; max-width: 11rem; margin: 0.25rem 0 0; padding: 0.15rem 0.3rem; font-size: 0.78rem; }
.inv-actions { display: flex; align-items: center; gap: 0.5rem; }
.inv-actions .cf-button { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
.inv-cat > th {
  background: #eef3fb; color: var(--ink); font-size: 0.82rem; font-weight: 700;
  letter-spacing: 0.02em; padding-top: 0.5rem; padding-bottom: 0.5rem;
}
.inv-cat .muted { font-weight: 400; }

/* The parts of the coloured bar: resting on one opens what it is made of. */
.stack-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 6; display: none;
  min-width: 15rem; max-width: 22rem; padding: 0.5rem 0.6rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 22px rgba(15, 30, 60, 0.16); text-align: left;
}
.stack-menu.is-right { left: auto; right: 0; }
.stack-seg:hover > .stack-menu, .stack-seg:focus > .stack-menu, .stack-seg:focus-within > .stack-menu { display: block; }
.stack-menu-head { margin: 0 0 0.35rem; font-size: 0.78rem; font-weight: 700; color: var(--ink); }
.stack-menu ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.stack-menu li { display: flex; gap: 0.75rem; font-size: 0.8rem; }
.stack-menu-name { flex: 1 1 auto; color: var(--muted); }
.stack-menu-value { font-variant-numeric: tabular-nums; }
.inv-more { font-size: 0.85rem; }
.inv-more summary { cursor: pointer; color: var(--accent); }
.inv-more .inv-row-form { margin: 0.4rem 0; }
.inv-history { margin: 0.3rem 0 0; padding-left: 1rem; color: var(--muted); font-size: 0.82rem; }

/* ---------- Retraite ---------- */
.ret-top { max-width: 1100px; }

/* One bar per year: the outline is the budget, the filling what really went out. */
.budget-bar {
  position: relative; width: 100%; max-width: 26px; min-height: 2px;
  display: flex; align-items: flex-end;
  background: var(--accent-soft); border: 1px solid #b9cdea;
  border-radius: 4px 4px 0 0; overflow: hidden;
}
.budget-fill { width: 100%; background: var(--series-1); }
.budget-bar.is-over { border-color: #f5a3ae; }
.budget-bar.is-over .budget-fill { background: var(--danger); }
.chart-col:hover .budget-bar { border-color: var(--accent); }

.budget-legend { flex-direction: row; flex-wrap: wrap; gap: 0.25rem 1.1rem; margin-top: 0.7rem; }
.budget-swatch-plan { background: var(--accent-soft); border: 1px solid #b9cdea; }
.budget-swatch-real { background: var(--series-1); }
.budget-swatch-over { background: var(--danger); }

.ret-entries th, .ret-entries td { padding: 0.35rem 0.4rem; font-size: 0.86rem; vertical-align: middle; }
.ret-entries tr.is-past td { color: var(--muted); }
.ret-entries .ret-placed { white-space: nowrap; }

/* The years whose real spending has been typed, under the bars they fill. */
.ret-years { max-width: 46rem; margin-top: 0.5rem; }
.ret-years th, .ret-years td { padding: 0.35rem 0.5rem; white-space: nowrap; vertical-align: middle; }
.ret-years .inv-row-form input { width: 7.5rem; }

/* ---------- Bascule entre applications ----------
   Chaque application du serveur a sa couleur ; la pastille rappelle où l'on se trouve. */
:root { --env: #2a78d6; }

.brand .env-dot { margin-right: 0.45rem; }
/* Sans cette règle la pastille colle au nom dans le titre de la carte de connexion. */
h1 .env-dot { margin-right: 0.4rem; }
.env-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--env); flex: 0 0 10px;
}

/* Ouverture au clic, pas au survol : le menu est décalé de quelques pixels sous le bouton, et
   en descendant la souris on traversait cette bande morte — le menu se refermait avant qu'on
   puisse cliquer dessus. <details> le garde ouvert jusqu'au prochain clic. */
.env-switch { position: relative; }
.env-switch > summary { list-style: none; cursor: pointer; }
.env-switch > summary::-webkit-details-marker { display: none; }
.env-switch > summary::after { content: " ▾"; color: var(--muted); }
.env-switch[open] > summary { border-color: var(--env); }
.env-current {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 999px;
  padding: 0.3rem 0.75rem; font-size: 0.85rem; white-space: nowrap;
}
.env-current:hover { border-color: var(--env); }
.env-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30;
  min-width: 15rem; padding: 0.35rem; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 26px rgba(15, 30, 60, 0.18);
}
.env-menu a {
  display: grid; grid-template-columns: auto 1fr; gap: 0.1rem 0.5rem; align-items: center;
  padding: 0.45rem 0.55rem; border-radius: 7px; text-decoration: none; color: var(--ink);
}
.env-menu a:hover { background: var(--bg); }
.env-menu .env-name { font-weight: 600; font-size: 0.9rem; }
.env-menu .env-desc { grid-column: 2; font-size: 0.78rem; color: var(--muted); line-height: 1.3; }
