/* Layout : barre d'application en haut, sous-menu vertical à gauche, écran principal, panneau de détail à droite */
:root {
  --orange: #E4884F; --orange-deep: #B8622E; --ink: #2B2724; --cream: #FEFFF2; --peach: #FBF1E6;
  --beige: #E9D8C8; --sage: #E2EBD6; --muted: #7A716A;
  --bg: #FBF8F4; --surface: #FFFFFF; --surface-2: #FBF1E6; --line: #E9D8C8; --line-soft: #F2E7DC;
  --fg: #2B2724; --fg-2: #5E5650; --head-bg: #2B2724; --head-fg: #FFFFFF; --accent: #E4884F; --accent-ink: #B8622E;
  --accent-soft: #FCE9DC; --pos: #4E7A3A; --pos-soft: #E2EBD6; --neg: #B23A2B; --neg-soft: #F8DDD8; --warn: #A86A12; --warn-soft: #FBEBC9;
  --calc: #3F6E8C; --calc-soft: #E1ECF3; --assoc: #7A5C93; --assoc-soft: #EDE5F3; --fin: #4E7A3A; --fin-soft: #E2EBD6;
  --shadow: 0 10px 30px rgba(43, 39, 36, .14);
  --font-ui: "Figtree", "Segoe UI", Arial, sans-serif;
  --font-num: "Figtree", "Segoe UI", Arial, sans-serif;
  --font-code: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191715; --surface: #221F1C; --surface-2: #2A2622; --line: #3A342F; --line-soft: #2F2A26;
    --fg: #F1EAE2; --fg-2: #BDB3AA; --muted: #9A9088; --head-bg: #120F0D; --head-fg: #F1EAE2; --accent: #E4884F; --accent-ink: #F0A36F;
    --accent-soft: #3A2A1F; --pos: #9CC487; --pos-soft: #26321F; --neg: #F08A7A; --neg-soft: #3B221E; --warn: #E8B45A; --warn-soft: #3A2E18;
    --calc: #8DB9D6; --calc-soft: #1F2D37; --assoc: #C3A6DB; --assoc-soft: #2D2436; --fin: #9CC487; --fin-soft: #26321F;
    --cream: #26231F; --peach: #2A2622; --sage: #26321F; --beige: #3A342F; --shadow: 0 10px 30px rgba(0, 0, 0, .5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #191715; --surface: #221F1C; --surface-2: #2A2622; --line: #3A342F; --line-soft: #2F2A26;
  --fg: #F1EAE2; --fg-2: #BDB3AA; --muted: #9A9088; --head-bg: #120F0D; --head-fg: #F1EAE2; --accent: #E4884F; --accent-ink: #F0A36F;
  --accent-soft: #3A2A1F; --pos: #9CC487; --pos-soft: #26321F; --neg: #F08A7A; --neg-soft: #3B221E; --warn: #E8B45A; --warn-soft: #3A2E18;
  --calc: #8DB9D6; --calc-soft: #1F2D37; --assoc: #C3A6DB; --assoc-soft: #2D2436; --fin: #9CC487; --fin-soft: #26321F;
  --cream: #26231F; --peach: #2A2622; --sage: #26321F; --beige: #3A342F; --shadow: 0 10px 30px rgba(0, 0, 0, .5); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--fg); font-family: var(--font-ui); font-size: 14px; line-height: 1.45; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 50; background: var(--surface); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.code { font-family: var(--font-code); font-size: 12px; letter-spacing: .01em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Barre supérieure ---------- */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 40; background: var(--surface); border-bottom: 2px solid var(--accent);
  display: flex; align-items: center; gap: 18px; padding-block: 8px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; }
.brand img { height: 26px; width: auto; }
.brand b { font-size: 15px; letter-spacing: .01em; }
.brand span { color: var(--muted); font-weight: 500; }
.crumbs { display: flex; align-items: center; gap: 6px; color: var(--fg-2); min-width: 0; font-size: 13px; }
.crumbs button { background: none; border: 0; padding: 2px 4px; border-radius: 4px; color: var(--fg-2); }
.crumbs button:hover { background: var(--surface-2); color: var(--fg); }
.crumbs .cur { color: var(--fg); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 2px; margin-left: auto; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 7px 12px; border-radius: 6px; font-weight: 600; color: var(--fg-2); }
.tabs button:hover { background: var(--surface-2); color: var(--fg); }
.tabs button[aria-current="true"] { background: var(--ink); color: #fff; }
:root[data-theme="dark"] .tabs button[aria-current="true"] { background: var(--accent); color: #1A1512; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tabs button[aria-current="true"] { background: var(--accent); color: #1A1512; } }
.pill-demo { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent-ink); background: var(--accent-soft); padding: 3px 8px; border-radius: 99px; }

/* ---------- Coque ---------- */
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: calc(100% - 52px); }
.side { border-right: 1px solid var(--line); background: var(--surface); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.side h4 { margin: 10px 8px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.side button { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; color: var(--fg-2); }
.side button:hover { background: var(--surface-2); color: var(--fg); }
.side button[aria-current="true"] { background: var(--accent-soft); color: var(--fg); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.side .cnt { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.side .note { margin: 14px 8px 0; padding: 10px; border-radius: 6px; background: var(--cream); border: 1px solid var(--line); font-size: 12px; color: var(--fg-2); }
.main { min-width: 0; padding-block: 22px 60px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.main-inner { max-width: 1320px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
@media (min-width: 900px) { .main { padding-left: 28px; padding-right: max(28px, env(safe-area-inset-right, 0px)); } }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .side h4, .side .note { display: none; }
  .side button { width: auto; white-space: nowrap; }
}

/* ---------- En-têtes d'écran ---------- */
.screen-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.screen-head h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; text-wrap: balance; }
.screen-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 7px 12px; border-radius: 6px; font-weight: 600; color: var(--fg); }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #000; }
:root[data-theme="dark"] .btn.primary { background: var(--accent); border-color: var(--accent); color: #1A1512; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { background: var(--accent); border-color: var(--accent); color: #1A1512; } }
.btn.ghost { background: none; border-color: transparent; color: var(--fg-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.danger { color: var(--neg); }
.btn[aria-pressed="true"] { background: var(--surface-2); border-color: var(--accent); }

/* ---------- Tuiles chiffres ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.tile .k { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
.tile .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.tile .s { font-size: 12px; color: var(--fg-2); }
.tile.neg .v { color: var(--neg); }

/* ---------- Panneaux ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.panel > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.panel > header h2 { margin: 0; font-size: 15px; }
.panel > .body { padding: 14px 16px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1050px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- Tableaux ---------- */
.tbl-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { background: var(--head-bg); color: var(--head-fg); font-weight: 700; text-align: left; padding: 8px 10px; border-bottom: 2px solid var(--accent); white-space: nowrap; font-size: 12px; position: sticky; top: 0; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.t tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--peach) 55%, var(--surface)); }
table.t tbody tr.row-click { cursor: pointer; }
table.t tbody tr.row-click:hover td { background: var(--accent-soft); }
table.t tbody tr.is-open td { background: var(--accent-soft); box-shadow: inset 0 1px 0 var(--accent), inset 0 -1px 0 var(--accent); }
table.t tbody tr.flash td { animation: flash 1.4s ease-out; }
@keyframes flash { 0% { background: var(--accent); } 100% { } }
table.t tfoot td { font-weight: 700; background: var(--cream); border-top: 2px solid var(--line); }
table.t td.lbl { font-weight: 600; min-width: 190px; }
table.t .sel { width: 30px; }
.fin-table td, .fin-table th { padding: 6px 10px; }
.fin-table tr.grp td { font-weight: 700; background: var(--surface-2) !important; text-transform: uppercase; font-size: 11px; letter-spacing: .07em; color: var(--fg-2); }
.fin-table tr.tot td { font-weight: 700; background: var(--cream) !important; border-top: 1px solid var(--line); }
.fin-table tr.big td { font-weight: 800; background: var(--sage) !important; }
.fin-table tr.sub td:first-child { padding-left: 28px; color: var(--fg-2); }
.fin-table tr.sub td { font-size: 12px; }
.fin-table td.neg, .neg-t { color: var(--neg); }
.fin-table th.ex { background: color-mix(in srgb, var(--head-bg) 85%, var(--accent)); }
.fin-table td.first { position: sticky; left: 0; background: inherit; z-index: 1; min-width: 230px; }
.fin-table th.first { left: 0; z-index: 2; }
.toggle-row { background: none; border: 0; padding: 0; display: inline-flex; gap: 6px; align-items: center; font-weight: inherit; text-align: left; }
.toggle-row .car { display: inline-block; width: 10px; color: var(--muted); transition: transform .15s; }
.toggle-row[aria-expanded="true"] .car { transform: rotate(90deg); }

/* ---------- Pastilles (paiement, indexation, liens) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 2px 9px 2px 7px; font-size: 12px; line-height: 18px; border: 1px solid transparent; white-space: nowrap; background: var(--surface-2); color: var(--fg-2); }
button.chip { cursor: pointer; }
button.chip:hover { border-color: currentColor; }
.chip .c { font-family: var(--font-code); font-size: 11px; opacity: .85; }
.chip.calc { background: var(--calc-soft); color: var(--calc); }
.chip.assoc { background: var(--assoc-soft); color: var(--assoc); }
.chip.fin { background: var(--fin-soft); color: var(--fin); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.pay { background: transparent; border-color: var(--line); color: var(--fg-2); }
.chip.idx { background: transparent; border-color: var(--line); color: var(--fg-2); }
.chip svg { flex: none; }
.dash { color: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--fg-2); align-items: center; }

/* ---------- Barre d'action groupée ---------- */
.bulk { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; background: var(--ink); color: #fff; border-radius: 8px; }
.bulk select, .bulk input { background: #3a3430; border: 1px solid #5a514b; color: #fff; border-radius: 5px; padding: 4px 6px; }
.bulk .btn { background: var(--accent); border-color: var(--accent); color: #1A1512; }
.bulk .btn.ghost { background: none; color: #fff; border-color: #5a514b; }

/* ---------- Graphiques ---------- */
.chart { width: 100%; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font-ui); }
.chart .axis { stroke: var(--line); }
.chart .zero { stroke: var(--fg-2); stroke-dasharray: 3 3; }
.chart .bar { fill: var(--accent); }
.chart .bar.alt { fill: var(--orange-deep); }
.chart .bar.neg { fill: var(--neg); }
.chart .line { fill: none; stroke: var(--ink); stroke-width: 2; }
:root[data-theme="dark"] .chart .line { stroke: var(--fg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chart .line { stroke: var(--fg); } }
.chart .area { fill: var(--accent); opacity: .16; }
.chart .grid { stroke: var(--line-soft); }
.chart .exsep { stroke: var(--line); stroke-dasharray: 2 4; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .dot.neg { fill: var(--neg); }

/* ---------- Panneau de détail (tiroir) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(20, 16, 13, .28); z-index: 60; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100%); background: var(--surface); z-index: 61; box-shadow: var(--shadow);
  display: flex; flex-direction: column; border-left: 3px solid var(--accent); padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); padding-right: env(safe-area-inset-right, 0px); }
.drawer .dh { padding: 14px 18px 0; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.drawer .dh-top { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.drawer .dh h2 { margin: 0; font-size: 18px; display: flex; gap: 10px; align-items: baseline; min-width: 0; }
.drawer .dh h2 .code { font-size: 13px; color: var(--accent-ink); }
.drawer .dtabs { display: flex; gap: 2px; overflow-x: auto; }
.drawer .dtabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 10px; font-weight: 600; color: var(--fg-2); white-space: nowrap; }
.drawer .dtabs button[aria-current="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.drawer .dtabs .n { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--surface-2); font-size: 11px; }
.drawer .db { flex: 1; overflow-y: auto; padding: 16px 18px 24px; display: flex; flex-direction: column; gap: 16px; }
.drawer .df { border-top: 1px solid var(--line); padding: 10px 18px; display: flex; justify-content: space-between; gap: 8px; background: var(--cream); }
.backlink { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--accent-ink); background: var(--accent-soft); border: 0; border-radius: 99px; padding: 3px 10px; align-self: flex-start; }
.iconbtn { background: none; border: 0; padding: 6px; border-radius: 6px; color: var(--fg-2); line-height: 0; }
.iconbtn:hover { background: var(--surface-2); color: var(--fg); }

/* ---------- Formulaires ---------- */
.form { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px 14px; }
.f { display: flex; flex-direction: column; gap: 4px; grid-column: span 3; min-width: 0; }
.f.s2 { grid-column: span 2; } .f.s6 { grid-column: span 6; } .f.s4 { grid-column: span 4; }
@media (max-width: 520px) { .f, .f.s2, .f.s4 { grid-column: span 6; } }
.f label, .lab { font-size: 12px; font-weight: 600; color: var(--fg-2); }
.f input, .f select, .f textarea, .inp { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 7px 9px; width: 100%; min-width: 0; }
.f input:focus, .f select:focus, .inp:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.f input.num { text-align: right; }
.f .hint { font-size: 12px; color: var(--muted); }
.unit { position: relative; }
.unit input { padding-right: 46px; }
.unit span { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; pointer-events: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; padding: 2px; gap: 2px; background: var(--surface-2); flex-wrap: wrap; }
.seg button { border: 0; background: none; border-radius: 5px; padding: 5px 10px; font-weight: 600; color: var(--fg-2); font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.sec { display: flex; flex-direction: column; gap: 10px; }
.sec > h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--accent-ink); display: flex; align-items: center; gap: 8px; }
.sec > h3::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.callout { background: var(--cream); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 6px; padding: 10px 12px; font-size: 13px; color: var(--fg-2); }
.callout b { color: var(--fg); }
.season { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; }
.season div { display: flex; flex-direction: column; gap: 3px; align-items: stretch; }
.season span { font-size: 10px; text-align: center; color: var(--muted); }
.season input { border: 1px solid var(--line); border-radius: 5px; padding: 4px 2px; text-align: center; font-size: 12px; width: 100%; background: var(--surface); font-variant-numeric: tabular-nums; }
@media (max-width: 520px) { .season { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.terms { display: flex; flex-direction: column; gap: 6px; }
.term { display: grid; grid-template-columns: 110px 1fr 32px; gap: 8px; align-items: center; }
.bar100 { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--surface-2); }
.bar100 i { display: block; height: 100%; }
.linkrow { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.linkrow .who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.linkrow .who .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.linkrow .pctin { width: 80px; }
.addlink { display: grid; grid-template-columns: minmax(0, 1fr) 140px 90px auto; gap: 8px; align-items: end; }
@media (max-width: 520px) { .addlink { grid-template-columns: 1fr 1fr; } }
.mini-tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.mini-tbl th { text-align: right; font-weight: 600; color: var(--muted); padding: 4px 6px; border-bottom: 1px solid var(--line); }
.mini-tbl th:first-child, .mini-tbl td:first-child { text-align: left; }
.mini-tbl td { padding: 4px 6px; border-bottom: 1px solid var(--line-soft); text-align: right; font-variant-numeric: tabular-nums; }
.checklist { display: flex; flex-direction: column; gap: 6px; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.check input[type=checkbox] { width: 16px; height: 16px; flex: none; accent-color: var(--accent); }
.check .amt { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--fg-2); }

/* ---------- Alertes ---------- */
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 10px 12px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface); }
.alert .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; }
.alert.red .dot { background: var(--neg); } .alert.orange .dot { background: var(--warn); } .alert.green .dot { background: var(--pos); }
.alert b { display: block; }
.alert p { margin: 2px 0 0; color: var(--fg-2); font-size: 13px; }

/* ---------- Carte des liens ---------- */
.map-wrap { position: relative; overflow-x: auto; }
.map { position: relative; display: grid; grid-template-columns: repeat(4, minmax(190px, 1fr)); gap: 0 70px; padding: 8px 4px 20px; min-width: 960px; }
.map svg.edges { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.map .col { display: flex; flex-direction: column; gap: 8px; position: relative; z-index: 1; }
.map .col h3 { margin: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.node { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 7px 10px; display: flex; flex-direction: column; gap: 1px; transition: opacity .15s, border-color .15s; }
.node .c { font-family: var(--font-code); font-size: 11px; color: var(--accent-ink); }
.node .l { font-size: 13px; font-weight: 600; line-height: 1.25; }
.node:hover { border-color: var(--accent); }
.node.dim { opacity: .3; }
.node.hot { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.node.lonely { border-style: dashed; }
.edge { fill: none; stroke-width: 1.6; opacity: .75; transition: opacity .15s; }
.edge.calc { stroke: var(--calc); } .edge.assoc { stroke: var(--assoc); stroke-dasharray: 4 4; } .edge.fin { stroke: var(--fin); stroke-width: 2.4; }
.edge.dim { opacity: .07; }

/* ---------- Accueil ---------- */
.home { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.clients { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.client { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.client h3 { margin: 0; font-size: 16px; }
.dossier { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 7px; padding: 9px 11px; background: var(--cream); text-align: left; width: 100%; }
.dossier:hover:not([disabled]) { border-color: var(--accent); }
.dossier[disabled] { cursor: default; opacity: .65; background: var(--surface); }
.dossier .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent-ink); font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 7px; z-index: 80; font-size: 13px; box-shadow: var(--shadow); }
.kpi-row { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.tag { white-space: nowrap; display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--fg-2); }
.tag.ok { background: var(--pos-soft); color: var(--pos); } .tag.ko { background: var(--neg-soft); color: var(--neg); } .tag.mid { background: var(--warn-soft); color: var(--warn); }
.ex-switch { display: inline-flex; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

@media (max-width: 820px) {
  .topbar { position: static; gap: 8px 12px; }
  .crumbs { display: none; }
  .tabs { margin-left: 0; width: 100%; flex-wrap: nowrap; overflow-x: auto; order: 3; }
  .tabs button { white-space: nowrap; }
  .pill-demo { margin-left: auto; }
  .drawer { border-left: 0; }
}

/* ---------- V2 : accueil, modèles, assistant ---------- */
.client-h { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.dossier-row { display: flex; flex-direction: column; gap: 4px; }
.dossier-acts { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.tpls { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.tpl { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.tpl h3 { margin: 0; font-size: 15px; }
.tpl p { margin: 0; }
.modal { position: fixed; z-index: 70; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(760px, calc(100% - 24px)); max-height: calc(100% - 40px); background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); display: flex; flex-direction: column; border-top: 3px solid var(--accent); }
.scrim + .modal { }
#modal-root .scrim { z-index: 69; }
.modal .mh { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal .mh h2 { margin: 0; font-size: 18px; }
.modal .mb { overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 18px; }
.modal .mf { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--cream); flex-wrap: wrap; border-radius: 0 0 10px 10px; }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 7px; cursor: pointer; background: var(--surface); }
.choice:hover { border-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 3px; accent-color: var(--accent); flex: none; }
.choice > span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

/* ---------- V2 : montants mensuels et arrêts ---------- */
.mgrid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 560px) { .mgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.mcell { position: relative; display: flex; flex-direction: column; gap: 2px; }
.mcell label { font-size: 11px; color: var(--muted); }
.mcell input { border: 1px solid var(--line); border-radius: 5px; padding: 5px 6px; width: 100%; text-align: right; font-size: 12px; background: var(--surface); font-variant-numeric: tabular-nums; }
.mcell input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.mcell.over input { border: 2px solid var(--accent); font-weight: 700; background: var(--accent-soft); }
.mcell.paused input { color: var(--muted); background: repeating-linear-gradient(135deg, var(--surface), var(--surface) 5px, var(--surface-2) 5px, var(--surface-2) 10px); }
.mreset { position: absolute; top: 0; right: 0; border: 0; background: none; color: var(--accent-ink); padding: 0 2px; line-height: 0; }
.mtag { position: absolute; top: 1px; right: 2px; font-size: 10px; color: var(--muted); }
.mtoggles { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; }
@media (max-width: 560px) { .mtoggles { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.mtoggles button { border: 1px solid var(--line); background: var(--surface); border-radius: 5px; padding: 5px 0; font-size: 12px; color: var(--fg-2); }
.mtoggles button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
:root[data-theme="dark"] .mtoggles button[aria-pressed="true"] { background: var(--accent); color: #1A1512; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .mtoggles button[aria-pressed="true"] { background: var(--accent); color: #1A1512; border-color: var(--accent); } }
.pause-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.inline-check { display: inline-flex; gap: 6px; align-items: center; }
.inline-check input { accent-color: var(--accent); }
.chip.adj { background: var(--warn-soft); color: var(--warn); font-size: 11px; padding: 0 8px; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent-ink); text-decoration: underline; font-size: 12px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
label.btn { cursor: pointer; }
label.btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; }
.chart .hlband { fill: var(--accent-soft); }
th.csa { background: color-mix(in srgb, var(--head-bg) 70%, var(--calc)) !important; }
.ex-strip { display: flex; gap: 4px; margin-top: 14px; }
.exb { display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; border-radius: 6px; background: var(--surface-2); border-top: 3px solid var(--accent); font-size: 12px; min-width: 0; }
.exb:first-child { border-top-color: var(--orange-deep); }
@media (max-width: 640px) { .ex-strip { flex-direction: column; } }

/* ---------- V2 : compte courant ---------- */
.mv-list { display: flex; flex-direction: column; gap: 6px; }
.mv { display: grid; grid-template-columns: 150px 170px 120px minmax(0, 1fr) auto; gap: 6px; align-items: center; }
@media (max-width: 620px) { .mv { grid-template-columns: 1fr 1fr; } }
.cc-tbl td:first-child { min-width: 170px; }
.cc-tbl tr.mh td { background: var(--surface-2); font-weight: 700; text-transform: uppercase; font-size: 10px; letter-spacing: .07em; color: var(--fg-2); text-align: left; padding-top: 8px; }
.cc-tbl tr.b td { font-weight: 700; }

.cc-tbl tr.b td .muted { font-weight: 400; }
.linkrow .pctin { width: 96px; }
.pctin input, .check .unit input, .mv .unit input { padding-right: 26px; }

/* ---------- V3 : commentaires ---------- */
textarea { font: inherit; color: inherit; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 9px 11px; width: 100%; line-height: 1.5; resize: vertical; }
textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.note-ta { background: color-mix(in srgb, var(--warn-soft) 45%, var(--surface)); }
.panel.cm .body { display: flex; flex-direction: column; gap: 8px; }
.cm-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cm-tools .muted { margin-left: auto; }
.cm-prev { border-left: 3px solid var(--accent); background: var(--cream); padding: 8px 12px; border-radius: 4px; font-size: 13px; }
.cm-prev p { margin: 0 0 6px; }
.chip.var { background: var(--surface); border-color: var(--line); font-family: var(--font-code); font-size: 11px; }
.nicons { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.ni { display: inline-flex; line-height: 0; padding: 2px; border-radius: 4px; }
.ni.c { color: var(--accent-ink); background: var(--accent-soft); }
.ni.n { color: var(--warn); background: var(--warn-soft); }

/* ---------- V3 : véhicules ---------- */
.chip.veh { background: var(--calc-soft); color: var(--calc); }
.veh-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .veh-layout { grid-template-columns: 1fr; } }
.veh-list { display: flex; flex-direction: column; gap: 6px; }
.veh-item { display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--fg); }
.veh-item > svg { margin-top: 3px; color: var(--accent-ink); flex: none; }
.veh-item span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.veh-item[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }
.bar-in { width: 74px; text-align: right; padding: 5px 7px; }
.f.s3 { grid-column: span 3; }

/* ---------- V3 : compte courant, échéanciers ---------- */
.plan { display: grid; grid-template-columns: 1.3fr 1fr 1fr .8fr 1.4fr; gap: 8px 10px; align-items: end; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); position: relative; }
.plan .f { grid-column: auto; }
.plan > input.inp { grid-column: span 4; }
.plan > .inline-check { grid-column: span 1; }
.plan > .iconbtn { position: absolute; top: 4px; right: 4px; }
@media (max-width: 620px) { .plan { grid-template-columns: 1fr 1fr; } .plan > input.inp { grid-column: span 2; } }

/* ---------- V3 : export ---------- */
.exp-layout { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1050px) { .exp-layout { grid-template-columns: 1fr; } }
.exp-cfg { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.choices.one { grid-template-columns: 1fr; }
.choice .iconbtn { margin-left: auto; padding: 2px; }
.sec-list { display: flex; flex-direction: column; gap: 2px; }
.sec-row { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.sec-row:hover { background: var(--surface-2); }
.sec-row input { accent-color: var(--accent); }
.sec-row.na { opacity: .5; cursor: default; }
.sec-row.warn { background: var(--neg-soft); }
.exp-prev { position: sticky; top: calc(64px + env(safe-area-inset-top, 0px)); }
.rp-paper { background: #FFFFFF; color: #2B2724; margin: 16px; padding: 32px 36px; box-shadow: 0 2px 14px rgba(43, 39, 36, .15); border-top: 3px solid #E4884F; max-height: 78vh; overflow: auto; font-size: 12px; line-height: 1.45; }
.rp-cover { display: flex; flex-direction: column; gap: 6px; padding: 40px 0 30px; }
.rp-cover img { width: 150px; margin-bottom: 26px; }
.rp-cv-t { font-size: 24px; font-weight: 800; }
.rp-cv-c { font-size: 17px; color: #B8622E; font-weight: 600; }
.rp-cv-s, .rp-cv-f { color: #7A716A; }
.rp-cv-f { margin-top: 20px; padding-top: 14px; border-top: 3px solid #E4884F; width: max-content; max-width: 100%; }
.rp-pb { border-top: 1px dashed #E9D8C8; margin: 18px -36px; position: relative; }
.rp-pb::after { content: "saut de page"; position: absolute; right: 8px; top: -9px; font-size: 10px; background: #FFFFFF; color: #7A716A; padding: 0 4px; }
.rp-h1 { color: #B8622E; font-size: 16px; margin: 20px 0 8px; }
.rp-h2 { font-size: 13px; margin: 12px 0 6px; color: #2B2724; }
.rp-p { margin: 0 0 8px; text-wrap: pretty; }
.rp-kpi { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 4px 0 12px; }
.rp-kpi div { background: #FEFFF2; border: 1px solid #E9D8C8; padding: 7px 9px; display: flex; flex-direction: column; gap: 2px; }
.rp-kpi span { font-size: 9px; text-transform: uppercase; letter-spacing: .06em; color: #7A716A; font-weight: 700; }
.rp-kpi b { font-size: 14px; font-variant-numeric: tabular-nums; }
.rp-notes { margin: -4px 0 12px; font-size: 11px; color: #5E5650; }
.rp-notes p { margin: 0 0 3px; }
.rp-tw { overflow-x: auto; margin: 0 0 12px; }
.rp-t { border-collapse: collapse; width: 100%; font-size: 11px; font-variant-numeric: tabular-nums; }
.rp-t.small { font-size: 10px; } .rp-t.tiny { font-size: 9px; }
.rp-t th { background: #2B2724; color: #FFFFFF; text-align: left; padding: 4px 6px; border-bottom: 2px solid #E4884F; white-space: nowrap; }
.rp-t td { padding: 3px 6px; border-bottom: 1px solid #F2E7DC; }
.rp-t th.r, .rp-t td.r { text-align: right; white-space: nowrap; }
.rp-t tbody tr:nth-child(even) td { background: #FBF1E6; }
.rp-t tr.tot td { font-weight: 700; background: #FEFFF2 !important; }
.rp-t tr.big td { font-weight: 800; background: #E2EBD6 !important; }
.rp-t tr.sub td { color: #5E5650; }
.rp-t tr.grp td { font-weight: 700; text-transform: uppercase; font-size: 9px; letter-spacing: .06em; color: #7A716A; background: #FBF1E6 !important; }
.f input[type=checkbox] { width: auto; }
.plan { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.plan > input.inp { grid-column: span 2; }
.plan > .inline-check { grid-column: span 1; align-self: center; }
.mv { grid-template-columns: 130px minmax(150px, 1fr) 110px minmax(0, 1fr) auto; }
@media (max-width: 620px) { .plan { grid-template-columns: 1fr 1fr; } .plan > input.inp { grid-column: span 2; } .mv { grid-template-columns: 1fr 1fr; } }

/* ---------- V4 : fenêtre centrée, déductibilité, affectation, mention de responsabilité ---------- */
.db-main, .db-side { display: contents; }
.dmode { gap: 5px; padding: 4px 8px; }
.dmode svg { flex: none; }
.scrim.dim { background: rgba(20, 16, 13, .45); }
.drawer.center { top: 50%; left: 50%; right: auto; bottom: auto; transform: translate(-50%, -50%); width: min(1200px, calc(100% - 48px)); height: min(940px, calc(100% - 48px));
  border-left: 0; border-top: 3px solid var(--accent); border-radius: 12px; overflow: hidden; padding-top: 0; }
.drawer.center .dh { padding: 16px 24px 0; }
.drawer.center .db { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); gap: 24px; align-items: start; padding: 20px 24px 28px; }
.drawer.center .db-main { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.drawer.center .db-side { display: block; position: sticky; top: 0; background: var(--cream); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.drawer.center .df { padding: 12px 24px; }
.drawer.center .mgrid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
@media (max-width: 900px) { .drawer.center .db { grid-template-columns: minmax(0, 1fr); } .drawer.center .db-side { position: static; } }
@media (max-width: 640px) { .drawer.center { width: 100%; height: 100%; border-radius: 0; } .dmode span { display: none; } }
.chip.ded { background: var(--assoc-soft); color: var(--assoc); font-size: 11px; padding: 0 8px; }
.chip.on { background: var(--accent); color: #fff; }
#dedsec .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.alloc-t td.n { vertical-align: top; }
.al-in { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.al-in .unit { width: 140px; }
.al-in input, .al-pp input { text-align: right; }
.al-pp { width: 140px; margin-left: auto; }
.al-rate { max-width: 220px; font-size: 12px; }
.rp-disc { margin-top: 18px; break-inside: avoid; }
.rp-disc p { background: #FEFFF2; border-left: 3px solid #E4884F; padding: 8px 10px; margin: 0; font-size: 12px; line-height: 1.5; }
.rp-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-top: 36px; }
.rp-sign div { border-top: 1px solid #7A716A; padding-top: 4px; display: flex; flex-direction: column; font-size: 11px; }
.rp-sign span { color: #7A716A; }
#exp-disc { width: 100%; }

/* ---------- Application en ligne : connexion, enregistrement ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: 12px; padding: 28px 26px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-logo { width: 150px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0; }
.login-ms { justify-content: center; padding: 10px 12px; }
.login-or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.login-or::before, .login-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { font-size: 12px; font-weight: 600; color: var(--fg-2); }
.login-form input { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 9px 10px; }
.login-form input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.login-form .btn { justify-content: center; }
.login-msg { font-size: 13px; color: var(--fg-2); min-height: 1em; }
.login-msg.err { color: var(--neg); }
.save-st { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.save-st.ok { background: var(--pos-soft); color: var(--pos); }
.save-st.mid { background: var(--warn-soft); color: var(--warn); }
.save-st.ko { background: var(--neg-soft); color: var(--neg); }
.user-chip { font-size: 12px; font-weight: 600; color: var(--fg-2); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Logo (lettres noires) lisible en mode sombre */
:root[data-theme="dark"] .login-logo { background: #FEFFF2; padding: 8px 12px; border-radius: 8px; box-sizing: content-box; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .login-logo { background: #FEFFF2; padding: 8px 12px; border-radius: 8px; box-sizing: content-box; } }
