:root {
  --purple: #4b2e83;
  --purple-dark: #3a2266;
  --bg: #f6f5f8;
  --card-bg: #ffffff;
  --border: #e2dfe8;
  --text: #2a2438;
  --muted: #746e80;
  --ok: #1f8a4c;
  --error: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--purple);
  color: white;
  padding: 14px 28px;
  flex-wrap: wrap;
  gap: 10px;
}
.topbar .brand {
  color: white;
  font-weight: 700;
  text-decoration: none;
  font-size: 1.05rem;
}
.topbar nav a {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  margin-left: 20px;
  font-size: 0.95rem;
}
.topbar nav a:hover { color: white; text-decoration: underline; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

h1 { margin-top: 0; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}
.card h2 { margin: 0 0 6px; font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.card .big { font-size: 2.2rem; font-weight: 700; margin: 4px 0; color: var(--purple); }

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
  margin-bottom: 20px;
}
.panel h2 { margin-top: 0; font-size: 1.1rem; }

.muted { color: var(--muted); font-size: 0.92rem; }
.path { font-family: ui-monospace, monospace; font-size: 0.8rem; color: var(--muted); word-break: break-all; }

.breakdown { list-style: none; padding: 0; margin: 8px 0 0; font-size: 0.88rem; color: var(--muted); }
.breakdown li { padding: 2px 0; }

.btn, .btn-link, button[type="submit"], #start-btn {
  display: inline-block;
  background: var(--purple);
  color: white;
  border: none;
  border-radius: 7px;
  padding: 10px 18px;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  margin-top: 8px;
}
.btn:hover, .btn-link:hover, button[type="submit"]:hover, #start-btn:hover { background: var(--purple-dark); }
.btn-link { background: transparent; color: var(--purple); padding-left: 0; }
.btn-link:hover { background: transparent; text-decoration: underline; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.upload-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.status-ok { color: var(--ok); font-weight: 600; }
.status-error { color: var(--error); font-weight: 600; }

.log-box {
  background: #1e1b26;
  color: #d9d4e3;
  padding: 16px;
  border-radius: 8px;
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 16px;
}

.progress-bar {
  background: var(--border);
  border-radius: 6px;
  height: 14px;
  overflow: hidden;
  margin-top: 16px;
}
.progress-fill {
  background: var(--purple);
  height: 100%;
  width: 0%;
  transition: width 0.4s ease;
}

.filter-bar { margin: 16px 0; display: flex; gap: 10px; align-items: center; }
.filter-bar input[type="text"], .filter-bar select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  min-width: 260px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.data-table th { background: #efecf4; color: var(--purple-dark); }
.data-table tr:last-child td { border-bottom: none; }

.tag {
  background: #efecf4;
  color: var(--purple-dark);
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 600;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 12px;
}
.gallery-item {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
}
.gallery-item img {
  width: 100%;
  height: 160px;
  object-fit: contain;
  background: white;
  display: block;
  border-bottom: 1px solid var(--border);
}
.gallery-item span {
  display: block;
  padding: 8px 10px;
  font-size: 0.78rem;
  word-break: break-all;
}

/* --- Corrections depuis la page "À vérifier" --- */

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 18px 0;
  padding: 12px 16px;
  border: 1px solid var(--purple);
  border-left-width: 4px;
  border-radius: 6px;
  background: #f6f2fb;
}

.choice { display: flex; align-items: center; gap: 6px; }

.btn-choice {
  padding: 5px 12px;
  border: 1px solid #cfc4de;
  border-radius: 4px;
  background: #fff;
  color: var(--purple);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn-choice:hover:not(:disabled) { border-color: var(--purple); background: #f6f2fb; }
.btn-choice:disabled { opacity: 0.5; cursor: default; }

/* Valeur actuellement déduite : pré-signalée pour que confirmer soit le geste le plus rapide. */
.btn-choice.is-current { border-color: var(--purple); font-weight: 600; }

.choice-status { margin-left: 4px; white-space: nowrap; }

/* Ligne traitée : barrée plutôt que retirée, pour garder une trace visible de ce qu'on vient
   de valider (et pouvoir se corriger immédiatement en cas de mauvais clic). */
.row-done { opacity: 0.5; }
.row-done td:not(:last-child) { text-decoration: line-through; }

.btn-undo {
  padding: 5px 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  text-decoration: underline;
  cursor: pointer;
}
.btn-undo:hover { color: #b3261e; }

#appliquees-section { margin: 26px 0; }
#appliquees-section h2 { font-size: 1.05rem; margin-bottom: 4px; }

/* --- Choix du document (bulletins / professions de foi) --- */

.doc-switch { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }

.doc-tab {
  padding: 7px 14px;
  border: 1px solid #cfc4de;
  border-radius: 20px;
  background: #fff;
  color: var(--purple);
  font-size: 0.92rem;
  text-decoration: none;
  cursor: pointer;
}
.doc-tab:hover { border-color: var(--purple); background: #f6f2fb; }
.doc-tab.is-active { background: var(--purple); color: #fff; border-color: var(--purple); }
.doc-tab input[type="radio"] { margin-right: 6px; }

#regen-zone .banner + .banner { margin-top: 8px; }

/* --- Page "Calques" : correspondance calque -> donnée --- */

.banner-error { border-color: var(--error); background: #fdf1ef; }

/* Séparateur de section dans le tableau (Titres, Binôme, Liste). */
.section-row td {
  background: #efecf4;
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--purple-dark);
}

.champ-ligne { margin-bottom: 6px; }
.champ-ligne:last-child { margin-bottom: 0; }

.champ-libelle {
  display: block;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-bottom: 2px;
}

.champ {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  background: white;
  color: var(--text);
}
.champ:focus { outline: none; border-color: var(--purple); }
.champ-bool { width: auto; }

/* Retour immédiat après enregistrement : vert bref, rouge persistant si refusé. */
.champ-ok { border-color: var(--ok); background: #f1faf4; }
.champ-ko { border-color: var(--error); background: #fdf1ef; }

.champ-erreur {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--error);
  line-height: 1.35;
}
.champ-note { margin: 4px 0 0; font-size: 0.78rem; }

.tag-warn { background: #fdf1ef; color: var(--error); }

.vars { margin-top: 6px; }
.vars summary {
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--muted);
}
.vars .breakdown { margin-top: 4px; }

.var-chip {
  font-family: ui-monospace, monospace;
  font-size: 0.76rem;
  background: #efecf4;
  border-radius: 4px;
  padding: 1px 5px;
}

/* L'aperçu contient des retours à la ligne significatifs (un calque = plusieurs lignes). */
.cell-apercu {
  white-space: pre-wrap;
  font-size: 0.8rem;
  line-height: 1.35;
  word-break: break-word;
}

#mapping-table td { vertical-align: top; }
#orphelins { margin-top: 30px; }
#orphelins h2 { font-size: 1.05rem; margin-bottom: 4px; }

/* Les modèles de texte sont des textarea : un titre peut tenir sur plusieurs lignes, et un
   <input> aurait silencieusement supprimé les retours à la ligne à la première modification. */
textarea.champ {
  resize: vertical;
  min-height: 46px;
  line-height: 1.4;
}

/* Qui est connecté (base.html) : nom, niveau, déconnexion, à droite de la barre. */
.topbar .qui { margin-left: auto; display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.topbar .qui a { color: white; text-decoration: none; font-weight: 600; }
.topbar .qui .muted { color: rgba(255,255,255,.7); }
.topbar .qui .btn { padding: .2rem .6rem; font-size: .85rem; }
