/* PH-154e — invoice review, Figma « Lecture des factures » F02–F05, F07c, F08, F09.
   Tokens only (colors_and_type.css). One column: no inline preview (CSP), the file card
   carries « Ouvrir l'original ». At 375 px every grid stacks. */

.ir-page {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}
.ir-breadcrumb {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.ir-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-link);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.ir-link:hover { color: var(--text-link-hover); }
.ir-link:focus-visible,
.ir-steps button:focus-visible,
.ir-toggle button:focus-visible,
.ir-choice button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.ir-title {
  margin: 0;
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  overflow-wrap: anywhere;
}
.ir-muted {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}
.ir-error {
  display: inline-flex;
  gap: var(--space-1);
  align-items: flex-start;
  color: var(--text-danger);
  font-size: var(--text-sm);
}
.ir-warning {
  display: inline-flex;
  gap: var(--space-1);
  align-items: flex-start;
  margin-top: calc(var(--space-2) * -1);
  color: var(--text-warning);
  font-size: var(--text-sm);
}
.ir-line-issues { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); align-items: center; }
.ir-line-issues .ir-warning { margin-top: 0; }
.ir-mono { font-family: var(--font-mono); font-size: var(--text-sm); }
.ir-static { display: inline-block; padding: var(--space-2) 0; font-weight: var(--font-weight-medium); }

/* Banners: F07c / F08 info (blue), F05 / F08 duplicate (coral). */
.ir-banner {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.ir-banner p { margin: var(--space-1) 0 0; }
.ir-banner--info { background: var(--bg-info-subtle); color: var(--text-primary); }
.ir-banner--info svg { color: var(--icon-info); }
.ir-banner--error { background: var(--bg-danger-subtle); color: var(--text-primary); }
.ir-banner--error svg { color: var(--icon-danger); }
.ir-banner-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin-top: var(--space-3); }

/* Stepper: three cards, the current one on the brand tint, a blocked one in coral. */
.ir-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}
.ir-steps button {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  width: 100%;
  min-height: var(--target-min);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.ir-steps button:disabled { cursor: not-allowed; }
.ir-steps strong { display: block; font-weight: var(--font-weight-medium); }
.ir-steps small { display: block; color: var(--text-secondary); font-size: var(--text-xs); }
.ir-step-num {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  font-size: var(--text-xs);
}
.ir-step.is-current button { border: 2px solid var(--border-selected); background: var(--bg-brand-subtle); }
.ir-step.is-current .ir-step-num { background: var(--bg-inverse); color: var(--text-inverse); }
.ir-step.is-current small { color: var(--text-warning); }
.ir-step.is-done .ir-step-num { background: var(--bg-success-subtle); color: var(--text-success); }
.ir-step.is-blocked button { border: 2px solid var(--border-danger); background: var(--bg-danger-subtle); }
.ir-step.is-blocked small { color: var(--text-danger); }

.ir-file {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.ir-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}
.ir-stack, .ir-lines { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.ir-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--space-5);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
}
.ir-card-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  justify-content: space-between;
}
.ir-card-head h2 { margin: 0; font-size: var(--text-lg); font-weight: var(--font-weight-semibold); }
.ir-chip {
  padding: var(--space-0-5) var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.ir-field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.ir-field input, .ir-field select, .ir-amount input, .ir-units input { width: 100%; box-sizing: border-box; }
.ir-field-head { display: flex; gap: var(--space-2); align-items: center; justify-content: space-between; font-size: var(--text-sm); font-weight: var(--font-weight-medium); }
.ir-grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.ir-grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); }
.ir-confirm-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: flex-start; }

/* Confidence: « ✓ 96 % », « ● 72 % · à vérifier » (amber), « ● Vérifié par vous · 81 % » (sage). */
.ir-confidence { display: inline-flex; gap: var(--space-1); align-items: center; color: var(--text-secondary); font-size: var(--text-xs); white-space: nowrap; }
.ir-badge { padding: var(--space-0-5) var(--space-2); border-radius: var(--radius-pill); font-size: var(--text-xs); white-space: nowrap; }
.ir-badge::before { content: '● '; }
.ir-badge--warn { background: var(--bg-warning-subtle); color: var(--text-warning); }
.ir-badge--ok { background: var(--bg-success-subtle); color: var(--text-success); }

.ir-amount {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(96px, 130px);
  gap: var(--space-3);
  align-items: center;
}
.ir-amount > span:first-child { display: flex; flex-direction: column; }
.ir-amount input { text-align: right; }
/* F02d rule 11: the discount, shown negative, typed positive. */
.ir-signed { display: flex; align-items: center; gap: var(--space-1); }
.ir-signed > span { color: var(--text-secondary); }
.ir-amount--total { font-weight: var(--font-weight-medium); }
/* F02d: a tax IT added (type, optional label for « Autre », Retirer, amount). */
.ir-amount--added .ir-added-type { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-1); }
.ir-add-tax { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.ir-check { display: flex; gap: var(--space-2); align-items: flex-start; font-size: var(--text-sm); cursor: pointer; }
.ir-check input { margin-top: 3px; }

.ir-coherence {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--bg-success-subtle);
  font-size: var(--text-sm);
}
.ir-coherence ul { display: flex; flex-direction: column; gap: var(--space-1); margin: var(--space-2) 0 0; padding: 0; list-style: none; }
.ir-coherence li { display: flex; gap: var(--space-2); align-items: center; }
.ir-coherence.is-failing { background: var(--bg-danger-subtle); }
/* E7 (F02d rule 8): no check possible, one neutral line. */
.ir-coherence.is-neutral { background: var(--bg-subtle); }
/* E8 (rule 9): a corrected amount keeps its « J'ai vérifié » height. */
.ir-check.is-reserved { visibility: hidden; }
/* E1 (rule 10): the new supplier's name, normalized and editable. */
.ir-new-supplier { display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-sm); }
/* E8 (rule 9): the amounts card measures its own width (the label never under ~160 px). */
.ir-amounts { container: ir-amounts / inline-size; }
/* Under 460 px the label would get less than 160 px (badge ~150 + amount 130 + gaps). */
@container ir-amounts (max-width: 460px) {
  .ir-amount { grid-template-columns: minmax(0, 1fr) minmax(96px, 130px); }
  .ir-amount > span:first-child { grid-column: 1 / -1; }
  .ir-amount--added .ir-added-type { grid-column: 1 / -1; align-items: stretch; }
  .ir-amount--added { grid-template-columns: minmax(0, 1fr) auto; }
  .ir-amount--added > button { order: 3; }
}

/* F02 « Candidats proposés ». */
.ir-candidates {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  font-size: var(--text-sm);
}
.ir-candidates legend { float: left; width: 100%; padding: 0; margin-bottom: var(--space-1); color: var(--text-secondary); font-size: var(--text-xs); }
.ir-candidate { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--space-2); align-items: center; cursor: pointer; }
.ir-candidates .ir-link { align-self: flex-start; text-align: left; }
.ir-reason { font-style: italic; }

/* Lines (F03, F09). */
.ir-line {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
}
.ir-line-head { display: flex; gap: var(--space-3); align-items: flex-start; }
.ir-line-num {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  font-size: var(--text-xs);
}
.ir-line-title { display: flex; flex: 1; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.ir-line-title strong { font-weight: var(--font-weight-medium); }
.ir-line-amount { white-space: nowrap; }
.ir-line-body { display: flex; flex-direction: column; gap: var(--space-2); }
.ir-asset-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; font-size: var(--text-sm); }
.ir-toggle { display: inline-flex; gap: var(--space-1); }
.ir-toggle button, .ir-choice button {
  display: inline-flex;
  gap: var(--space-1);
  align-items: center;
  min-height: var(--control-h-md);
  padding: 0 var(--space-4);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
}
.ir-toggle button.is-on, .ir-choice button.is-on { border: 2px solid var(--border-selected); background: var(--bg-brand-subtle); }
.ir-choice button { justify-content: flex-start; width: 100%; padding: var(--space-2) var(--space-4); text-align: left; }

.ir-discarded {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
}
.ir-discarded-row {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  font-size: var(--text-sm);
}
.ir-discarded-row > span { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }

/* Units (F04): a table that becomes stacked rows on a phone. */
.ir-units { display: flex; flex-direction: column; border-radius: var(--radius-md); overflow: hidden; background: var(--bg-subtle); }
.ir-units-row {
  display: grid;
  grid-template-columns: 90px minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  font-size: var(--text-sm);
}
.ir-units-row > span { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.ir-units-head { background: var(--bg-subtle); color: var(--text-secondary); font-size: var(--text-xs); letter-spacing: var(--tracking-caps); text-transform: uppercase; }
.ir-units-group { padding: var(--space-3) var(--space-4); background: var(--bg-subtle); }
.ir-units-group span { display: flex; flex-direction: column; }
.ir-units-row.is-error { background: var(--bg-danger-subtle); }
.ir-pill { align-self: flex-start; padding: var(--space-0-5) var(--space-2); border-radius: var(--radius-pill); background: var(--bg-subtle); font-size: var(--text-xs); }

/* Footer: the state of the step on the left, the actions on the right. */
.ir-footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
}
.ir-footer > svg { color: var(--icon-warning); }
.ir-footer--error > svg { color: var(--icon-danger); }
.ir-footer--info > svg { color: var(--icon-info); }
.ir-footer-text { display: flex; flex: 1 1 240px; flex-direction: column; gap: var(--space-1); min-width: 0; }
.ir-footer-text small { color: var(--text-secondary); font-size: var(--text-xs); }
.ir-footer-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

@media (max-width: 900px) {
  .ir-columns { grid-template-columns: minmax(0, 1fr); }
}
/* E8 (rule 9): 768–1023 px, the amounts in their mobile layout: label and note on the whole width,
   then the badge and the amount. */
@media (max-width: 1023px) {
  .ir-amount { grid-template-columns: minmax(0, 1fr) minmax(96px, 130px); }
  .ir-amount > span:first-child { grid-column: 1 / -1; }
  .ir-amount--added { grid-template-columns: minmax(0, 1fr) auto; }
  .ir-amount--added .ir-added-type { grid-column: 1 / -1; align-items: stretch; }
  .ir-amount--added > button { order: 3; }
}
@media (max-width: 640px) {
  .ir-steps, .ir-grid2, .ir-grid3 { grid-template-columns: minmax(0, 1fr); }
  .ir-units-head { display: none; }
  .ir-units-row { grid-template-columns: minmax(0, 1fr); }
  .ir-amount { grid-template-columns: minmax(0, 1fr) minmax(96px, 130px); }
  .ir-amount .ir-confidence, .ir-amount .ir-badge { grid-column: 1; }
  /* F02d at 375: the type on its own row, then the amount and « Retirer ». */
  .ir-amount--added { grid-template-columns: minmax(0, 1fr) auto; }
  .ir-amount--added .ir-added-type { grid-column: 1 / -1; align-items: stretch; }
  .ir-amount--added > button { order: 3; }
  .ir-card { padding: var(--space-4); }
}
