:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8eb;
  --text-dim: #9aa1ad;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #3ba55c;
  --green-bg: rgba(59, 165, 92, 0.12);
  --red: #ed4245;
  --red-bg: rgba(237, 66, 69, 0.12);
  --yellow: #faa61a;
  --purple: #9b59f6;
  --purple-bg: rgba(155, 89, 246, 0.14);
  --cyan: #17a2b8;
  --cyan-bg: rgba(23, 162, 184, 0.14);
  --orange: #e67e22;
  --orange-bg: rgba(230, 126, 34, 0.14);
  --pink: #ec4899;
  --pink-bg: rgba(236, 72, 153, 0.14);
  --radius: 10px;
}

* { box-sizing: border-box; }

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

#app { min-height: 100vh; }

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  color: var(--text-dim);
}

/* Layout */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar .brand {
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar .brand .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}

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

.tab-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.tab-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.tab-btn.active { background: var(--accent); color: white; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  flex-wrap: wrap;
}
.user-chip span { overflow-wrap: anywhere; }

.user-chip img { width: 28px; height: 28px; border-radius: 50%; }

.btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--bg-elev-2); color: var(--text); }
.btn.secondary:hover { background: #2a2f3a; }
.btn.danger { background: var(--red); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}
main.wide { max-width: 1500px; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 { margin-top: 0; font-size: 17px; }
.card h3 { font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
  margin-top: 10px;
}

input, select, textarea {
  width: 100%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 60px; }
select { padding-right: 40px; }
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  flex-direction: column;
  gap: 20px;
  text-align: center;
  padding: 20px;
}
.login-screen h1 { font-size: 22px; margin-bottom: 0; }
.login-screen p { color: var(--text-dim); max-width: 400px; margin-top: 0; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.neutral { background: var(--bg-elev-2); color: var(--text-dim); }
.badge.yellow { background: rgba(250,166,26,0.12); color: var(--yellow); }
.badge.triche { background: rgba(237,66,69,0.18); color: var(--red); border: 1px solid var(--red); white-space: nowrap; }
.badge.accent { background: rgba(88,101,242,0.14); color: var(--accent); }
.badge.purple { background: var(--purple-bg); color: var(--purple); }
.badge.cyan { background: var(--cyan-bg); color: var(--cyan); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.pink { background: var(--pink-bg); color: var(--pink); }
.badge-decision { display: inline-block; min-width: 62px; text-align: center; }

tr.row-triche td { background: rgba(237,66,69,0.07); }
tr.row-triche:hover td { background: rgba(237,66,69,0.14); }

.blacklist-banner {
  position: sticky;
  top: 66px;
  z-index: 20;
  background: var(--red);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  line-height: 1.4;
  padding: 16px 20px;
  border-radius: 8px;
  margin: 14px 0;
  text-align: center;
  box-shadow: 0 6px 20px rgba(237,66,69,0.45);
  animation: blacklist-pulse 1.4s ease-in-out infinite;
}

@keyframes blacklist-pulse {
  0%, 100% { box-shadow: 0 6px 20px rgba(237,66,69,0.45); }
  50% { box-shadow: 0 6px 28px rgba(237,66,69,0.85); }
}

.triche-alert {
  background: rgba(237,66,69,0.12);
  border: 1px solid var(--red);
  color: var(--red);
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 10px;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-wrap { overflow-x: auto; }
.table-wrap table { min-width: 560px; }

.log-desc-cell {
  max-width: 560px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.log-row-clickable { cursor: pointer; }
.log-row-clickable:hover td { background: var(--bg-elev-2); }

.log-field-diff {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.log-field-name {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.log-field-row { font-size: 13px; padding: 2px 0; overflow-wrap: break-word; }
.log-field-label { color: var(--text-dim); font-weight: 600; margin-right: 6px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:hover td { background: var(--bg-elev-2); cursor: pointer; }
#r-table, #log-table, #q-list { overflow-x: auto; }

.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 160px; }

.score-pill {
  font-weight: 700;
  font-size: 15px;
}

.question-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
  background: var(--bg-elev-2);
}
.question-block .q-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.question-block .q-text { font-weight: 600; font-size: 14px; }
.question-block textarea { overflow: hidden; resize: none; }

.save-bar {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}
.question-block .q-expected {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 6px;
  border-left: 2px solid var(--accent);
}
.points-input { display: flex; align-items: center; gap: 6px; }
.points-input input { width: 60px; text-align: center; }

.score-summary {
  position: sticky;
  bottom: 0;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -20px -20px;
  border-radius: 0 0 var(--radius) var(--radius);
}

.tab-sub {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  flex-wrap: wrap;
}
.tab-sub button {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  border-radius: 6px;
}
.tab-sub button.active { background: var(--bg-elev-2); color: var(--text); }

.toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 4px;
  padding: 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.toc-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}
.toc-link:hover { background: var(--bg-elev-2); color: var(--text); border-color: var(--accent); }

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 6px;
}
.icon-btn svg { display: block; }
.icon-btn:hover { color: var(--text); background: var(--bg-elev-2); }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.icon-btn:disabled:hover { color: var(--text-dim); background: none; }
.icon-btn-danger:hover { color: var(--red); background: var(--bg-elev-2); }

.role-glow { animation: role-pulse 2.4s ease-in-out infinite; display: inline-block; }
@keyframes role-pulse {
  0%, 100% { text-shadow: 0 0 4px var(--role-color, transparent), 0 0 1px var(--role-color, transparent); }
  50% { text-shadow: 0 0 16px var(--role-color, transparent), 0 0 6px var(--role-color, transparent); }
}
@media (prefers-reduced-motion: reduce) {
  .role-glow { animation: none; text-shadow: 0 0 8px var(--role-color, transparent); }
}

.q-number {
  font-weight: 700;
  color: var(--text-dim);
  margin-right: 4px;
  white-space: nowrap;
}

.scenario-group {
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 28px;
  background: var(--bg-elev);
}
.scenario-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 2px solid var(--border);
}
.scenario-group h4 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.scenario-item {
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  margin-bottom: 16px;
}
.scenario-item + .scenario-item {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  margin-top: 4px;
}
.scenario-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.scenario-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(88, 101, 242, 0.12);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.scenario-item textarea {
  overflow: hidden;
  resize: none;
}
.consultation-block {
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  background: var(--bg-elev);
}
.consultation-block-header h3 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 800;
  color: var(--accent);
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.consultation-question {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.consultation-question:last-child { border-bottom: none; }
.consultation-question-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.consultation-question-text { font-weight: 600; font-size: 14px; flex: 1; }
.consultation-answer {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 6px;
  border-left: 2px solid var(--accent);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

.perm-table-wrap { overflow-x: auto; }
.perm-table { width: 100%; border-collapse: collapse; }
.perm-table th, .perm-table td { padding: 8px 10px; text-align: center; border-bottom: 1px solid var(--border); }
.perm-table th:first-child, .perm-table td:first-child { text-align: left; }
.perm-table thead th { color: var(--text-dim); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.perm-table tbody tr:hover { background: var(--bg-elev-2); }
.perm-table input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; }

.scenario-add {
  margin-top: 20px;
  padding: 18px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: var(--bg);
}
.scenario-item input[type=checkbox] { width: auto; margin-top: 3px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; max-width: 500px; width: 100%; max-height: 85vh; overflow-y: auto;
  overflow-wrap: break-word; word-break: break-word;
}
.modal-lg { max-width: 820px; }
.modal-xl { max-width: 1140px; }
.detail-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.detail-section h3 { margin: 0 0 10px; }
.detail-section .grid-2 > div { font-size: 13px; }

/* Responsive : mobile / tablette */
@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 14px;
  }
  .tabs { justify-content: flex-start; }
  .user-chip { justify-content: space-between; }
  .blacklist-banner { position: static; }

  main { padding: 16px 12px 60px; }
  .card { padding: 14px; }

  .score-summary {
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 -14px -14px;
    padding: 12px 14px;
  }

  .question-block .q-header,
  .scenario-item-header,
  .consultation-question-head {
    flex-wrap: wrap;
  }

  .filters { flex-direction: column; align-items: stretch; }
  .filters input, .filters select { width: 100%; min-width: 0; }

  .grid-3 > div, .grid-2 > div { min-width: 0; }
}
