/* ─── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #f7f5f0;
  --bg-2:         #ffffff;
  --bg-3:         #f0ede6;
  --border:       rgba(0,0,0,0.08);
  --border-hover: rgba(0,0,0,0.15);
  --text:         #1c1a17;
  --text-2:       #6b6860;
  --text-3:       #a8a49e;
  --accent:       #2a5c2a;
  --accent-dim:   rgba(42,92,42,0.08);
  --accent-text:  #ffffff;
  --danger:       #c0392b;
  --danger-dim:   rgba(192,57,43,0.08);
  --row-alt:      rgba(42,92,42,0.03);
  --mono:         'DM Mono', monospace;
  --serif:        'Fraunces', serif;
  --radius-sm:    6px;
  --radius-md:    10px;
  --radius-lg:    16px;
  --transition:   0.18s ease;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ───────────────────────────────────────────────────────── */
.header {
  position: relative;
  overflow: hidden;
  padding: 3.5rem 2rem 2.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}

.header-inner { position: relative; z-index: 1; max-width: 1100px; margin: 0 auto; }

.logo {
  font-family: var(--serif);
  font-size: 2.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
  margin-bottom: 0.6rem;
}

.logo-bracket { color: var(--accent); font-style: italic; font-weight: 300; }
.logo-text    { color: var(--text); }

.header-sub {
  font-size: 13px;
  color: var(--text-2);
  max-width: 560px;
  line-height: 1.7;
}

.header-deco {
  position: absolute;
  top: -40px; right: -60px;
  width: 320px; height: 320px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(42,92,42,0.07) 0%, transparent 70%);
  pointer-events: none;
}

/* ─── Main ─────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  padding: 2rem 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ─── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition), opacity var(--transition), transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-outline { background: transparent; border-color: var(--border-hover); color: var(--text-2); }
.btn-outline:hover { background: var(--bg-3); color: var(--text); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-3); }
.btn-ghost:hover { background: var(--bg-3); color: var(--text-2); }

.btn-danger:hover { background: var(--danger-dim); color: var(--danger); border-color: rgba(192,57,43,0.2); }

.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-primary:hover { opacity: 0.86; }

/* ─── Toolbar ──────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border-hover);
  margin: 0 2px;
  flex-shrink: 0;
}

.record-badge {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--bg-3);
  color: var(--text-3);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* ─── Table Section ─────────────────────────────────────────────────── */
.table-section {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-scroll { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; }

th {
  background: var(--bg-3);
  border: 1px solid var(--border);
  padding: 9px 12px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}

td { border: 1px solid var(--border); padding: 0; vertical-align: middle; }

/* Alternating row tint */
#records-body tr:nth-child(even) td { background: var(--row-alt); }
#records-body tr:hover td { background: var(--accent-dim); }

/* ── Column widths ── */
.th-num    { width: 42px; text-align: center; }
.th-code   { width: 70px; text-align: center; }
.th-action { width: 36px; }

/* Row number cell */
.td-num {
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
  padding: 0 6px;
  background: var(--bg-3) !important;
  border-right: 1px solid var(--border);
  user-select: none;
}

/* Editable input cells */
.td-input { padding: 0; }

.cell-input {
  display: block;
  width: 100%;
  min-width: 120px;
  padding: 9px 12px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: none;
  outline: none;
  transition: background var(--transition);
}

.cell-input:focus { background: rgba(42,92,42,0.06); }
.cell-input::placeholder { color: var(--text-3); }

/* Question cell — wider and wraps */
.td-question { min-width: 240px; }

.cell-question {
  min-width: 240px;
  resize: none;
  line-height: 1.55;
  min-height: 40px;
  max-height: 100px;
  overflow-y: auto;
  field-sizing: content; /* auto-grow where supported */
}

/* Code badge */
.td-code-cell { text-align: center; padding: 6px 8px; }

.code-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 8px;
  border-radius: 4px;
  min-width: 40px;
  text-align: center;
  letter-spacing: 0.04em;
  transition: color 0.2s, background 0.2s;
}

.code-badge.is-empty { color: var(--text-3); background: transparent; }

/* Delete row button */
.td-del { text-align: center; }

.btn-del-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 15px;
  transition: background var(--transition), color var(--transition);
  padding: 0; line-height: 1;
}
.btn-del-row:hover { background: var(--danger-dim); color: var(--danger); }

/* Add row inline */
.table-add-row { border-top: 1px solid var(--border); padding: 6px 10px; }

.btn-add-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.btn-add-inline:hover { color: var(--accent); background: var(--accent-dim); }

/* ─── Mapping section ───────────────────────────────────────────────── */
.mapping-label-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-3);
}

.mapping-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: 0.04em;
}

.mapping-sub { font-size: 11px; color: var(--text-3); font-style: italic; }

#mapping-table td { padding: 9px 14px; font-size: 13px; color: var(--text); }
#mapping-table td:nth-child(3) { font-weight: 500; color: var(--accent); letter-spacing: 0.06em; }
#mapping-table td:nth-child(4) { color: var(--text-3); font-size: 11px; }
#mapping-table tr:nth-child(even) td { background: var(--row-alt); }

.tr-empty td {
  text-align: center;
  color: var(--text-3);
  font-style: italic;
  font-size: 12px;
  padding: 16px;
}

/* ─── Preview ───────────────────────────────────────────────────────── */
.preview-section {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-3);
}

.preview-title-group { display: flex; align-items: center; gap: 8px; }

.preview-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px rgba(42,92,42,0.35);
}

.preview-title { font-size: 12px; font-weight: 500; color: var(--text-2); letter-spacing: 0.04em; }

.preview-type-badge {
  font-size: 10px; padding: 2px 8px; border-radius: 20px;
  background: var(--accent-dim); color: var(--accent);
  border: 1px solid rgba(42,92,42,0.2);
}

.toggle-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-3); cursor: pointer; user-select: none;
}
.toggle-label input { accent-color: var(--accent); cursor: pointer; }
.toggle-label:hover { color: var(--text-2); }

.json-preview {
  margin: 0; padding: 16px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.7;
  color: var(--text); overflow-x: auto; max-height: 340px; overflow-y: auto;
  white-space: pre; background: transparent;
}

.json-preview .j-key   { color: #1d5fa6; }
.json-preview .j-str   { color: #2a7a2a; }
.json-preview .j-num   { color: #b45309; }
.json-preview .j-bool  { color: #9333ea; }
.json-preview .j-null  { color: #9ca3af; }
.json-preview .j-punct { color: var(--text-3); }

.preview-empty {
  padding: 2rem; text-align: center;
  color: var(--text-3); font-size: 12px; font-style: italic;
}

/* ─── Toast ─────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg-2);
  padding: 9px 20px; border-radius: 20px;
  font-size: 12px; font-family: var(--mono);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── Footer ─────────────────────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--border); padding: 1rem 2rem;
  text-align: center; font-size: 11px; color: var(--text-3);
}

/* ─── Scrollbars ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }

/* ─── Animations ─────────────────────────────────────────────────────── */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.main > * { animation: fadeSlideIn 0.35s ease both; }
.main > *:nth-child(1) { animation-delay: 0.05s; }
.main > *:nth-child(2) { animation-delay: 0.10s; }
.main > *:nth-child(3) { animation-delay: 0.15s; }
.main > *:nth-child(4) { animation-delay: 0.20s; }

@keyframes rowIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.row-new { animation: rowIn 0.22s ease both; }

/* ─── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .header { padding: 2rem 1.25rem 1.5rem; }
  .logo { font-size: 1.8rem; }
  .toolbar { flex-direction: column; align-items: flex-start; }
  .toolbar-right { width: 100%; flex-wrap: wrap; }
  .main { padding: 1.25rem 1rem 2rem; }
}

/* ─── Convertisseur XLSX → JSON ─────────────────────────────────────── */
.converter-section {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.converter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-3);
}

.converter-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.conv-file-name {
  font-size: 11px;
  color: var(--text-3);
  font-style: italic;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Drop zone */
.conv-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 3rem 2rem;
  cursor: pointer;
  transition: background var(--transition);
  border: 2px dashed transparent;
  margin: 1rem;
  border-radius: var(--radius-md);
}

.conv-dropzone:hover,
.conv-dropzone.drag-over {
  background: var(--accent-dim);
  border-color: rgba(42,92,42,0.25);
}

.conv-dropzone.drag-over { border-style: solid; }

.conv-drop-icon { color: var(--text-3); transition: color var(--transition); }
.conv-dropzone:hover .conv-drop-icon,
.conv-dropzone.drag-over .conv-drop-icon { color: var(--accent); }

.conv-drop-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
}

.conv-drop-sub {
  font-size: 12px;
  color: var(--text-3);
}

.conv-drop-hint {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
}

/* Sheet tabs */
.conv-sheet-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-3);
  flex-wrap: wrap;
}

.conv-sheet-label {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.conv-sheet-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.conv-sheet-tab {
  padding: 3px 12px;
  border-radius: 20px;
  border: 1px solid var(--border-hover);
  background: transparent;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.conv-sheet-tab:hover { background: var(--bg-2); color: var(--text); }

.conv-sheet-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Stats bar */
.conv-stats-bar {
  display: flex;
  gap: 16px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-3);
  font-size: 11px;
  color: var(--text-3);
  flex-wrap: wrap;
}

.conv-stat {
  display: flex;
  align-items: center;
  gap: 5px;
}

.conv-stat strong {
  color: var(--text-2);
  font-weight: 500;
}

/* JSON result preview */
.conv-json-preview {
  max-height: 380px;
  border-top: 1px solid var(--border);
}

/* Error */
.conv-error {
  margin: 1rem 1.25rem;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--danger-dim);
  border: 1px solid rgba(192,57,43,0.2);
  color: var(--danger);
  font-size: 12px;
}

/* ─── Ajouts Quizz Invités ───────────────────────────────────────────── */

/* Numéro d'étape */
.step-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
}

/* Ligne de saisie prénom */
.prenom-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}

.prenom-main-input {
  flex: 1;
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  background: var(--bg);
  transition: border-color var(--transition), background var(--transition);
}
.prenom-main-input:focus {
  border-color: var(--accent);
  background: var(--bg-2);
  outline: none;
}

/* Bouton régénérer un code individuel */
.btn-regen-code {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  font-size: 14px;
  padding: 0 4px;
  margin-left: 4px;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
  vertical-align: middle;
  line-height: 1;
}
.btn-regen-code:hover {
  color: var(--accent);
  background: var(--accent-dim);
}

/* Select dans les cellules */
.cell-select {
  width: 100%;
  min-width: 110px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23a8a49e' stroke-width='1.3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px !important;
  cursor: pointer;
  border-radius: 0;
}
.cell-select:focus { background-color: rgba(42,92,42,0.06); outline: none; }

/* Spinner */
.spinner {
  display: none;
  width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* code dans header */
header code, footer code {
  font-family: var(--mono);
  background: var(--bg-3);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.9em;
}

/* ─── Modal Chargement bdd.php ───────────────────────────────────────── */
.load-modal {
  position: fixed; inset: 0;
  background: rgba(28,26,23,0.55);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.load-modal-box {
  background: var(--bg-2);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-lg);
  padding: 1.6rem 1.8rem;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  animation: fadeSlideIn 0.2s ease both;
}

.load-modal-box h3 {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.6rem;
}

.load-modal-msg {
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 0.8rem;
}
.load-modal-loading { color: var(--text-3); font-style: italic; }
.load-modal-error   { color: var(--danger); }

/* Aperçu */
.load-modal-preview {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.8rem 1rem;
  margin-bottom: 1rem;
}

.load-preview-stat {
  display: inline-block;
  font-size: 12px;
  color: var(--text-2);
  margin-right: 16px;
  margin-bottom: 6px;
}
.load-preview-stat strong { color: var(--accent); }

.load-preview-list {
  border-top: 1px solid var(--border);
  padding-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.load-preview-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
  line-height: 1.5;
  flex-wrap: wrap;
}

.load-pname {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}
.load-psep { color: var(--text-3); font-size: 10px; }
.load-pq {
  color: var(--text-3);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}
.load-preview-more {
  font-size: 11px;
  color: var(--text-3);
  font-style: italic;
  padding-top: 2px;
}

/* Options fusion/remplacement */
.load-modal-actions { font-size: 13px; }

.load-merge-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.load-merge-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-2);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: background var(--transition), border-color var(--transition);
}
.load-merge-label:hover { background: var(--bg-3); border-color: var(--border-hover); }
.load-merge-label input[type="radio"] { accent-color: var(--accent); cursor: pointer; }
.load-merge-label input[type="radio"]:checked + span { color: var(--text); font-weight: 500; }

.footer-sep {
  margin: 0 0.6rem;
  color: var(--text-3);
}

.footer-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: opacity 0.15s;
}
.footer-link:hover { opacity: 0.75; }
