/* Briefs to Propal — chat UI */

:root {
  --primary:   #1f3864;
  --primary-2: #2e75b6;
  --primary-soft: #eef2f8;
  --bg:        #f7f8fb;
  --bg-2:      #eef1f7;
  --card:      #ffffff;
  --text:      #1a1d26;
  --muted:     #6b7280;
  --muted-2:   #9aa3b2;
  --border:    #e4e7ef;
  --border-2:  #d6dbe6;
  --err:       #b42318;
  --err-bg:    #fee4e2;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow:    0 4px 16px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

a { color: var(--primary-2); }
a:hover { text-decoration: underline; }

/* ── Topbar ──────────────────────────────────────────────────────────────── */

.topbar {
  background: var(--primary);
  color: #fff;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 52px;
  flex-shrink: 0;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.05);
}
.topbar .brand {
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  text-decoration: none;
  letter-spacing: 0.2px;
}
.topbar-step {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  padding-left: 12px;
  border-left: 1px solid rgba(255, 255, 255, 0.18);
}
.topbar-user {
  margin-left: auto;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-logout-form { margin: 0; }
.topbar-logout {
  background: transparent;
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s;
}
.topbar-logout:hover { background: rgba(255, 255, 255, 0.12); }

/* ── App layout (sidebar + chat) ─────────────────────────────────────────── */

body:has(.app-layout) { overflow: hidden; }

.app-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: 1fr;
  height: calc(100vh - 52px);
  min-height: 0;
}
@media (max-width: 780px) {
  .app-layout { grid-template-columns: 0 1fr; }
  .sidebar { display: none; }
}

.sidebar {
  background: rgba(255, 255, 255, 0.65);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 999px; }

.sidebar-new {
  display: block;
  width: 100%;
  padding: 9px 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  text-decoration: none;
  text-align: center;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}
.sidebar-new:hover { background: #16294a; text-decoration: none; color: #fff; }
.sidebar-new:disabled {
  background: var(--border-2);
  color: var(--muted);
  cursor: not-allowed;
}
.sidebar-new:disabled:hover { background: var(--border-2); color: var(--muted); }

/* Retour à l'écran des études + rappel de l'étude courante */
.sidebar-back {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 7px;
  transition: background .12s, color .12s;
}
.sidebar-back:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
.sidebar-study {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  padding: 2px 2px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Accueil (sélection d'étude) : pleine largeur, sans colonne d'historique */
.select-wrap {
  height: calc(100vh - 52px);
  overflow-y: auto;
  width: 100%;
}

.sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
}
.sidebar-item {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 6px;
  transition: background .1s;
  min-width: 0;
}
.sidebar-item:hover { background: var(--primary-soft); }
.sidebar-item-active {
  background: var(--primary-soft);
}
.sidebar-item-link {
  flex: 1;
  min-width: 0;
  padding: 8px 4px 8px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
  text-decoration: none;
  overflow: hidden;
}
.sidebar-item-link:hover { text-decoration: none; }
.sidebar-item-active .sidebar-item-link {
  color: var(--primary);
  font-weight: 600;
}
.sidebar-item-pin {
  flex-shrink: 0;
  font-size: 11px;
  line-height: 1;
}
.sidebar-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.sidebar-item-menu {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 4px 8px;
  margin-right: 4px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  opacity: 0;
  transition: opacity .12s, background .12s, color .12s;
}
.sidebar-item:hover .sidebar-item-menu,
.sidebar-item-active .sidebar-item-menu { opacity: 1; }
.sidebar-item-menu:hover { background: rgba(31, 56, 100, 0.08); color: var(--primary); }

.sidebar-empty {
  font-size: 12.5px;
  color: var(--muted);
  padding: 8px 10px;
  font-style: italic;
}

/* Dropdown menu — épingler / renommer / supprimer */
.sidebar-menu {
  position: fixed;
  z-index: 1000;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12);
  padding: 4px;
  min-width: 170px;
  display: flex;
  flex-direction: column;
  animation: menuFade .12s ease-out;
}
@keyframes menuFade {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.sidebar-menu button {
  background: transparent;
  border: none;
  text-align: left;
  padding: 8px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  border-radius: 5px;
  transition: background .1s;
}
.sidebar-menu button:hover { background: var(--primary-soft); }
.sidebar-menu-danger { color: var(--err); }
.sidebar-menu-danger:hover { background: var(--err-bg) !important; }

.chat-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;               /* autorise les enfants flex à scroll */
  max-width: 820px;
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
  overflow: hidden;            /* le scroll se fait dans .chat-messages */
}

.chat-messages {
  flex: 1 1 auto;
  min-height: 0;               /* débloque le scroll des enfants flex */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 4px 8px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 999px; }

/* ── Bulles de message ───────────────────────────────────────────────────── */

.msg {
  display: flex;
  max-width: 82%;
  animation: slideUp .25s ease-out;
}
.msg-user {
  flex-direction: row;
  align-items: flex-end;
  align-self: flex-end;
  gap: 6px;
}
.msg-assistant {
  flex-direction: column;
  align-self: flex-start;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-content {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.6;
  word-break: break-word;
}
.msg-user .msg-content {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: var(--shadow-sm);
}
.msg-assistant .msg-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm);
}

/* Markdown bot */
.msg-assistant .msg-content h1,
.msg-assistant .msg-content h2,
.msg-assistant .msg-content h3 {
  color: var(--primary);
  margin: 14px 0 6px;
  font-size: 15px;
  font-weight: 700;
}
.msg-assistant .msg-content h1:first-child,
.msg-assistant .msg-content h2:first-child { margin-top: 2px; }
.msg-assistant .msg-content p     { margin: 0 0 8px; }
.msg-assistant .msg-content p:last-child { margin-bottom: 0; }
.msg-assistant .msg-content ul,
.msg-assistant .msg-content ol    { padding-left: 20px; margin: 6px 0 8px; }
.msg-assistant .msg-content li    { margin-bottom: 3px; }
.msg-assistant .msg-content strong { color: var(--primary); }
.msg-assistant .msg-content code {
  background: var(--primary-soft);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.msg-assistant .msg-content a { color: var(--primary-2); text-decoration: underline; text-decoration-color: rgba(46, 117, 182, 0.35); }
.msg-assistant .msg-content a:hover { text-decoration-color: var(--primary-2); }
.msg-assistant .msg-content hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.msg-assistant .msg-content blockquote {
  border-left: 3px solid var(--primary-2);
  margin: 6px 0;
  padding: 2px 12px;
  color: var(--muted);
}

/* Actions discrètes sur le dernier message (régénérer / éditer) */
.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  opacity: 0.55;
  transition: opacity .15s;
}
.msg-actions:hover { opacity: 1; }
/* Pour les messages user, l'icône edit se place À GAUCHE du prompt */
.msg-user .msg-actions {
  order: -1;
  margin-top: 0;
  flex-shrink: 0;
}
.msg-action-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-family: inherit;
  transition: background .12s, color .12s, transform .08s;
}
.msg-action-btn svg { width: 14px; height: 14px; }
.msg-action-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
}
.msg-action-btn:active { transform: scale(0.92); }

/* Mode édition d'un message utilisateur — bulle élargie sur toute la conversation */
.msg.msg-editing {
  max-width: 100%;
  width: 100%;
  flex-direction: column;
  align-self: stretch;
  align-items: stretch;   /* override le align-items: flex-end de .msg-user */
  gap: 0;
}
.msg.msg-editing .msg-content {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--primary-2);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.08);
}
.msg-edit-textarea {
  width: 100%;
  min-height: 80px;
  background: transparent;
  color: var(--text);
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}
.msg-edit-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 8px;
}
.msg-edit-actions button {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: background .12s;
}
.msg-edit-actions button:hover { background: var(--primary-soft); }
.msg-edit-actions button.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.msg-edit-actions button.primary:hover { background: #16294a; }

/* Artefacts */
.msg-artifacts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.artifact-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--primary-soft);
  border: 1px solid var(--primary-2);
  border-radius: 8px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background .12s, transform .08s;
}
.artifact-link:hover { background: #dfe7f3; text-decoration: none; transform: translateY(-1px); }

/* ── Cartes de sélection inline ──────────────────────────────────────────── */

.nodes-inline {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 4px 0 8px;
  transition: opacity .25s;
  align-self: stretch;
}
@media (max-width: 560px) {
  .nodes-inline { grid-template-columns: 1fr; }
}
.node-chip {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  position: relative;
  transition: border-color .15s, box-shadow .15s, transform .08s;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
}
.node-chip:hover:not(.node-chip-disabled) {
  border-color: var(--primary-2);
  box-shadow: 0 4px 14px rgba(31, 56, 100, 0.1);
  transform: translateY(-1px);
}
.node-chip:active:not(.node-chip-disabled) { transform: translateY(0); }
.node-chip-disabled { opacity: 0.55; cursor: not-allowed; }

.node-chip-icon { font-size: 22px; flex-shrink: 0; line-height: 1; padding-top: 2px; }
.node-chip-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.node-chip-label { font-weight: 700; font-size: 14px; color: var(--primary); }
.node-chip-desc  { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.node-chip-badge {
  position: absolute;
  top: 10px; right: 12px;
  background: var(--border);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ── Indicateur de chargement ────────────────────────────────────────────── */

.thinking-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 5px;
  width: fit-content;
  max-width: 100%;
  box-shadow: var(--shadow-sm);
}
.thinking-dots {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--primary-soft);
  border-top-color: var(--primary-2);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}
.thinking-dots span { display: none; }  /* legacy markup, on garde la structure mais on n'affiche pas les dots */
@keyframes spin {
  to { transform: rotate(360deg); }
}
.thinking-status {
  font-size: 13.5px;
  color: var(--muted);
  font-style: italic;
  transition: opacity .2s;
  opacity: 1;
}

/* ── Suggestions ─────────────────────────────────────────────────────────── */

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 0 4px;
  min-height: 34px;
}
.suggestion-btn {
  padding: 7px 14px;
  background: var(--card);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: border-color .12s, background .12s, transform .08s;
}
.suggestion-btn:hover { border-color: var(--primary-2); background: var(--primary-soft); transform: translateY(-1px); }

/* ── Formulaire de saisie ────────────────────────────────────────────────── */

.chat-form {
  padding: 12px 0 18px;
  flex-shrink: 0;
}

/* Sélecteur de mode Rapide / Approfondi */
.mode-switch {
  display: inline-flex;
  gap: 2px;
  margin-bottom: 8px;
  padding: 3px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.mode-btn:hover { color: var(--primary); }
.mode-btn.mode-active {
  background: var(--card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.chat-input-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 6px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
.chat-input-row:focus-within {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.08);
}

.attach-btn {
  cursor: pointer;
  font-size: 18px;
  padding: 0;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  transition: background .1s, color .1s;
}
.attach-btn:hover { background: var(--primary-soft); color: var(--primary); }
.attach-btn input { display: none; }

.chat-form textarea {
  flex: 1;
  padding: 8px 6px;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 14.5px;
  resize: none;
  min-height: 24px;
  max-height: 180px;
  overflow-y: auto;
  line-height: 1.5;
  background: transparent;
  color: var(--text);
}
.chat-form textarea:disabled { opacity: 0.55; }
.chat-form textarea::placeholder { color: var(--muted-2); }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, transform .08s;
}
.send-btn:hover:not(:disabled) { background: #162a4a; }
.send-btn:active:not(:disabled) { transform: scale(0.94); }
.send-btn:disabled { background: var(--muted-2); cursor: not-allowed; }

.file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.file-preview.hidden { display: none; }

/* ── Overlay drag & drop (affiché quand un fichier est traîné sur la page) ─ */
body.dragging::after {
  content: "📎  Dépose tes fichiers ici";
  position: fixed;
  inset: 0;
  background: rgba(31, 56, 100, 0.06);
  border: 3px dashed var(--primary-2);
  color: var(--primary);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  pointer-events: none;
  backdrop-filter: blur(2px);
  animation: dragPulse 1.6s ease-in-out infinite;
}
@keyframes dragPulse {
  0%, 100% { background-color: rgba(31, 56, 100, 0.04); }
  50%      { background-color: rgba(31, 56, 100, 0.10); }
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--primary);
  padding: 5px 6px 5px 12px;
  background: var(--primary-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  max-width: 100%;
}
.file-chip-name {
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-chip-remove {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 999px;
  font-family: inherit;
  transition: background .1s, color .1s;
}
.file-chip-remove:hover { background: rgba(180, 35, 24, 0.1); color: var(--err); }

/* ── Login / Signup ──────────────────────────────────────────────────────── */

.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 52px);
  padding: 32px 20px;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.auth-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  color: var(--primary);
}
.auth-card .lede {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 20px;
}
.auth-error {
  background: var(--err-bg);
  border: 1px solid #fca19b;
  border-radius: 8px;
  color: var(--err);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form .field { display: flex; flex-direction: column; gap: 6px; }
.auth-form .field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.auth-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14.5px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.auth-form input:focus {
  outline: none;
  border-color: var(--primary-2);
  box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.08);
}
.btn-primary {
  padding: 11px 18px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s;
  margin-top: 4px;
}
.btn-primary:hover { background: #16294a; }
.auth-alt {
  margin-top: 18px;
  font-size: 13.5px;
  color: var(--muted);
  text-align: center;
}

.btn-microsoft {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  background: #fff;
  color: #1f1f1f;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  font-family: inherit;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn-microsoft:hover {
  background: #f6f7fb;
  border-color: var(--muted-2);
  text-decoration: none;
  color: #1f1f1f;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.auth-divider span {
  flex-shrink: 0;
}

/* ── Page de sélection d'étude ───────────────────────────────────────────── */

.select-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 64px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.select-title {
  font-size: 26px;
  color: var(--primary);
  margin: 0 0 8px;
}
.select-lede {
  color: var(--muted);
  font-size: 14.5px;
  margin: 0 0 32px;
  max-width: 560px;
}
.dataset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 260px));
  justify-content: center;
  gap: 14px;
  width: 100%;
}
.dataset-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  text-align: left;
  padding: 18px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, transform .08s;
}
.dataset-card:hover {
  border-color: var(--primary-2);
  box-shadow: 0 6px 18px rgba(31, 56, 100, 0.1);
  transform: translateY(-2px);
}
.dataset-card.is-loading { opacity: 0.5; cursor: progress; }
.dataset-card-client {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--primary-2);
}
.dataset-card-name {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.3;
}
.dataset-card-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.dataset-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--primary-soft);
  padding: 2px 9px;
  border-radius: 999px;
}
.dataset-card-q {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
  margin-top: 2px;
}
.select-empty {
  padding: 28px;
  background: var(--card);
  border: 1px dashed var(--border-2);
  border-radius: 12px;
  color: var(--muted);
  font-size: 14.5px;
}

/* ── Back-office admin ───────────────────────────────────────────────────── */

.admin-page {
  max-width: 880px;
  margin: 0 auto;
  padding: 28px 22px 60px;
}
.admin-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-sm);
}
.admin-card h2 {
  margin: 0 0 6px;
  font-size: 17px;
  color: var(--primary);
}
.admin-hint { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }
.admin-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.admin-field label { font-size: 13px; font-weight: 600; }
.admin-field input,
.admin-field select {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.admin-field input:focus,
.admin-field select:focus {
  outline: none;
  border-color: var(--primary-2);
  box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.08);
}
.admin-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}
.admin-span-2 { grid-column: 1 / -1; }
@media (max-width: 620px) { .admin-grid-2 { grid-template-columns: 1fr; } }
.admin-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 620px) { .admin-cols { grid-template-columns: 1fr; } }
.col-checklist {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  background: var(--bg);
}
.col-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  font-size: 13px;
  border-radius: 5px;
  cursor: pointer;
}
.col-check:hover { background: var(--primary-soft); }
.col-name { font-weight: 600; color: var(--text); }
.col-ex { color: var(--muted-2); font-size: 11.5px; margin-left: auto; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-inspect.hidden { display: none; }
.admin-inspect-info {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-2);
  margin-bottom: 14px;
}
.admin-status { font-size: 13px; margin-top: 10px; color: var(--muted); }
.admin-status code {
  background: var(--primary-soft);
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 13px;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 13px;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}
.admin-table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
.admin-mono { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 11.5px; color: var(--muted); }

.reimport-btn {
  background: var(--card);
  border: 1px solid var(--border-2);
  color: var(--primary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.reimport-btn:hover:not(:disabled) { background: var(--primary-soft); border-color: var(--primary-2); }
.reimport-btn:disabled { opacity: 0.6; cursor: progress; }

.role-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.role-root   { background: #fef3c7; color: #92400e; }
.role-admin  { background: var(--primary-soft); color: var(--primary); }
.role-client { background: var(--bg-2); color: var(--muted); }
.role-btn {
  background: var(--card);
  border: 1px solid var(--border-2);
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.role-btn:hover:not(:disabled) { background: var(--err-bg); border-color: #fca19b; color: var(--err); }
.role-btn.role-promote:hover:not(:disabled) { background: var(--primary-soft); border-color: var(--primary-2); color: var(--primary); }
.role-btn:disabled { opacity: 0.6; cursor: progress; }
.pwd-btn {
  background: var(--card);
  border: 1px solid var(--border-2);
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.pwd-btn:hover:not(:disabled) { background: var(--primary-soft); border-color: var(--primary-2); color: var(--primary); }
.pwd-btn:disabled { opacity: 0.6; cursor: progress; }

.admin-detect-cols { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.admin-detect-cols > div { line-height: 1.5; }
.detect-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-right: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.detect-verbatim { background: #dcfce7; color: #166534; }
.detect-profile  { background: var(--primary-soft); color: var(--primary); }
.detect-ignore   { background: var(--bg-2); color: var(--muted); }

/* Boutons de suppression (back-office) — danger, discrets mais explicites */
.admin-row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.del-user-btn, .del-dataset-btn {
  border: 1px solid #e6b8b2;
  background: #fdf1ef;
  color: #b42318;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 11px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.del-user-btn:hover, .del-dataset-btn:hover { background: #fbe3df; border-color: #d68b82; }
.del-user-btn:disabled, .del-dataset-btn:disabled { opacity: .5; cursor: default; }

/* ── Boutons de question (périmètre) côté chat ─────────────────────────────── */
/* Pastilles qui s'enroulent, plusieurs par ligne. Libellés longs tronqués
   proprement par CSS (ellipsis) ; le libellé complet reste en info-bulle. */
.question-bar {
  margin-bottom: 10px;
  max-height: 128px;
  overflow-y: auto;
}
.question-bar-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.question-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.question-btn {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  border: 1px solid var(--border-2);
  background: var(--card);
  color: var(--primary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  padding: 5px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.question-btn:hover { background: var(--primary-soft); border-color: var(--primary-2); }
.question-btn.question-active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}
@media (max-width: 640px) {
  /* Sur mobile : une pastille par ligne, pleine largeur. */
  .question-btn { flex-basis: 100%; }
}

/* ── Sélection des questions à l'import (back-office) ──────────────────────── */
.admin-questions {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.admin-questions-hd { font-size: 13px; font-weight: 600; color: var(--primary); margin-bottom: 8px; }
.admin-question-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.admin-question-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 108px;
  cursor: pointer;
}
/* Code = simple référence technique interne (secondaire, gris, monospace). */
.admin-question-check .q-code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg-2);
  padding: 1px 6px;
  border-radius: 5px;
}
.admin-question-row .q-label {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border-2);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
}

/* Modale (sélection des questions au réimport) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 50, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}
.modal-box {
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(20, 30, 50, 0.3);
  padding: 22px 24px;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-box h3 { margin: 0 0 6px; color: var(--primary); font-size: 17px; }
.modal-box #reimport-questions-list { margin: 14px 0 4px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}
