:root {
  --ink: #16202e;
  --side-bg: #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;
}

[data-theme="dark"] {
  --ink: #e7edf4;
  --side-bg: #0a0e15;
  --ink-soft: #b3bfcd;
  --muted: #8593a2;
  --line: #2b3440;
  --surface: #171d26;
  --bg: #0e131a;
  --accent: #d8843a;
  --accent-soft: #382818;
  --navy: #a9c2e0;
  --ok: #4fae7a;
  --warn: #d0a24e;
  --bad: #d46a5a;
  --shadow: 0 1px 2px rgba(0,0,0,.45), 0 6px 20px rgba(0,0,0,.35);
}
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
  background: #0e131a; color: var(--ink); border-color: var(--line);
}
/* Contraste mode sombre : cartes de taches + survol de ligne ne doivent pas paraitre blancs */
[data-theme="dark"] .pipe-card { background: #1c2532; border-color: #2f3a48; color: var(--ink); }
[data-theme="dark"] .pipe-card .meta { color: #9fb0c2; }
[data-theme="dark"] tbody tr:hover { background: #1c2532; }

* { 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(--side-bg); color: #cdd6e0; padding: 20px 14px; display: flex; flex-direction: column; height: 100vh; position: sticky; top: 0; align-self: start; z-index: 1000; }
.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; }

/* Groupes de navigation (sous-menus) */
.nav-group { position: relative; }
.grp-head {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: #b9c4d1; font-size: 13.5px; font-weight: 500; cursor: pointer; user-select: none;
}
.grp-head:hover, .grp-head.active { background: #20303f; color: #fff; }
.grp-head .ic { width: 16px; text-align: center; opacity: .9; }
.grp-head .caret { margin-left: auto; opacity: .5; font-size: 16px; transition: transform .15s; }
.grp-head .grp-badge { margin-left: auto; }
.grp-head .grp-badge + .caret { margin-left: 6px; }
.flyout { display: none; }
.flyout a { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 7px; color: #b9c4d1; text-decoration: none; font-size: 13px; cursor: pointer; }
.flyout a:hover { background: #20303f; color: #fff; }
.flyout a.active { background: #25394d; color: #fff; }
.flyout a .ic { width: 16px; text-align: center; opacity: .9; }

@media (min-width: 801px) {
  .flyout {
    position: absolute; left: 100%; top: -6px; min-width: 210px;
    background: #1b2a38; border: 1px solid #2c3e51; border-radius: 12px; padding: 6px;
    box-shadow: 0 18px 44px rgba(0,0,0,.45); z-index: 120;
  }
  .nav-group:hover > .flyout { display: block; }
}

.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; }

/* Interrupteur glissant */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; cursor: pointer; inset: 0; background: var(--line); border-radius: 26px; transition: .2s; }
.switch .slider:before { content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(20px); }

.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: var(--bg); }
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: var(--surface); 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: 2000; }
.modal { background: var(--surface); 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; }

/* --- Barre mobile + menu coulissant (caches sur grand ecran) --- */
.topbar { display: none; }
.iconbtn { background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink); padding: 4px 8px; }
.backdrop { display: none; }

.subtabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.subtab { padding: 7px 14px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink); }
.subtab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.dropmenu { position: fixed; z-index: 3000; min-width: 180px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.18); padding: 6px; display: flex; flex-direction: column; }
.dropmenu button, .dropmenu a { display: block; width: 100%; text-align: left; background: none; border: none; padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--ink); text-decoration: none; }
.dropmenu button:hover, .dropmenu a:hover { background: var(--bg); }
.dropmenu button.danger { color: var(--bad); }

@media (max-width: 800px) {
  .shell { display: block; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 9px 12px; background: var(--side-bg); color: #fff; position: sticky; top: 0; z-index: 50;
  }
  .topbar-brand { display: flex; align-items: center; gap: 8px; font-size: 15px; }
  .topbar-brand b { color: #fff; }
  .topbar .iconbtn, .topbar .bell { color: #fff; }
  .side {
    position: fixed; top: 0; left: 0; bottom: 0; width: 270px; height: 100vh; max-width: 82vw;
    transform: translateX(-100%); transition: transform .25s ease; z-index: 60;
    flex-direction: column; align-items: stretch; gap: 0; overflow-y: auto;
    padding: 20px 14px;
  }
  .shell.menu-open .side { transform: translateX(0); }
  .nav { flex-direction: column; margin-top: 24px; }
  .flyout { padding-left: 22px; }
  .nav-group.open > .flyout { display: block; }
  .nav-group.open > .grp-head .caret { transform: rotate(90deg); }
  .side .me, .side .brand .sub { display: block; }
  .shell.menu-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 55; }
  .main { padding: 16px 14px; }
  .pipeline { grid-template-columns: 1fr; }
  .row-2 { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr !important; }
  .stats-grid { grid-template-columns: 1fr !important; }
  /* Tableaux : defilement horizontal au lieu de deborder */
  table { display: block; overflow-x: auto; white-space: nowrap; max-width: 100%; }
  /* En-tetes de page : actions qui passent a la ligne */
  .page-head > div:last-child { display: flex; flex-wrap: wrap; gap: 8px; }
}

/* 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;
}

/* Cloche de notifications */
.bell { background: none; border: none; cursor: pointer; font-size: 16px; position: relative; padding: 4px; line-height: 1; }
.side .bell { color: #cbd5e1; }
.side .bell:hover { color: #fff; }
.bell .navbadge { position: absolute; top: -4px; right: -4px; }
.bellpanel { position: fixed; z-index: 3000; width: 300px; max-height: 70vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.18); }
.bellhead { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.bellrow { padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13.5px; color: var(--ink); }
.bellrow:hover { background: var(--bg); }
.bellrow.unr { background: var(--accent-soft); }

/* --- Banniere licence (edition WELCOME : grace / lecture seule) --- */
.licence-banner{padding:9px 16px;font-size:13px;font-weight:600;text-align:center;line-height:1.35}
.licence-banner.warn{background:#fff6e5;color:#8a5a00;border-bottom:1px solid #f1d9a8}
.licence-banner.danger{background:#fdecec;color:#a11;border-bottom:1px solid #f3b6b6}
@media (prefers-color-scheme: dark){
  .licence-banner.warn{background:#3a2e12;color:#ffd27a;border-bottom-color:#5a4715}
  .licence-banner.danger{background:#3a1717;color:#ff9c9c;border-bottom-color:#5a1f1f}
}
