/* ═══ Éditeur intelligent du document ═══ */

.smart-doc-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 6px 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.smart-doc-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.smart-mode-btn {
  font: 500 11px/1.2 system-ui, sans-serif;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.smart-mode-btn:hover {
  border-color: var(--accent-pale);
  color: var(--text-primary);
}

.smart-mode-btn.active {
  background: var(--accent-pale);
  border-color: var(--accent);
  color: var(--accent-dark, #92400e);
  font-weight: 600;
}

.smart-doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: auto;
}

.smart-action-btn {
  font: 500 11px/1.2 system-ui, sans-serif;
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.smart-action-btn:hover {
  background: var(--bg-hover, rgba(0, 0, 0, 0.04));
  color: var(--text-primary);
}

.smart-action-btn.primary {
  background: var(--accent-pale);
  color: var(--accent-dark, #92400e);
  border-color: rgba(180, 83, 9, 0.25);
}

/* ── Capsules intelligentes ── */

.smart-token {
  display: inline;
  font: inherit;
  line-height: inherit;
  border-radius: 3px;
  padding: 0 4px;
  margin: 0 1px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: pre-wrap;
  transition: background 0.12s, box-shadow 0.12s, border-color 0.12s;
}

.smart-token:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-pale);
}

.smart-field-token.status-missing {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.28);
  color: #991b1b;
}

.smart-field-token.status-verify {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.35);
  color: #92400e;
}

.smart-field-token.status-ok {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.25);
  color: inherit;
}

.smart-field-token.status-manual {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.3);
}

.smart-field-token.status-optional {
  background: rgba(100, 116, 139, 0.06);
  border-color: rgba(100, 116, 139, 0.2);
  color: var(--text-secondary);
  font-style: italic;
}

.smart-field-token.status-forced {
  background: rgba(139, 92, 246, 0.08);
  border-color: rgba(139, 92, 246, 0.3);
}

.smart-field-token.field-token-active,
.smart-field-token.smart-token-active {
  background: rgba(180, 83, 9, 0.18) !important;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px var(--accent-pale);
  animation: token-pulse 1.2s ease 2;
}

.smart-src {
  display: inline-block;
  font: 600 8px/1 system-ui, sans-serif;
  padding: 1px 4px;
  margin-left: 4px;
  border-radius: 3px;
  vertical-align: middle;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.smart-src-pdf { background: rgba(239, 68, 68, 0.12); color: #b91c1c; }
.smart-src-excel { background: rgba(16, 185, 129, 0.12); color: #047857; }
.smart-src-calc { background: rgba(139, 92, 246, 0.12); color: #6d28d9; }
.smart-src-src { background: rgba(100, 116, 139, 0.12); color: #475569; }

.smart-token-tech {
  font-family: ui-monospace, monospace;
  font-size: 0.92em;
  background: rgba(100, 116, 139, 0.08);
  border: 1px dashed rgba(100, 116, 139, 0.35);
  color: #475569;
}

/* ── Sections ── */

.smart-section-marker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 8px;
  padding: 4px 0;
  border-top: 1px solid rgba(100, 116, 139, 0.15);
  font: 600 10px/1.3 system-ui, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  cursor: pointer;
}

.smart-section-marker.active { color: var(--text-secondary); }
.smart-section-marker.inactive { opacity: 0.55; }
.smart-section-marker.conditional { border-left: 3px solid rgba(139, 92, 246, 0.45); padding-left: 8px; }

.smart-section-tag {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(100, 116, 139, 0.1);
}

.smart-section-state {
  font-weight: 500;
  font-size: 9px;
  opacity: 0.75;
}

.smart-section-minimal {
  border: none;
  margin: 12px 0 4px;
  font-size: 9px;
  opacity: 0.5;
}

/* ── Sections conditionnelles ── */

.smart-conditional {
  margin: 12px 0;
  border-left: 3px solid rgba(245, 158, 11, 0.5);
  padding-left: 12px;
}

.smart-conditional.inactive {
  border-left-color: rgba(100, 116, 139, 0.35);
  background: rgba(100, 116, 139, 0.04);
  padding: 10px 12px;
  border-radius: 0 6px 6px 0;
}

.smart-conditional.active {
  border-left-color: rgba(139, 92, 246, 0.45);
}

.smart-conditional-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font: 600 10px/1.3 system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.smart-cond-tag {
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(245, 158, 11, 0.15);
  color: #92400e;
}

.smart-conditional.inactive .smart-cond-tag {
  background: rgba(100, 116, 139, 0.12);
  color: #475569;
}

.smart-cond-reason,
.smart-cond-rule {
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  font-size: 11px;
}

.smart-conditional-preview {
  font-size: 12px;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 8px;
}

.smart-conditional-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.smart-cond-btn {
  font: 500 10px/1 system-ui, sans-serif;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
  color: var(--text-secondary);
}

.smart-cond-btn:hover {
  border-color: var(--accent);
  color: var(--accent-dark, #92400e);
}

/* ── Variantes ── */

.smart-variant {
  margin: 10px 0 4px;
}

.smart-variant-head {
  font: 600 10px/1.3 system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6d28d9;
  padding: 4px 0;
}

.smart-variant-tag {
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(139, 92, 246, 0.12);
  margin-right: 6px;
}

/* ── Modes d'affichage ── */

.doc-mode-final .smart-token,
.doc-mode-final .field-token,
.doc-mode-final .doc-section-label,
.doc-mode-final .smart-section-marker,
.doc-mode-final .smart-conditional-head,
.doc-mode-final .smart-variant,
.doc-mode-final .smart-conditional.inactive,
.doc-mode-final .smart-conditional-actions,
.doc-mode-final .smart-conditional-preview {
  display: none !important;
}

.doc-mode-final .smart-conditional.active .smart-conditional-body {
  display: block !important;
}

.doc-mode-clean .smart-field-token.status-ok {
  background: transparent !important;
  border-color: transparent !important;
  padding: 0;
  margin: 0;
  color: inherit;
}

.doc-mode-clean .smart-field-token.status-ok .smart-src {
  display: none;
}

.doc-mode-clean .smart-field-token.status-ok::before,
.doc-mode-clean .smart-field-token.status-ok::after {
  content: none;
}

.doc-mode-clean .smart-section-marker,
.doc-mode-clean .smart-variant-head,
.doc-mode-clean .smart-conditional-head {
  opacity: 0.35;
  font-size: 9px;
}

.doc-mode-logic .smart-conditional,
.doc-mode-logic .smart-section-marker.conditional,
.doc-mode-logic .smart-field-token[data-token-kind="choice"] {
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.2);
}

.doc-mode-logic .smart-conditional.inactive {
  opacity: 1;
}

.doc-mode-technical .smart-field-token:not(.smart-token-tech) {
  display: none;
}

/* ── Popover de saisie ── */

.field-edit-popover {
  position: fixed;
  z-index: 9000;
  width: min(320px, calc(100vw - 24px));
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.14);
  padding: 12px;
}

.field-edit-popover.hidden {
  display: none;
}

.field-popover-label {
  font: 600 13px/1.3 system-ui, sans-serif;
  margin: 0 0 8px;
  color: var(--text-primary);
}

.field-popover-meta {
  font: 400 11px/1.4 system-ui, sans-serif;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.field-popover-input {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  resize: vertical;
}

.field-popover-yn {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.field-popover-yn button {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
  font-weight: 600;
}

.field-popover-yn button.active {
  background: var(--accent-pale);
  border-color: var(--accent);
}

.field-popover-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.field-popover-actions .btn {
  flex: 1;
  min-width: 0;
}

.field-popover-occurrences {
  font-size: 11px;
  color: var(--text-secondary);
  margin: 6px 0;
}

/* ── Complétion guidée ── */

.guided-completion-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: linear-gradient(90deg, rgba(180, 83, 9, 0.08), rgba(245, 158, 11, 0.06));
  border: 1px solid rgba(180, 83, 9, 0.2);
  border-radius: 8px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.guided-completion-bar.hidden {
  display: none;
}

.guided-progress {
  font: 600 12px/1.3 system-ui, sans-serif;
  color: var(--accent-dark, #92400e);
  white-space: nowrap;
}

.guided-field-name {
  flex: 1;
  font-size: 12px;
  color: var(--text-primary);
}

.guided-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* ── Barre de sélection ── */

.selection-toolbar {
  position: fixed;
  z-index: 8500;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.selection-toolbar.hidden {
  display: none;
}

.selection-toolbar button {
  font: 500 11px/1 system-ui, sans-serif;
  padding: 5px 10px;
  border: none;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  color: var(--text-primary);
  white-space: nowrap;
}

.selection-toolbar button:hover {
  background: var(--accent-pale);
}

/* ── Tiroir Logique ── */

.logic-block {
  margin-bottom: 16px;
}

.logic-block h4 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin: 0 0 8px;
}

.logic-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.logic-list li {
  font-size: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.45;
}

.logic-effect {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.logic-state-active em { color: #047857; font-style: normal; }
.logic-state-inactive em { color: #64748b; font-style: normal; }
.logic-state-incomplete em { color: #b45309; font-style: normal; }

.logic-detect-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.logic-detect-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.logic-detect-item sample {
  font-style: italic;
  color: var(--text-secondary);
}

/* Occurrences surlignées */
.decision-doc-editor.occurrence-highlight .smart-token[data-field-key] {
  opacity: 0.35;
}

.decision-doc-editor.occurrence-highlight .smart-token.occurrence-active {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--accent);
}

.review-action-btn[data-drawer="logic"].active {
  background: var(--accent-pale);
  border-color: var(--accent);
}

/* ── Tokens structurés label / valeur ── */

.smart-field-token.smart-field-compact {
  gap: 0;
}

.smart-field-token.smart-field-compact .field-value-primary {
  font-weight: 500;
}

.smart-field-token.smart-field-plain {
  background: transparent;
  border-color: transparent;
  padding: 0 2px;
  margin: 0 1px;
}

.smart-field-token.smart-field-plain.status-missing,
.smart-field-token.smart-field-plain.status-verify,
.smart-field-token.smart-field-plain.status-optional {
  background: rgba(239, 68, 68, 0.06);
  border: 1px solid rgba(239, 68, 68, 0.22);
  padding: 1px 6px;
  border-radius: 4px;
}

.doc-display-values .smart-field-token.status-ok,
.doc-display-values .smart-field-token.status-manual {
  border-width: 1px;
  border-style: solid;
}

.doc-display-read .smart-field-token.smart-field-plain.status-ok {
  background: transparent;
  border-color: transparent;
}

.doc-display-variables .smart-field-token .field-label {
  display: inline;
}

.doc-display-values .smart-field-token .field-label {
  display: none;
}

.field-token .field-value-primary {
  font-weight: 500;
}

.field-token {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 2px 8px;
  margin: 0 2px;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  vertical-align: baseline;
  line-height: 1.45;
  min-height: 1.6em;
  box-sizing: border-box;
  user-select: none;
}

.field-token:hover {
  box-shadow: 0 0 0 1px rgba(180, 83, 9, 0.2);
}

.field-token .field-label {
  font-size: 0.82em;
  font-weight: 600;
  opacity: 0.72;
  text-transform: none;
}

.field-token .field-value {
  font-weight: 500;
}

.field-token.status-local {
  border-style: dashed;
  border-color: rgba(59, 130, 246, 0.45);
}

.field-local-mark {
  font: 600 8px/1 system-ui, sans-serif;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(59, 130, 246, 0.12);
  color: #1d4ed8;
  text-transform: uppercase;
}

.field-token-detached {
  background: rgba(100, 116, 139, 0.06);
  border: 1px dotted rgba(100, 116, 139, 0.35);
  padding: 0 2px;
}

/* ── Labels de section sobres ── */

.doc-section-label {
  font: 600 9px/1.3 system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(100, 116, 139, 0.65);
  margin: 16px 0 4px;
  padding: 0;
  cursor: pointer;
}

.doc-section-label:hover {
  color: var(--accent-dark, #92400e);
}

.doc-section-conditional {
  color: rgba(139, 92, 246, 0.75);
}

.smart-conditional-head-compact {
  margin-bottom: 4px;
  font-size: 10px;
  opacity: 0.8;
}

/* ── Panneau champs unifié ── */

.field-row {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 0;
  background: #fff;
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
}

.field-row:hover {
  border-color: rgba(180, 83, 9, 0.35);
}

.field-row.field-row-active,
.field-row-active {
  border-color: var(--accent, #b45309);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
}

.field-row.row-missing {
  border-left: 4px solid #dc2626;
  background: #fef2f2;
}

.field-row.row-error {
  border-left: 4px solid #dc2626;
  background: #fef2f2;
}

.field-row.row-neutral {
  border-left: 4px solid #eab308;
  background: #fffbeb;
}

.field-row.row-ok {
  border-left: 4px solid #16a34a;
}

.field-row-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.field-row-label {
  display: block;
  font: 600 14px/1.35 system-ui, sans-serif;
  color: var(--text-primary);
  cursor: pointer;
}

.field-required-mark {
  color: #dc2626;
}

.field-row-badge {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field-row-badge-ok {
  background: #dcfce7;
  color: #166534;
}

.field-row-badge-missing,
.field-row-badge-error {
  background: #fee2e2;
  color: #991b1b;
}

.field-row-badge-neutral {
  background: #fef9c3;
  color: #854d0e;
}

.field-row-help {
  margin: -4px 0 8px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-secondary);
}

.field-row-title {
  margin: 0;
  font: 600 13px/1.3 system-ui, sans-serif;
}

.field-row-input {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  padding: 9px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fff;
  min-height: 40px;
}

.field-row-input:focus {
  outline: none;
  border-color: var(--accent, #b45309);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}

.field-row-input.textarea,
textarea.field-row-input {
  min-height: 72px;
  resize: vertical;
}

.field-row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field-row-meta-tag {
  padding: 2px 7px;
  border-radius: 4px;
  background: #fef9c3;
  color: #854d0e;
  font-weight: 600;
}

.field-row-ref {
  font-size: 11px;
  color: var(--text-secondary);
  margin: 0 0 8px;
  padding: 8px;
  background: #f1f5f9;
  border-radius: 6px;
  line-height: 1.45;
}

.field-row-ref-label {
  display: block;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  color: #64748b;
}

.field-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.field-row-action {
  padding: 6px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #f8fafc;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.field-row-action:hover {
  border-color: #cbd5e1;
  color: var(--text-primary);
}

.field-row-action-primary {
  border-color: var(--accent, #b45309);
  background: var(--accent-pale, #fffbeb);
  color: var(--accent-dark, #92400e);
}

.field-popover-reference {
  margin-bottom: 8px;
  padding: 8px;
  background: rgba(100, 116, 139, 0.06);
  border-radius: 6px;
  font-size: 11px;
}

.field-popover-ref-label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-secondary);
}

/* ── Plan du document ── */

.doc-plan {
  margin: 0;
  padding: 0;
  list-style: none;
}

.doc-plan-item {
  margin-bottom: 4px;
}

.doc-plan-btn {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.doc-plan-btn:hover {
  background: var(--accent-pale);
}

.doc-plan-item.disabled .doc-plan-label {
  opacity: 0.5;
}

.doc-plan-index {
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 1.5em;
}

.doc-plan-tag {
  font: 600 9px/1 system-ui, sans-serif;
  padding: 2px 5px;
  border-radius: 3px;
  background: rgba(139, 92, 246, 0.12);
  color: #6d28d9;
  margin-left: auto;
}

/* ── Résultat d'analyse ── */

.analysis-block {
  margin-bottom: 16px;
}

.analysis-block h4 {
  font-size: 12px;
  font-weight: 700;
  margin: 0 0 8px;
}

.analysis-list {
  margin: 0;
  padding-left: 1.1em;
  font-size: 12px;
  line-height: 1.5;
}

.analysis-conf,
.analysis-ref {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.attach-field-sample {
  font-style: italic;
  margin-bottom: 10px;
}

.attach-field-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.attach-field-option {
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
  font: inherit;
}

.attach-field-option:hover {
  border-color: var(--accent);
  background: var(--accent-pale);
}

.doc-mode-clean .field-token.status-ok .field-label {
  display: none;
}

.doc-mode-clean .field-token.status-ok {
  background: transparent !important;
  border-color: transparent !important;
  padding: 0 2px;
}

.doc-mode-clean .field-token.status-ok .field-value {
  font-weight: inherit;
}

