/* ==========================================================================
   TB-Partenaire — Plateforme Prescripteurs
   Style : Clair & neutre (blanc cassé · gris doux · accent bleu discret)
   Police : Inter
   100% CSS vanilla, aucun framework.
   ========================================================================== */

/* ---- Variables de couleurs (la "charte" de l'app) ---- */
:root {
  --bg:           #f6f7f9;   /* fond général, blanc cassé */
  --surface:      #ffffff;   /* cartes, panneaux */
  --surface-2:    #fbfbfc;   /* zones légèrement grisées */
  --border:       #e7e9ee;   /* traits de séparation */
  --border-strong:#d7dae1;

  --text:         #1b1f27;   /* texte principal */
  --text-soft:    #4b5563;   /* texte secondaire */
  --muted:        #8b919e;   /* texte discret */

  --accent:       #2f6fed;   /* bleu doux (accent unique) */
  --accent-hover: #2a63d4;
  --accent-soft:  #eaf1fe;   /* fond bleu très clair */

  --green:        #16a34a;   --green-soft:#e7f6ec;
  --amber:        #b7791f;   --amber-soft:#fbf3e2;
  --red:          #dc2626;   --red-soft:#fcebeb;
  --slate:        #64748b;   --slate-soft:#eef1f5;

  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --shadow-md:    0 4px 16px rgba(16,24,40,.08);

  --sidebar-w:    232px;
}

/* ---- Reset léger ---- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: 14px; }

/* ==========================================================================
   Boutons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-weight: 500; font-size: 14px;
  transition: all .15s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ==========================================================================
   Page de connexion (index.html) & formulaire public (parrainage.html)
   ========================================================================== */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, #eef2f8 0%, transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-md); padding: 36px 32px;
}
.auth-card .logo {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px; letter-spacing: -.2px; margin-bottom: 22px;
}
.auth-card .logo .dot {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #6aa0ff);
}
.auth-card h1 { font-size: 22px; letter-spacing: -.4px; margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); margin-bottom: 24px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 500; color: var(--text-soft); margin-bottom: 6px; }
.input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.code { letter-spacing: 1px; font-weight: 600; text-transform: uppercase; }

.auth-foot { margin-top: 20px; text-align: center; font-size: 13px; color: var(--muted); }
.error-msg {
  display: none; margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--red-soft); color: var(--red); font-size: 13px;
}
.error-msg.show { display: block; }
.success-msg {
  display: none; margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--green-soft); color: var(--green); font-size: 14px;
}
.success-msg.show { display: block; }

/* ==========================================================================
   Layout application (sidebar + contenu)
   ========================================================================== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); padding: 18px 14px;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px;
  font-weight: 700; font-size: 15px; letter-spacing: -.2px;
}
.sidebar .brand .dot { width: 24px; height: 24px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #6aa0ff); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  border-radius: var(--radius-sm); color: var(--text-soft); font-weight: 500;
  text-decoration: none; transition: background .12s, color .12s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a .ico { width: 18px; text-align: center; opacity: .9; }
.sidebar .foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.sidebar .who { padding: 4px 8px; font-size: 13px; }
.sidebar .who .name { font-weight: 600; }
.sidebar .who .role { color: var(--muted); font-size: 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 28px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; letter-spacing: -.3px; }
.topbar .right { display: flex; align-items: center; gap: 12px; }

.select {
  padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-weight: 500;
}
.select:focus { outline: none; border-color: var(--accent); }

.content { padding: 24px 28px 60px; max-width: 1180px; width: 100%; }
.page { display: none; }
.page.active { display: block; }
.page-title { font-size: 16px; font-weight: 600; margin: 4px 0 16px; }

/* ==========================================================================
   Cartes KPI
   ========================================================================== */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi .label { font-size: 12.5px; color: var(--muted); font-weight: 500; margin-bottom: 8px;
  text-transform: uppercase; letter-spacing: .3px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.6px; }
.kpi .value small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 20px; }
.kpi .delta { font-size: 12px; color: var(--green); margin-top: 4px; }

/* ==========================================================================
   Panneau / Carte générique
   ========================================================================== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.card .card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.card .card-head h2 { font-size: 15px; font-weight: 600; }
.card .card-head .hint { font-size: 12.5px; color: var(--muted); }
.card .card-body { padding: 18px; }

/* Carte "Mon code de parrainage" mise en avant */
.referral {
  background: linear-gradient(135deg, #f3f7ff, #ffffff);
  border: 1px solid var(--border);
}
.referral .code-box {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 4px;
}
.code-pill {
  font-size: 22px; font-weight: 700; letter-spacing: 1px;
  background: var(--surface); border: 1px dashed var(--border-strong);
  padding: 10px 18px; border-radius: var(--radius-sm); color: var(--accent);
}

/* ==========================================================================
   Tableaux
   ========================================================================== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: .3px;
  padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td .strong { font-weight: 600; }
td .muted { color: var(--muted); font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 36px 14px; }

/* ==========================================================================
   Badges de statut & projet
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.prospect   { background: var(--slate-soft); color: var(--slate); }
.badge.discussion { background: var(--amber-soft); color: var(--amber); }
.badge.signe      { background: var(--green-soft); color: var(--green); }
.badge.perdu      { background: var(--red-soft); color: var(--red); }
.badge.actif      { background: var(--green-soft); color: var(--green); }
.badge.inactif    { background: var(--slate-soft); color: var(--slate); }

.tag-projet {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.tag-projet .swatch { width: 8px; height: 8px; border-radius: 2px; }

/* ==========================================================================
   Modale (pour créer / éditer)
   ========================================================================== */
.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(20,24,33,.45);
  align-items: center; justify-content: center; padding: 24px; z-index: 50;
}
.modal-backdrop.show { display: flex; }
.modal {
  width: 100%; max-width: 480px; background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-md); overflow: hidden;
}
.modal .modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; }
.modal .modal-head h3 { font-size: 16px; font-weight: 600; }
.modal .modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal .modal-foot { padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px; }
.x-close { border: none; background: transparent; font-size: 20px; color: var(--muted); line-height: 1; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Cases à cocher des marques (fiche prescripteur) */
.marque-checks { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 4px 0 2px; }
.mq-check { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; cursor: pointer; }
.mq-check input { width: 15px; height: 15px; }

/* Aligner les badges de la table des prescripteurs (Contrat / Statut sur la même ligne) */
#tablePresc tbody td { vertical-align: top; }

/* Petite icône "télécharger le contrat" sous le statut */
.dl-contrat { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 6px;
  width: 30px; height: 25px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-soft); cursor: pointer; transition: all .12s; }
.dl-contrat:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.dl-contrat svg { width: 14px; height: 14px; }

/* Puce "Signature" du dirigeant (passe au vert une fois définie) */
.sig-chip { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-soft);
  border-radius: 999px; padding: 2px 11px; font-size: 11px; font-weight: 600; cursor: pointer; transition: all .12s; }
.sig-chip:hover { border-color: var(--muted); }
.sig-chip.done { background: var(--green-soft); border-color: #bfe3c9; color: var(--green); }
/* À moins d'1 mois de l'échéance : entourée de jaune */
.dl-contrat.dl-warn { border-color: var(--amber); color: var(--amber); box-shadow: 0 0 0 2px var(--amber-soft); }
.dl-contrat.dl-warn:hover { background: var(--amber-soft); }
/* Contrat expiré : totalement rouge */
.dl-contrat.dl-exp { border-color: var(--red); background: var(--red); color: #fff; }
.dl-contrat.dl-exp:hover { background: var(--red); border-color: var(--red); color: #fff; }

/* Petit utilitaire de "toast" copie */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ==========================================================================
   Icônes SVG (style fin, monochrome — couleur héritée du texte)
   ========================================================================== */
svg { flex-shrink: 0; }
.ico { display: inline-flex; align-items: center; justify-content: center; }
.nav a .ico svg { width: 18px; height: 18px; }
.btn svg { width: 15px; height: 15px; }
.search .ico svg { width: 16px; height: 16px; }
.auth-card .logo svg, .sidebar .brand svg { width: 18px; height: 18px; color: #fff; }
.level-medal svg { width: 32px; height: 32px; }
.alert-relance .ico { color: var(--amber); }
.alert-relance .ico svg { width: 19px; height: 19px; }

/* ==========================================================================
   Graphiques
   ========================================================================== */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; }
.chart-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.chart-card .hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.chart-box { position: relative; height: 200px; }

/* ==========================================================================
   Carte Niveau / Motivation (gamification)
   ========================================================================== */
.level-card { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.level-medal {
  width: 64px; height: 64px; border-radius: 16px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 30px;
  color: #fff; box-shadow: var(--shadow-md);
}
.level-info { flex: 1; min-width: 220px; }
.level-info .lvl-name { font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
.level-info .lvl-sub { font-size: 13px; color: var(--muted); margin: 2px 0 10px; }
.progress { height: 9px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), #6aa0ff); border-radius: 999px;
  transition: width .4s ease; }

/* ==========================================================================
   Barre de recherche & en-têtes triables
   ========================================================================== */
.search {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 6px 11px; background: var(--surface);
}
.search input { border: none; outline: none; font-size: 13px; width: 170px; background: transparent; }
.search .ico { color: var(--muted); }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable .arrow { opacity: .4; font-size: 10px; margin-left: 3px; }
th.sortable.sorted .arrow { opacity: 1; color: var(--accent); }

/* ==========================================================================
   Alertes de relance
   ========================================================================== */
.alert-relance {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--amber-soft); border: 1px solid #f0e0b8; border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 20px;
}
.alert-relance .ico { font-size: 18px; }
.alert-relance .txt { flex: 1; font-size: 13.5px; color: #7a5a12; }
.alert-relance .txt b { color: #6a4e0e; }

/* ==========================================================================
   Fiche client — timeline (historique)
   ========================================================================== */
.fiche-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.fiche-row:last-child { border-bottom: none; }
.fiche-row .k { color: var(--muted); }
.fiche-row .v { font-weight: 600; text-align: right; }
.timeline { list-style: none; margin: 8px 0 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 20px; border-left: 2px solid var(--border); }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 2px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
.timeline .t-date { font-size: 12px; color: var(--muted); }
.timeline .t-note { font-size: 13.5px; }
.textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); font-family: inherit; font-size: 14px; resize: vertical; min-height: 70px; }
.textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ==========================================================================
   Pipeline (tableau type "kanban") + médaillon
   ========================================================================== */
.pipeline-board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.pl-col { flex: 1 0 230px; min-width: 230px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; }
.pl-col-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13px; }
.pl-col-head .dotc { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.pl-col-head .count { margin-left: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 9px; font-size: 12px; color: var(--muted); }
.pl-col-body { padding: 10px; display: flex; flex-direction: column; gap: 10px; min-height: 60px; }
.pl-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 12px; box-shadow: var(--shadow); }
.pl-card .pc-nom { font-weight: 600; font-size: 13.5px; }
.pl-card .pc-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.pl-card .pc-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 6px; }
.pl-move { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 6px;
  width: 28px; height: 26px; display: inline-flex; align-items: center; justify-content: center; color: var(--text-soft); }
.pl-move:hover:not(:disabled) { background: var(--surface-2); border-color: var(--muted); }
.pl-move:disabled { opacity: .3; cursor: default; }
.pl-move svg { width: 15px; height: 15px; }
.pl-empty { color: var(--muted); font-size: 12.5px; text-align: center; padding: 16px 6px; }

.medaillon { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; }

/* ==========================================================================
   Écran de signature du contrat (gate de première connexion)
   ========================================================================== */
body.gated .app { filter: blur(3px) grayscale(.55); pointer-events: none; user-select: none; }
.gate { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-start; justify-content: center;
  padding: 28px 16px; overflow-y: auto; background: rgba(20,24,33,.55); }
.gate[hidden] { display: none; }
.gate-card { width: 100%; max-width: 780px; background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-md); overflow: hidden; margin: auto; }
.gate-head { padding: 22px 26px; border-bottom: 1px solid var(--border); }
.gate-title { font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
.gate-sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.gate-body { max-height: 44vh; overflow-y: auto; padding: 20px 26px; border-bottom: 1px solid var(--border);
  font-size: 13px; line-height: 1.6; color: var(--text-soft); background: var(--surface-2); }
.gate-body h3.art { font-size: 13.5px; font-weight: 700; color: var(--text); margin: 16px 0 4px; }
.gate-body h3.art:first-child { margin-top: 0; }
.gate-body p { margin-bottom: 8px; }
.gate-body .c-parties { color: var(--text); }
.gate-sign { padding: 20px 26px; }
.gate-check { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; cursor: pointer; margin-bottom: 16px; }
.gate-check input { margin-top: 2px; width: 16px; height: 16px; flex-shrink: 0; }
.sign-label { font-size: 13px; color: var(--text-soft); font-weight: 500; margin-bottom: 8px; }
.sign-pad-wrap { position: relative; }
.sign-pad { width: 100%; height: 170px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  background: #fff; touch-action: none; cursor: crosshair; display: block; }
.sign-clear { position: absolute; top: 8px; right: 8px; }
.gate-actions { margin-top: 18px; }
.gate-success { padding: 40px 26px; text-align: center; }
.gate-success .ok-ico { width: 54px; height: 54px; margin: 0 auto 14px; border-radius: 50%;
  background: var(--green-soft); color: var(--green); display: flex; align-items: center; justify-content: center; }
.gate-success .ok-ico svg { width: 28px; height: 28px; }
.gate-success h3 { font-size: 18px; margin-bottom: 8px; }
.gate-success p { color: var(--muted); margin-bottom: 20px; }
.gate-success .btn { margin: 4px; }

/* ==========================================================================
   Responsive (mobile)
   ========================================================================== */
@media (max-width: 860px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .sidebar { display: none; }       /* on simplifie sur mobile : nav en haut */
  .content { padding: 16px; }
  .topbar { padding: 14px 16px; }
  .row-2 { grid-template-columns: 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
}
