/* Fiche facture : document original + vérification de la lecture IA. */

.crumbs { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.crumbs a {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 13px;
}
.crumbs a:hover { color: var(--ink); }
.crumbs svg { width: 16px; height: 16px; }
.crumbs-next { color: var(--success-600) !important; }

.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.inv-head .supplier { gap: 14px; }
.inv-head h1 { margin-bottom: 4px; }
.inv-sum { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }
.inv-amount { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }

.inv-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap; }
.inv-actions:empty { display: none; }
.action-hint { flex-basis: 100%; text-align: right; font-size: 12px; color: var(--warn); font-weight: 600; }

.inv-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: var(--gap); align-items: start; }
.side { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }

/* Visionneuse */
.viewer {
  position: sticky; top: 20px;
  background: #dfe2ec;
  border-radius: var(--radius);
  overflow: hidden;
}
.viewer-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 10px 8px 14px;
  background: #121420; color: #fff;
  font-size: 13px;
}
.viewer-name { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-name svg { width: 16px; height: 16px; flex: none; color: var(--gray-600); }
.viewer-tools { display: flex; align-items: center; gap: 2px; }
.viewer-zoom { min-width: 44px; text-align: center; font-size: 12px; color: #c9ccd8; font-variant-numeric: tabular-nums; }
.icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 0; border-radius: 8px;
  background: none; color: #c9ccd8;
  cursor: pointer;
}
.icon-btn:hover { background: #23263a; color: #fff; }
.icon-btn svg { width: 16px; height: 16px; }
.viewer-stage { padding: 24px; overflow: auto; max-height: calc(100vh - 120px); }

/* Le document lui-même : tout en em pour suivre le zoom */
.doc {
  --z: 1;
  font: calc(12px * var(--z)) / 1.5 "Helvetica Neue", Arial, sans-serif;
  color: #23262d;
  background: #fff;
  width: 100%;
  max-width: calc(620px * var(--z));
  margin: 0 auto;
  padding: 3.4em 3.2em 3em;
  box-shadow: 0 2px 6px rgba(18, 20, 32, 0.08), 0 16px 40px rgba(18, 20, 32, 0.1);
  border-radius: 2px;
}
.doc p { margin: 0; }
.doc-head { display: flex; justify-content: space-between; gap: 2em; margin-bottom: 2.6em; }
.doc-sup { font-size: 1.5em; font-weight: 700; margin-bottom: 0.3em !important; color: #3a2a1f; }
.doc-title { text-align: right; }
.doc-h { font-size: 1.9em; font-weight: 300; letter-spacing: 0.12em; color: #8a8f9c; margin-bottom: 0.3em !important; }
.doc-client { margin-left: auto; width: 45%; padding: 1em 1.2em; background: #f6f6f4; margin-bottom: 2.4em; }
.doc-label { font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.08em; color: #8a8f9c; margin-bottom: 0.3em !important; }

.doc-lines { width: 100%; border-collapse: collapse; margin-bottom: 1.6em; }
.doc-lines th { text-align: left; font-weight: 600; font-size: 0.9em; color: #5a5f6b; border-bottom: 1.5px solid #23262d; padding: 0.5em 0.4em; }
.doc-lines td { padding: 0.9em 0.4em; border-bottom: 1px solid #e3e3e0; }
.doc-lines th:not(:first-child), .doc-lines td:not(:first-child) { text-align: right; white-space: nowrap; }

.doc-totals { margin-left: auto; width: 50%; margin-bottom: 2.6em; }
.doc-totals p { display: flex; justify-content: space-between; padding: 0.35em 0.4em; }
.doc-ttc { font-weight: 700; font-size: 1.15em; border-top: 1.5px solid #23262d; margin-top: 0.3em !important; padding-top: 0.6em !important; }

.doc-foot { border-top: 1px solid #e3e3e0; padding-top: 1.2em; display: flex; flex-direction: column; gap: 0.4em; color: #5a5f6b; }
.doc-foot p:last-child { font-size: 0.85em; color: #8a8f9c; margin-top: 0.6em; }

.doc-f { border-radius: 3px; padding: 0 2px; margin: 0 -2px; transition: background 0.15s, box-shadow 0.15s; }
.doc-f.is-flag { background: #ffefd9; box-shadow: 0 0 0 1.5px #f0a64a; }
.doc-f.is-hl { background: #ece8ff; box-shadow: 0 0 0 2px var(--accent); }

/* Cartes du panneau */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 1px 2px rgba(18, 20, 32, 0.04), 0 8px 24px rgba(18, 20, 32, 0.05);
}
.card-title { font-size: 14px; font-weight: 700; margin-bottom: 12px; }
.card-text { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: flex-start; }
.card-text svg { width: 14px; height: 14px; flex: none; margin-top: 3px; color: var(--accent); }

.conf {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 700; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.conf svg { width: 13px; height: 13px; }
.conf--warn { color: var(--warn); }

.ia-card { display: flex; flex-direction: column; gap: 10px; }
.ia-head { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.ia-head svg { width: 18px; height: 18px; }
.ia-card.is-warn { box-shadow: inset 0 0 0 1.5px #f6c88a, 0 8px 24px rgba(18, 20, 32, 0.05); }
.ia-card.is-warn .ia-head svg { color: var(--warn); }
.ia-card.is-ok .ia-head svg { color: var(--s-payer); }

.check { border-radius: var(--radius-sm); background: #fff7ec; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.check-title { display: flex; align-items: center; gap: 8px; }
.check-title svg { width: 16px; height: 16px; color: var(--warn); flex: none; }
.check-text { font-size: 13px; color: #5b4a33; }
.check-options { display: flex; gap: 8px; flex-wrap: wrap; }
.check.is-hl { box-shadow: 0 0 0 2px var(--accent); }
.check.is-done { background: var(--s-payer-bg); flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.check-done { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; }
.check-done svg { width: 16px; height: 16px; color: var(--s-payer); flex: none; margin-top: 2px; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 700; font-size: 13px; cursor: pointer; padding: 2px 4px; }
.link-btn:hover { text-decoration: underline; }

.fields { display: flex; flex-direction: column; }
.field {
  display: grid; grid-template-columns: 130px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 9px 10px; margin: 0 -10px;
  border-radius: var(--radius-sm);
  cursor: default;
}
.field + .field { box-shadow: 0 -1px 0 var(--line-soft); }
.field dt { color: var(--muted); font-size: 13px; }
.field dd { font-weight: 600; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.field.is-review { background: #fff7ec; box-shadow: none; }
.field.is-review dd { color: #8a4b00; }
.field.is-resolved .conf { color: var(--s-payer); }
.field.is-hl { background: var(--selected); box-shadow: none; }
.field:focus-visible { outline-offset: -2px; }

.imputation { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.imputation-value { font-weight: 700; margin-bottom: 2px; }

/* Circuit */
.stepper { list-style: none; display: flex; gap: 6px; margin-bottom: 16px; }
.stepper li {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--muted);
  position: relative;
}
.stepper li::after {
  content: ""; position: absolute; top: 11px; left: 30px; right: 4px;
  height: 2px; background: var(--line);
}
.stepper li:last-child::after { display: none; }
.stepper li.is-done::after { background: var(--accent); }
.step-dot {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 800;
  background: var(--bg); color: var(--muted);
}
.step-dot svg { width: 13px; height: 13px; }
.stepper li.is-done { color: var(--ink); }
.stepper li.is-done .step-dot { background: var(--accent); color: #fff; }
.stepper li.is-current { color: var(--accent); }
.stepper li.is-current .step-dot { background: var(--surface); color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.stepper.is-refused li:last-child .step-dot { background: var(--s-refusee); }
.stepper.is-refused li:last-child { color: var(--s-refusee); }

.timeline { list-style: none; display: flex; flex-direction: column; gap: 10px; border-left: 2px solid var(--line-soft); padding-left: 14px; }
.timeline li { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 8px; font-size: 13px; color: var(--muted); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -19px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.timeline li:last-child::before { background: var(--accent); }
.timeline strong { color: var(--ink); font-weight: 600; }
.tl-when { font-variant-numeric: tabular-nums; }

@media (max-width: 1100px) {
  .inv-grid { grid-template-columns: minmax(0, 1fr); }
  /* Sur écran étroit, les points à vérifier passent avant le document. */
  .side { order: -1; }
  .viewer { position: static; }
  .viewer-stage { max-height: none; }
}

@media (max-width: 640px) {
  .inv-sum { align-items: flex-start; text-align: left; }
  .inv-actions { justify-content: stretch; }
  .inv-actions .btn { flex: 1; justify-content: center; }
  .action-hint { text-align: left; }
  .viewer-stage { padding: 12px; }
  .doc { padding: 2em 1.6em; }
  .doc-head { flex-direction: column; gap: 1em; }
  .doc-title { text-align: left; }
  .doc-client, .doc-totals { width: 100%; }
  .field { grid-template-columns: minmax(0, 1fr) auto; }
  .field dd { grid-column: 1; grid-row: 2; }
  .field .conf { grid-row: 1 / 3; grid-column: 2; }
  .timeline li { grid-template-columns: minmax(0, 1fr); gap: 0; }
}

.sup-link { color: var(--gray-800); font-weight: 600; text-decoration: none; }
.sup-link:hover { text-decoration: underline; }

/* Habillage de la fiche aux couleurs du thème */
.crumbs a { font-size: 14px; font-weight: 400; color: var(--gray-600); }
.crumbs-next { font-weight: 600 !important; }
.inv-amount { font-size: 24px; font-weight: 700; letter-spacing: 0; color: var(--gray-900); }
.inv-sum .pill { margin-bottom: 4px; }
.action-hint { font-size: 14px; font-weight: 500; }

.viewer { background: var(--gray-50); border: 1px solid var(--gray-100); border-radius: 16px; }
.viewer-bar { background: #fff; color: var(--gray-900); border-bottom: 1px solid var(--gray-100); padding: 8px 12px 8px 16px; font-size: 14px; }
.viewer-name svg { color: var(--gray-600); width: 20px; height: 20px; }
.viewer-zoom { color: var(--gray-600); font-size: 14px; }
.icon-btn { width: 32px; height: 32px; border-radius: 50%; background: var(--gray-50); color: var(--gray-700); margin-left: 4px; }
.icon-btn:hover { background: var(--gray-100); color: var(--gray-900); }

.card { border: 1px solid var(--gray-100); box-shadow: none; padding: 24px; border-radius: 16px; }
.card-title { font-size: 16px; font-weight: 600; color: var(--gray-900); margin-bottom: 16px; }
.card-text { font-size: 14px; color: var(--gray-600); }
.ia-head { font-size: 16px; color: var(--gray-900); }
.ia-head strong { font-weight: 600; }
.ia-card.is-warn { box-shadow: none; border-color: var(--warning-100); }
.ia-card.is-warn .ia-head svg { color: var(--warning-500); }
.ia-card.is-ok .ia-head svg { color: var(--success-500); }
.conf { font-weight: 500; font-size: 14px; }

.check { background: var(--warning-50); border-radius: 8px; padding: 16px; gap: 12px; }
.check-title { color: var(--gray-900); font-size: 14px; }
.check-title strong { font-weight: 600; }
.check-title svg { color: var(--warning-500); width: 20px; height: 20px; }
.check-text { color: var(--gray-700); font-size: 14px; line-height: 20px; }
.check-options .btn-ghost { background: #fff; }
.check-options .btn-ghost:hover { background: var(--primary-50); }
.check.is-done { background: var(--success-50); }
.check-done svg { color: var(--success-500); }
.link-btn { color: var(--success-600); font-weight: 600; font-size: 14px; }

.field { padding: 12px; margin: 0 -12px; border-radius: 8px; }
.field + .field { box-shadow: 0 -1px 0 var(--gray-100); }
.field dt { font-size: 14px; color: var(--gray-600); }
.field dd { font-weight: 500; color: var(--gray-900); }
.field.is-review { background: var(--warning-50); }
.field.is-review dd { color: var(--warning-600); }
.field.is-resolved .conf { color: var(--success-600); }
.field.is-hl { background: var(--primary-50); }

.imputation-value { color: var(--gray-900); font-weight: 600; }

.step-dot { width: 28px; height: 28px; font-size: 12px; background: var(--gray-50); color: var(--gray-600); }
.stepper li { font-size: 14px; font-weight: 500; }
.stepper li::after { top: 13px; left: 34px; background: var(--gray-100); }
.stepper li.is-done .step-dot { background: var(--primary-500); }
.stepper li.is-done::after { background: var(--primary-500); }
.timeline { border-left-color: var(--gray-100); gap: 12px; }
.timeline li { font-size: 14px; color: var(--gray-600); grid-template-columns: 96px minmax(0, 1fr); }
.timeline strong { color: var(--gray-900); font-weight: 500; }
.timeline li::before { background: var(--gray-300); }
.timeline li:last-child::before { background: var(--primary-500); }
.doc-f.is-hl { background: var(--primary-50); box-shadow: 0 0 0 2px var(--primary-500); }
.doc-f.is-flag { background: var(--warning-50); box-shadow: 0 0 0 1.5px var(--warning-500); }

/* Étape en cours du circuit : couleur de l'état, comme les étiquettes de la liste */
.stepper.is-verifier { --step: var(--warning-500); --step-ink: var(--warning-600); }
.stepper.is-valider { --step: var(--gray-600); --step-ink: var(--gray-800); }
.stepper.is-payer { --step: var(--blue-500); --step-ink: var(--blue-600); }
.stepper li.is-current { color: var(--step-ink); }
.stepper li.is-current .step-dot { color: var(--step-ink); box-shadow: inset 0 0 0 2px var(--step); }

/* « À valider » : Clara attend le gérant, elle ne valide pas elle-même */
.waiting {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px 10px 12px;
  background: #f3f5f7; border-radius: 14px;
}
.waiting p { display: flex; flex-direction: column; line-height: 1.35; }
.waiting strong { color: var(--gray-900); font-weight: 600; font-size: 14px; }
.waiting p span { font-size: 12px; color: var(--gray-600); }
.waiting-avatar { width: 38px; height: 38px; font-size: 12px; flex: none; }
.waiting-avatar .kpi-badge { width: 18px; height: 18px; }
.demo-link { flex-basis: 100%; text-align: right; font-size: 12px; color: var(--gray-600); font-weight: 600; }
.demo-link:hover { color: var(--gray-700); }
.action-hint.is-info { color: var(--gray-600); font-weight: 500; }

/* Correction à la main */
.fields-hint { margin: -4px 0 6px; font-size: 13px; }
.field-end { display: flex; align-items: center; gap: 4px; justify-self: end; }
.field-edit {
  width: 28px; height: 28px; border: 0; border-radius: 8px; display: grid; place-items: center;
  background: none; color: var(--gray-600); cursor: pointer; opacity: 0; transition: opacity 0.15s;
}
.field-edit svg.i { width: 15px; height: 15px; }
.field:hover .field-edit, .field:focus-within .field-edit, .field.is-review .field-edit, .field-edit:focus-visible { opacity: 1; }
.field-edit:hover { background: #fff; color: var(--gray-900); }
.field.is-edited { background: var(--blue-50); }
.field.is-edited .conf { color: var(--blue-600); }
.field.is-editing { grid-template-columns: minmax(0, 1fr); gap: 8px; background: var(--gray-50); box-shadow: none; }
.field.is-editing label { font-size: 13px; font-weight: 600; color: var(--gray-800); }
.edit-hint { font-size: 12px; color: var(--gray-600); }
.edit-hint.is-error { color: var(--danger-600); font-weight: 600; }
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; }
.edit-actions .btn-ghost { background: #fff; }
.check-fix { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; font-size: 13px; color: var(--gray-700); padding: 0; }
.check-fix svg.i { width: 14px; height: 14px; }
.check-wait { font-size: 13px; color: var(--warning-600); font-weight: 600; }

/* Vue du gérant : décider */
.decide-note { display: flex; align-items: center; gap: 6px; margin-right: auto; font-size: 13px; color: var(--gray-600); }
.decide-note svg.i { width: 16px; height: 16px; color: var(--gray-600); }

@keyframes slide-up { from { transform: translateY(100%); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .inv-actions.is-decide { animation: none; } }

/* Ce que Julien valide : l'essentiel d'un coup d'œil */
.decide-card { display: flex; flex-direction: column; gap: 12px; }
.decide-obj { font-size: 15px; font-weight: 600; color: var(--gray-900); }
.decide-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.decide-grid > div { padding: 10px 12px; border-radius: 12px; background: var(--gray-50); }
.decide-grid dt { font-size: 12px; color: var(--gray-600); }
.decide-grid dd { font: 600 16px/1.3 var(--font-num); color: var(--gray-900); }
.decide-grid dd.is-late { color: var(--danger-600); }
.decide-checks { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.decide-checks li { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--gray-700); }
.decide-checks svg.i { width: 16px; height: 16px; color: var(--success-500); margin-top: 1px; }
.decide-checks li.is-warn { color: var(--warning-600); font-weight: 600; }
.decide-checks li.is-warn svg.i { color: var(--warning-500); }
.decide-doc { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; font-size: 13px; font-weight: 700; color: var(--gray-900); text-decoration: none; }
.decide-doc svg.i { width: 16px; height: 16px; }
.decide-doc:hover { text-decoration: underline; }
.decide-done { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.decide-done > svg.i { width: 28px; height: 28px; color: var(--success-500); }
.decide-done span { display: flex; flex-direction: column; font-size: 12px; color: var(--gray-600); }
.decide-done strong { font-size: 14px; color: var(--gray-900); }
.inv-actions .btn-primary svg.i:last-child:not(:first-child) { margin-left: 2px; }

/* Facture refusée : le motif et la suite */
.refusal {
  flex: 1; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border-radius: 14px; background: var(--gray-50); box-shadow: inset 0 0 0 1px var(--gray-100);
}
.refusal-ico { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none; background: #fff; color: var(--gray-600); box-shadow: inset 0 0 0 1.5px var(--gray-300); }
.refusal-ico svg.i { width: 16px; height: 16px; }
.refusal-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 260px; }
.refusal-main strong { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.refusal-main span { font-size: 12px; color: var(--gray-600); }
.refusal-next { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.refusal-step { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 99px; background: #fff; font-size: 12px; font-weight: 600; color: var(--warning-600); }
.refusal-step svg.i { width: 14px; height: 14px; }
.refusal-step.is-done { color: var(--success-600); }
.refusal .btn-ghost { background: #fff; }

@media (max-width: 640px) {
  /* Julien sur téléphone : refuser / valider restent sous le pouce */
  .inv-actions.is-decide {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: grid; grid-template-columns: 1fr 1.6fr; gap: 8px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: #fff; box-shadow: 0 -8px 24px rgba(16, 24, 40, 0.1);
    animation: slide-up 0.25s ease-out;
  }
  .inv-actions.is-decide .decide-note { display: none; }
  .inv-actions.is-decide .btn { height: 48px; justify-content: center; font-size: 15px; }
  .decide-done { flex-basis: 100%; }
  .inv-actions > a.btn { width: 100%; justify-content: center; height: 48px; }
  .field-edit { opacity: 1; }
  .decide-note { flex-basis: 100%; }
  .timeline li { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .waiting { flex-wrap: wrap; }
  .demo-link { text-align: left; }
}
