/* EducExtract — design system
   Couleurs cohérentes : Source / Transformation / Succès / Avertissement / Erreur
   La couleur n'est jamais le seul vecteur d'information : icône + texte + badge. */

:root {
  --color-bg: #f6f7fb;
  --color-surface: #ffffff;
  --color-border: #e3e6ee;
  --color-text: #1f2430;
  --color-text-muted: #6b7280;

  --color-source: #2563eb;
  --color-source-bg: #eaf0fe;
  --color-transform: #7c3aed;
  --color-transform-bg: #f2ebfe;
  --color-success: #15803d;
  --color-success-bg: #e7f7ec;
  --color-warning: #b45309;
  --color-warning-bg: #fef3e0;
  --color-error: #b91c1c;
  --color-error-bg: #fdeaea;

  --radius: 10px;
  --shadow-card: 0 1px 2px rgba(20, 24, 40, .06), 0 1px 8px rgba(20, 24, 40, .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

a { color: var(--color-source); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 8px;
}
@media (max-width: 760px) {
  .app-header { flex-direction: column; align-items: flex-start; }
  .header-actions { margin-left: 0; }
  .header-actions a { margin-left: 0; margin-right: 14px; }
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--color-text);
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: block;
}

.header-actions { display: flex; flex-wrap: wrap; align-items: center; row-gap: 6px; }
.header-actions a {
  margin-left: 16px;
  color: var(--color-text-muted);
  font-size: 14px;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px;
}

.container-wide { max-width: 1320px; }

/* Wizard stepper */
.stepper {
  display: flex;
  gap: 6px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 600;
}
.step .num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--color-border);
  color: var(--color-text);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
}
.step.active {
  background: var(--color-source-bg);
  border-color: var(--color-source);
  color: var(--color-source);
}
.step.active .num { background: var(--color-source); color: white; }
.step.done { color: var(--color-success); }
.step.done .num { background: var(--color-success); color: white; }
.step.disabled { opacity: .5; }
.step-arrow { color: var(--color-border); align-self: center; }

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 22px;
  margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 18px; }
.card h3 { font-size: 15px; margin-top: 0; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card-muted { color: var(--color-text-muted); font-size: 13px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 860px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: #f0f1f6; text-decoration: none; }
.btn-primary { background: var(--color-source); border-color: var(--color-source); color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-success { background: var(--color-success); border-color: var(--color-success); color: white; }
.btn-success:hover { background: #106b32; }
.btn-danger { background: transparent; border-color: var(--color-error); color: var(--color-error); }
.btn-danger:hover { background: var(--color-error-bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

/* Forms */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--color-text); }
input[type=text], input[type=number], input[type=file], input[type=email],
input[type=password], input[type=tel], input[type=url], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--color-border);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  background: white;
  color: var(--color-text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--color-source); outline-offset: 1px; }
.field { margin-bottom: 14px; }
.field-hint { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* Comptes (django-allauth) : cf. templates/allauth/ */
.container.auth-container {
  max-width: 420px;
  margin: 40px auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 28px 26px;
}
.auth-container form p { margin: 0 0 14px; }
.auth-container form p:has(input[type=checkbox]) { display: flex; align-items: center; gap: 8px; }
.auth-container form p:has(input[type=checkbox]) label { margin: 0; font-weight: 500; }
.auth-container form p:has(input[type=checkbox]) input { width: auto; order: -1; }
.auth-container .btn { width: 100%; text-align: center; margin-top: 6px; }
.auth-container hr { border: none; border-top: 1px solid var(--color-border); margin: 20px 0; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.badge-source { background: var(--color-source-bg); color: var(--color-source); }
.badge-transform { background: var(--color-transform-bg); color: var(--color-transform); }
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-error { background: var(--color-error-bg); color: var(--color-error); }
.badge-neutral { background: #eef0f5; color: var(--color-text-muted); }

/* Chips (mapping columns) */
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
}
.chip-source { background: var(--color-source-bg); color: var(--color-source); border-color: #c8d9fc; }
.chip-target { background: var(--color-transform-bg); color: var(--color-transform); border-color: #ddc9fc; }
.chip-target.mapped { background: var(--color-success-bg); color: var(--color-success); border-color: #bfe6cc; }
.chip-target.required::after { content: "*"; color: var(--color-error); margin-left: 2px; }
.chip-target.selected { outline: 2px solid var(--color-transform); }
.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* Groupes d'unification : une couleur par regroupement de colonnes,
   toujours accompagnée du nom de la colonne (jamais la couleur seule). */
.chip-group-0 { background: #eaf0fe; color: #2563eb; border-color: #c8d9fc; }
.chip-group-1 { background: #e7f7ec; color: #15803d; border-color: #bfe6cc; }
.chip-group-2 { background: #fef3e0; color: #b45309; border-color: #f8dfa8; }
.chip-group-3 { background: #f2ebfe; color: #7c3aed; border-color: #ddc9fc; }
.chip-group-4 { background: #fdeaea; color: #b91c1c; border-color: #f5c2c2; }
.chip-group-5 { background: #e0f7fa; color: #0e7490; border-color: #a8e6ef; }
.chip-group-6 { background: #fce7f3; color: #a8286b; border-color: #f6bfe0; }
.chip-group-7 { background: #ecfccb; color: #4d7c0f; border-color: #d3f0a0; }
.chip-neutral { background: #eef0f5; color: var(--color-text-muted); font: inherit; }

/* Mapping layout */
.mapping-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
@media (max-width: 900px) { .mapping-columns { grid-template-columns: 1fr; } }

.target-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: white;
  cursor: pointer;
}
.target-row:hover { border-color: var(--color-transform); }
.target-row.selected { border-color: var(--color-transform); background: var(--color-transform-bg); }
.target-row .rule-summary { font-size: 12px; color: var(--color-text-muted); }

/* Tables */
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table th, table.data-table td {
  border: 1px solid var(--color-border);
  padding: 7px 10px;
  text-align: left;
  white-space: nowrap;
}
table.data-table th { background: #f5f6fa; font-weight: 700; }
.table-scroll { overflow-x: auto; border-radius: 8px; border: 1px solid var(--color-border); }
table.data-table.striped tr:nth-child(even) { background: #fafbfd; }
.cell-empty { color: #c3c7d1; font-style: italic; }
.cell-error { background: var(--color-error-bg); }
.cell-warning { background: var(--color-warning-bg); }

/* Alerts / help */
.alert {
  display: flex; gap: 10px;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.alert-info { background: var(--color-source-bg); color: #1e40af; border-color: #c8d9fc; }
.alert-success { background: var(--color-success-bg); color: var(--color-success); border-color: #bfe6cc; }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: #f7dfad; }
.alert-error { background: var(--color-error-bg); color: var(--color-error); border-color: #f5c6c6; }

.inline-rename { display: flex; gap: 6px; align-items: center; }
.inline-rename-input { width: auto !important; flex: 1; min-width: 140px; padding: 5px 8px !important; }

.ad-slot {
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 20px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 12px;
  background: var(--color-bg);
}
.ad-slot-label { text-transform: uppercase; letter-spacing: .04em; }

.help-tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--color-border);
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 700;
  cursor: help;
  position: relative;
}
.help-tip .tip-bubble {
  display: none;
  position: absolute;
  bottom: 130%; left: 50%;
  transform: translateX(-50%);
  width: 240px;
  background: #1f2430;
  color: white;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  z-index: 20;
}
.help-tip:hover .tip-bubble { display: block; }

/* Stats */
.stat-tile {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  background: white;
}
.stat-tile .stat-value { font-size: 26px; font-weight: 800; }
.stat-tile .stat-label { font-size: 12px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .03em; }
.stat-tile.stat-error .stat-value { color: var(--color-error); }
.stat-tile.stat-warning .stat-value { color: var(--color-warning); }
.stat-tile.stat-success .stat-value { color: var(--color-success); }

.file-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-bottom: 8px;
}
.file-item .file-name { font-weight: 600; }
.file-item .file-meta { font-size: 12px; color: var(--color-text-muted); }

.op-params { display: none; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--color-border); }
.op-params.active { display: block; }

.muted { color: var(--color-text-muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.small { font-size: 12px; }

.example-box {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 14px 16px;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 13px;
  white-space: pre-wrap;
}

.demo-banner {
  background: linear-gradient(90deg, var(--color-transform-bg), var(--color-source-bg));
  border: 1px solid #ddc9fc;
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 20px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.loading { opacity: .6; pointer-events: none; }

/* Barre d'action persistante (édition locale / brouillon — spec V3) */
body.has-action-bar { padding-bottom: 76px; }

.action-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -2px 12px rgba(20, 24, 40, .08);
}
.action-bar__count {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text-muted);
}
.action-bar.is-dirty .action-bar__count { color: var(--color-warning); }
.action-bar.is-success .action-bar__count { color: var(--color-success); }
.action-bar.is-error .action-bar__count { color: var(--color-error); }
.action-bar__actions { display: flex; gap: 10px; }
.action-bar.is-saving .btn-primary { opacity: .75; cursor: progress; }

/* Toasts */
.toast-region {
  position: fixed;
  right: 20px;
  bottom: 92px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-card);
  border: 1px solid transparent;
  background: var(--color-surface);
  color: var(--color-text);
}
.toast--info { background: var(--color-source-bg); color: #1e40af; border-color: #c8d9fc; }
.toast--success { background: var(--color-success-bg); color: var(--color-success); border-color: #bfe6cc; }
.toast--warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: #f7dfad; }
.toast--error { background: var(--color-error-bg); color: var(--color-error); border-color: #f5c6c6; }
.toast__close {
  margin-left: auto;
  background: none; border: none; cursor: pointer;
  color: inherit; opacity: .6; font-size: 12px; line-height: 1;
}
.toast__close:hover { opacity: 1; }

/* Page Contexte — état des candidats en brouillon local */
.ctx-candidate.is-ignored { opacity: .5; }
.ctx-candidate.is-confirmed { outline: 2px solid var(--color-success); outline-offset: 1px; }
.ctx-candidate.is-invalid { outline: 2px solid var(--color-error); outline-offset: 1px; }

/* Mise en évidence générique d'une erreur de validation renvoyée par un
   endpoint batch (Contexte/Unification/Mapping) sur l'élément concerné. */
.target-row.is-invalid { outline: 2px solid var(--color-error); outline-offset: 1px; }

/* Bouton principal dans l'en-tête : garder le texte blanc (la couleur grise des liens d'en-tête l'écrasait). */
.header-actions a.btn-primary { color: #fff; }
