:root {
  --topbar-h: 66px;
  --bordeaux: #7b1e2b;
  --bordeaux-dark: #5e1520;
  --bordeaux-soft: #f7eced;
  --bg: #ffffff;
  --text: #1f1f1f;
  --muted: #6b6b6b;
  --border: #e6e2e2;
  --success: #2f7a4b;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(123, 30, 43, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--bordeaux); }

/* ---------- En-tête ---------- */

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

.brand {
  font-weight: 800;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
  color: var(--bordeaux);
  text-decoration: none;
}

.topbar-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-user { color: var(--muted); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Boutons et champs ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--bordeaux);
  background: var(--bordeaux);
  color: #fff;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn:hover { background: var(--bordeaux-dark); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-outline { background: #fff; color: var(--bordeaux); }
.btn-outline:hover { background: var(--bordeaux-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); font-weight: 500; }
.btn-ghost:hover { background: #f4f4f4; color: var(--text); }
.btn-danger { background: #fff; color: #b3261e; border-color: #e3b5b2; }
.btn-danger:hover { background: #fbeceb; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn-block { width: 100%; }

label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }

input, textarea {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px; /* évite le zoom automatique sur iPhone */
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--bordeaux);
  box-shadow: 0 0 0 3px rgba(123, 30, 43, 0.15);
}
textarea { resize: vertical; min-height: 80px; }

.field { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.error { color: #b3261e; font-size: 0.9rem; min-height: 1.2em; margin: 8px 0 0; }
.hidden { display: none !important; }

/* ---------- Page de connexion ---------- */

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--bordeaux);
  margin: 0 0 4px;
}

.login-tagline { color: var(--muted); margin: 0 0 32px; }

.login-box {
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.login-box h2 { margin: 0 0 4px; font-size: 1.25rem; }
.login-box .subtitle { color: var(--muted); margin: 0 0 20px; font-size: 0.95rem; }

/* ---------- Mise en page des espaces ---------- */

.container { max-width: 960px; margin: 0 auto; padding: 24px 20px 60px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.page-head h1 { margin: 0; font-size: 1.6rem; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: #fff;
  margin-bottom: 20px;
}
.card h2 { margin: 0 0 16px; font-size: 1.15rem; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; margin: 0; }
.toggle input { width: 18px; height: 18px; accent-color: var(--bordeaux); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- Liste des prospects ---------- */

.prospect-list { display: grid; gap: 12px; }

.prospect {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--bordeaux);
  border-radius: var(--radius);
  padding: 16px;
  background: #fff;
}

.prospect-info { min-width: 0; flex: 1; }
.prospect-name { font-weight: 700; font-size: 1.05rem; margin: 0; overflow-wrap: anywhere; }
.prospect-phone { color: var(--bordeaux); font-weight: 600; margin: 2px 0 0; }
.prospect-note { color: var(--muted); margin: 6px 0 0; font-size: 0.95rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.prospect-meta { color: var(--muted); font-size: 0.8rem; margin: 6px 0 0; }

.prospect-actions { display: flex; gap: 8px; flex-shrink: 0; }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e8f3ec;
  color: var(--success);
  margin-left: 6px;
  vertical-align: middle;
}

/* ---------- Liste des commerces (admin) ---------- */

.merchant-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }

.merchant {
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: #fff;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.merchant:hover { border-color: var(--bordeaux); box-shadow: var(--shadow); }
.merchant-name { font-weight: 700; margin: 0; color: var(--bordeaux); overflow-wrap: anywhere; }
.merchant-meta { color: var(--muted); font-size: 0.9rem; margin: 4px 0 0; }

.back { margin-bottom: 12px; padding-left: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.95rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
  z-index: 50;
  max-width: calc(100% - 32px);
}

/* ---------- Onglets ---------- */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

/* Onglets principaux toujours visibles, collés sous l'en-tête. */
#tabs {
  position: sticky;
  top: var(--topbar-h);
  z-index: 9;
  background: var(--bg);
}
.tab {
  flex-shrink: 0;
  padding: 10px 14px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--bordeaux); border-bottom-color: var(--bordeaux); }
.tab .count {
  display: inline-block;
  min-width: 22px;
  padding: 0 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: #f1eeee;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}
.tab.active .count { background: var(--bordeaux); color: #fff; }

/* ---------- Statuts ---------- */

.status {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
  white-space: nowrap;
}
.status-nouveau { background: var(--bordeaux-soft); color: var(--bordeaux); }
.status-a_rappeler { background: #fff3dc; color: #8a5a00; }
.status-appele { background: #eef1f6; color: #3d4b63; }
.status-rendez_vous { background: #e9f0fd; color: #1f4fa8; }
.status-signe { background: var(--success); color: #fff; }
.status-pas_signe { background: #c0392b; color: #fff; }
.status-alert { background: #fbeceb; color: #b3261e; border: 1px solid #e3b5b2; }

.prospect.st-signe { border-color: #b9dcc5; border-left-color: var(--success); background: #eaf6ee; }
.prospect.st-pas_signe { border-color: #efc4bf; border-left-color: #c0392b; background: #fcecea; }
.prospect.st-appele, .prospect.st-rendez_vous { border-left-color: #1f4fa8; }
.prospect.st-a_rappeler { border-left-color: #c98a00; }

.prospect-reason { margin: 6px 0 0; font-size: 0.9rem; }

select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
.prospect-actions select { width: auto; min-width: 160px; }

/* ---------- Historique ---------- */

.history { margin-top: 8px; font-size: 0.85rem; }
.history summary { cursor: pointer; color: var(--bordeaux); font-weight: 600; }
.history ol { list-style: none; margin: 8px 0 0; padding: 0 0 0 12px; border-left: 2px solid var(--border); }
.history li { margin: 0 0 6px; color: var(--text); }
.history time { color: var(--muted); margin-right: 6px; }
.history .actor { color: var(--muted); }

/* ---------- Fenêtre (dialog) ---------- */

dialog {
  width: min(440px, calc(100% - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h2 { margin: 0 0 4px; font-size: 1.2rem; }
dialog .subtitle { color: var(--muted); margin: 0 0 16px; }
.choices { display: grid; gap: 8px; margin-bottom: 16px; }
.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-weight: 500;
  margin: 0;
  cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--bordeaux); background: var(--bordeaux-soft); }
.choice input { width: 18px; height: 18px; accent-color: var(--bordeaux); margin: 0; }

/* ---------- Tableau de bord ---------- */

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--bordeaux); line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { white-space: normal; line-height: 1.3; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: #fbfafa; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--bordeaux-soft); }

.section-title { margin: 28px 0 12px; font-size: 1.15rem; }
.hint { color: var(--muted); font-size: 0.9rem; margin: -6px 0 12px; }

.alert-box {
  border: 1px solid #f0c9c6;
  background: #fdf5f4;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.message-preview {
  background: #fbfafa;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0 0;
  font-size: 0.9rem;
  white-space: pre-wrap;
  color: var(--text);
}

.verify-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* ---------- Logos ---------- */

/* Photos de profil des commerces : rondes, l'image remplit tout le cercle (aucun bord blanc). */

.merchant-logo {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: 50%;
}
.merchant-logo-small { width: 36px; height: 36px; }
.merchant-logo-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bordeaux-soft);
  color: var(--bordeaux);
  font-weight: 800;
  font-size: 1.4rem;
}
.merchant-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.merchant-head-text { min-width: 0; }
a.merchant { display: flex; align-items: center; gap: 14px; text-decoration: none; }
.merchant-body { min-width: 0; }

input[type=file] { padding: 10px; font-size: 0.9rem; }

/* ---------- Téléphone ---------- */

@media (max-width: 640px) {
  :root { --topbar-h: 60px; }

  /* Tous les onglets principaux tiennent sur la largeur du téléphone. */
  #tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0; overflow: visible; }
  #tabs .tab {
    padding: 10px 2px;
    font-size: 0.82rem;
    line-height: 1.25;
    white-space: normal;
    text-align: center;
  }
  #tabs .tab .count { min-width: 18px; padding: 0 5px; margin-left: 2px; font-size: 0.72rem; }
  .topbar { padding: 0 16px; }
  .topbar-user { display: none; }
  .container { padding: 16px 16px 48px; }
  .page-head h1 { font-size: 1.35rem; }
  .card { padding: 16px; }
  .form-row { grid-template-columns: 1fr; gap: 0; }

  .prospect { flex-direction: column; align-items: stretch; }
  .prospect-actions { width: 100%; }
  .prospect-actions .btn { flex: 1; }

  .merchant-list { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .prospect-actions { flex-wrap: wrap; }
  .prospect-actions select { flex: 1; min-width: 0; }
  .verify-actions .btn { flex: 1 1 45%; }
  .login-box { padding: 24px 18px; }
}
