:root {
  --navy: #0f1b33; --navy-2: #1d3461; --blue: #2d5bd7; --anthracite: #2b2f36;
  --text: #1f2329; --muted: #6b7280; --line: #e5e7eb; --bg: #f5f6f8; --card: #fff;
  --ok: #157347; --ok-bg: #e8f5ee; --warn: #9a5b00; --warn-bg: #fff4e0; --err: #b42318; --err-bg: #fdecea;
  --info-bg: #eaf0fd; --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --nav-h: 64px; --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 var(--font); color: var(--text); background: var(--bg); }
h1 { font-size: 1.55rem; margin: 0 0 .2rem; color: var(--navy); letter-spacing: -.01em; }
h2 { font-size: 1.12rem; margin: 0 0 .8rem; color: var(--navy); }
h3 { font-size: 1rem; margin: .4rem 0; color: var(--anthracite); }
a { color: var(--blue); }
code { background: #eef0f3; padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.muted { color: var(--muted); } .small { font-size: .875rem; } .ok { color: var(--ok); } .err { color: var(--err); }
[hidden] { display: none !important; }

/* ---------- Structure ---------- */
.app { min-height: 100vh; }
.view { padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; outline: none; }
.nav { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; background: var(--navy); padding-bottom: env(safe-area-inset-bottom); }
.nav .brand { display: none; }
.nav ul { display: flex; list-style: none; margin: 0; padding: 0; height: var(--nav-h); }
.nav li { flex: 1; }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 100%;
  color: #aab4c8; text-decoration: none; font-size: .68rem; font-weight: 500; }
.nav a.active { color: #fff; }
.nav .ico svg { width: 24px; height: 24px; fill: currentColor; }
.nav .lbl-long { display: none; }
@media (min-width: 900px) {
  .nav { top: 0; right: auto; width: 250px; padding: 24px 14px; }
  .nav .brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 1.1rem; margin: 0 8px 28px; }
  .nav .brand img { width: 34px; height: 34px; border-radius: 9px; }
  .nav ul { flex-direction: column; height: auto; gap: 4px; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 12px 14px; border-radius: 10px; font-size: .95rem; }
  .nav a.active { background: rgba(255,255,255,.1); }
  .nav .lbl-short { display: none; } .nav .lbl-long { display: inline; }
  .view { margin-left: 250px; padding: 32px 36px 48px; }
}
@media (min-width: 1360px) { .view { margin-left: calc(250px + (100vw - 250px - 1100px) / 2); } }

.page-head { margin-bottom: 18px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; font-size: .9rem; }

/* ---------- Cartes ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card-error { border-left: 4px solid var(--err); } .card-danger { border: 1px solid #f3c7c2; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.kpis .card { margin: 0; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
.kpi-label { margin: 0 0 6px; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.kpi-num { margin: 0; font-size: 1.3rem; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.kpi-small { margin: 0 0 4px; font-weight: 600; }
.kpi-hero { background: linear-gradient(135deg, var(--navy), var(--navy-2)); color: #fff; padding: 22px; }
.kpi-hero .kpi-label { color: #c7d2ea; font-size: .76rem; } .kpi-hero .muted { color: #c7d2ea; }
.kpi-value { margin: 4px 0 8px; font-size: 2.4rem; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-strong .kpi-num { font-size: 1.6rem; }
.tax-grid { display: grid; gap: 12px; grid-template-columns: 1fr; margin-bottom: 16px; } .tax-grid .card { margin: 0; }
@media (min-width: 700px) { .tax-grid { grid-template-columns: 1fr 1fr; } }
.two-col { display: grid; gap: 16px; } @media (min-width: 700px) { .two-col { grid-template-columns: 1fr 1fr; } }
.result-line { display: flex; justify-content: space-between; gap: 12px; align-items: center; background: var(--info-bg); padding: 14px 16px; border-radius: 10px; margin-top: 14px; }
.result-line b { font-size: 1.3rem; color: var(--navy); white-space: nowrap; }

.scan-cta { display: flex; align-items: center; justify-content: center; gap: 14px; min-height: 76px; margin-bottom: 16px; border-radius: var(--radius);
  background: var(--blue); color: #fff; text-decoration: none; font-weight: 750; font-size: 1.1rem; letter-spacing: .03em; box-shadow: 0 6px 18px rgba(45,91,215,.35); }
.scan-cta:active { transform: scale(.99); }
.scan-ico svg { width: 30px; height: 30px; fill: #fff; display: block; }

/* ---------- Boutons & champs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 18px; border-radius: 11px;
  border: 1px solid var(--line); background: #fff; color: var(--anthracite); font: 600 .95rem var(--font); cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn-lg { min-height: 54px; font-size: 1.02rem; } .btn-sm { min-height: 36px; padding: 6px 12px; font-size: .85rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 42px; height: 42px; border-radius: 10px; border: 0; background: #f1f3f6; cursor: pointer; font-size: 1.05rem; text-decoration: none; color: var(--anthracite); }
.icon-btn.danger { background: var(--err-bg); }
.link { background: none; border: 0; color: var(--blue); font: inherit; cursor: pointer; padding: 6px 0; } .link.danger { color: var(--err); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span, .field-label { font-size: .88rem; font-weight: 600; color: var(--anthracite); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
input, select { width: 100%; min-height: 46px; padding: 10px 12px; font: 16px var(--font); color: var(--text); background: #fff; border: 1px solid #d0d5dd; border-radius: 10px; }
input:focus, select:focus { outline: 3px solid rgba(45,91,215,.25); border-color: var(--blue); }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
.stack { display: flex; flex-direction: column; }
.chk { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.segmented { display: flex; gap: 0; border: 0; padding: 0; margin: 14px 0; background: #eef0f3; border-radius: 11px; padding: 4px; }
.segmented label { flex: 1; } .segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; text-align: center; padding: 10px 8px; border-radius: 8px; font-size: .9rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented input:checked + span { background: #fff; color: var(--navy); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--blue); }

/* ---------- Badges & alertes ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .74rem; font-weight: 700; white-space: nowrap; vertical-align: middle; }
.b-ok { background: var(--ok-bg); color: var(--ok); } .b-warn { background: var(--warn-bg); color: var(--warn); }
.b-err { background: var(--err-bg); color: var(--err); } .b-info { background: var(--info-bg); color: var(--navy-2); } .b-muted { background: #eef0f3; color: var(--muted); }
.alert { padding: 11px 14px; border-radius: 10px; margin: 0 0 10px; font-size: .92rem; }
.alert-ok { background: var(--ok-bg); color: var(--ok); } .alert-warning { background: var(--warn-bg); color: var(--warn); }
.alert-error { background: var(--err-bg); color: var(--err); } .alert-info { background: var(--info-bg); color: var(--navy-2); }

/* ---------- Listes & tableaux ---------- */
.list { list-style: none; padding: 0; margin: 0; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.plain { padding-left: 18px; margin: 0; } .plain li { margin-bottom: 6px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tfoot th { color: var(--navy); } .num { text-align: right !important; } .row-empty { color: #a0a6b0; }

/* ---------- Documents ---------- */
.filters { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.filters input[type=search] { grid-column: 1 / -1; } .filters .chk { grid-column: 1 / -1; }
@media (min-width: 900px) { .filters { grid-template-columns: 2fr 1fr 1fr 1.4fr 1fr; } .filters input[type=search] { grid-column: auto; } }
.year summary { display: flex; justify-content: space-between; align-items: baseline; cursor: pointer; list-style: none; }
.year summary::-webkit-details-marker { display: none; } .year summary h2 { margin: 0; }
.month { margin-top: 12px; } .month h3 { border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.doc { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid #f0f1f3; }
.doc-old { opacity: .6; }
.doc-main { text-decoration: none; color: inherit; display: flex; flex-direction: column; min-width: 0; }
.doc-title { font-weight: 650; } .doc-meta { font-size: .84rem; color: var(--muted); }
.doc-actions { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
@media (min-width: 700px) { .doc { grid-template-columns: 1fr auto auto; } .doc-actions { grid-column: auto; } }
.empty { text-align: center; padding: 32px; }

/* ---------- Ajout / scanner ---------- */
.source-grid { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.source-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 108px; padding: 14px; border-radius: 13px;
  border: 1.5px dashed #c5cbd6; background: #fafbfc; font-weight: 650; text-align: center; cursor: pointer; color: var(--anthracite); }
.source-main { grid-column: 1 / -1; background: var(--navy); color: #fff; border: 0; min-height: 120px; font-size: 1.1rem; }
.source-ico { font-size: 1.9rem; }
@media (min-width: 700px) { .source-grid { grid-template-columns: repeat(3, 1fr); } .source-main { grid-column: auto; } }
.editor { position: relative; width: 100%; max-width: 640px; margin: 0 auto; touch-action: none; user-select: none; -webkit-user-select: none; }
.editor canvas { display: block; width: 100%; height: auto; border-radius: 8px; }
.editor svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.crop-poly { fill: rgba(45,91,215,.16); stroke: #2d5bd7; stroke-width: 3; vector-effect: non-scaling-stroke; }
.crop-handle { fill: #fff; stroke: #2d5bd7; stroke-width: 4; vector-effect: non-scaling-stroke; cursor: grab; }
.scan-preview { background: #e9ebef; border-radius: 10px; padding: 10px; text-align: center; }
.scan-preview img { max-width: 100%; max-height: 70vh; box-shadow: 0 4px 16px rgba(0,0,0,.15); }
.thumbs { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.thumbs figure { margin: 0; flex: 0 0 110px; } .thumbs img { width: 110px; border-radius: 6px; box-shadow: var(--shadow); }
.thumbs figcaption { font-size: .78rem; display: flex; justify-content: space-between; align-items: center; }
.steps { list-style: none; padding: 0; margin: 10px 0; }
.step { display: grid; grid-template-columns: 22px 1fr; column-gap: 10px; padding: 7px 0; color: var(--muted); }
.step small { grid-column: 2; font-size: .8rem; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #c5cbd6; margin-top: 4px; }
.step-running { color: var(--navy); font-weight: 600; } .step-running .dot { border-color: var(--blue); border-top-color: transparent; animation: spin .8s linear infinite; }
.step-done { color: var(--text); } .step-done .dot { background: var(--ok); border-color: var(--ok); }
.step-error { color: var(--err); } .step-error .dot { background: var(--err); border-color: var(--err); }

/* ---------- Vérification ---------- */
.review { display: grid; gap: 16px; }
@media (min-width: 1100px) { .review { grid-template-columns: 1fr 1fr; align-items: start; } .review-doc { position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow: auto; } }
.review .card { margin: 0; }
.fgroup { border: 0; padding: 0; margin: 18px 0 0; } .fgroup legend { font-weight: 750; color: var(--navy); margin-bottom: 10px; font-size: 1rem; }
.conf { font-style: normal; font-size: .72rem; padding: 2px 7px; border-radius: 999px; font-weight: 700; }
.conf-ok { background: var(--ok-bg); color: var(--ok); } .conf-low { background: var(--warn-bg); color: var(--warn); }
.field-low input, .field-low select { border-color: #f0b44c; background: #fffaf0; }
.field-issue input, .field-issue select { border-color: var(--err); }
.confirm-chk { display: flex; gap: 8px; align-items: center; font-size: .85rem; color: var(--warn); }
.sticky-actions { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: rgba(255,255,255,.96); backdrop-filter: blur(6px);
  margin: 16px -18px -18px; padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; border-radius: 0 0 var(--radius) var(--radius); }
.sticky-actions .btn-primary { flex: 1; }
@media (min-width: 900px) { .sticky-actions { bottom: 0; } }
.raw pre { white-space: pre-wrap; font-size: .78rem; background: #f6f7f9; padding: 10px; border-radius: 8px; max-height: 300px; overflow: auto; }
.pdf-viewer { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.pdf-page { max-width: 100%; height: auto !important; box-shadow: 0 2px 10px rgba(0,0,0,.12); background: #fff; }

/* ---------- Graphiques ---------- */
.chart { width: 100%; height: auto; } .chart .bar { fill: var(--navy-2); } .chart .grid { stroke: var(--line); }
.chart .axis { font-size: 11px; fill: var(--muted); } .chart .axis-cum { fill: var(--blue); }
.chart .cum-line { fill: none; stroke: var(--blue); stroke-width: 2.5; stroke-linejoin: round; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.lg-bar { background: var(--navy-2); } .lg-line { background: var(--blue); height: 3px !important; vertical-align: 3px !important; }
.hbars { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 30%) 1fr auto; gap: 10px; align-items: center; font-size: .88rem; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { background: #eef0f3; border-radius: 6px; height: 12px; } .hbar-fill { display: block; height: 100%; background: var(--navy-2); border-radius: 6px; }
.hbar-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.export-grid { display: grid; gap: 10px; } @media (min-width: 700px) { .export-grid { grid-template-columns: 1fr 1fr; } }

/* ---------- Authentification ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--navy), var(--navy-2)); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 18px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); text-align: center; }
.auth-card form { text-align: left; margin-top: 18px; } .auth-logo { width: 64px; height: 64px; border-radius: 16px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 8px; }

/* ---------- Divers ---------- */
.boot, .loading { display: grid; place-items: center; min-height: 40vh; text-align: center; color: var(--muted); }
.boot { min-height: 100vh; }
.spinner { width: 36px; height: 36px; border: 3px solid #d6dbe4; border-top-color: var(--navy); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; width: min(92vw, 440px); }
.toast { background: var(--anthracite); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-size: .92rem; transition: opacity .3s, transform .3s; }
.toast-ok { background: var(--ok); } .toast-error { background: var(--err); } .toast-warn { background: #b26a00; }
.toast.out { opacity: 0; transform: translateY(8px); }
.modal { border: 0; border-radius: 16px; padding: 0; width: min(94vw, 480px); box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.modal-wide { width: min(96vw, 900px); }
.modal::backdrop { background: rgba(15,27,51,.55); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; } .modal-body { padding: 18px; max-height: 70vh; overflow: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
@media print { .nav, .scan-cta, .btn, .toasts { display: none !important; } .view { margin: 0; padding: 0; } .card { box-shadow: none; border: 1px solid #ddd; } }
