/* ===== Pilot — thème clair (par défaut) ===== */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f1f3f6;
  --appbar: #0d3d35;
  --appbar-2: #15514a;
  --appbar-text: #e6f2ef;
  --text: #101828;
  --text-2: #475467;
  --muted: #667085;
  --border: #e7eaee;
  --border-strong: #d0d5dd;
  --accent: #12805c;
  --accent-hover: #0d6a4b;
  --accent-soft: #e8f6f0;
  --accent-text: #ffffff;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --ok-border: #abefc6;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --warn-border: #fedf89;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --danger-border: #fecdca;
  --info-bg: #f2f4f7;
  --tone-a: #4f6cf7;
  --tone-b: #f08a6c;
  --tone-c: #e5a50a;
  --tone-d: #0e9384;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 16px -4px rgba(16, 24, 40, .1), 0 4px 6px -2px rgba(16, 24, 40, .04);
  --radius: 12px;
  --radius-sm: 8px;
  --ring: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
  color-scheme: light;
}

/* ===== Thème sombre (au choix) ===== */
:root[data-theme="dark"] {
  --bg: #0b1110;
  --surface: #121a19;
  --surface-2: #151f1d;
  --surface-3: #1c2725;
  --appbar: #071311;
  --appbar-2: #12302b;
  --appbar-text: #d5e7e2;
  --text: #f1f4f3;
  --text-2: #c3ccca;
  --muted: #8a9895;
  --border: #22302d;
  --border-strong: #34443f;
  --accent: #3ccf98;
  --accent-hover: #5fdcae;
  --accent-soft: #123228;
  --accent-text: #052016;
  --ok: #47cd89;
  --ok-bg: #0d2a1d;
  --ok-border: #145236;
  --warn: #fdb022;
  --warn-bg: #2e2208;
  --warn-border: #5c4210;
  --danger: #f97066;
  --danger-bg: #2f1414;
  --danger-border: #5f2420;
  --info-bg: #1c2725;
  --tone-a: #7b93ff;
  --tone-b: #f6a38a;
  --tone-c: #f5c451;
  --tone-d: #3ccbb7;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-lg: 0 12px 24px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv11", "ss01";
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0; font-weight: 600; letter-spacing: -.02em; }
h2 { font-size: 1.02rem; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.2em; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
button { font: inherit; }
.block { display: block; }
.grow { flex: 1; min-width: 0; }

/* ===== Barre du haut (sombre, pleine largeur) ===== */
.appbar {
  position: sticky; top: 0; z-index: 20; height: 52px;
  display: flex; align-items: center; gap: 1rem; padding: 0 1rem 0 .85rem;
  background: var(--appbar); color: var(--appbar-text);
}
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; color: #fff; letter-spacing: -.02em; }
.brand:hover { color: #fff; }
.brand .mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: #fff; color: var(--appbar); }
.brand .mark .icon { width: 19px; height: 19px; }
.workspace-pill {
  display: inline-flex; align-items: center; gap: .55rem; list-style: none; cursor: pointer;
  padding: .32rem .7rem .32rem .6rem; border-radius: 99px;
  background: var(--appbar-2); color: #fff; font-weight: 500; font-size: .85rem; white-space: nowrap;
}
.workspace-pill::-webkit-details-marker { display: none; }
.workspace-pill:hover { background: color-mix(in srgb, var(--appbar-2) 80%, #fff); }
.ws-dots { display: inline-flex; }
.ws-dots .dot { width: 9px; height: 9px; border: 2px solid var(--appbar-2); box-sizing: content-box; }
.ws-dots .dot + .dot { margin-left: -5px; }
.top-search { position: relative; flex: 1; max-width: 26rem; margin: 0 0 0 auto; }
.top-search .icon { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: color-mix(in srgb, var(--appbar-text) 70%, transparent); }
.top-search input {
  width: 100%; padding: .42rem .8rem .42rem 2.2rem; font-size: .85rem;
  background: var(--appbar-2); border: 1px solid transparent; color: #fff; box-shadow: none; border-radius: var(--radius-sm);
}
.top-search input::placeholder { color: color-mix(in srgb, var(--appbar-text) 65%, transparent); }
.top-search input:focus { border-color: color-mix(in srgb, #fff 35%, transparent); box-shadow: none; background: color-mix(in srgb, var(--appbar-2) 85%, #fff); }
.top-actions { display: flex; align-items: center; gap: .15rem; }
.top-btn {
  position: relative; display: grid; place-items: center; width: 36px; height: 36px; list-style: none;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--appbar-text); cursor: pointer;
}
.top-btn::-webkit-details-marker { display: none; }
.top-btn:hover { background: var(--appbar-2); color: #fff; }
.top-btn .count {
  position: absolute; top: 3px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 99px; font-size: .65rem; font-weight: 700; line-height: 17px; text-align: center;
  background: #fff; color: var(--appbar);
}
.top-btn .count.warning { background: var(--warn); color: #fff; }
.user-btn { display: inline-flex; align-items: center; gap: .3rem; list-style: none; cursor: pointer; padding: .2rem .3rem .2rem .2rem; border-radius: 99px; color: var(--appbar-text); margin-left: .35rem; }
.user-btn::-webkit-details-marker { display: none; }
.user-btn:hover { background: var(--appbar-2); }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: #c9eadf; color: var(--appbar); font-weight: 700; font-size: .85rem; }
.theme-dark { display: none !important; }
[data-theme="dark"] .theme-dark { display: grid !important; }
[data-theme="dark"] .theme-light { display: none !important; }

/* Menus déroulants */
details.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 17rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: .4rem;
}
.menu-panel.left { left: 0; right: auto; }
.menu-head { padding: .55rem .7rem .6rem; font-weight: 600; font-size: .85rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; }
.menu-item, .notif {
  display: flex; align-items: center; gap: .65rem; width: 100%; padding: .55rem .7rem; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text-2); font-size: .88rem; text-align: left; cursor: pointer;
}
.menu-item:hover, .notif:hover { background: var(--surface-3); color: var(--text); }
.menu-item .icon, .notif .icon { color: var(--muted); }
.menu-panel form { margin: 0; }
.notif { align-items: flex-start; line-height: 1.4; }
.notif.warning .icon { color: var(--warn); }
.notif.info .icon { color: var(--accent); }
.menu-empty { display: flex; align-items: center; gap: .5rem; padding: .75rem .7rem; color: var(--muted); font-size: .88rem; }

/* ===== Colonne d'icônes + contenu ===== */
.shell { display: flex; min-height: calc(100vh - 52px); }
.rail {
  position: sticky; top: 52px; height: calc(100vh - 52px); flex: none; width: 76px;
  display: flex; flex-direction: column; align-items: center; gap: .25rem; padding: .9rem .4rem;
  background: var(--surface); border-right: 1px solid var(--border);
}
.rail a {
  display: flex; flex-direction: column; align-items: center; gap: .2rem; width: 100%;
  padding: .55rem .2rem; border-radius: 10px; color: var(--muted); font-size: .66rem; font-weight: 500;
}
.rail a .icon { width: 21px; height: 21px; }
.rail a:hover { background: var(--surface-3); color: var(--text); }
.rail a.active { background: var(--accent-soft); color: var(--accent); }
.rail-sep { width: 28px; height: 1px; background: var(--border); margin: .4rem 0; }
.content { flex: 1; min-width: 0; }

/* Titre de section + onglets */
.section-bar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 1.2rem 2.25rem 0; }
.section-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; max-width: 1180px; margin: 0 auto; }
.sync-badge {
  display: inline-flex; align-items: center; gap: .45rem; padding: .38rem .8rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-size: .82rem; font-weight: 600; color: var(--text); background: var(--surface);
}
.sync-badge .icon { color: var(--ok); }
.sync-badge .muted { font-weight: 400; }
.sync-badge.warning .icon { color: var(--warn); }
.sync-badge:hover { color: var(--text); border-color: var(--accent); }
.tabs { display: flex; gap: 1.6rem; max-width: 1180px; margin: .9rem auto 0; overflow-x: auto; }
.tabs a { padding: .55rem 0 .7rem; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { max-width: 1180px; margin: 0 auto; padding: 1.5rem 2.25rem 4rem; }

/* ===== En-têtes de page ===== */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.25rem; }
.page-head p { margin: 0; color: var(--muted); }
.page-title { font-size: 1.3rem; margin-top: .45rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin: 2.25rem 0 .9rem; }
.back-link { display: inline-flex; align-items: center; gap: .35rem; font-size: .85rem; font-weight: 500; color: var(--muted); }

/* ===== Boutons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  padding: .55rem 1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-weight: 600; font-size: .88rem; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-text); }
.btn.small { padding: .4rem .8rem; font-size: .84rem; }
.btn.secondary { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-2); color: var(--text); }
.btn.ghost { background: transparent; color: var(--text-2); border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ===== Messages ===== */
.flash {
  display: flex; align-items: flex-start; gap: .65rem;
  padding: .8rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem;
  background: var(--info-bg); color: var(--text-2); border: 1px solid var(--border); font-weight: 500;
}
.flash .icon { margin-top: .1rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.flash.warning { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.flash.danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }

/* ===== Utilitaires ===== */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.credit { color: var(--ok); font-weight: 600; }
.debit { color: var(--text); }
.error-text { color: var(--danger); }
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace; font-size: .88em; letter-spacing: .02em; }
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .74rem; font-weight: 600; line-height: 1.5;
  padding: .02rem .5rem; border-radius: 6px;
  background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap;
}
.badge .icon { width: .85em; height: .85em; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.badge.warning { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.badge.danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dot { width: .5rem; height: .5rem; border-radius: 50%; display: inline-block; flex: none; background: var(--muted); }
.tone-a { --tone: var(--tone-a); } .tone-b { --tone: var(--tone-b); }
.tone-c { --tone: var(--tone-c); } .tone-d { --tone: var(--tone-d); }
.dot[class*="tone-"] { background: var(--tone); }
.account-chip { display: inline-flex; align-items: center; gap: .45rem; font-size: .82rem; color: var(--text-2); white-space: nowrap; }

/* ===== Cartes ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr)); gap: 1.25rem; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.progress.warning > span { background: var(--warn); }
.progress.danger > span { background: var(--danger); }

/* ===== Pilotage : indicateurs + graphique ===== */
.pilotage { display: grid; grid-template-columns: 17rem 1fr; gap: 0; padding: 0; overflow: hidden; }
.kpi-list { display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.kpi-row { display: flex; flex-direction: column; gap: .2rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); color: inherit; }
.kpi-row:last-child { border-bottom: 0; }
a.kpi-row:hover { background: var(--surface-2); color: inherit; }
.kpi-label { display: flex; align-items: center; gap: .45rem; font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kpi-label .icon { width: 15px; height: 15px; color: var(--accent); }
.kpi-line { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.kpi-line strong { font-size: 1.2rem; font-weight: 650; letter-spacing: -.015em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: .78rem; color: var(--muted); }
.chart { padding: 1.25rem 1.25rem .75rem; min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.chart-legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--text-2); }
.chart-legend span { display: inline-flex; align-items: center; gap: .4rem; }
svg.bars { width: 100%; height: auto; display: block; overflow: visible; }
svg.bars .gridline { stroke: var(--border); stroke-dasharray: 3 4; }
svg.bars .axis { fill: var(--muted); font-size: 11px; font-family: inherit; }
svg.bars .axis.current { fill: var(--accent); font-weight: 600; }
svg.bars .value { fill: var(--text-2); font-size: 11px; font-weight: 600; font-family: inherit; }
svg.bars .current-band { fill: var(--accent-soft); }
svg.bars .bar-part { fill: var(--tone); transition: opacity .15s; }
svg.bars a:hover .bar-part { opacity: .8; }

/* ===== Tableaux ===== */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { padding: .8rem 1.25rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: .75rem; color: var(--muted); font-weight: 500; background: var(--surface-2); white-space: nowrap; padding-top: .65rem; padding-bottom: .65rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
tfoot td { border-top: 1px solid var(--border); border-bottom: 0; background: var(--surface-2); font-weight: 600; }
table.compact td, table.compact th { padding: .6rem 1.25rem; }
tr.ignored td { opacity: .45; }
.empty-row { text-align: center; color: var(--muted); padding: 3rem 1rem; }

.tx-main { font-weight: 500; color: var(--text); overflow-wrap: anywhere; }
.tx-sub { font-size: .8rem; color: var(--muted); margin-top: .1rem; overflow-wrap: anywhere; }
.tx-date { font-variant-numeric: tabular-nums; color: var(--text-2); white-space: nowrap; }
.tx-amount { white-space: nowrap; font-weight: 600; }

.payer-select {
  appearance: none; -webkit-appearance: none;
  font: inherit; font-size: .8rem; font-weight: 500;
  border: 1px solid var(--border); border-radius: 6px; box-shadow: none;
  padding: .2rem 1.7rem .2rem .6rem; max-width: 14rem; cursor: pointer;
  background: var(--surface-3) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right .5rem center / .75rem;
  color: var(--text-2);
}
.payer-select.auto { background-color: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.payer-select.manual { background-color: var(--accent-soft); color: var(--accent); border-color: transparent; }
.payer-select.none { background-color: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }

/* ===== Grille ===== */
table.grid th, table.grid td { padding: .6rem .5rem; }
table.grid th:first-child, table.grid td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); padding-left: 1.25rem; min-width: 13rem; }
table.grid th:first-child { background: var(--surface-2); z-index: 2; }
table.grid th.current { color: var(--accent); font-weight: 600; }
table.grid tr.group td { background: var(--surface-2); font-size: .75rem; color: var(--muted); font-weight: 600; padding-top: .5rem; padding-bottom: .5rem; }
table.grid tbody tr:hover td { background: var(--surface); }
table.grid tbody tr.group:hover td { background: var(--surface-2); }
.payer-name { font-weight: 500; color: var(--text); }
a.payer-name:hover { color: var(--accent); }
.payer-meta { display: flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--muted); margin-top: .1rem; }
td.cell { text-align: center; }
.chip {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 6.75rem; padding: .28rem .6rem; border-radius: 6px;
  font-size: .8rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.35;
  border: 1px solid transparent; color: inherit; transition: box-shadow .15s;
}
a.chip:hover { box-shadow: var(--shadow-lg); }
.chip small { font-size: .68rem; font-weight: 400; opacity: .85; }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.chip.partial { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.chip.pending { background: transparent; color: var(--muted); border: 1px dashed var(--border-strong); font-weight: 500; }
.chip.missing { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.chip.neutral { background: var(--surface-3); color: var(--text-2); border-color: var(--border); }
.chip.empty { color: var(--muted); font-weight: 400; }
.legend { display: flex; flex-wrap: wrap; gap: 1.25rem; margin-top: 1rem; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .45rem; }
.legend i { width: .7rem; height: .7rem; border-radius: 3px; display: inline-block; }
.legend i.ok { background: var(--ok); } .legend i.partial { background: var(--warn); }
.legend i.missing { background: var(--danger); } .legend i.pending { border: 1.5px dashed var(--muted); }

.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow); background: var(--surface); }
.seg a { padding: .4rem .85rem; color: var(--text-2); font-size: .83rem; font-weight: 600; border-left: 1px solid var(--border-strong); }
.seg a:first-child { border-left: 0; }
.seg a:hover { background: var(--surface-2); color: var(--text); }
.seg a.active { background: var(--surface-3); color: var(--text); }

.bar-cell { display: flex; align-items: center; gap: .75rem; justify-content: flex-end; }
.bar { flex: 1; max-width: 9rem; height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--tone, var(--accent)); border-radius: 99px; }

/* ===== Formulaires ===== */
input, select, textarea {
  font: inherit; font-size: .9rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: .55rem .8rem; max-width: 100%; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--shadow), var(--ring); }
input::placeholder, textarea::placeholder { color: var(--muted); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 1rem; height: 1rem; box-shadow: none; }
.stack { display: flex; flex-direction: column; gap: 1.25rem; }
.field { display: flex; flex-direction: column; gap: .4rem; font-weight: 500; font-size: .88rem; color: var(--text-2); }
.field input, .field select, .field textarea { font-weight: 400; }
.hint { font-size: .8rem; color: var(--muted); font-weight: 400; }
label.check { display: flex; align-items: center; gap: .6rem; font-weight: 500; color: var(--text-2); cursor: pointer; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1.25rem; }
.form-actions { display: flex; gap: .6rem; padding-top: 1.25rem; border-top: 1px solid var(--border); margin-top: .25rem; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1.25rem; }
.filters select, .filters input { padding: .45rem .7rem; font-size: .85rem; }
.search { position: relative; flex: 1; min-width: 14rem; }
.search .icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { width: 100%; padding-left: 2.3rem; }
form.inline { margin: 0; }
.choice { display: flex; align-items: center; gap: .85rem; padding: .9rem 1rem; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
.choice:hover { border-color: var(--border-strong); background: var(--surface-2); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: var(--ring); }

/* ===== Comptes ===== */
.account-card { display: flex; flex-direction: column; gap: 1.25rem; }
.account-head { display: flex; align-items: center; gap: .9rem; }
.bank-logo { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 10px; background: color-mix(in srgb, var(--tone) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--tone) 25%, var(--border)); color: var(--tone); font-weight: 700; font-size: .9rem; letter-spacing: -.02em; }
.account-head h2 { font-size: 1.05rem; }
.account-head .badge { margin-left: auto; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: .65rem 1.5rem; margin: 0; font-size: .88rem; padding: 1rem 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; overflow-wrap: anywhere; color: var(--text); font-weight: 500; }
.consent { display: flex; flex-direction: column; gap: .5rem; }
.consent-line { display: flex; justify-content: space-between; gap: 1rem; font-size: .84rem; color: var(--text-2); }

/* ===== États vides ===== */
.empty-state { text-align: center; padding: 3rem 1.5rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.empty-state .empty-icon { display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); margin-bottom: 1rem; }
.empty-state .empty-icon .icon { width: 24px; height: 24px; }
.empty-state h2 { margin-bottom: .4rem; }
.empty-state p { color: var(--muted); max-width: 32rem; margin: 0 auto 1.5rem; }
.danger-zone { margin-top: 2.5rem; padding: 1rem 1.25rem; background: var(--surface); border: 1px solid var(--danger-border); border-radius: var(--radius); display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; }

/* ===== Connexion ===== */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; margin: -1.5rem -2.25rem -4rem; background: linear-gradient(180deg, var(--appbar) 0 38%, var(--bg) 38%); }
.login { width: 100%; max-width: 24rem; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2.5rem 2.25rem; box-shadow: var(--shadow-lg); }
.login .brand { font-size: 1.4rem; margin-bottom: .5rem; color: var(--text); }
.login .brand .mark { width: 40px; height: 40px; background: var(--appbar); color: #fff; }
.login .brand .mark .icon { width: 23px; height: 23px; }
.login > p { color: var(--muted); margin: 0 0 1.75rem; }
.login .btn { width: 100%; padding: .7rem; margin-top: .25rem; }
.legal { max-width: 46rem; }
.legal p { color: var(--text-2); }

/* ===== Tablette / mobile ===== */
@media (max-width: 900px) {
  .pilotage { grid-template-columns: 1fr; }
  .kpi-list { border-right: 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr 1fr; }
  .kpi-row:nth-child(odd) { border-right: 1px solid var(--border); }
  .kpi-row:nth-last-child(-n+2) { border-bottom: 0; }
  .top-search { display: none; }
  .top-actions { margin-left: auto; }
}
@media (max-width: 640px) {
  .appbar { gap: .5rem; padding: 0 .5rem; }
  .brand span:last-child { display: none; }
  .workspace-pill > span:not(.ws-dots) { display: none; }
  .shell { flex-direction: column; }
  .rail {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; z-index: 20; height: auto; width: auto;
    flex-direction: row; justify-content: space-around; padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom, 0px));
    border-right: 0; border-top: 1px solid var(--border);
  }
  .rail-sep { display: none; }
  .section-bar { padding: 1rem 1rem 0; }
  main { padding: 1.25rem 1rem 6rem; }
  .sync-badge .muted { display: none; }
  .hide-mobile { display: none; }
  th, td { padding: .65rem .75rem; }
  .cards { grid-template-columns: 1fr; }
  .login-wrap { margin: -1.25rem -1rem -6rem; }
}

/* ===== Couleur de la structure courante (--brand, posée sur <html>) ===== */
:root {
  --brand: #12805c;
  --accent: var(--brand);
  --accent-hover: color-mix(in srgb, var(--brand) 82%, #000);
  --accent-soft: color-mix(in srgb, var(--brand) 9%, #fff);
  --accent-text: #fff;
  --appbar: color-mix(in srgb, var(--brand) 42%, #0b1210);
  --appbar-2: color-mix(in srgb, var(--brand) 62%, #16211e);
  --appbar-text: color-mix(in srgb, var(--brand) 10%, #fff);
}
:root[data-theme="dark"] {
  --accent: color-mix(in srgb, var(--brand) 62%, #fff);
  --accent-hover: color-mix(in srgb, var(--brand) 45%, #fff);
  --accent-soft: color-mix(in srgb, var(--brand) 20%, #121a19);
  --accent-text: #0b1110;
  --appbar: color-mix(in srgb, var(--brand) 16%, #050908);
  --appbar-2: color-mix(in srgb, var(--brand) 32%, #121a19);
  --appbar-text: color-mix(in srgb, var(--brand) 15%, #fff);
}
.avatar { background: color-mix(in srgb, var(--accent) 22%, #fff); }

/* Marque d'une structure : logo ou picto sur sa couleur */
.mark-tile {
  --mark: var(--brand);
  display: grid; place-items: center; flex: none; overflow: hidden;
  width: 34px; height: 34px; border-radius: 9px;
  background: color-mix(in srgb, var(--mark) 14%, var(--surface)); color: var(--mark);
}
.mark-tile .icon { width: 55%; height: 55%; }
.mark-tile img { width: 100%; height: 100%; object-fit: contain; }
.mark-tile.has-logo { background: #fff; border: 1px solid var(--border); padding: 2px; }
.mark-tile.xs { width: 22px; height: 22px; border-radius: 6px; }
.mark-tile.sm { width: 30px; height: 30px; border-radius: 8px; }
.mark-tile.md { width: 40px; height: 40px; border-radius: 10px; }
.mark-tile.lg { width: 44px; height: 44px; border-radius: 11px; background: var(--mark); color: #fff; }
.mark-tile.lg.has-logo { background: #fff; }
.workspace-pill .mark-tile.xs { background: color-mix(in srgb, #fff 18%, transparent); color: #fff; }
.workspace-pill .mark-tile.xs.has-logo { background: #fff; }
.menu-item.current { background: var(--surface-3); color: var(--text); }
.structure-inline { display: inline-flex; align-items: center; gap: .45rem; }
.badge.structure-badge { background: color-mix(in srgb, var(--mark) 12%, var(--surface)); color: var(--mark); border-color: transparent; }

/* Colonne des structures */
.rail { width: 84px; gap: .35rem; }
.rail a { gap: .3rem; padding: .45rem .2rem; font-size: .68rem; text-align: center; line-height: 1.2; }
.rail a:hover { background: transparent; color: var(--text); }
.rail a.active { background: transparent; color: var(--space, var(--accent)); font-weight: 600; }
.rail .mark-tile.rail-tile, .rail-tile.plain {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px;
  background: var(--surface-3); color: var(--muted); transition: background .15s, color .15s, box-shadow .15s;
}
.rail-tile .icon { width: 20px; height: 20px; }
.rail .mark-tile.rail-tile.has-logo { background: #fff; filter: grayscale(.6); opacity: .8; }
.rail a:hover .mark-tile.rail-tile { background: color-mix(in srgb, var(--space) 14%, var(--surface)); color: var(--space); filter: none; opacity: 1; }
.rail a.active .mark-tile.rail-tile { background: var(--space); color: #fff; filter: none; opacity: 1; box-shadow: 0 4px 10px color-mix(in srgb, var(--space) 35%, transparent); }
.rail a.active .mark-tile.rail-tile.has-logo { background: #fff; box-shadow: 0 0 0 2px var(--space), 0 4px 10px color-mix(in srgb, var(--space) 35%, transparent); }
.rail a.admin-link:hover .rail-tile, .rail a.admin-link.active .rail-tile { background: var(--surface-3); color: var(--text); }
.rail a.admin-link.active { color: var(--text); }

/* Titre d'espace */
.space-title { display: flex; align-items: center; gap: .85rem; }
.space-title .muted { display: inline-flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.space-badge { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 11px; background: var(--accent); color: var(--accent-text); flex: none; }
.space-badge .icon { width: 22px; height: 22px; }
.section-bar { border-top: 3px solid var(--accent); }

/* Cartes d'activité (vue d'ensemble) */
.activity-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(24rem, 1fr)); gap: 1.25rem; margin-bottom: .5rem; }
.activity-card {
  display: flex; flex-direction: column; background: var(--surface); color: inherit;
  border: 1px solid var(--border); border-top: 4px solid var(--space); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; transition: box-shadow .15s, transform .15s;
}
.activity-card:hover { color: inherit; box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.activity-head { display: flex; align-items: center; gap: .85rem; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); }
.open-link { display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; font-weight: 600; color: var(--space); white-space: nowrap; }
.activity-kpis { display: grid; grid-template-columns: repeat(4, 1fr); }
.activity-kpis > div { display: flex; flex-direction: column; gap: .15rem; padding: 1rem 1.1rem; border-right: 1px solid var(--border); }
.activity-kpis > div:last-child { border-right: 0; }
.activity-kpis span { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.activity-kpis strong { font-size: 1.15rem; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.activity-kpis small { font-size: .74rem; }

/* Transactions : entrées / sorties */
.flow-cards { display: flex; flex-wrap: wrap; align-items: stretch; gap: 1rem; margin-bottom: 1.25rem; }
.flow-card { flex: 1; min-width: 12rem; display: flex; flex-direction: column; gap: .3rem; padding: 1rem 1.2rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.flow-card strong { font-size: 1.35rem; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.015em; }
.flow-note { flex-basis: 100%; }
.bar.flow-in > span { background: var(--ok); }
.bar.flow-out > span { background: var(--danger); opacity: .7; }

/* Renommage d'un compte */
details.rename summary { display: inline-flex; align-items: center; gap: .45rem; list-style: none; cursor: pointer; }
details.rename summary::-webkit-details-marker { display: none; }
.rename-hint { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; color: var(--muted); opacity: .6; }
details.rename summary:hover .rename-hint { opacity: 1; background: var(--surface-3); color: var(--text); }
details.rename[open] summary { display: none; }
.rename-form { display: flex; gap: .5rem; align-items: center; }
.rename-form input { flex: 1; padding: .4rem .6rem; font-weight: 600; }

@media (max-width: 900px) {
  .activity-kpis { grid-template-columns: 1fr 1fr; }
  .activity-kpis > div:nth-child(2) { border-right: 0; }
  .activity-kpis > div:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
}
@media (max-width: 640px) {
  .rail { width: auto; }
  .rail-tile { width: 34px; height: 34px; border-radius: 10px; }
  .activity-cards { grid-template-columns: 1fr; }
  .open-link { display: none; }
  .space-badge { width: 36px; height: 36px; }
}

/* ===== Utilisateurs et droits ===== */
.user-cell { display: flex; align-items: center; gap: .75rem; color: inherit; }
.user-cell:hover .payer-name { color: var(--accent); }
.avatar.sm { width: 34px; height: 34px; font-size: .85rem; flex: none; }
.badge.role-admin { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.role-gestionnaire { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.roles-matrix td .icon { width: 1.1em; height: 1.1em; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.plain[disabled] input, fieldset.plain[disabled] select, fieldset.plain[disabled] textarea { background: var(--surface-2); color: var(--text-2); box-shadow: none; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .9rem 1rem 1rem; margin: 0; display: flex; flex-direction: column; gap: .75rem; }
.fieldset legend { padding: 0 .4rem; font-weight: 600; font-size: .88rem; color: var(--text-2); }
.fieldset.disabled { opacity: .45; pointer-events: none; }
.role-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .6rem; }
.role-choices .choice { align-items: flex-start; }
.role-choices .choice input { margin-top: .2rem; }
.rail-push { margin-top: auto; }

/* Pages publiques (connexion, mentions) : pleine largeur */
.public main { max-width: none; padding: 0; }
.public .login-wrap { margin: 0; }
.public .flash { position: fixed; top: 1rem; left: 50%; transform: translateX(-50%); z-index: 5; box-shadow: var(--shadow-lg); max-width: calc(100% - 2rem); }
.public .legal { margin: 0 auto; padding: 2.5rem 1.25rem; }

/* Cartes de structures et comptes */
.activity-card { border-top-color: var(--space); }
.structure-card { color: inherit; display: flex; flex-direction: column; gap: 1rem; border-top: 4px solid var(--space); transition: box-shadow .15s; }
.structure-card:hover { color: inherit; box-shadow: var(--shadow-lg); }
.block-chip { display: flex; margin-bottom: .2rem; }
.card-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; }
.card-actions form { margin: 0; }
.inline-confirm { display: flex; align-items: center; gap: .4rem; }
.structure-assign select { padding: .3rem .55rem; font-size: .85rem; }
.add-card { border-style: dashed; }
.add-card h2 { display: flex; align-items: center; gap: .4rem; margin-bottom: 1rem; }
.section-bar.admin { border-top-color: var(--border-strong); }
.role-choices .choice { align-items: center; }

/* Éditeur de structure */
.structure-editor { display: grid; grid-template-columns: minmax(0, 1fr) 20rem; gap: 1.25rem; align-items: start; max-width: 72rem; }
.mode-switch { align-self: flex-start; }
.mode-switch label { padding: .4rem .9rem; font-size: .84rem; font-weight: 600; color: var(--text-2); cursor: pointer; border-left: 1px solid var(--border-strong); }
.mode-switch label:first-child { border-left: 0; }
.mode-switch input { display: none; }
.mode-switch label:has(input:checked) { background: var(--surface-3); color: var(--text); }
#structure-form .mode-logo { display: none; }
#structure-form.is-logo .mode-logo { display: block; }
#structure-form.is-logo .mode-icon { display: none; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: .4rem; }
.icon-choice input { display: none; }
.icon-choice span { display: grid; place-items: center; height: 44px; border: 1px solid var(--border); border-radius: 10px; color: var(--text-2); cursor: pointer; }
.icon-choice span:hover { border-color: var(--border-strong); background: var(--surface-2); }
.icon-choice input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); box-shadow: var(--ring); }
.logo-drop { display: flex; align-items: center; gap: .85rem; padding: 1rem; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); cursor: pointer; color: var(--text-2); }
.logo-drop:hover { border-color: var(--accent); background: var(--surface-2); }
.logo-drop .icon { width: 26px; height: 26px; color: var(--muted); }
.logo-drop input { display: none; }
.color-row { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border-strong); cursor: pointer; padding: 0; }
.swatch.active { box-shadow: 0 0 0 2px var(--text); }
.color-row input[type="color"] { width: 44px; height: 32px; padding: 2px; cursor: pointer; }
.preview { position: sticky; top: 70px; display: flex; flex-direction: column; gap: .6rem; }
.preview-bar { height: 44px; display: flex; align-items: center; padding: 0 .75rem; border-radius: var(--radius) var(--radius) 0 0; background: color-mix(in srgb, var(--brand) 42%, #0b1210); }
.preview-pill { display: inline-flex; align-items: center; gap: .45rem; padding: .25rem .6rem .25rem .3rem; border-radius: 99px; background: color-mix(in srgb, var(--brand) 62%, #16211e); color: #fff; font-size: .8rem; font-weight: 500; }
.preview-pill .mark-tile { background: color-mix(in srgb, #fff 18%, transparent); color: #fff; }
.preview-pill .mark-tile.has-logo { background: #fff; }
.preview-body { margin-top: -.6rem; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--brand); border-radius: 0 0 var(--radius) var(--radius); display: flex; flex-direction: column; gap: .9rem; }
.preview-tabs { display: flex; gap: 1rem; font-size: .82rem; color: var(--muted); border-bottom: 1px solid var(--border); }
.preview-tabs span { padding-bottom: .45rem; }
.preview-tabs .active { color: var(--text); font-weight: 600; border-bottom: 2px solid var(--brand); }
.preview-body .btn { align-self: flex-start; background: var(--brand); border-color: var(--brand); color: #fff; pointer-events: none; }
.preview-accounts { display: flex; flex-direction: column; gap: .3rem; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
@media (max-width: 900px) {
  .structure-editor { grid-template-columns: 1fr; }
  .preview { position: static; }
}

/* ===== Réordonnancement (public/reorder.js) ===== */
.reorder-controls { display: inline-flex; align-items: center; gap: 1px; margin-right: .35rem; vertical-align: middle; flex: none; }
.reorder-handle { display: grid; place-items: center; width: 22px; height: 28px; border-radius: 6px; color: var(--muted); cursor: grab; opacity: .55; }
.reorder-handle:hover { opacity: 1; background: var(--surface-3); color: var(--text); }
.reorder-handle:active { cursor: grabbing; }
.reorder-handle .icon { width: 16px; height: 16px; }
.reorder-btn { display: none; place-items: center; width: 22px; height: 22px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text-2); cursor: pointer; }
.reorder-btn .icon { width: 14px; height: 14px; }
.reorder-btn:hover { color: var(--accent); border-color: var(--accent); }
.reorder-btn:focus-visible { display: grid; }
[data-id]:hover > * .reorder-btn, [data-id]:focus-within .reorder-btn, [data-id]:hover .reorder-btn { display: grid; }
@media (hover: none) { .reorder-handle { display: none; } .reorder-btn { display: grid; } }
[data-reorder] [data-id].dragging { opacity: .45; outline: 2px dashed var(--accent); outline-offset: 2px; }
[data-reorder].saving { cursor: progress; }
tr[data-id].dragging td { background: var(--accent-soft); }
.reorder-row { display: flex; align-items: center; gap: .25rem; padding: .15rem 0; border-radius: 6px; }
.reorder-toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 1rem); z-index: 50;
  padding: .55rem 1rem; border-radius: 99px; background: var(--text); color: var(--surface);
  font-size: .85rem; font-weight: 500; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.reorder-toast.visible { opacity: 1; transform: translate(-50%, 0); }
.reorder-toast.error { background: var(--danger); color: #fff; }
@media (max-width: 640px) { .reorder-toast { bottom: 5.5rem; } }
