:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e2e6ec;
  --text: #1a2030;
  --muted: #6b7280;
  --primary: #2156d4;
  --primary-hover: #1a45ab;
  --success: #1f9d55;
  --warning: #b97200;
  --error: #c12a2a;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 32px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.brand h1 { margin: 0; font-size: 20px; }
.subtitle { margin: 0; color: var(--muted); font-size: 13px; }

.profile-selector { display: flex; align-items: center; gap: 8px; }
.profile-selector select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
}

.layout {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Layout 2 colonnes quand la prévisualisation PDF est active */
.layout-with-preview {
  max-width: 1800px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 520px;
  gap: 16px;
  align-items: start;
}
.layout-with-preview.preview-collapsed {
  grid-template-columns: minmax(0, 1fr) 40px;
}
.layout-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.layout-preview {
  position: sticky;
  top: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: #f4f6f9;
  flex-shrink: 0;
}
.preview-toolbar strong { font-size: 13px; }
.preview-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}
.preview-actions button {
  padding: 2px 8px;
  font-size: 14px;
  line-height: 1;
  min-width: 28px;
}
#zoom-level {
  min-width: 40px;
  text-align: center;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--muted);
}
.preview-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #e9ecef;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.preview-page {
  max-width: 100%;
  height: auto;
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  border: 1px solid #d0d5dc;
}
.preview-page-label {
  font-size: 10px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  margin-bottom: 4px;
}
.preview-loading, .preview-error {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.preview-error { color: var(--error); }

.layout-with-preview.preview-collapsed .preview-toolbar strong,
.layout-with-preview.preview-collapsed .preview-actions > *:not(#toggle-preview),
.layout-with-preview.preview-collapsed .preview-content {
  display: none;
}
.layout-with-preview.preview-collapsed #toggle-preview { transform: rotate(180deg); }

/* Responsive : sur écran étroit, preview en bas */
@media (max-width: 1100px) {
  .layout-with-preview { grid-template-columns: 1fr; }
  .layout-preview { position: static; height: 600px; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}

.card h2 {
  margin: 0 0 16px;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.hidden { display: none !important; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  background: #fafbfc;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone.drag { background: #eef3ff; border-color: var(--primary); }
.dropzone p { margin: 4px 0; }
.hint { color: var(--muted); font-size: 12px; }

.source-info {
  margin-top: 12px;
  padding: 12px;
  background: #eef3ff;
  border-radius: var(--radius);
  font-size: 13px;
}

.detection-report {
  margin-top: 12px;
  padding: 14px 16px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  font-size: 13px;
}
.detection-report h3 { margin: 0 0 8px; font-size: 14px; color: var(--text); }
.detection-report .det-alert {
  padding: 12px 14px;
  background: #fef2f2;
  border: 1px solid #f5b5b5;
  border-left: 4px solid var(--error);
  border-radius: 6px;
  margin-bottom: 12px;
  color: #6b1818;
  line-height: 1.4;
}
.detection-report .det-row { margin: 4px 0; }
.detection-report .det-label { display: inline-block; min-width: 160px; color: var(--muted); }
.detection-report .det-value { color: var(--text); font-weight: 500; }
.detection-report .det-reason { color: var(--muted); font-size: 11px; font-style: italic; }
.detection-report .det-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  background: #e5edff;
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  margin-right: 4px;
}
.detection-report .det-tag.warn { background: #fff3e0; color: var(--warning); }
.detection-report ul { margin: 4px 0 0 18px; padding: 0; }
.detection-report ul li { margin: 2px 0; }

.det-debug {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}
.det-debug summary { cursor: pointer; user-select: none; }
.det-debug ol {
  margin: 6px 0 0 20px;
  padding: 8px 10px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  max-height: 240px;
  overflow-y: auto;
}

.siren-title {
  margin: 14px 0 8px;
  font-size: 13px;
  color: var(--text);
}
.siren-loading { color: var(--muted); font-style: italic; }
.siren-card {
  margin: 6px 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: white;
  border-left: 4px solid var(--border);
  font-size: 12px;
  line-height: 1.5;
}
.siren-card.siren-ok { border-left-color: var(--success); background: #f0faf3; }
.siren-card.siren-warn { border-left-color: var(--warning); background: #fff7e6; }
.siren-card.siren-error { border-left-color: var(--error); background: #fef2f2; }
.siren-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 13px;
}
.siren-body > div { margin: 2px 0; }
.siren-compare { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--border); }
.siren-active { background: #d1fae5; color: #047857; }
.siren-inactive { background: #fee2e2; color: #991b1b; }

.siren-summary {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
  font-size: 12px;
}
.siren-matrix { display: flex; flex-direction: column; gap: 4px; }
.siren-field-check {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12px;
}
.siren-field-check.ok { background: rgba(31, 157, 85, 0.08); }
.siren-field-check.ko { background: rgba(193, 42, 42, 0.08); }
.siren-field-check.ok .siren-check-status { color: var(--success); }
.siren-field-check.ko .siren-check-status { color: var(--error); }
.siren-check-icon { font-size: 14px; }

.siren-conform-warn {
  margin-top: 8px;
  padding: 8px 10px;
  background: #fef2f2;
  border: 1px solid #f5b5b5;
  border-radius: 4px;
  font-size: 12px;
  color: #6b1818;
}

.siren-hint {
  font-size: 11px;
  color: var(--muted);
  margin: 4px 0 10px;
  font-style: italic;
}

.siren-actions {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.siren-apply {
  padding: 6px 12px;
  background: var(--primary);
  color: white;
  border: 1px solid var(--primary);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 500;
}
.siren-apply:hover { background: var(--primary-hover); }

.ocr-prompt {
  margin-top: 12px;
  padding: 14px 16px;
  background: #fff7e6;
  border: 1px solid #f0c674;
  border-left: 4px solid var(--warning);
  border-radius: var(--radius);
  font-size: 13px;
}
.ocr-prompt p { margin: 8px 0; color: var(--muted); }
.ocr-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.ocr-progress {
  margin-top: 12px;
  padding: 10px 14px;
  background: white;
  border-radius: 4px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.ocr-spinner {
  width: 18px;
  height: 18px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: ocr-spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes ocr-spin { to { transform: rotate(360deg); } }
.ocr-tag {
  display: inline-block;
  padding: 1px 6px;
  background: var(--primary);
  color: white;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  vertical-align: middle;
}

.raw-text-debug {
  margin-top: 12px;
  padding: 10px 14px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
}
.raw-text-debug summary {
  cursor: pointer;
  user-select: none;
  color: var(--muted);
  font-weight: 500;
}
.raw-text-debug summary:hover { color: var(--text); }
.raw-text-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0;
}
#raw-text-content {
  max-height: 400px;
  overflow: auto;
  background: #1f2330;
  color: #e6e9ef;
  padding: 12px;
  border-radius: 4px;
  font-size: 11px;
  font-family: ui-monospace, monospace;
  white-space: pre;
  line-height: 1.4;
}

.toast-success {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 18px;
  background: var(--success);
  color: white;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 1000;
  animation: slideIn 0.2s ease-out;
}
@keyframes slideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.totals-discrepancy {
  margin-bottom: 12px;
  padding: 12px 14px;
  background: #fef2f2;
  border: 1px solid #f5b5b5;
  border-left: 4px solid var(--error);
  border-radius: var(--radius);
  font-size: 13px;
}
.discrepancy-table {
  margin: 8px 0;
  border-collapse: collapse;
  font-size: 12px;
}
.discrepancy-table th, .discrepancy-table td {
  padding: 4px 10px;
  text-align: left;
  border-bottom: 1px solid #f5d5d5;
}
.discrepancy-table th { color: var(--muted); font-weight: 500; }
.discrepancy-table td { font-weight: 600; }
.discrepancy-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.missing-fields {
  margin: 12px 0;
  padding: 12px 14px;
  background: #fef7e7;
  border: 1px solid #f0c674;
  border-left: 4px solid var(--warning);
  border-radius: var(--radius);
  font-size: 13px;
}
.missing-fields h4 { margin: 0 0 6px; font-size: 13px; color: var(--warning); }
.missing-fields ul { margin: 0; padding-left: 20px; }
.missing-fields li { margin: 2px 0; }
.missing-fields .code {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--warning);
  margin-right: 6px;
}
.missing-fields.ok {
  background: #e7f7ec;
  border-color: #7cc59a;
  border-left-color: var(--success);
}
.missing-fields.ok h4 { color: var(--success); }

/* Champ requis vide en rouge */
input.required-empty, select.required-empty {
  border-color: var(--error) !important;
  background: #fef5f5;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px 16px;
  margin: 0 0 16px;
}
legend { padding: 0 6px; font-weight: 600; color: var(--text); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px 16px;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  gap: 4px;
}
input, select, textarea {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}
input[readonly] { background: #f4f6f9; color: var(--text); }

.lines-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 8px;
}
.lines-table th, .lines-table td {
  border: 1px solid var(--border);
  padding: 4px 6px;
  text-align: left;
}
.lines-table th { background: #f4f6f9; font-weight: 600; }
.lines-table input, .lines-table select {
  padding: 4px 6px;
  font-size: 12px;
  width: 100%;
}
.lines-table .col-line { width: 28px; text-align: center; }
.lines-table .col-qty, .lines-table .col-rate { width: 70px; }
.lines-table .col-unit, .lines-table .col-cat { width: 200px; }
.lines-table .col-pu, .lines-table .col-total { width: 90px; }
.lines-table .remove-line { background: transparent; color: var(--error); border: none; cursor: pointer; }

.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
button {
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
button:hover { background: #f4f6f9; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
button.primary:hover { background: var(--primary-hover); }
button.primary.btn-warning {
  background: var(--warning);
  border-color: var(--warning);
}
button.primary.btn-warning:hover { background: #9a5c00; }
button.secondary {
  background: white;
  color: var(--primary);
  border-color: var(--primary);
}

.validation-item {
  display: flex;
  gap: 12px;
  padding: 8px 12px;
  border-left: 4px solid var(--border);
  background: #fafbfc;
  margin-bottom: 6px;
  border-radius: 4px;
  font-size: 13px;
}
.validation-item.error { border-color: var(--error); background: #fef2f2; }
.validation-item.warning { border-color: var(--warning); background: #fff7e6; }
.validation-item.success { border-color: var(--success); background: #f0faf3; }
.validation-item .code { font-weight: 600; min-width: 90px; font-family: ui-monospace, monospace; }
.validation-summary {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-weight: 600;
}
.validation-summary.ok { background: #e7f7ec; color: #126638; }
.validation-summary.ko { background: #fde7e7; color: #8a1c1c; }

.hint-inline { font-style: italic; color: var(--muted); font-weight: normal; }

.rec-panel {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: white;
}
.rec-panel-ok { border-left: 4px solid var(--success); background: #f0faf3; }
.rec-panel-ko { border-left: 4px solid var(--error); background: #fef2f2; }
.rec-panel h4 { margin: 0 0 8px; font-size: 13px; }
.rec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 6px;
}
.rec-table th, .rec-table td {
  padding: 5px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.rec-table thead th { color: var(--muted); font-weight: 500; font-size: 11px; }
.rec-table tbody th { width: 25%; font-weight: 600; }
.rec-bt { font-family: ui-monospace, monospace; font-size: 10px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.rec-num { font-family: ui-monospace, monospace; text-align: right; width: 25%; }
.rec-diff { font-family: ui-monospace, monospace; text-align: right; font-weight: 600; }
.rec-table .rec-ok .rec-diff { color: var(--success); }
.rec-table .rec-ko { background: #fff5f5; }
.rec-table .rec-ko .rec-diff { color: var(--error); }
.rec-msg-ok { margin: 6px 0 0; font-size: 12px; color: var(--success); }
.rec-msg-ko { margin: 6px 0 0; font-size: 12px; color: var(--error); }

.seres-h3 {
  margin: 16px 0 8px;
  font-size: 14px;
  border-top: 2px solid var(--border);
  padding-top: 16px;
}

.seres-summary {
  padding: 12px 14px;
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.seres-summary-ok { background: #e7f7ec; border: 1px solid #7cc59a; }
.seres-summary-ko { background: #fde7e7; border: 1px solid #f5b5b5; }
.seres-verdict { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.seres-stats { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; }
.seres-stat {
  padding: 2px 8px;
  border-radius: 10px;
  background: white;
  border: 1px solid var(--border);
}
.seres-stat.pass { color: var(--success); border-color: var(--success); }
.seres-stat.fail { color: var(--error); border-color: var(--error); font-weight: 700; }
.seres-stat.warn { color: var(--warning); border-color: var(--warning); }
.seres-stat.na, .seres-stat.nc, .seres-stat.manual { color: var(--muted); }
.seres-stat.total { background: var(--bg); }

.seres-section {
  margin-bottom: 10px;
  padding: 10px 12px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.seres-section summary {
  cursor: pointer;
  font-size: 13px;
  user-select: none;
}
.seres-section[open] summary { margin-bottom: 8px; }

.seres-bc-list, .seres-list { margin: 0; padding: 0; list-style: none; }
.seres-bc {
  padding: 8px 10px;
  margin-bottom: 4px;
  background: #eef3ff;
  border-left: 3px solid var(--primary);
  border-radius: 4px;
  font-size: 12px;
}
.seres-bc-empty { color: var(--muted); font-style: italic; font-size: 12px; }

.seres-item {
  padding: 6px 10px;
  margin-bottom: 4px;
  border-left: 3px solid var(--border);
  background: white;
  border-radius: 4px;
  font-size: 12px;
}
.seres-item.seres-pass { border-left-color: var(--success); }
.seres-item.seres-fail.seres-fatal { border-left-color: var(--error); background: #fef2f2; }
.seres-item.seres-fail.seres-warning { border-left-color: var(--warning); background: #fff7e6; }
.seres-item.seres-na { opacity: 0.6; }
.seres-item.seres-not-checkable { opacity: 0.5; }
.seres-item.seres-manual { border-left-color: var(--primary); background: #eef3ff; }
.seres-item strong { font-family: ui-monospace, monospace; margin-right: 6px; }
.seres-sev {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: #ddd;
  color: #555;
}
.seres-item.seres-fatal .seres-sev { background: var(--error); color: white; }
.seres-item.seres-warning .seres-sev { background: var(--warning); color: white; }
.seres-desc { margin-top: 3px; }
.seres-detail { margin-top: 3px; color: var(--error); font-weight: 500; }

pre#xml-preview {
  max-height: 420px;
  overflow: auto;
  background: #1f2330;
  color: #e6e9ef;
  padding: 12px;
  border-radius: 6px;
  font-size: 12px;
  white-space: pre;
}

footer {
  max-width: 1100px;
  margin: 32px auto 24px;
  padding: 0 16px;
  font-size: 11px;
  color: var(--muted);
}
