/* ============================================================
   Design tokens
   ============================================================ */
:root {
  /* Base palette (dark) */
  --bg-app: #0a0c10;
  --bg-1: #11141a;
  --bg-2: #181c24;
  --bg-3: #21262f;
  --bg-hover: #262b36;
  --border: #2a2f3a;
  --border-strong: #3a4150;

  /* Text */
  --text: #e8ebf0;
  --text-2: #b4bcc8;
  --text-dim: #7d8693;
  --text-faint: #555c69;

  /* Brand / accent */
  --accent: #5b8def;
  --accent-hover: #7aa3ff;
  --accent-soft: rgba(91, 141, 239, 0.15);

  /* Semantic */
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.12);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.12);
  --error: #f87171;
  --error-soft: rgba(248, 113, 113, 0.12);

  /* Type colors for placeholders */
  --c-person-h: #5b9bd5;
  --c-person-f: #e07abd;
  --c-person-u: #9aa3b2;
  --c-email: #b19cd9;
  --c-phone: #4db6ac;
  --c-address: #ffb74d;
  --c-iban: #81c784;
  --c-credit: #66bb6a;
  --c-tax: #fff176;
  --c-id: #ffd54f;
  --c-org: #ba68c8;
  --c-job: #a1887f;
  --c-date: #90caf9;
  --c-dob: #64b5f6;
  --c-ip: #f06292;
  --c-mac: #f48fb1;
  --c-api: #ef5350;
  --c-url: #4fc3f7;
  --c-medical: #ff8a65;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  --radius-sm: 4px;
  --radius: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);

  --font-sans: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', Monaco, Menlo, ui-monospace, monospace;
}

/* ============================================================
   Reset & base
   ============================================================ */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg-app);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ============================================================
   Header
   ============================================================ */
.app-header {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  padding: var(--sp-3) var(--sp-5);
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.brand-icon { font-size: 18px; }
.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.health {
  display: flex;
  gap: var(--sp-2);
  flex: 1;
  justify-content: center;
}

.health-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 5px var(--sp-3);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  transition: background 0.15s;
}
.health-badge:hover { background: var(--bg-3); }

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background 0.2s;
}
.health-badge.ok .health-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success-soft);
}
.health-badge.err .health-dot {
  background: var(--error);
  box-shadow: 0 0 8px var(--error-soft);
}
.health-badge.loading .health-dot {
  background: var(--warn);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.health-label { font-weight: 500; color: var(--text-2); }
.health-detail { color: var(--text-dim); font-size: 11px; }

.header-actions {
  display: flex;
  gap: var(--sp-2);
}

/* Segmented control mode (Anonymisation | Conversation) */
.mode-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.mode-btn {
  padding: 5px var(--sp-4);
  font-size: 12.5px;
  color: var(--text-dim);
  border-radius: 999px;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.15s;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active {
  background: var(--accent);
  color: white;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   Body layout
   ============================================================ */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  width: 240px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar.hidden { display: none; }

.sidebar-section-header {
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-section-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
}
.sidebar-section-action {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.sidebar-section-action:hover { background: var(--accent-soft); color: var(--accent); }

.sidebar-search {
  padding: 0 var(--sp-3) var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.sidebar-search input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  outline: none;
  font-size: 12.5px;
}
.sidebar-search input:focus {
  border-color: var(--accent);
  background: var(--bg-3);
}

.session-list {
  list-style: none;
  margin: 0;
  padding: var(--sp-2) 0;
  overflow-y: auto;
  flex: 1;
}

.session-item {
  padding: var(--sp-2) var(--sp-3);
  margin: 2px var(--sp-2);
  cursor: pointer;
  border-radius: var(--radius);
  position: relative;
  transition: background 0.1s;
}
.session-item:hover { background: var(--bg-2); }
.session-item.active {
  background: var(--accent-soft);
  border-left: 2px solid var(--accent);
  padding-left: 10px;
}

.session-title {
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  margin-bottom: 2px;
}
.session-meta {
  font-size: 10.5px;
  color: var(--text-dim);
  display: flex;
  gap: var(--sp-2);
}
.session-meta .chip {
  background: var(--bg-3);
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 9.5px;
}

.session-delete {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 18px;
  height: 18px;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 14px;
  border-radius: 3px;
}
.session-item:hover .session-delete { display: inline-flex; }
.session-delete:hover { color: var(--error); background: var(--bg-3); }

.session-list .empty-state {
  padding: var(--sp-5);
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}

/* ============================================================
   Main
   ============================================================ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  padding: var(--sp-4) var(--sp-5);
  gap: var(--sp-3);
}
.main.hidden { display: none; }

/* ============================================================
   Presets bar
   ============================================================ */
.presets-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.presets {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-wrap: wrap;
}
.presets-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: var(--sp-2);
}

.preset-btn {
  padding: 5px var(--sp-3);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-2);
  transition: all 0.15s;
}
.preset-btn:hover {
  background: var(--bg-3);
  color: var(--text);
}
.preset-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}

/* ============================================================
   Types avancés (collapsible)
   ============================================================ */
.types-advanced {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-3);
}
.types-advanced.hidden { display: none; }

#entity-checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--sp-2);
}

.entity-checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px var(--sp-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  user-select: none;
  transition: background 0.1s;
}
.entity-checkbox:hover { background: var(--bg-2); }

.entity-checkbox input { cursor: pointer; accent-color: var(--accent); }

.entity-checkbox-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ============================================================
   Workspace : 2 panels + action column
   ============================================================ */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: var(--sp-3);
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.panel-icon { font-size: 14px; opacity: 0.7; }
.panel-hint {
  font-size: 11px;
  color: var(--text-dim);
}

.panel textarea {
  flex: 1;
  background: transparent;
  color: var(--text);
  border: none;
  outline: none;
  padding: var(--sp-4);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.55;
  resize: none;
  min-height: 0;
}
.panel textarea::placeholder { color: var(--text-faint); white-space: pre-wrap; }

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--border);
  background: var(--bg-1);
  min-height: 36px;
}

.char-counter, .output-stats, .status {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.status.ok { color: var(--success); }
.status.warn { color: var(--warn); }
.status.err { color: var(--error); }

/* ============================================================
   Action column : bouton run + progress
   ============================================================ */
.action-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-2);
}

.btn-run {
  background: var(--accent);
  color: white;
  padding: var(--sp-4) var(--sp-4);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 130px;
  box-shadow: var(--shadow);
  transition: all 0.15s;
  font-weight: 500;
}
.btn-run:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}
.btn-run:disabled {
  background: var(--bg-3);
  color: var(--text-dim);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}
.btn-run-label { font-size: 14px; }
.btn-run-sublabel { font-size: 10.5px; opacity: 0.75; font-weight: 400; }

.progress {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: 100%;
  margin-top: var(--sp-2);
}
.progress[hidden] { display: none; }

.progress-step {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 11px;
  color: var(--text-dim);
}
.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}
.progress-step.active .progress-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse 1.5s ease-in-out infinite;
}
.progress-step.done .progress-dot {
  background: var(--success);
  border-color: var(--success);
}
.progress-step.active, .progress-step.done { color: var(--text); }

/* ============================================================
   Rich text (zone d'affichage avec placeholders coloriés)
   ============================================================ */
.rich-text {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  outline: none;
}
.rich-text:empty::before {
  content: attr(data-empty);
  color: var(--text-faint);
  font-style: italic;
}

/* Placeholders coloriés */
.ph {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  cursor: help;
  border: 1px solid currentColor;
  background: color-mix(in srgb, currentColor 10%, transparent);
  transition: all 0.15s;
  vertical-align: baseline;
}
.ph:hover {
  background: color-mix(in srgb, currentColor 25%, transparent);
  transform: translateY(-1px);
}
.ph.ph-highlight {
  animation: ph-flash 1.5s ease;
}
@keyframes ph-flash {
  0%, 100% { background: color-mix(in srgb, currentColor 10%, transparent); }
  30%, 70% { background: color-mix(in srgb, currentColor 50%, transparent); box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 20%, transparent); }
}

/* Couleurs par type */
.ph-PERSON, .ph-PERSON_H_ { color: var(--c-person-h); }
.ph-PERSON_F_ { color: var(--c-person-f); }
.ph-PERSON_U_ { color: var(--c-person-u); }
.ph-EMAIL_ { color: var(--c-email); }
.ph-PHONE_ { color: var(--c-phone); }
.ph-ADDRESS_ { color: var(--c-address); }
.ph-IBAN_ { color: var(--c-iban); }
.ph-CREDIT_CARD_ { color: var(--c-credit); }
.ph-TAX_ID_ { color: var(--c-tax); }
.ph-ID_NUMBER_ { color: var(--c-id); }
.ph-ORG_ { color: var(--c-org); }
.ph-JOB_TITLE_ { color: var(--c-job); }
.ph-DATE_ { color: var(--c-date); }
.ph-DATE_OF_BIRTH_ { color: var(--c-dob); }
.ph-IP_ADDRESS_ { color: var(--c-ip); }
.ph-MAC_ADDRESS_ { color: var(--c-mac); }
.ph-API_KEY_ { color: var(--c-api); }
.ph-URL_ { color: var(--c-url); }
.ph-MEDICAL_CONDITION_ { color: var(--c-medical); }
.ph-orphan {
  color: var(--error);
  background: var(--error-soft);
  border-style: dashed;
  text-decoration: line-through;
  text-decoration-color: var(--error);
}

/* Tooltip */
.tooltip {
  position: fixed;
  z-index: 1000;
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  font-size: 12px;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  max-width: 320px;
  word-wrap: break-word;
}
.tooltip.hidden { display: none; }
.tooltip-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}
.tooltip-value {
  font-family: var(--font-mono);
  color: var(--text);
}
.tooltip-type {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  margin-top: 4px;
  font-family: var(--font-mono);
}

/* ============================================================
   Alerts
   ============================================================ */
.alerts-zone {
  background: var(--bg-1);
  border: 1px solid var(--warn-soft);
  border-radius: var(--radius-md);
  padding: var(--sp-3);
  flex-shrink: 0;
}
.alerts-zone[hidden] { display: none; }

.alerts-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}
.alerts-icon { color: var(--warn); font-size: 14px; }
.alerts-title {
  font-size: 12.5px;
  font-weight: 600;
  flex: 1;
}

.alerts-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 120px;
  overflow-y: auto;
}

.alert-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px var(--sp-3);
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--warn);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.1s;
}
.alert-item:hover { background: var(--bg-3); }
.alert-item.severity-error { border-left-color: var(--error); }
.alert-item.severity-warn { border-left-color: var(--warn); }

.alert-kind {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  color: var(--text-2);
  flex-shrink: 0;
}
.alert-message { flex: 1; color: var(--text); }
.alert-locate { font-size: 11px; color: var(--text-dim); }

/* ============================================================
   Details zone (collapsible technical view)
   ============================================================ */
.details-zone {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  flex-shrink: 0;
}
.details-zone summary {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  font-size: 12.5px;
  list-style: none;
  user-select: none;
}
.details-zone summary::-webkit-details-marker { display: none; }
.details-zone summary:hover { background: var(--bg-2); }

.details-chevron {
  font-size: 10px;
  color: var(--text-dim);
  transition: transform 0.15s;
}
.details-zone[open] .details-chevron { transform: rotate(180deg); }

.details-title { color: var(--text-2); font-weight: 500; }
.details-summary { color: var(--text-dim); font-size: 11.5px; margin-left: auto; }

.details-content { border-top: 1px solid var(--border); }

.details-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.details-tab {
  padding: var(--sp-2) var(--sp-4);
  font-size: 12px;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.details-tab:hover { color: var(--text); }
.details-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.details-panel {
  padding: var(--sp-3);
  max-height: 280px;
  overflow-y: auto;
}
.details-panel.hidden { display: none; }
.details-panel .rich-text {
  padding: var(--sp-3);
  background: var(--bg-2);
  border-radius: var(--radius);
  font-size: 12.5px;
  max-height: 220px;
}

.mapping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: var(--font-mono);
}
.mapping-table td {
  padding: 5px var(--sp-2);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.mapping-table tr:last-child td { border-bottom: none; }
.mapping-table .cell-ph {
  width: 1%;
  white-space: nowrap;
}
.mapping-table .cell-arrow {
  width: 20px;
  color: var(--text-faint);
  text-align: center;
}
.mapping-table .cell-value { color: var(--text); word-break: break-all; }

/* ============================================================
   Buttons (généraux)
   ============================================================ */
.btn-primary {
  background: var(--accent);
  color: white;
  padding: 6px var(--sp-3);
  border-radius: var(--radius);
  font-size: 12.5px;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled {
  background: var(--bg-3);
  color: var(--text-dim);
  cursor: not-allowed;
}

.btn-ghost {
  color: var(--text-2);
  padding: 5px var(--sp-3);
  border-radius: var(--radius);
  font-size: 12px;
  transition: background 0.1s;
}
.btn-ghost:hover { background: var(--bg-3); color: var(--text); }

.btn-small { padding: 3px var(--sp-2); font-size: 11.5px; }

/* ============================================================
   Vue Conversation (chat anonymisé multi-tours)
   ============================================================ */
.conv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.conv-header-main h2 {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 600;
}
.conv-header-main .hint { font-size: 11.5px; color: var(--text-dim); }
.conv-header-actions { display: flex; gap: var(--sp-2); align-items: center; }

/* Layout chat avec panneau mapping latéral */
.chat-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
  min-height: 0;
  transition: grid-template-columns 0.2s ease;
}
.chat-layout.with-mapping {
  grid-template-columns: 1fr 280px;
}

.chat-area {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: var(--sp-3);
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-height: 0;
}

.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
  max-width: 460px;
  padding: var(--sp-5);
}
.chat-empty-icon { font-size: 48px; opacity: 0.4; margin-bottom: var(--sp-3); }
.chat-empty h3 { color: var(--text); font-size: 16px; margin: 0 0 var(--sp-3); font-weight: 600; }
.chat-empty p { font-size: 13px; line-height: 1.6; margin: 0 0 var(--sp-3); }
.chat-empty-hint { color: var(--text-faint); font-size: 12px; }

.chat-bubble {
  max-width: 75%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg);
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  position: relative;
  animation: bubble-in 0.2s ease-out;
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-bottom-right-radius: var(--radius-sm);
}
.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--radius-sm);
}

/* Auteur en haut de chaque bulle */
.chat-bubble-author {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  letter-spacing: 0.2px;
}
.chat-bubble.user .chat-bubble-author { color: var(--accent); }
.chat-bubble.assistant .chat-bubble-author { color: var(--text-2); }
.chat-bubble-author-name { flex-shrink: 0; }
.chat-bubble-author-date {
  font-size: 10.5px;
  font-weight: 400;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.chat-bubble-content {
  word-wrap: break-word;
}

/* ---- Markdown rendering (bulles assistant) — compact ---- */
.chat-bubble-content.markdown { font-size: 13.5px; line-height: 1.45; }
.chat-bubble-content.markdown > *:first-child { margin-top: 0 !important; }
.chat-bubble-content.markdown > *:last-child { margin-bottom: 0 !important; }

.markdown h1, .markdown h2, .markdown h3, .markdown h4, .markdown h5, .markdown h6 {
  margin: 10px 0 3px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  line-height: 1.3;
}
.markdown h1 { font-size: 17px; }
.markdown h2 { font-size: 15px; }
.markdown h3 { font-size: 14px; }
.markdown h4 { font-size: 13.5px; }

.markdown p { margin: 0 0 6px; }
.markdown p:last-child { margin-bottom: 0; }

.markdown strong { font-weight: 600; color: var(--text); }
.markdown em { font-style: italic; }
.markdown del { color: var(--text-dim); text-decoration: line-through; }

.markdown a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.markdown a:hover { color: var(--accent-hover); }

.markdown ul, .markdown ol { margin: 4px 0 6px; padding-left: 22px; }
.markdown li { margin: 0; padding: 1px 0; }
.markdown li > p { margin: 0; }
.markdown li > ul, .markdown li > ol { margin: 2px 0 2px; }

.markdown blockquote {
  border-left: 3px solid var(--accent);
  padding: 2px 10px;
  margin: 6px 0;
  color: var(--text-2);
  background: rgba(255,255,255,0.02);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.markdown blockquote p { margin: 2px 0; }

.markdown code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-3);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text);
}

.markdown pre {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin: 6px 0;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.4;
}
.markdown pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: 12px;
  color: var(--text);
}

.markdown table {
  border-collapse: collapse;
  margin: 6px 0;
  font-size: 12.5px;
  width: 100%;
}
.markdown th, .markdown td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}
.markdown th {
  background: var(--bg-3);
  font-weight: 600;
  color: var(--text);
}
.markdown tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

.markdown hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

.markdown img { max-width: 100%; height: auto; border-radius: var(--radius); }
.chat-bubble-actions {
  display: none;
  position: absolute;
  top: -10px;
  right: var(--sp-3);
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 2px;
  gap: 0;
  box-shadow: var(--shadow);
  z-index: 5;
}
.chat-bubble:hover .chat-bubble-actions { display: flex; }
.chat-bubble-action {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13px;
  transition: background 0.1s, color 0.1s;
}
.chat-bubble-action:hover { background: var(--bg-2); color: var(--text); }
.chat-bubble-action.danger:hover { color: var(--error); }

.chat-bubble-meta {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 6px;
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}
.chat-bubble-meta .alert-pill {
  background: var(--warn-soft);
  color: var(--warn);
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  cursor: pointer;
}

.chat-bubble.thinking {
  background: var(--bg-2);
  border: 1px dashed var(--border-strong);
  align-self: flex-start;
  color: var(--text-dim);
  font-style: italic;
}
.chat-bubble.thinking::after {
  content: '▍';
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.chat-input-bar {
  display: flex;
  gap: var(--sp-2);
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-2);
}
.chat-input-bar textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  resize: none;
  padding: var(--sp-2);
  min-height: 36px;
  max-height: 200px;
}
.chat-input-bar textarea::placeholder { color: var(--text-faint); white-space: pre; }

.chat-input-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
}
.chat-input-wrap textarea { width: 100%; }
.chat-word-counter {
  align-self: flex-end;
  padding: 2px 8px 0;
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.chat-send-group {
  display: flex;
  gap: var(--sp-1);
  align-self: flex-end;
}
.chat-send {
  padding: var(--sp-2) var(--sp-4);
  font-size: 14px;
  height: 38px;
}
.chat-send-review {
  background: var(--bg-3);
  color: var(--text-2);
  border: 1px solid var(--border-strong);
  padding: var(--sp-2) var(--sp-3);
}
.chat-send-review:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

/* Mapping side panel */
.mapping-panel {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.mapping-panel.hidden { display: none; }

.mapping-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.mapping-panel-header h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}
.mapping-panel-count {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  min-width: 22px;
  text-align: center;
}
.mapping-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-3);
}
.mapping-panel-empty {
  color: var(--text-dim);
  font-size: 12px;
  font-style: italic;
  text-align: center;
  margin: var(--sp-5) 0;
  padding: 0 var(--sp-3);
  line-height: 1.6;
}

/* Popup d'info message (raw anonymisé) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  backdrop-filter: blur(2px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  max-width: 640px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 14px; font-weight: 600; }
.modal-close {
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: var(--bg-3); color: var(--text); }
.modal-body { padding: var(--sp-4); }
.modal-footer {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  background: var(--bg-2);
}
.modal-section { margin-bottom: var(--sp-4); }
.modal-section:last-child { margin-bottom: 0; }
.modal-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: var(--sp-2);
}
.modal-section-content {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3);
  font-size: 12.5px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.55;
  max-height: 280px;
  overflow-y: auto;
}

/* Conv list items (réutilise .session-item) — highlight pour message count */
.session-item .conv-count {
  background: var(--bg-3);
  color: var(--text-2);
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 9.5px;
}

/* ============================================================
   Pages publiques (vitrine, sign-in, sign-up)
   ============================================================ */
body.page-public {
  display: block;
  overflow-y: auto;
}

.public-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-6);
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}
.public-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
}
.public-brand .brand-icon { font-size: 18px; }
.public-nav { display: flex; gap: var(--sp-2); }
.public-nav a { text-decoration: none; }

.landing {
  max-width: 980px;
  margin: 0 auto;
  padding: var(--sp-7) var(--sp-5);
}
.hero {
  text-align: center;
  margin-bottom: var(--sp-7);
}
.hero h1 {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 var(--sp-4);
  color: var(--text);
}
.hero-tagline {
  font-size: 16px;
  color: var(--text-2);
  max-width: 640px;
  margin: 0 auto var(--sp-5);
  line-height: 1.6;
}
.hero-cta { display: flex; justify-content: center; gap: var(--sp-3); flex-wrap: wrap; }

.btn-lg {
  padding: var(--sp-3) var(--sp-5);
  font-size: 14px;
  border-radius: var(--radius-md);
  text-decoration: none;
  display: inline-block;
}
.btn-block { width: 100%; }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-4);
}
.feature {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
}
.feature-icon { font-size: 24px; margin-bottom: var(--sp-2); }
.feature h3 { margin: 0 0 var(--sp-2); font-size: 14px; }
.feature p { color: var(--text-2); margin: 0; font-size: 13px; line-height: 1.5; }

.public-footer {
  display: flex;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-4);
  color: var(--text-dim);
  font-size: 12px;
  border-top: 1px solid var(--border);
}
.public-footer a { color: var(--text-dim); text-decoration: none; }
.public-footer a:hover { color: var(--text); }

/* ===== Onboarding steps indicator ===== */
.onboarding-steps {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  font-size: 11.5px;
}
.onboarding-steps .step {
  padding: 4px 10px;
  color: var(--text-dim);
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--border);
}
.onboarding-steps .step.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
.onboarding-steps .step.done {
  color: var(--success);
  border-color: var(--success-soft);
}
.onboarding-steps .step.done::before { content: '✓ '; }

/* ===== Auth pages (sign-in, sign-up) ===== */
.page-auth { display: flex; flex-direction: column; min-height: 100vh; }
.auth-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
}
.auth-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-6);
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.auth-card-inline { padding: 0; border: none; background: transparent; }
.auth-card h1 { margin: 0; font-size: 22px; }
.auth-subtitle { color: var(--text-2); font-size: 13px; margin: -8px 0 var(--sp-2); }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-field span { font-size: 12px; color: var(--text-2); font-weight: 500; }
.auth-field input, .auth-field select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px var(--sp-3);
  color: var(--text);
  outline: none;
  font-size: 14px;
}
.auth-field input:focus, .auth-field select:focus { border-color: var(--accent); }
.auth-hint { color: var(--text-dim); font-size: 11px; }
.auth-error {
  background: var(--error-soft);
  color: var(--error);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  font-size: 12.5px;
  margin: 0;
}
.auth-alt {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  margin: 0;
}
.auth-alt a { color: var(--accent); text-decoration: none; }
.auth-alt a:hover { text-decoration: underline; }

/* ===== Console superadmin ===== */
.console-main {
  padding: var(--sp-5);
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  overflow-y: auto;
}
.console-section {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.console-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.console-section-header h2 { margin: 0; font-size: 14px; font-weight: 600; }
.console-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-3);
  padding: var(--sp-4);
}
.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  text-align: center;
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.stat-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }

.console-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.console-table th, .console-table td {
  text-align: left;
  padding: 10px var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.console-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  background: var(--bg-2);
}
.console-table tr:last-child td { border-bottom: none; }
.console-table tr:hover td { background: var(--bg-2); }
.row-actions { display: flex; gap: var(--sp-1); justify-content: flex-end; }
.row-actions .danger:hover { color: var(--error); }

.role-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 8px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.role-pill.role-superadmin { background: var(--error-soft); color: var(--error); }
.role-pill.role-admin { background: var(--warn-soft); color: var(--warn); }
.role-pill.role-user { background: var(--accent-soft); color: var(--accent); }

.badge-self {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 9.5px;
  font-weight: 600;
  margin-left: 4px;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px var(--sp-3);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-2);
  text-decoration: none;
}
.user-chip-link {
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.user-chip-link:hover {
  background: var(--bg-3);
  border-color: var(--accent);
  color: var(--text);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr auto 1fr; }
  .action-column { flex-direction: row; }
  .progress { flex-direction: row; }
}
@media (max-width: 700px) {
  .sidebar { display: none; }
  .health { display: none; }
}
