:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #714b67; --accent-soft: #f3edf2; --ok: #1f7a4d; --ok-soft: #e7f5ee;
  --bad: #b42318; --bad-soft: #fdecea; --warn: #8a5a00; --warn-soft: #fff5dc;
  --z-libelle: rgba(59, 130, 246, .13); --z-reference: rgba(139, 92, 246, .15);
  --z-debit: rgba(220, 38, 38, .14); --z-credit: rgba(22, 163, 74, .15); --z-montant: rgba(234, 179, 8, .18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b; --card: #1d2027; --text: #e6e8ec; --muted: #9aa1ad; --line: #2f333c;
    --accent: #c79bbd; --accent-soft: #2e2530; --ok: #5ccf94; --ok-soft: #173024;
    --bad: #ff8a80; --bad-soft: #3a1d1b; --warn: #f5c451; --warn-soft: #3a2f14;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
h1, h2, h3 { margin: 0 0 .5rem; }
h2 { font-size: 1.35rem; margin-top: .5rem; }
h3 { font-size: 1rem; margin-top: .25rem; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: .75rem; }
.login-card label { display: grid; gap: .25rem; }

/* En-tête */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.25rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { color: var(--accent); font-size: 1.05rem; }
.tabs, .subtabs { display: flex; gap: .25rem; flex-wrap: wrap; }
.tabs { flex: 1; }
.tabs button, .subtabs button { border: 0; background: none; padding: .45rem .8rem; border-radius: 6px; cursor: pointer; color: var(--muted); font: inherit; }
.tabs button.active, .subtabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.subtabs { margin: .5rem 0 1rem; border-bottom: 1px solid var(--line); padding-bottom: .5rem; }
.who { color: var(--muted); }
.version { font-size: .8rem; }
main { padding: 1rem 1.25rem 4rem; max-width: 1400px; margin: 0 auto; }

/* Blocs */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .75rem 1rem; align-items: start; }
.field { display: grid; gap: .25rem; }
.field > span { font-weight: 600; font-size: .85rem; }
.check { display: inline-flex; align-items: center; gap: .35rem; }
.actions { display: flex; gap: .5rem; margin: 0 0 1rem; flex-wrap: wrap; }
.actions.sticky { position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; border-top: 1px solid var(--line); }
.export-bar { display: flex; gap: 1rem; align-items: end; flex-wrap: wrap; }
.test-file { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .75rem; }
.test-file p { flex-basis: 100%; margin: .25rem 0 0; }
.fichiers { list-style: none; margin: 0; padding: 0; display: flex; gap: .5rem; flex-wrap: wrap; }
.fichiers li { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .2rem .5rem; }
.explications { margin: .25rem 0; padding-left: 1.1rem; }
.explications li { margin-bottom: .2rem; }
.odoo-send { display: flex; gap: .75rem; align-items: end; flex-wrap: wrap; padding-left: 1rem; border-left: 1px solid var(--line); }
.odoo-link { color: var(--accent); font-weight: 600; align-self: center; }
.msg.problems { flex-basis: 100%; }
.msg.problems ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.test-report { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .75rem; }
.test-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin: .75rem 0; }
.test-grid h4, .test-report h4 { margin: 0 0 .35rem; font-size: .9rem; }
.ok-text { color: var(--ok); font-weight: 600; }
.warn-text { color: var(--warn); font-weight: 600; }
.file-pick { display: inline-flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.file-name { color: var(--ok); font-weight: 600; }
.file-list { margin: .5rem 0 0; padding-left: 1.1rem; }
.file-list li { display: flex; gap: .5rem; align-items: center; margin-bottom: .2rem; }
.inline-add { display: flex; gap: .5rem; margin-top: .75rem; }

input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: .4rem .5rem; width: 100%; min-width: 0; }
input[type=checkbox] { width: auto; }
input[type=file] { border: 0; padding: 0; width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input.acct { font-variant-numeric: tabular-nums; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: .45rem .9rem; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.icon { border: 0; background: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; line-height: 1; }
.icon:hover { color: var(--bad); }

/* Messages et contrôles */
.msg { padding: .55rem .8rem; border-radius: 8px; margin-bottom: .5rem; }
.msg.error, .error { background: var(--bad-soft); color: var(--bad); }
.msg.warn { background: var(--warn-soft); color: var(--warn); }
.control.ok { border-left: 4px solid var(--ok); background: var(--ok-soft); }
.control.bad { border-left: 4px solid var(--bad); background: var(--bad-soft); }
div.control:not(.card) { padding: .5rem .8rem; border-radius: 8px; margin: .5rem 0; }

/* Tableaux */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: .35rem .4rem; border-bottom: 1px solid var(--line); }
td { padding: .2rem .4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.plain td { padding: .4rem; }
table.small { font-size: .85rem; }
.edit-table { overflow-x: auto; }
.edit-table > .btn { margin-top: .5rem; }
.edit-table td input, .edit-table td select { padding: .3rem .4rem; }
tr.totals td { font-weight: 700; border-top: 2px solid var(--line); padding: .5rem .4rem; }
tr.totals.bad td { color: var(--bad); }
tr.debit input.num { color: var(--bad); }
.row-actions { white-space: nowrap; display: flex; gap: .35rem; }
details > summary { cursor: pointer; font-weight: 600; }

/* Paramètres : liste + éditeur */
.split { display: grid; grid-template-columns: 280px 1fr; gap: 1rem; align-items: start; }
.split > * { min-width: 0; }
.famille h4 { margin: .75rem 0 .15rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--accent); }
.famille ul { margin: 0; }
.list ul { list-style: none; margin: .75rem 0 0; padding: 0; }
.list li { padding: .5rem .6rem; border-radius: 6px; cursor: pointer; display: grid; }
.list li:hover { background: var(--bg); }
.list li.active { background: var(--accent-soft); }
.zone-inputs { display: flex; align-items: center; gap: .35rem; }
.zone-inputs input { width: 6rem; }

/* Calibrage PDF */
.calib-panel { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.calib-tools { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin: .75rem 0; }
.calib-tools .btn.active { outline: 2px solid var(--text); }
.btn.z-libelle { background: var(--z-libelle); } .btn.z-reference { background: var(--z-reference); }
.btn.z-debit { background: var(--z-debit); } .btn.z-credit { background: var(--z-credit); } .btn.z-montant { background: var(--z-montant); }
.legend { color: var(--muted); font-size: .85rem; margin-left: auto; }
.legend i { display: inline-block; width: .8rem; height: .8rem; border-radius: 2px; margin: 0 .2rem 0 .6rem; vertical-align: -1px; }
.legend i.op, .pline.op { background: var(--ok-soft); }
.legend i.solde, .pline.solde { background: var(--warn-soft); }
.legend i.ignore { background: var(--line); }
.pline.ignore { opacity: .45; }
.calib-view { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.calib-canvas { position: relative; font: 11px/1 ui-monospace, Consolas, monospace; }
.band { position: absolute; top: 0; bottom: 0; pointer-events: none; }
.band span { position: sticky; top: 3.2rem; font: 600 10px system-ui; padding: 1px 3px; opacity: .8; }
.band.z-libelle { background: var(--z-libelle); } .band.z-reference { background: var(--z-reference); }
.band.z-debit { background: var(--z-debit); } .band.z-credit { background: var(--z-credit); } .band.z-montant { background: var(--z-montant); }
.pline { position: relative; height: 17px; border-bottom: 1px dotted var(--line); }
.pitem { position: absolute; top: 2px; white-space: nowrap; cursor: pointer; padding: 0 1px; border-radius: 2px; }
.pitem:hover { outline: 1px solid var(--accent); background: var(--card); z-index: 2; }
.page-sep { background: var(--accent-soft); color: var(--accent); font: 600 11px system-ui; padding: 2px 6px; }

.toast { position: fixed; bottom: 1.25rem; right: 1.25rem; max-width: min(480px, calc(100vw - 32px)); padding: .7rem 1rem; border-radius: 8px; background: var(--ok); color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 50; }
.toast.error { background: var(--bad); }

@media (max-width: 800px) {
  .split { grid-template-columns: 1fr; }
  main { padding: 1rem 16px 4rem; }
}
