/* =============================================================================
   CRM 3A CF — feuille de style (maquette validée du 29/09/2026)
   Identité : marine #0a2267, bleu clair #929fbb, accent #3f3bd1.
   Polices : Archivo (titres), Inter (texte), JetBrains Mono (heures, chiffres).
   Aucun style inline dans le HTML (CSP style-src sans 'unsafe-inline') : seules
   les largeurs de barres sont posées en JS via element.style (CSSOM, autorisé).
   ============================================================================= */

:root {
  --navy: #0a2267;
  --navy-active: #1d3a8f;
  --navy-line: #1f3a86;
  --blue-light: #929fbb;
  --nav-text: #c5cde3;
  --nav-muted: #aab5d3;
  --accent: #3f3bd1;
  --accent-hover: #2c28a8;
  --ink: #141a33;
  --ink-2: #3a4260;
  --muted: #5a6380;
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e3e7f0;
  --border-input: #cfd5e4;
  --line: #eef0f5;
  --head-bg: #f8f9fc;
  --track: #eef1f8;
  --selected: #eef1fb;
  --ok-bg: #e3f4ec;   --ok: #146c47;
  --warn-bg: #fcefdc; --warn: #8a4a06;
  --neutral-bg: #eef0f4; --neutral: #4a5270;
  --new-bg: #e8ebfb;  --new: #3730a3;
  --rdv-bg: #dff1f4;  --rdv: #0e6170;
  --danger: #a33a1f;
  --radius: 14px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-title: Archivo, Inter, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
[hidden] { display: none !important; }
button { font: inherit; }
.mono { font-family: var(--font-mono); font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Structure ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--navy); display: flex; flex-direction: column;
  gap: 4px; padding: 24px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 22px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; background: #fff; color: var(--navy);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-title); font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.brand-text strong { display: block; font-family: var(--font-title); font-size: 16px; color: #fff; }
.brand-text span { display: block; font-size: 12px; color: var(--nav-muted); margin-top: 2px; }

.nav-link {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 8px;
  text-decoration: none; font-size: 14px; font-weight: 500; color: var(--nav-text);
}
.nav-link svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.nav-link:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-link.is-active { background: var(--navy-active); color: #fff; font-weight: 600; }
.nav-link.is-disabled { opacity: .55; cursor: default; }
.nav-link.is-disabled:hover { background: none; color: var(--nav-text); }
.nav-label { flex-grow: 1; }
.nav-badge { font-size: 12px; font-weight: 700; background: var(--blue-light); color: var(--navy); border-radius: 999px; padding: 2px 8px; }
.nav-soon { font-size: 11px; color: var(--nav-muted); border: 1px solid var(--navy-line); border-radius: 999px; padding: 1px 7px; }
.sidebar-spacer { flex-grow: 1; }
.user-box { display: flex; align-items: center; gap: 10px; padding: 14px 10px 0; border-top: 1px solid var(--navy-line); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--blue-light); color: var(--navy);
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.user-text strong { display: block; font-size: 13px; color: #fff; }
.user-text span { display: block; font-size: 12px; color: var(--nav-muted); margin-top: 2px; }
.user-actions { display: flex; gap: 14px; padding: 8px 10px 0 52px; flex-wrap: wrap; }
.link-btn { background: none; border: 0; padding: 0; color: var(--nav-muted); font-size: 12px; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.lead-panel .section-title { margin-bottom: 6px; }
.link-btn:hover { color: #fff; }

.main { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 20px; padding: 28px 36px; outline: none; }

/* ---------- En-tête de page ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head .kicker { font-size: 13px; color: var(--muted); }
.page-head h1 { margin: 4px 0 0; font-family: var(--font-title); font-size: 28px; font-weight: 700; color: var(--navy); }
.head-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.search {
  display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px; background: #fff;
  border: 1px solid #dfe3ee; border-radius: 10px; width: 300px; color: var(--muted);
}
.search svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; flex-shrink: 0; }
.search input { border: 0; outline: none; font: inherit; font-size: 14px; flex-grow: 1; background: transparent; color: var(--ink); min-width: 0; }

/* ---------- Boutons ---------- */
.btn {
  height: 44px; padding: 0 18px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border-input); background: #fff; color: var(--navy);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn:hover { border-color: var(--navy); }
.btn-primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-primary:hover { background: var(--navy-active); color: #fff; }
.btn-ghost { color: var(--neutral); font-weight: 500; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border-input); }
.btn-primary:disabled:hover { background: var(--navy); }

/* ---------- Cartes & KPI ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.card h2 { margin: 0; font-family: var(--font-title); font-size: 17px; font-weight: 700; color: var(--navy); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi-value { font-family: var(--font-title); font-size: 34px; font-weight: 700; color: var(--navy); }
.kpi-sub { font-size: 13px; color: var(--neutral); font-weight: 500; }
.kpi-sub.is-good { color: var(--ok); }
.kpi.is-future { opacity: .6; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; }

/* Barres (entonnoir, origine) */
.bar-row { display: flex; align-items: center; gap: 12px; }
.bar-label { width: 170px; font-size: 13px; color: var(--ink-2); flex-shrink: 0; }
.bar-track { flex-grow: 1; height: 24px; background: var(--track); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--navy); border-radius: 6px; width: 0; }
.bar-track.is-thin { height: 10px; border-radius: 5px; }
.bar-track.is-thin .bar-fill { background: var(--accent); border-radius: 5px; }
.bar-value { width: 36px; text-align: right; font-family: var(--font-mono); font-size: 13px; }
.card-note { font-size: 12px; color: var(--muted); padding-top: 4px; }

/* Listes simples (derniers leads, activité) */
.row-link {
  display: flex; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); text-decoration: none; color: inherit; align-items: flex-start;
}
.row-link:hover .row-title { color: var(--accent); }
.row-time { width: 46px; flex-shrink: 0; font-family: var(--font-mono); font-size: 12px; color: var(--muted); padding-top: 1px; }
.row-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex-grow: 1; }
.row-title { font-size: 13px; font-weight: 600; }
.row-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { font-size: 13px; color: var(--muted); padding: 16px 0; border-top: 1px solid var(--line); }

/* ---------- Pastilles ---------- */
.pill { font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 999px; white-space: nowrap; display: inline-block; }
.st-nouveau { background: var(--new-bg); color: var(--new); }
.st-qualifie { background: var(--ok-bg); color: var(--ok); }
.st-rdv { background: var(--rdv-bg); color: var(--rdv); }
.st-converti { background: var(--navy); color: #fff; }
.st-hors_cible { background: var(--neutral-bg); color: var(--neutral); }
.score { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 7px; font-weight: 700; font-size: 13px; }
.score-A { background: var(--ok-bg); color: var(--ok); }
.score-B { background: var(--warn-bg); color: var(--warn); }
.score-C, .score-none { background: var(--neutral-bg); color: var(--neutral); }

/* ---------- Écran Leads ---------- */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab {
  height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid #d7dcea; background: #fff;
  color: var(--ink-2); font-size: 13px; font-weight: 500; cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 600; }
.leads-layout { display: flex; gap: 20px; align-items: flex-start; }
.leads-list { flex-grow: 1; min-width: 0; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.lead-row {
  display: grid; grid-template-columns: 62px minmax(0, 1.7fr) 104px minmax(0, 1.2fr) 48px 118px; gap: 10px;
  align-items: center; padding: 13px 16px; border-top: 1px solid var(--line); cursor: pointer; width: 100%;
  background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; color: inherit;
}
.lead-row:hover { background: #f8f9fd; }
.lead-row.is-selected { background: var(--selected); }
.lead-row.is-head { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--head-bg); border-top: 0; cursor: default; padding: 12px 16px; }
.lead-when { font-family: var(--font-mono); font-size: 12px; color: var(--ink-2); }
.lead-who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lead-who strong { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-who span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-besoin { font-size: 13px; font-weight: 500; }
.lead-source { font-size: 12px; color: var(--ink-2); }
.list-foot { padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

/* Fiche lead */
.lead-panel {
  width: 392px; flex-shrink: 0; background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; display: flex; flex-direction: column; gap: 16px; position: sticky; top: 20px;
  max-height: calc(100vh - 40px); overflow-y: auto;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.panel-head h2 { margin: 0; font-family: var(--font-title); font-size: 20px; font-weight: 700; color: var(--navy); }
.panel-head p { margin: 4px 0 0; font-size: 13px; color: var(--ink-2); }
.score-big { display: inline-flex; align-items: center; justify-content: center; height: 30px; padding: 0 10px; border-radius: 8px; font-weight: 700; font-size: 13px; white-space: nowrap; }
.kv { display: grid; grid-template-columns: 110px minmax(0, 1fr); row-gap: 8px; column-gap: 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.box { background: #f5f6fa; border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.section-title { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.message { font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.check { display: flex; gap: 10px; align-items: center; font-size: 13px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--ok); flex-shrink: 0; }
.segmented { display: inline-flex; border: 1px solid var(--border-input); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; background: #fff; height: 32px; min-width: 38px; font-weight: 700; font-size: 13px; cursor: pointer; color: var(--neutral); border-left: 1px solid var(--border-input); }
.segmented button:first-child { border-left: 0; }
.segmented button[aria-pressed="true"] { background: var(--navy); color: #fff; }
.panel-actions { display: flex; flex-direction: column; gap: 8px; }
.panel-actions .row { display: flex; gap: 8px; }
.panel-actions .row > * { flex-grow: 1; }
.hint { font-size: 12px; color: var(--muted); }
.link-inline { background: none; border: 0; padding: 0; color: var(--accent); font-size: 12px; font-weight: 600; cursor: pointer; }

/* Timeline */
.timeline { display: flex; flex-direction: column; }
.tl-item { padding: 10px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px; }
.tl-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; }
.tl-type { font-weight: 600; color: var(--ink-2); }
.tl-body { font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }

/* ---------- Formulaires ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .input {
  height: 40px; border: 1px solid var(--border-input); border-radius: 8px; padding: 0 12px; font: inherit;
  font-size: 14px; font-weight: 400; color: var(--ink); background: #fff; width: 100%;
}
.field textarea, textarea.input { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.form-error { color: var(--danger); font-size: 13px; margin: 0; }

/* ---------- Modale, toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 34, 103, .35); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: var(--radius); padding: 24px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 60px rgba(10,34,103,.25); }
.modal h2 { margin: 0 0 16px; font-family: var(--font-title); font-size: 20px; color: var(--navy); }
.modal p { font-size: 14px; line-height: 1.5; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 13px; z-index: 60; max-width: 360px; }
.toast.is-error { background: var(--danger); }

/* ---------- Connexion ---------- */
.login-page { background: var(--navy); }
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: #fff; border-radius: var(--radius); padding: 32px; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 16px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.login-brand .brand-mark { background: var(--navy); color: #fff; }
.login-brand strong { display: block; font-family: var(--font-title); font-size: 18px; color: var(--navy); }
.login-brand span { display: block; font-size: 13px; color: var(--muted); }

/* ---------- Adaptation écrans étroits ---------- */
@media (max-width: 1180px) {
  .leads-layout { flex-direction: column; align-items: stretch; }
  .lead-panel { width: auto; position: static; max-height: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; }
  .brand { padding: 0 8px 0 0; }
  .brand-text span, .sidebar-spacer, .nav-link.is-disabled, .user-box { display: none; }
  .user-actions { padding: 0; margin-left: auto; }
  .main { padding: 20px 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .search { width: 100%; }
  .lead-row { grid-template-columns: 52px minmax(0, 1fr) 36px 96px; }
  .lead-row > :nth-child(3), .lead-row > :nth-child(4) { display: none; }
  .bar-label { width: 120px; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
}
