:root {
  --navy: #1F3A5F; --navy-dark: #132640; --ink: #15202B; --muted: #4A5868; --line: #DDE2E8;
  --bg: #F4F5F7; --soft: #EEF1F5; --green: #1E7A46; --green-ink: #14502E; --green-bg: #E5F4E4;
  --red: #B42318; --amber-ink: #7A4A0E; --amber-bg: #FFF0D9; --focus: #F2A541;
  --mono: "Cascadia Mono", Consolas, "Courier New", ui-monospace, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: "Segoe UI", Inter, system-ui, -apple-system, sans-serif; font-size: 17px; line-height: 1.4; }
a { color: var(--navy); }
a:hover { color: var(--navy-dark); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Menu latéral fixe */
.layout { display: flex; min-height: 100vh; align-items: flex-start; }
.sidebar { position: sticky; top: 0; height: 100vh; width: 232px; flex: none; background: var(--navy); color: #fff; display: flex; flex-direction: column; gap: 22px; padding: 22px 14px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: 700; padding: 0 8px; }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav a { display: flex; align-items: center; gap: 12px; color: #D5DEEA; text-decoration: none; padding: 13px 14px; font-size: 17px; font-weight: 500; border-radius: 10px; }
.side-nav a svg { flex: none; }
.side-nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.side-nav a.active { color: var(--navy); background: #fff; font-weight: 700; }
.side-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 14px; padding: 0 6px; }
.sync { font-size: 14px; font-weight: 600; padding: 6px 12px; border-radius: 999px; align-self: flex-start; }
.sync::before { content: "● "; }
.sync-ok { background: rgba(159, 227, 180, .18); color: #BDF0CB; }
.sync-wait { background: rgba(242, 165, 65, .2); color: #FFD9A3; }
.me-box { display: flex; flex-direction: column; gap: 4px; color: #D5DEEA; }
.me-name { font-size: 17px; font-weight: 700; color: #fff; }
.me-role { font-size: 14px; }
.me-actions { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; }
.me-link { background: none; border: 0; padding: 6px 0; font: inherit; font-size: 15px; color: #fff; text-decoration: underline; cursor: pointer; min-height: 36px; }

/* Connexion */
.login-wrap { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 56px 16px; background: var(--bg, #F4F6F9); }
.login-card { width: 100%; max-width: 560px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 36px; display: flex; flex-direction: column; gap: 20px; box-shadow: 0 8px 30px rgba(31,58,95,.08); }
.login-brand { display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: 700; color: var(--navy); }
.login-title { font-size: 28px; }
.login-form { display: flex; flex-direction: column; gap: 18px; }
.login-form .btn { width: 100%; justify-content: center; }
.code-input { font-size: 30px; letter-spacing: .25em; text-align: center; font-variant-numeric: tabular-nums; }
.login-help summary { cursor: pointer; font-weight: 600; color: var(--navy); padding: 6px 0; }
.setup-steps { margin: 0; padding-left: 24px; display: flex; flex-direction: column; gap: 14px; line-height: 1.5; }
.qr-box { width: 230px; height: 230px; margin: 12px 0 4px; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.qr-box svg { width: 100%; height: 100%; display: block; }
.secret { font-size: 18px; word-break: break-all; background: #F4F6F9; padding: 10px 12px; border-radius: 8px; }
.recovery-codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 24px; padding: 18px; border: 2px dashed var(--line); border-radius: 10px; font-size: 20px; }
@media print {
  .login-card .actions, .login-card .check, .login-brand svg { display: none !important; }
  .login-wrap { padding: 0; background: #fff; } .login-card { box-shadow: none; border: 0; }
}

/* Mise en page */
.main { flex: 1; min-width: 0; max-width: 1500px; margin: 0 auto; padding: 32px 24px 64px; display: flex; flex-direction: column; gap: 24px; outline: none; }
.main.narrow { max-width: 1000px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
h1 { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 22px; font-weight: 700; }
.lead { margin: 6px 0 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 12px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 22px; }
.card.tight { padding: 18px 20px; flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: 24px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.span2 { grid-column: span 2; }
.note { margin: 0; font-size: 15px; color: var(--muted); }
.back { font-size: 17px; font-weight: 600; text-decoration: none; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } .span2 { grid-column: auto; } }

/* Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 17px; font-weight: 600; min-height: 50px; padding: 10px 20px; border-radius: 10px; border: 2px solid var(--navy); background: #fff; color: var(--navy); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--soft); color: var(--navy); }
.btn.primary { background: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-dark); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.big { font-size: 18px; min-height: 56px; padding: 14px 30px; font-weight: 700; }
.btn[disabled] { background: var(--soft); border-color: #C9D2DC; color: var(--muted); cursor: not-allowed; }
.pill { font-size: 16px; font-weight: 600; min-height: 50px; padding: 10px 18px; border-radius: 10px; cursor: pointer; background: #fff; color: var(--navy); border: 2px solid #9AA9BA; }
.pill[aria-pressed="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }
.pills { display: flex; flex-wrap: wrap; gap: 10px; }
.copy { font-size: 14px; font-weight: 600; min-height: 36px; min-width: 64px; padding: 6px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; background: #fff; color: var(--navy); border: 2px solid #9AA9BA; }
.copy.done { background: var(--green); border-color: var(--green); color: #fff; }
.link-btn { background: none; border: none; padding: 6px 4px; color: var(--navy); font-weight: 600; text-decoration: underline; cursor: pointer; font-size: 15px; }

/* Formulaires */
.field { display: flex; flex-direction: column; gap: 8px; }
.field > label, .field > .label { font-weight: 600; }
.input { font-size: 18px; padding: 12px 16px; border: 2px solid #B8C2CE; border-radius: 10px; min-height: 52px; background: #fff; width: 100%; }
textarea.input { resize: vertical; min-height: 80px; }
select.input { padding: 12px 14px; }
.input.mono { font-family: var(--mono); }
.input.ok { border-color: var(--green); }
.input.bad { border-color: var(--red); }
.input.warn { border-color: #D98A1F; background: #FFF8EC; }
.help.warn { color: var(--amber-ink); font-weight: 600; }
.input[readonly] { background: var(--bg); border-color: var(--line); }
.help { font-size: 15px; color: var(--muted); }
.help.ok { color: var(--green-ink); font-weight: 600; }
.help.bad { color: var(--red); font-weight: 600; }
.amount { text-align: right; font-variant-numeric: tabular-nums; }

/* Encadrés */
.banner { border-radius: 12px; padding: 16px 22px; font-size: 18px; font-weight: 600; }
.banner.ok { background: var(--green-bg); border: 2px solid var(--green); color: var(--green-ink); }
.banner.bad { background: #FDECEC; border: 2px solid var(--red); color: var(--red); }
.banner.info { background: var(--amber-bg); border: 2px solid #F2C98A; color: var(--amber-ink); }

/* Chiffres clés */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; display: flex; flex-direction: column; gap: 6px; }
.kpi .k-label { font-size: 16px; color: var(--muted); font-weight: 500; }
.kpi .k-value { white-space: nowrap; font-size: clamp(22px, 1.8vw, 32px); font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .k-sub { font-size: 15px; color: var(--muted); }
.kpi.main { background: var(--navy); color: #fff; border-color: var(--navy); }
.kpi.main .k-label, .kpi.main .k-sub { color: #D5DEEA; }
.kpi.warn { background: #FFF6E8; border-color: #F2C98A; }
.kpi.warn .k-label, .kpi.warn .k-value, .kpi.warn .k-sub { color: var(--amber-ink); }
.kpi.bad { background: #FDECEC; border-color: #F1B5B0; }
.kpi.bad .k-label, .kpi.bad .k-value, .kpi.bad .k-sub { color: #8F1D14; }
.kpi.ok { background: #EEF8EE; border-color: #B5DDB9; }
.kpi.ok .k-label, .kpi.ok .k-value, .kpi.ok .k-sub { color: #14502E; }
.kpi.muted { background: #F0EFEC; border-color: #D6D3CC; }
.kpi.muted .k-label, .kpi.muted .k-sub { color: #4A4740; }
.kpi .k-row { display: flex; justify-content: space-between; gap: 12px; font-size: 16px; font-variant-numeric: tabular-nums; }

/* Tableaux */
.table-box { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; font-size: 16px; }
table.grid.wide { min-width: 1100px; }
table.grid.wide td:first-child { min-width: 120px; }
table.grid.wide td:nth-child(2) { min-width: 140px; }
table.grid th, table.grid td { padding: 14px 10px; vertical-align: middle; text-align: left; }
table.grid th:first-child, table.grid td:first-child { padding-left: 18px; }
table.grid th:last-child, table.grid td:last-child { padding-right: 18px; }
table.grid thead th { background: var(--soft); font-size: 15px; color: #33414F; font-weight: 600; }
table.grid tbody tr { border-top: 1px solid #E6EAEF; }
table.grid tr.group { background: #F7F9FB; border-top: 2px solid #C9D2DC; }
table.grid tr.group th { font-weight: 400; padding-top: 16px; padding-bottom: 16px; }
.g-name { font-size: 19px; font-weight: 700; color: var(--ink); }
.g-meta { font-size: 15px; color: var(--muted); margin-left: 12px; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.center { text-align: center !important; }
.sub { font-size: 14px; color: var(--muted); }
.strong { font-weight: 600; }
.mono { font-family: var(--mono); white-space: nowrap; font-size: 14px; }
.iban-cell { display: flex; align-items: center; gap: 10px; }
.badge { display: inline-block; font-weight: 700; font-size: 14px; padding: 4px 10px; border-radius: 6px; background: var(--soft); color: #33414F; }
.badge.stale { font-size: 13px; font-weight: 600; padding: 3px 8px; background: var(--amber-bg); color: var(--amber-ink); margin-top: 4px; }
.badge.closed { background: #F0EFEC; color: var(--muted); }
tr.review td { background: #FFF7F6; }
.badge.review { font-size: 13px; padding: 3px 8px; margin-top: 4px; background: #FDECEC; color: #8F1D14; }
.review-reason { font-size: 14px; color: #8F1D14; font-weight: 600; margin-top: 4px; }
.pill-bad[aria-pressed="true"] { background: #B42318; border-color: #B42318; }
.toggles { display: flex; flex-direction: column; gap: 4px; }
.toggle { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border-radius: 10px; cursor: pointer; }
.toggle:hover { background: var(--soft); }
.toggle input { width: 26px; height: 26px; flex: none; accent-color: var(--navy); }
tr.edited { background: #FBFDF9; }
.empty { padding: 40px; text-align: center; font-size: 18px; color: var(--muted); }
@keyframes flash { from { background: #FFF3C4; } to { background: transparent; } }
tr.flash td { animation: flash 2.5s ease-out; }

/* Barre d'enregistrement */
.savebar { background: #fff; border: 2px solid var(--navy); border-radius: 14px; padding: 18px 22px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; position: sticky; bottom: 16px; box-shadow: 0 6px 24px rgba(21, 32, 43, .12); }
.savebar .msg { font-size: 18px; font-weight: 600; }

/* Messages éphémères */
.toasts { position: fixed; right: 24px; bottom: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 50; }
.toast { background: var(--ink); color: #fff; padding: 14px 20px; border-radius: 10px; font-size: 16px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 420px; }
.toast.ok { background: var(--green-ink); }
.toast.bad { background: var(--red); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Cases à cocher, pastilles de statut, boutons-icônes */
.check { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--navy); }
.status-badge { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; padding: 4px 12px 4px 10px; border-radius: 999px; background: var(--soft); white-space: nowrap; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; display: inline-block; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 46px; height: 46px; border-radius: 10px; border: 2px solid transparent; text-decoration: none; }
.icon-btn.small { width: 32px; height: 32px; border-radius: 8px; }
.icon-btn.small svg { width: 18px; height: 18px; }
.icon-btn.edit { background: #E7F1FB; color: #1F5FA8; border-color: #B9D3F0; }
.icon-btn.edit:hover { background: #D3E5F8; color: #174C88; }
.icon-btn.add { background: #E5F4E4; color: #1E7A46; border-color: #B5DDB9; }
.icon-btn.add:hover { background: #D2ECD4; color: #14502E; }
.order-list { display: flex; flex-direction: column; gap: 8px; }
.order-row { display: flex; align-items: center; gap: 14px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.order-row .num-pos { width: 28px; font-weight: 700; color: var(--muted); }
.order-row .lbl { flex: 1; display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 600; }
.arrow-btn { width: 46px; height: 46px; border-radius: 10px; border: 2px solid #9AA9BA; background: #fff; color: var(--navy); font-size: 20px; font-weight: 700; cursor: pointer; }
.arrow-btn[disabled] { opacity: .35; cursor: not-allowed; }
.color-input { width: 56px; height: 46px; padding: 2px; border: 2px solid #B8C2CE; border-radius: 10px; background: #fff; cursor: pointer; }
table.grid.wide th, table.grid.wide td { padding-left: 7px; padding-right: 7px; }
table.grid.wide th:first-child, table.grid.wide td:first-child { padding-left: 16px; }
table.grid.wide th:last-child, table.grid.wide td:last-child { padding-right: 14px; }

/* Gestion des flux */
.flux-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; display: flex; flex-direction: column; gap: 18px; }
.flux-card.full { background: #F3F3F2; border: 2px solid #D9534A; }
.flux-card.full .g-name, .flux-card.full .mono { color: #6B6F75; }
.flux-card.full .table-box { opacity: .85; }
.flux-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 14px; }
.flux-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1100px) { .flux-grid { grid-template-columns: 1fr; } }
.flux-cap { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-radius: 10px; background: var(--bg); }
.flux-card.full .flux-cap { background: #FDECEC; }
.bar { height: 14px; border-radius: 999px; background: #DDE2E8; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 999px; }
@keyframes flashcard { from { box-shadow: 0 0 0 4px #FFE08A; } to { box-shadow: 0 0 0 0 transparent; } }
.flash-card { animation: flashcard 2.5s ease-out; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; border-bottom: 2px solid var(--line); }
.tab { font-size: 18px; font-weight: 600; padding: 12px 22px; min-height: 50px; border: none; background: none; color: var(--muted); cursor: pointer; border-bottom: 4px solid transparent; margin-bottom: -2px; }
.tab:hover { color: var(--navy); }
.tab[aria-selected="true"] { color: var(--navy); border-bottom-color: var(--navy); font-weight: 700; }
.kpi.info { background: #E7F1FB; border-color: #B9D3F0; }
.kpi.info .k-label, .kpi.info .k-value, .kpi.info .k-sub { color: #174C88; }
