:root {
  --bg: #f3f6f6;
  --card: #ffffff;
  --text: #13252b;
  --muted: #5d6f75;
  --line: #dde5e6;
  --accent: #0f766e;
  --accent-dark: #0b5953;
  --accent-soft: #e3f2f0;
  --ok: #15803d; --ok-bg: #e5f6ea;
  --ecart: #b42318; --ecart-bg: #fde8e6;
  --check: #b45309; --check-bg: #fff1dc;
  --unknown: #55636b; --unknown-bg: #e7ebee;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 40, 44, .06), 0 2px 10px rgba(16, 40, 44, .04);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.45; }
h2 { font-size: 18px; margin: 0 0 4px; }
h3 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
[hidden] { display: none !important; }

/* ---------- Barre supérieure ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; padding-top: max(10px, env(safe-area-inset-top));
  background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-title { font-weight: 700; font-size: 17px; color: var(--accent-dark); }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.lang button {
  border: 0; background: #fff; padding: 6px 9px; font: inherit; font-size: 13px; cursor: pointer; color: var(--muted);
  display: inline-flex; gap: 4px; align-items: center;
}
.lang button + button { border-left: 1px solid var(--line); }
.lang button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 16px 20px 40px; }
.privacy { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--accent-dark); margin-bottom: 14px; flex-wrap: wrap; }
.privacy .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.privacy .offline { margin-left: auto; color: var(--muted); }

/* ---------- Cartes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.help { margin-bottom: 16px; }
.help ol { margin: 6px 0 8px; padding-left: 20px; }

.uploads { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.uploads > * { min-width: 0; }
.card-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.card-head p { margin: 0; font-size: 13px; }
.doc-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.doc-icon.bl { background: var(--accent-soft); color: var(--accent-dark); }
.doc-icon.wp { background: #e6eefb; color: #1f4e79; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center;
  border: 1.5px dashed #b7c8ca; border-radius: 10px; padding: 22px 12px; cursor: pointer; color: var(--accent-dark);
  background: #fafcfc; min-height: 118px;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.dropzone small { color: var(--muted); }

.scan-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.scan-msg { margin: 6px 0 0; }
/* Bouton « appareil photo » réservé aux tablettes / téléphones : sur ordinateur il ouvrirait une fenêtre
   de choix limitée aux images (sans TIFF). Le choix de fichier normal reste disponible. */
@media (hover: hover) and (pointer: fine) { #btnCamera { display: none; } }
.paste-hint { margin-top: 4px !important; font-size: 12px !important; }
.files { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.file { border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.file-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.file-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 12px; color: var(--muted); }
.file-actions { display: flex; gap: 4px; flex-shrink: 0; }
.thumbs { display: flex; gap: 8px; overflow-x: auto; padding-top: 8px; }
.thumb { position: relative; flex-shrink: 0; width: 96px; height: 120px; border: 1px solid var(--line); border-radius: 6px; background: #f6f8f8; display: grid; place-items: center; overflow: hidden; }
.thumb img { max-width: 100%; max-height: 100%; transition: none; }
.thumb .pno { position: absolute; left: 4px; top: 4px; font-size: 11px; background: rgba(255,255,255,.9); border-radius: 4px; padding: 0 4px; }
.thumb .rot { position: absolute; right: 3px; bottom: 3px; }
.thumb .kind { position: absolute; left: 4px; bottom: 4px; font-size: 10px; background: var(--accent); color: #fff; border-radius: 4px; padding: 0 4px; }

/* ---------- Boutons ---------- */
.btn {
  font: inherit; border-radius: 9px; border: 1px solid transparent; padding: 9px 16px; cursor: pointer; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; min-height: 38px;
}
.btn.small { padding: 5px 10px; font-size: 13px; min-height: 32px; font-weight: 500; }
.btn.big { padding: 13px 28px; font-size: 16px; min-height: 48px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.primary:disabled { background: #9fb9b7; cursor: not-allowed; }
.btn.outline { background: #fff; color: var(--accent-dark); border-color: #b9cfcd; }
.btn.outline:hover { background: var(--accent-soft); }
.btn.ghost { background: transparent; color: var(--accent-dark); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { background: #fff; color: var(--ecart); border-color: #f0c2bd; }
.btn.warn { background: #fff; color: var(--check); border-color: #f2d3a6; }
.icon-btn { border: 0; background: transparent; font-size: 18px; cursor: pointer; width: 32px; height: 32px; border-radius: 8px; color: var(--muted); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent-dark); }
.icon-btn.mini { width: 24px; height: 24px; font-size: 14px; background: rgba(255,255,255,.92); }

.verify-bar { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 22px 0; }
.verify-secondary { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }

.alert { border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.alert.error { background: var(--ecart-bg); color: var(--ecart); border: 1px solid #f3c5c0; }
.alert.warn { background: var(--check-bg); color: #7a3e06; border: 1px solid #f2d3a6; }
.alert.info { background: var(--accent-soft); color: var(--accent-dark); border: 1px solid #c5e1dd; }

/* ---------- Progression ---------- */
.progress { margin-bottom: 18px; }
.progress-line { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 8px; gap: 10px; }
.progress .bar { height: 8px; background: #e6eeee; border-radius: 6px; overflow: hidden; }
.progress .bar div { height: 100%; width: 0; background: var(--accent); }

/* ---------- Résultats ---------- */
.results-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.export { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.tiles { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; margin-bottom: 12px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; border-top: 3px solid var(--line); }
.tile .n { font-size: 26px; font-weight: 700; line-height: 1.1; }
.tile .l { font-size: 12px; color: var(--muted); }
.tile.ok { border-top-color: var(--ok); } .tile.ok .n { color: var(--ok); }
.tile.ecart { border-top-color: var(--ecart); } .tile.ecart .n { color: var(--ecart); }
.tile.check { border-top-color: var(--check); } .tile.check .n { color: var(--check); }
.tile.unknown { border-top-color: var(--unknown); } .tile.unknown .n { color: var(--unknown); }
.tile.fusion { border-top-color: #7c5cc4; } .tile.fusion .n { color: #6145a8; }
.banner { border-radius: 10px; padding: 12px 14px; font-weight: 600; margin-bottom: 14px; display: flex; gap: 8px; align-items: center; }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.bad { background: var(--check-bg); color: #7a3e06; }

.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 10px 3px 7px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.badge svg { flex-shrink: 0; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.ecart { background: var(--ecart-bg); color: var(--ecart); }
.badge.check { background: var(--check-bg); color: var(--check); }
.badge.unknown { background: var(--unknown-bg); color: var(--unknown); }
.badge.ignored { background: #f1f3f4; color: #7b8a8f; border: 1px dashed #c6d0d3; }
.results-table tr.row-ignored td { color: #7b8a8f; background: #fafbfb; }
.results-table tr.row-ignored td:first-child { box-shadow: inset 3px 0 0 #c6d0d3; }
.tile.ignored { border-top-color: #c6d0d3; } .tile.ignored .n { color: #7b8a8f; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #efe9fb; color: #5b3fa0; font-weight: 600; margin-top: 3px; }
.chip.wp { background: #e6eefb; color: #1f4e79; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.bad { background: var(--ecart-bg); color: var(--ecart); }
.manual-box { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; align-items: center; }
.btn.ok-outline { background: #fff; color: var(--ok); border-color: #b7dfc2; }
.btn.ok-outline:hover { background: var(--ok-bg); }

.table-card { padding: 0; overflow: hidden; margin-top: 14px; }
.toolbar { display: flex; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar input, .toolbar select, .field input, .field textarea {
  font: inherit; border: 1px solid #c9d6d7; border-radius: 9px; padding: 8px 10px; background: #fff; min-height: 38px; color: var(--text);
}
.toolbar input { flex: 1 1 220px; }
.table-scroll { overflow-x: auto; }
.results-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.results-table th { text-align: left; font-size: 12px; text-transform: none; color: var(--muted); font-weight: 600; padding: 10px; background: #f7fafa; border-bottom: 1px solid var(--line); cursor: pointer; white-space: nowrap; user-select: none; }
.results-table th[data-dir="asc"]::after { content: " ▲"; font-size: 9px; }
.results-table th[data-dir="desc"]::after { content: " ▼"; font-size: 9px; }
.results-table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.results-table tr.row-ecart td:first-child { box-shadow: inset 3px 0 0 var(--ecart); }
.results-table tr.row-check td:first-child { box-shadow: inset 3px 0 0 var(--check); }
.results-table tr.row-unknown td:first-child { box-shadow: inset 3px 0 0 var(--unknown); }
.results-table tr.row-ok td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
.results-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.results-table .prod { min-width: 220px; font-weight: 500; }
.results-table .prod .sub { font-weight: 400; font-size: 12px; color: var(--muted); }
.code { font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 13px; white-space: nowrap; }
.code .ck { font-size: 11px; margin-left: 3px; }
.code .ck.good { color: var(--ok); } .code .ck.bad { color: var(--ecart); }
.na { color: #8b999e; font-size: 12px; font-style: italic; }
.ecart-neg { color: var(--ecart); font-weight: 700; }
.ecart-pos { color: #b54708; font-weight: 700; }
.ecart-zero { color: var(--ok); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
.notes { margin: 4px 0 0; padding-left: 16px; font-size: 12.5px; color: var(--muted); }
tr.detail td { background: #fbfcfc; }
.empty { padding: 16px; text-align: center; }

/* ---------- Fusion ---------- */
.fusion-card { border: 1px solid #f2d3a6; background: #fffaf2; border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.fusion-card.done { border-color: #c9b8ec; background: #faf7ff; }
.fusion-title { display: flex; align-items: center; gap: 8px; font-weight: 700; color: #8a4b0a; margin-bottom: 10px; }
.fusion-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.fusion-side { background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 10px; }
.fusion-side .lbl { font-size: 12px; color: var(--muted); }
.fusion-side .val { font-weight: 600; }
.feat-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 13px; }
.feat-list ul { margin: 4px 0 0; padding-left: 18px; }
.feat-list .same li::marker { color: var(--ok); }
.feat-list .diff li::marker { color: var(--check); }
.fusion-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.fusion-actions label { font-size: 13px; display: flex; gap: 6px; align-items: center; margin-right: auto; }
.winpharma-card { border: 1px solid #c9b8ec; background: #faf7ff; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px; font-size: 14px; }
.winpharma-card b { color: #5b3fa0; }

/* ---------- Texte reconnu ---------- */
.rawtext { margin-top: 14px; }
.rawtext summary { cursor: pointer; font-weight: 600; color: var(--accent-dark); }
.rawtext pre { white-space: pre-wrap; font-size: 12px; background: #f7fafa; border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 320px; overflow: auto; }
.cols { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.cols span { font-size: 12px; border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; background: #fff; }
.cols span.ignore { color: #9aa7ab; }

/* ---------- Fenêtre modale ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(920px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 30, 34, .45); }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
#modalBody { padding: 16px 18px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-foot:empty { display: none; }
.src-block { margin-bottom: 16px; }
.src-block img { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; display: block; margin-top: 6px; }
.src-block code { display: block; font-size: 12px; background: #f7fafa; padding: 6px 8px; border-radius: 6px; margin-top: 6px; white-space: pre-wrap; }
.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.edit-grid fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 0; }
.edit-grid legend { font-weight: 600; padding: 0 6px; }
.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px; font-size: 13px; }
.field .conf { font-size: 11px; color: var(--muted); }
.dict-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 14px; }
.dict-table td, .dict-table th { border-bottom: 1px solid var(--line); padding: 6px; text-align: left; vertical-align: top; }

.footer { text-align: center; font-size: 12px; color: var(--muted); padding: 20px; padding-bottom: max(20px, env(safe-area-inset-bottom)); }

/* ---------- Adaptation mobile / tablette ---------- */
@media (max-width: 1024px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 820px) {
  .uploads { grid-template-columns: minmax(0, 1fr); }
  .brand-sub { display: none; }
  .wrap { padding: 12px 12px 30px; }
  .topbar { padding: 8px 12px; }
  .top-actions .btn { display: none; }
  .top-actions .btn#btnDict { display: inline-flex; padding: 5px 6px; }
  .fusion-grid, .feat-list, .edit-grid { grid-template-columns: 1fr; }
  /* Tableau -> cartes */
  .results-table thead { display: none; }
  .results-table, .results-table tbody, .results-table tr, .results-table td { display: block; width: 100%; }
  .results-table tr { border-bottom: 6px solid var(--bg); padding: 6px 0; }
  .results-table td { border: 0; padding: 4px 12px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .results-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex-shrink: 0; max-width: 45%; }
  .results-table td.prod { display: block; text-align: left; font-size: 15px; }
  .results-table td.prod::before, .results-table td.status-cell::before, .results-table td.actions-cell::before { display: none; }
  .results-table td.status-cell { justify-content: flex-start; }
  .results-table td.actions-cell { justify-content: flex-end; }
  .results-table tr td:first-child { box-shadow: none !important; }
  .results-table tr.row-ecart { box-shadow: inset 4px 0 0 var(--ecart); }
  .results-table tr.row-check { box-shadow: inset 4px 0 0 var(--check); }
  .results-table tr.row-unknown { box-shadow: inset 4px 0 0 var(--unknown); }
  .results-table tr.row-ok { box-shadow: inset 4px 0 0 var(--ok); }
  tr.detail td { display: block; text-align: left; }
  tr.detail td::before { display: none; }
}
@media (max-width: 480px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .lang button .lname { display: none; }
  .btn.big { width: 100%; }
}
@media print {
  .topbar, .uploads, .verify-bar, .toolbar, .export, .row-actions, .rawtext, .footer { display: none !important; }
}

.engine-pick { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.engine-pick select { font: inherit; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--line, #d0d7de); background: var(--card, #fff); color: inherit; }
