@font-face {
  font-family: "Montserrat";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/Montserrat-VariableFont_wght.ttf") format("truetype");
}
@font-face {
  font-family: "Montserrat";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/Montserrat-Italic-VariableFont_wght.ttf") format("truetype");
}

:root {
  --bg: #f7fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --blue: #0076bd;
  --blue-dark: #004f9f;
  --blue-soft: #f0faff;
  --green: #95c11f;
  --green-dark: #7ca517;
  --ink: #1a202c;
  --text: #2d3748;
  --muted: #4a5568;
  --faint: #94a3b8;
  --red: #e30613;
  --red-soft: #fef2f2;
  --radius: 16px;
  --radius-sm: 10px;
  --pill: 24px;
  --shadow: 0 4px 14px rgba(26, 32, 44, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Montserrat", "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
input, textarea, select, button { font-family: inherit; }
::placeholder { color: var(--faint); }

/* =================== Barre de navigation admin =================== */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: wrap;
}
.brand { height: 30px; width: auto; flex: none; }
.nav {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  flex: 1;
}
.nav a {
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 0;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.15s ease;
}
.nav a:hover { color: var(--blue); }
.nav a.active {
  font-weight: 700;
  color: var(--blue);
  border-bottom-color: var(--blue);
}
.logout {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s ease;
}
.logout:hover { color: var(--red); }

/* =================== Mise en page admin =================== */
.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 36px 24px 64px;
}
.wrap.wide { max-width: 1180px; }

header h1 {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--blue);
}
header p { margin: 0 0 28px; font-size: 15px; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.section-title { margin: 0 0 16px; font-size: 17px; font-weight: 700; color: var(--ink); }

.field { margin-bottom: 18px; }
label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 7px;
}
.req { color: var(--red); }

input, textarea, select {
  width: 100%;
  font-size: 15px;
  color: var(--text);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--surface);
}
textarea { resize: vertical; line-height: 1.7; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); }
input[readonly], input:disabled { background: var(--bg); color: var(--faint); }

.hint { font-size: 13px; color: var(--muted); margin-top: 7px; line-height: 1.6; }
.count { color: var(--muted); font-weight: 600; font-size: 0.9em; }
.error { color: var(--red); margin-top: 10px; font-size: 14px; }

.divider { border: none; border-top: 1px solid var(--border); margin: 26px 0; }

/* =================== Boutons =================== */
button {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: var(--blue);
  border: none;
  padding: 12px 26px;
  border-radius: var(--pill);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
button:hover { background: var(--blue-dark); }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.55; cursor: default; transform: none; }

button.ghost,
a.ghost {
  display: inline-block;
  text-decoration: none;
  background: var(--surface);
  color: var(--blue);
  border: 1.5px solid var(--blue);
  font-weight: 600;
}
button.ghost:hover, a.ghost:hover { background: var(--blue-soft); }
button.ghost.small, a.ghost.small { padding: 7px 16px; font-size: 13px; border-radius: 20px; }
button.ghost.danger, a.ghost.danger { color: var(--red); border-color: var(--red); }
button.ghost.danger:hover, a.ghost.danger:hover { background: var(--red-soft); }

.actions { display: flex; gap: 12px; margin-top: 24px; flex-wrap: wrap; }

.result {
  margin-top: 20px;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  background: var(--blue-soft);
  border: 1px solid #cfe9fb;
  display: none;
}
.result.show { display: block; }
.result code {
  display: block;
  background: #fff;
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 8px;
  margin-top: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  word-break: break-all;
  color: var(--text);
}

/* =================== Recherche HubSpot =================== */
.search-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--pill);
  padding: 4px;
  gap: 4px;
  margin-bottom: 18px;
}
.search-toggle .seg {
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 20px;
}
.search-toggle .seg:hover { background: transparent; color: var(--blue); }
.search-toggle .seg.active { background: var(--blue); color: #fff; }
.search-toggle .seg.active:hover { background: var(--blue); color: #fff; }

.results-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.result-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name id" "email id";
  gap: 2px 12px;
  text-align: left;
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-weight: 500;
}
.result-row:hover { border-color: var(--blue); background: var(--blue-soft); }
.result-row .rr-name { grid-area: name; font-weight: 700; }
.result-row .rr-email { grid-area: email; font-size: 0.85rem; color: var(--muted); }
.result-row .rr-id {
  grid-area: id;
  align-self: center;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}
.empty { color: var(--faint); padding: 8px 0; }

/* =================== Tableau (Enregistrements) =================== */
table.records { width: 100%; border-collapse: collapse; min-width: 760px; }
table.records th {
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  padding: 16px 12px;
  border-bottom: 1px solid var(--border);
}
table.records td {
  font-size: 14px;
  color: var(--text);
  padding: 16px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.records tbody tr:hover { background: var(--bg); }
.table-scroll { overflow-x: auto; }

.badge {
  display: inline-block;
  background: #edf2f7;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
}
.badge-current, .badge-done { background: var(--green-dark); color: #fff; }

/* =================== Consommation (stats) =================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.stat-value { font-size: 40px; font-weight: 800; color: var(--blue); line-height: 1; letter-spacing: -0.02em; }
.stat-label { font-size: 15px; font-weight: 600; color: var(--text); margin-top: 10px; }
.stat-sub { font-size: 13px; color: var(--faint); margin-top: 4px; }

/* =================== Page API =================== */
code.inline {
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.api-url { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
.api-url code {
  flex: 1;
  min-width: 260px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--text);
  overflow-x: auto;
  white-space: nowrap;
}
pre.code-block {
  margin: 0;
  background: var(--ink);
  color: #cbd5e1;
  border-radius: 12px;
  padding: 20px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.7;
  overflow-x: auto;
}
.api-errors { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; }
.api-errors li { font-size: 14px; color: var(--text); }

/* =================== Config (2 colonnes) =================== */
.layout {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.layout > .card { flex: 1 1 520px; }
.layout > .history { flex: 1 1 320px; }

.history-list { display: flex; flex-direction: column; gap: 14px; }
.history-item { border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.history-meta {
  font-size: 12px;
  color: var(--faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin: 6px 0 10px;
}
.history-content { font-size: 13px; line-height: 1.5; color: var(--text); max-height: 200px; overflow: auto; }
.history-content .hc-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 7px; }
.history-content .hc-empty { color: var(--faint); }

.panel-static { display: block; }

/* =================== Bouton icône (poubelle) =================== */
.icon-btn {
  background: var(--surface);
  border: 1.5px solid var(--red);
  color: var(--red);
  border-radius: 10px;
  padding: 7px 9px;
  line-height: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--red-soft); }
.icon-btn svg { width: 16px; height: 16px; display: block; }

/* =================== Modale Analyse =================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 32, 44, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 60;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 640px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(26, 32, 44, 0.25);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 700; color: var(--blue); }
.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 20px;
  padding: 4px 8px;
  cursor: pointer;
}
.modal-close:hover { background: transparent; color: var(--ink); }
.modal-body { padding: 22px 24px; max-height: 60vh; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

.analyse-section { margin-bottom: 18px; }
.analyse-section h4 { margin: 0 0 8px; font-size: 14px; font-weight: 700; color: var(--ink); }
.analyse-section ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.analyse-section li { font-size: 14px; line-height: 1.55; color: var(--text); }
.analyse-section p { margin: 0; font-size: 14px; line-height: 1.6; color: var(--text); }
.niveau { font-size: 13px; font-weight: 600; padding: 4px 12px; border-radius: 20px; display: inline-block; }
.niveau.faible { background: #edf2f7; color: var(--muted); }
.niveau.moyen { background: #fef3c7; color: #92660a; }
.niveau.eleve { background: var(--green-dark); color: #fff; }

/* =================== Toast =================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }

/* =================== Connexion / page neutre =================== */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  text-align: center;
}
.auth-card .brand { height: 34px; margin-bottom: 18px; }
.auth-card form { text-align: left; margin-top: 12px; }
.auth-card button { width: 100%; margin-top: 4px; }
.auth-card p { color: var(--muted); font-size: 14px; }

/* =================== Chat candidat =================== */
.chat-shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.chat-col {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.chat-header {
  background: linear-gradient(180deg, var(--blue) 0%, var(--blue-dark) 100%);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}
.chat-header .brand { height: 30px; align-self: flex-start; }
.chat-header p { margin: 0; font-size: 13px; font-weight: 500; line-height: 1.45; color: rgba(255, 255, 255, 0.82); }

@keyframes rvIn { from { transform: translateY(6px); } to { transform: translateY(0); } }
@keyframes rvDot { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-4px); opacity: 1; } }

#chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.msg {
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: rvIn 0.26s ease-out;
}
.msg.assistant {
  align-self: flex-start;
  max-width: 86%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-top-left-radius: 5px;
  padding: 14px 16px;
  box-shadow: 0 4px 14px rgba(26, 32, 44, 0.06);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
}
.msg.user {
  align-self: flex-end;
  max-width: 82%;
  background: var(--blue);
  color: #fff;
  border-radius: 16px;
  border-bottom-right-radius: 5px;
  padding: 11px 15px;
  font-size: 15px;
  line-height: 1.55;
  font-weight: 500;
  box-shadow: 0 4px 14px rgba(0, 118, 189, 0.18);
}
.typing {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-top-left-radius: 5px;
  padding: 14px 16px;
  box-shadow: 0 4px 14px rgba(26, 32, 44, 0.06);
  display: flex;
  gap: 5px;
  align-items: center;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--blue);
  display: inline-block; animation: rvDot 1.2s infinite;
}
.done-banner {
  margin: 8px 0 4px;
  text-align: center;
  font-size: 13px;
  font-style: italic;
  color: var(--muted);
  line-height: 1.5;
}

.composer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  align-items: center;
}
.composer textarea, .composer input {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  color: var(--text);
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--pill);
  background: var(--bg);
  resize: none;
}
.composer textarea:focus, .composer input:focus { border-color: var(--blue); background: var(--surface); }
.composer button {
  flex: none;
  background: var(--green);
  font-weight: 700;
  padding: 12px 22px;
}
.composer button:hover { background: var(--green-dark); }
