:root {
  --ink: #16202e;
  --ink-soft: #3a4757;
  --muted: #7b8896;
  --line: #e4e8ee;
  --surface: #ffffff;
  --bg: #f5f7fa;
  --accent: #c46a2a;      /* ambre/cuivre — reserve a la valeur (commissions, mises en relation) */
  --accent-soft: #f6e9dd;
  --navy: #1d3a5f;
  --ok: #2f8f5b;
  --warn: #b8893a;
  --bad: #b14a3c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22,32,46,.06), 0 6px 20px rgba(22,32,46,.05);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
a { color: var(--navy); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit; font-size: 14px; width: 100%;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--navy); outline-offset: -1px; }
label { display: block; font-size: 12px; color: var(--ink-soft); margin: 0 0 4px; font-weight: 550; }
.field { margin-bottom: 12px; }

.btn {
  border: 1px solid var(--navy); background: var(--navy); color: #fff;
  padding: 9px 16px; border-radius: 8px; font-weight: 600; font-size: 13px;
}
.btn:hover { background: #16314f; }
.btn.ghost { background: transparent; color: var(--navy); }
.btn.ghost:hover { background: #eef2f7; }
.btn.accent { background: var(--accent); border-color: var(--accent); }
.btn.accent:hover { background: #ac5a22; }
.btn.danger { background: transparent; border-color: var(--line); color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 12px; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.brand .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--accent); }
.brand b { font-size: 16px; letter-spacing: -.02em; }
.auth-card p.sub { color: var(--muted); margin: 2px 0 20px; font-size: 13px; }
.auth-switch { text-align: center; margin-top: 14px; font-size: 13px; color: var(--muted); }
.auth-switch a { cursor: pointer; font-weight: 600; }
.err { background: #fdecea; color: var(--bad); padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #cdd6e0; padding: 20px 14px; display: flex; flex-direction: column; }
.side .brand b { color: #fff; }
.side .brand .sub { font-size: 11px; color: #8493a6; letter-spacing: .04em; text-transform: uppercase; }
.nav { margin-top: 24px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: #b9c4d1; text-decoration: none; font-size: 13.5px; font-weight: 500;
}
.nav a:hover { background: #20303f; color: #fff; }
.nav a.active { background: #25394d; color: #fff; }
.nav a .ic { width: 16px; text-align: center; opacity: .9; }
.side .me { font-size: 12px; color: #8493a6; border-top: 1px solid #28384a; padding-top: 14px; }
.side .me b { color: #dde4ec; display: block; }
.side .me a { color: var(--accent); cursor: pointer; font-weight: 600; }

.main { padding: 26px 30px; overflow: auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; }
.page-head .desc { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- Cards / grid ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.kpi .val { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.kpi.value .val { color: var(--accent); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel + .panel { margin-top: 18px; }
.panel-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.panel-head h2 { font-size: 14px; }
.panel-body { padding: 16px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
td .name { font-weight: 600; }
td .meta { color: var(--muted); font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Badges / pipeline ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; background: #eef2f7; color: var(--ink-soft); }
.badge.signe { background: #e3f3ea; color: var(--ok); }
.badge.perdu { background: #fbe9e6; color: var(--bad); }
.badge.negociation, .badge.rdv { background: var(--accent-soft); color: var(--accent); }
.badge.a_qualifier, .badge.a_contacter { background: #eef2f7; color: var(--ink-soft); }

.pipeline { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.pipe-col { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; min-height: 60px; }
.pipe-col h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-bottom: 8px; display: flex; justify-content: space-between; }
.pipe-card { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-bottom: 7px; font-size: 12.5px; cursor: pointer; }
.pipe-card:hover { border-color: var(--navy); }
.pipe-card .c { color: var(--accent); font-weight: 600; font-size: 11px; }

/* ---------- Misc ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.toolbar .field { margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.empty b { color: var(--ink-soft); display: block; margin-bottom: 4px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.muted { color: var(--muted); }
.hint { background: #eef4fb; border: 1px solid #d6e4f3; color: #2b4a6b; padding: 10px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 14px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(22,32,46,.45); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.x { background: none; border: none; font-size: 20px; color: var(--muted); line-height: 1; }

/* Chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 130px); }
.chat-stream { flex: 1; overflow-y: auto; padding: 8px 4px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 70%; }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg .bubble { background: var(--surface); border: 1px solid var(--line); padding: 9px 12px; border-radius: 10px; }
.msg.mine { align-self: flex-end; text-align: right; }
.msg.mine .bubble { background: var(--navy); color: #fff; border-color: var(--navy); }
.chat-input { display: flex; gap: 10px; margin-top: 12px; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; align-items: center; gap: 12px; padding: 10px; overflow-x: auto; }
  .nav { flex-direction: row; margin-top: 0; }
  .side .me, .side .brand .sub { display: none; }
  .pipeline { grid-template-columns: 1fr 1fr; }
}

/* Pastilles de notification dans la navigation */
.nav a { position: relative; }
.navbadge {
  margin-left: auto; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 18px; height: 18px;
  border-radius: 9px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center;
}
