/* ---------- Jetons de design ---------- */
:root {
  --ink: #14213d;
  --ink-2: #55607a;
  --paper: #eef1ee;
  --surface: #fbfcfb;
  --line: #d3dad5;
  --green: #2a7a58;
  --green-soft: #dcefe5;
  --litchi: #bf3556;
  --litchi-soft: #f6dde3;
  --ylang: #e0a912;
  --ylang-soft: #faf0cc;
  --radius: 6px;
  --font-display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e9edf4;
    --ink-2: #9aa5bd;
    --paper: #0e1525;
    --surface: #161f33;
    --line: #28344f;
    --green: #5cc59a;
    --green-soft: #173a30;
    --litchi: #f0708c;
    --litchi-soft: #43202c;
    --ylang: #f0c443;
    --ylang-soft: #3b3314;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ylang); outline-offset: 2px; border-radius: 3px; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Structure ---------- */
.shell { display: grid; grid-template-columns: 15rem minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; align-self: start; height: 100vh;
  display: flex; flex-direction: column; gap: 2rem;
  padding: 2rem 1.25rem; border-right: 1px solid var(--line);
}
.brand { font: 700 1.5rem/1 var(--font-display); letter-spacing: -0.02em; text-decoration: none; display: flex; align-items: center; gap: .6rem; }
.brand img { width: 1.9rem; height: 1.9rem; }
.nav { display: flex; flex-direction: column; gap: .25rem; }
.nav a {
  display: flex; align-items: center; gap: .7rem; padding: .6rem .75rem; border-radius: var(--radius);
  text-decoration: none; color: var(--ink-2); font-weight: 500;
}
.nav a:hover { background: var(--surface); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--ink); color: var(--paper); }
.nav svg { width: 1.2rem; height: 1.2rem; flex: none; }
.main { padding: 2.5rem clamp(1rem, 4vw, 3.5rem) 5rem; max-width: 62rem; width: 100%; }

@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: fixed; z-index: 20; inset: auto 0 0 0; height: auto; flex-direction: row;
    padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line); border-right: 0; gap: 0;
  }
  .brand { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: .15rem; font-size: .75rem; padding: .4rem .6rem; }
  .main { padding-top: 1.5rem; padding-bottom: 6rem; }
}

/* ---------- Sections et titres ---------- */
.section { padding: 2rem 0; border-top: 1px solid var(--line); }
.section:first-child { border-top: 0; padding-top: 0; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .5rem 1rem; margin-bottom: 1.1rem; }
h1.page-title { font: 700 clamp(1.7rem, 4vw, 2.3rem)/1.1 var(--font-display); letter-spacing: -0.025em; }
h2 { font: 700 1.3rem/1.2 var(--font-display); letter-spacing: -0.015em; }
.crumb { font-size: .9rem; color: var(--ink-2); text-decoration: none; display: inline-block; margin-bottom: .75rem; }
.crumb:hover { color: var(--ink); text-decoration: underline; }
.lede { color: var(--ink-2); max-width: 46ch; }

/* ---------- Chiffre principal ---------- */
.hero-label { color: var(--ink-2); font-weight: 500; }
.hero-figure {
  font: 700 clamp(2.8rem, 9vw, 5.25rem)/1 var(--font-display);
  letter-spacing: -0.035em; font-variant-numeric: tabular-nums; margin: .15em 0 .3em;
}
.hero-figure.neg, .big.neg { color: var(--litchi); }
.unit { font-size: .42em; font-weight: 500; letter-spacing: 0; color: var(--ink-2); margin-left: .2em; }
.hero-note { color: var(--ink-2); font-size: .92rem; max-width: 60ch; }

.big { font: 700 clamp(1.9rem, 6vw, 3rem)/1.05 var(--font-display); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.big small { font: 500 1rem var(--font-body); letter-spacing: 0; color: var(--ink-2); margin-left: .4rem; }

/* ---------- Ruban du cycle ---------- */
.ribbon-wrap { margin-top: 1.4rem; }
.ribbon {
  position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  gap: 2px; height: 7rem; padding-bottom: 10px;
}
.ribbon .day { position: relative; display: flex; align-items: flex-end; height: 100%; }
.ribbon .bar { width: 100%; height: var(--h); min-height: 3px; background: var(--ink); border-radius: 2px 2px 0 0; opacity: .88; }
.ribbon .day.future .bar { background: var(--line); opacity: 1; }
.ribbon .day.over .bar { background: var(--litchi); opacity: 1; }
.ribbon .day.today::after {
  content: ''; position: absolute; left: -1px; right: -1px; bottom: -10px; height: 4px; background: var(--ylang); border-radius: 2px;
}
.ribbon .ref { position: absolute; left: 0; right: 0; bottom: calc(10px + (100% - 10px) * var(--ref)); border-top: 1.5px dashed var(--ink-2); pointer-events: none; }
.ribbon-axis { display: flex; justify-content: space-between; margin-top: .9rem; font-size: .8rem; color: var(--ink-2); }
.ribbon-legend { margin-top: .5rem; font-size: .82rem; color: var(--ink-2); }

/* ---------- Faits clés (listes de définitions) ---------- */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: 1.25rem 2rem; margin: 0; }
.facts div { min-width: 0; }
.facts dt { color: var(--ink-2); font-size: .88rem; }
.facts dd { margin: .1rem 0 0; font: 700 1.4rem/1.2 var(--font-display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.facts dd.pos { color: var(--green); }
.facts dd.neg { color: var(--litchi); }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; margin: 0 -.25rem; padding: 0 .25rem; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: .6rem .6rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 600; color: var(--ink-2); font-size: .85rem; white-space: nowrap; }
th.num, td.num { text-align: right; white-space: nowrap; }
tbody tr:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); }
tfoot td { font-weight: 600; border-bottom: 0; border-top: 2px solid var(--ink); }
tr.empty-row td { color: var(--ink-2); }
td a.row-link { font-weight: 600; text-decoration: none; }
td a.row-link:hover { text-decoration: underline; }
.date-row td { background: color-mix(in srgb, var(--ink) 5%, transparent); font-weight: 600; font-size: .85rem; color: var(--ink-2); padding-block: .35rem; }
.actions { display: flex; gap: .25rem; justify-content: flex-end; }

.status { display: inline-flex; align-items: center; gap: .45rem; font-size: .88rem; white-space: nowrap; }
.status::before { content: ''; width: .6rem; height: .6rem; border-radius: 50%; background: var(--green); flex: none; }
.status.goal_missed::before, .status.over_budget::before { background: var(--litchi); }
.status.empty::before { background: var(--line); }

.meter { height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: .3rem; min-width: 4rem; }
.meter > i { display: block; height: 100%; width: var(--w); background: var(--green); }
.meter.over > i { background: var(--litchi); }

/* ---------- Formulaires ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field > label { font-size: .88rem; font-weight: 500; color: var(--ink-2); }
input, select, textarea {
  width: 100%; min-height: 2.7rem; padding: .5rem .7rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
input:hover, select:hover, textarea:hover { border-color: var(--ink-2); }
textarea { min-height: 7rem; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: .9rem; align-items: end; }
.form-row.quick { grid-template-columns: 8.5rem 9rem 7.5rem minmax(8rem, 1fr) 8rem auto; }
@media (max-width: 800px) { .form-row.quick { grid-template-columns: 1fr 1fr; } .form-row.quick .field.grow, .form-row.quick .btn { grid-column: 1 / -1; } }
.form-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.25rem; align-items: center; }
.hint { font-size: .85rem; color: var(--ink-2); }
.error { color: var(--litchi); font-weight: 500; min-height: 1.4em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 2.7rem; padding: .5rem 1.1rem;
  border: 1px solid var(--ink); background: var(--ink); color: var(--paper); border-radius: var(--radius);
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { border-color: var(--ink); filter: none; }
.btn.danger { background: transparent; color: var(--litchi); border-color: var(--litchi); }
.icon-btn {
  display: inline-grid; place-items: center; width: 2.1rem; height: 2.1rem; padding: 0;
  border: 0; background: transparent; border-radius: var(--radius); color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--line); color: var(--ink); }
.icon-btn.danger:hover { background: var(--litchi-soft); color: var(--litchi); }
.icon-btn svg { width: 1.1rem; height: 1.1rem; }

.year-switch { display: inline-flex; align-items: center; gap: .25rem; }
.year-switch strong { font: 700 1.3rem var(--font-display); min-width: 3.5rem; text-align: center; font-variant-numeric: tabular-nums; }

.empty { padding: 2rem; border: 1px dashed var(--line); border-radius: var(--radius); display: grid; gap: 1rem; justify-items: start; }
.empty p { max-width: 50ch; }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login form { width: min(22rem, 100%); display: grid; gap: 1.1rem; }
.login .brand { font-size: 2rem; margin-bottom: .5rem; }

/* ---------- Dialogue et notifications ---------- */
dialog { width: min(34rem, calc(100vw - 2rem)); padding: 1.5rem; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; }
dialog::backdrop { background: rgb(8 12 24 / .55); }
dialog h2 { margin-bottom: 1rem; }
#toast {
  position: fixed; left: 50%; bottom: 5.5rem; transform: translate(-50%, 1rem); z-index: 50; opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper); padding: .65rem 1.1rem; border-radius: var(--radius); font-weight: 500;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--litchi); color: #fff; }
@media (min-width: 801px) { #toast { bottom: 2rem; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.loading { color: var(--ink-2); padding: 3rem 0; }
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 2rem; }

td.neg { color: var(--litchi); }
td.pos { color: var(--green); }
