:root {
  --bg: #f3f4f7; --panel: #fff; --ink: #1d2433; --muted: #667085; --line: #e3e6ec;
  --brand: #1f3a5f; --brand-2: #2e5c8a; --accent: #e8eef6; --excel: #1d6f42;
  --danger: #b42318; --warn-bg: #fff6e5; --warn: #8a5a00; --radius: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 24px; background: var(--brand); color: #fff; }
.brand { font-weight: 700; font-size: 1.2rem; display: flex; align-items: center; gap: 8px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: #fff; color: var(--brand);
  display: grid; place-items: center; font-weight: 800; }
.tagline { opacity: .8; font-size: .9rem; }
.layout { flex: 1; display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 20px;
  padding: 20px 24px; max-width: 1400px; width: 100%; margin: 0 auto; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; padding: 12px 16px; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; min-width: 0; }
h2 { font-size: 1rem; margin: 6px 0 12px; display: flex; align-items: center; gap: 8px; }
h2:not(:first-child) { margin-top: 22px; }
.step { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--brand);
  display: grid; place-items: center; font-size: .8rem; font-weight: 700; }

.dropzone { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  padding: 26px 12px; border: 2px dashed #c7cdd8; border-radius: var(--radius); cursor: pointer;
  color: var(--muted); transition: .15s; }
.dropzone strong { color: var(--ink); }
.dropzone.over, .dropzone:hover { border-color: var(--brand-2); background: var(--accent); }
.camera-btn { width: 100%; margin-top: 8px; }

.thumbs { list-style: none; padding: 0; margin: 12px 0 0; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.thumbs li { position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: #fafafa; aspect-ratio: 3 / 4; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs .num { position: absolute; top: 4px; left: 4px; background: var(--brand); color: #fff;
  font-size: .72rem; border-radius: 10px; padding: 1px 7px; }
.thumbs .state { position: absolute; bottom: 0; left: 0; right: 0; font-size: .7rem; padding: 2px 4px;
  background: rgba(0,0,0,.6); color: #fff; text-align: center; }
.thumbs .tools { position: absolute; top: 4px; right: 4px; display: flex; gap: 2px; }
.thumbs .tools button { border: 0; width: 22px; height: 22px; border-radius: 6px; cursor: pointer;
  background: rgba(255,255,255,.92); font-size: .8rem; line-height: 1; padding: 0; }

.field { margin-bottom: 14px; }
.field.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.label { font-size: .85rem; color: var(--muted); display: block; margin-bottom: 6px; }
.field.row .label { margin: 0; }
select, input[type=text] { font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); min-width: 0; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.segmented input { display: none; }
.segmented span { display: block; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; font-weight: 600; font-size: .9rem; }
.segmented small { display: block; font-weight: 400; color: var(--muted); font-size: .75rem; }
.segmented input:checked + span { border-color: var(--brand-2); background: var(--accent);
  box-shadow: inset 0 0 0 1px var(--brand-2); }
.segmented input:disabled + span { opacity: .45; cursor: not-allowed; }
.hint { color: var(--muted); font-size: .8rem; margin: 6px 0 0; }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: .92rem; margin-bottom: 18px; }
.switch input { display: none; }
.track { width: 38px; height: 22px; border-radius: 11px; background: #cfd4dc; position: relative; transition: .15s; flex: none; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + .track { background: var(--brand-2); }
.switch input:checked + .track::after { left: 19px; }

.btn { font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 8px; padding: 9px 14px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand-2); }
.btn.excel { background: var(--excel); color: #fff; }
.btn.secondary { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.big { width: 100%; padding: 12px; font-size: 1rem; }
.progress { margin-top: 12px; font-size: .85rem; color: var(--muted); }
.progress .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
.progress .bar div { height: 100%; width: 0; background: var(--brand-2); transition: width .3s; }

.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.preview-head h2 { margin: 0; }
.export { display: flex; gap: 8px; flex-wrap: wrap; }
.export input { width: 180px; }
#messages .msg { margin-top: 12px; padding: 10px 12px; border-radius: 8px; font-size: .88rem; }
.msg.error { background: #fdecea; color: var(--danger); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }
.corrections { margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: .88rem; }
.corrections summary { cursor: pointer; }
.corrections ul { margin: 8px 0 0; padding-left: 18px; max-height: 180px; overflow: auto; }
.corrections del { color: var(--danger); }
.corrections ins { color: var(--excel); text-decoration: none; font-weight: 600; }

/* Aperçu façon feuille A4 */
.page { margin-top: 16px; background: #fff; border: 1px solid var(--line); border-radius: 4px;
  box-shadow: 0 2px 12px rgba(16,24,40,.06); padding: 48px clamp(16px, 6vw, 64px);
  min-height: 60vh; font-family: Calibri, Carlito, "Segoe UI", sans-serif; font-size: 11pt; line-height: 1.45; }
.empty { text-align: center; color: var(--muted); padding-top: 18vh; font-family: inherit; }
.blk { position: relative; border-radius: 4px; margin: 0 -8px; padding: 2px 8px; }
.blk:hover { background: #f7f9fc; }
.blk .bar-tools { position: absolute; top: -12px; right: 4px; display: none; gap: 4px; z-index: 2; }
.blk:hover .bar-tools, .blk:focus-within .bar-tools { display: flex; }
.bar-tools select, .bar-tools button { font-size: .72rem; padding: 2px 6px; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; cursor: pointer; font-family: "Segoe UI", system-ui, sans-serif; }
.bar-tools button.del { color: var(--danger); }
[contenteditable] { outline: none; }
[contenteditable]:focus { box-shadow: 0 0 0 2px #bcd1ea; border-radius: 3px; }
.page h1, .page h2, .page h3 { color: var(--brand); display: block; margin: 14px 0 6px; }
.page h1 { font-size: 18pt; } .page h2 { font-size: 14pt; } .page h3 { font-size: 12pt; }
.page p { margin: 0 0 6pt; }
.page ul, .page ol { margin: 0 0 6pt; padding-left: 28px; }
.table-wrap { overflow-x: auto; margin: 6px 0 10px; }
.page table { border-collapse: collapse; width: 100%; font-size: 10.5pt; }
.page td { border: 1px solid #a6a6a6; padding: 4px 6px; vertical-align: top; min-width: 40px; }
.page tr.head td { background: #d9e2f3; font-weight: 700; }
.table-title { font-weight: 700; margin: 8px 0 4px; }
.pagebreak { border-top: 2px dashed #c7cdd8; margin: 22px -8px; text-align: center; font-size: .75rem;
  color: var(--muted); font-family: "Segoe UI", system-ui, sans-serif; }
.pagebreak span { background: #fff; padding: 0 8px; position: relative; top: -10px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 10px 16px 18px; }

/* ---------- Compte, paiement ---------- */
.account { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .88rem; }
.account .who { opacity: .85; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .balance { background: rgba(255,255,255,.14); padding: 5px 10px; border-radius: 20px; }
.btn.light { background: #fff; color: var(--brand); padding: 6px 12px; }
.btn.link { background: none; color: inherit; text-decoration: underline; padding: 6px 4px; font-weight: 400; }
.modal .btn.link { color: var(--muted); }
@media (max-width: 600px) { .account { margin-left: 0; width: 100%; } .tagline { display: none; } }

.paywall { margin-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; padding: 12px 14px; border-radius: 10px; background: #eef4fb; border: 1px solid #c9d9ee;
  font-size: .9rem; }
.msg.ok { background: #e7f5ec; color: var(--excel); }

.doc-page { position: relative; }
.doc-page.locked { -webkit-user-select: none; user-select: none; }
.lock-tag { position: absolute; top: -30px; right: 0; font-size: .72rem; color: var(--muted);
  font-family: "Segoe UI", system-ui, sans-serif; }
.blur { filter: blur(4.5px); opacity: .75; -webkit-user-select: none; user-select: none; pointer-events: none; }
tr.blur td { filter: blur(4px); }
tr.blur { filter: none; opacity: 1; }

.modal { position: fixed; inset: 0; background: rgba(16,24,40,.5); display: grid; place-items: center;
  padding: 16px; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { position: relative; background: #fff; border-radius: 14px; padding: 24px; width: min(420px, 100%);
  max-height: 90vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-card h3 { margin: 0 0 8px; font-size: 1.15rem; }
.modal-card form { display: grid; gap: 10px; margin-top: 12px; }
.modal-card input[type=email], .modal-card input[inputmode] { width: 100%; font-size: 1.05rem; padding: 11px 12px; }
.modal-card input[inputmode] { letter-spacing: .4em; text-align: center; font-size: 1.4rem; }
.modal-close { position: absolute; top: 10px; right: 10px; border: 0; background: none; font-size: 1rem;
  cursor: pointer; color: var(--muted); width: 32px; height: 32px; border-radius: 8px; }
.modal-close:hover { background: var(--bg); }
.modal-error { color: var(--danger); font-size: .88rem; margin: 10px 0 0; }
.muted { color: var(--muted); font-size: .9rem; }
.small { font-size: .8rem; }
.notice { background: var(--warn-bg); color: var(--warn); padding: 8px 10px; border-radius: 8px; font-size: .9rem; }
.amounts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 14px 0; }
.amounts input[type=radio] { display: none; }
.amounts label > span { display: block; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  cursor: pointer; }
.amounts small { display: block; color: var(--muted); font-size: .78rem; margin-top: 2px; }
.amounts input[type=radio]:checked + span { border-color: var(--brand-2); background: var(--accent);
  box-shadow: inset 0 0 0 1px var(--brand-2); }
.amounts input[type=number] { width: 70px; padding: 3px 6px; font: inherit; border: 1px solid var(--line); border-radius: 6px; }
.bill { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: .95rem; }
.bill td { padding: 7px 0; border-bottom: 1px solid var(--line); }
.bill td:last-child { text-align: right; }
.paywall[hidden] { display: none; }
/* Champ fichier invisible mais « présent » : plus fiable sur iPhone qu'un champ display:none */
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
.dropzone, .camera-btn { position: relative; }

/* ---------- Formulaires (cases étiquette / valeur) ---------- */
.doc-page { --accent: #1f3a5f; }
.doc-page h1, .doc-page h2, .doc-page h3 { color: var(--accent); }
.doc-page tr.head td { background: var(--accent); color: #fff; }
.doc-page td { border-color: color-mix(in srgb, var(--accent) 45%, white); }
.fields-title { background: var(--accent); color: #fff; font-weight: 700; font-size: 10pt; padding: 4px 8px;
  margin-top: 8px; border-radius: 3px 3px 0 0; }
.fields { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); margin-bottom: 10px;
  border-top: 1px solid color-mix(in srgb, var(--accent) 45%, white);
  border-left: 1px solid color-mix(in srgb, var(--accent) 45%, white); }
.fields-title + .fields { margin-top: 0; }
.field-box { padding: 4px 7px; min-height: 40px; background: color-mix(in srgb, var(--accent) 7%, white);
  border-right: 1px solid color-mix(in srgb, var(--accent) 45%, white);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 45%, white); }
.flabel { display: block; font-size: 8pt; font-weight: 700; color: var(--accent); }
.fvalue { display: block; font-size: 10pt; min-height: 1.2em; }
@media (max-width: 600px) { .fields:not([data-cols="1"]) { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
