:root {
  --primary: #8B0000; --primary-dark: #6d0000; --primary-soft: #f7e9e9;
  --bg: #f4f2f1; --card: #fff; --line: #e4dfdc; --ink: #221c1b; --muted: #6f6663;
  --ok: #1b7a43; --ok-soft: #e3f3e9; --warn: #a45f00; --warn-soft: #fbefd9;
  --bad: #b3261e; --bad-soft: #fbe6e4; --info: #1f5fa8; --info-soft: #e3edf9; --grey-soft: #ece9e7;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--primary) 0%, #3d0000 100%); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 14px; padding: 30px 28px; box-shadow: 0 20px 50px rgba(0,0,0,.3); display: grid; gap: 14px; }
.login-card h1 { font-size: 22px; }
.brand-mark { width: 52px; height: 52px; border-radius: 12px; background: var(--primary); color: #fff; font-weight: 800; display: grid; place-items: center; letter-spacing: .5px; }
.brand-mark.sm { width: 34px; height: 34px; border-radius: 8px; font-size: 11px; background: #fff; color: var(--primary); flex: none; }

/* Structure */
.app { display: flex; min-height: 100%; }
.sidebar { width: 232px; flex: none; background: var(--primary); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; font-weight: 700; font-size: 15px; border-bottom: 1px solid rgba(255,255,255,.15); }
#nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
#nav a { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 8px; color: #fff; text-decoration: none; opacity: .86; margin-bottom: 2px; }
#nav a:hover { background: rgba(255,255,255,.1); opacity: 1; }
#nav a.active { background: #fff; color: var(--primary); opacity: 1; font-weight: 600; }
.nav-count { background: rgba(255,255,255,.22); border-radius: 20px; padding: 0 8px; font-size: 12px; font-weight: 600; }
#nav a.active .nav-count { background: var(--primary-soft); }
.userbox { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.15); }
.user-name { font-weight: 600; } .user-role { font-size: 12px; opacity: .8; margin-bottom: 6px; }
.user-actions { display: flex; gap: 12px; }
.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; font-size: 12px; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 16px 24px 4px; }
.topbar h2 { font-size: 20px; }
.icon-btn { display: none; border: 1px solid var(--line); background: var(--card); border-radius: 8px; width: 38px; height: 38px; font-size: 18px; cursor: pointer; }
main { padding: 14px 24px 40px; }

/* Éléments */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h3 { font-size: 15px; margin-bottom: 10px; }
.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #bdb5b1; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: #e6b9b5; }
.btn.block { width: 100%; padding: 11px; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: #443c3a; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cfc8c4; border-radius: 8px; background: #fff; color: var(--ink); width: 100%; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
input[type=checkbox] { width: 16px; height: 16px; padding: 0; accent-color: var(--primary); }
textarea { min-height: 64px; resize: vertical; }
.form-error { color: var(--bad); font-size: 13px; min-height: 18px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.toolbar > * { flex: 0 1 auto; }
.toolbar .grow { flex: 1 1 200px; }
.toolbar label { min-width: 150px; }
.spacer { flex: 1 1 auto !important; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { border: 1px solid var(--line); background: var(--card); border-radius: 20px; padding: 7px 14px; cursor: pointer; font: inherit; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tab .n { opacity: .8; font-weight: 500; margin-left: 4px; }

/* Tableaux */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #faf8f7; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr[data-lead] { cursor: pointer; }
tbody tr[data-lead]:hover { background: #fbf6f5; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.ck, th.ck { width: 34px; padding-right: 0; }
.empty { padding: 34px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.late { color: var(--bad); font-weight: 600; }

/* Statuts : toujours une pastille + un libellé */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--grey-soft); color: #4a4340; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.s-nouveau { background: var(--info-soft); color: var(--info); }
.badge.s-a_confirmer, .badge.s-chez_commercial { background: var(--primary-soft); color: var(--primary); }
.badge.s-nrp, .badge.s-rappel, .badge.s-absent, .badge.s-injoignable { background: var(--warn-soft); color: var(--warn); }
.badge.s-confirme, .badge.s-vendu { background: var(--ok-soft); color: var(--ok); }
.badge.s-refuse, .badge.s-invalide, .badge.s-non_vendu { background: var(--bad-soft); color: var(--bad); }
.role-tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--grey-soft); }

/* Tuiles de chiffres */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; display: block; }
a.tile:hover { border-color: var(--primary); }
.tile .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.tile .v { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.accent { border-left: 4px solid var(--primary); }

/* Modale */
.modal-backdrop { position: fixed; inset: 0; background: rgba(30,10,10,.5); display: flex; align-items: flex-start; justify-content: center; padding: 30px 14px; overflow-y: auto; z-index: 50; }
.modal { background: var(--card); border-radius: 14px; width: 100%; max-width: 720px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal.narrow { max-width: 460px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 16px 20px 20px; display: grid; gap: 16px; }
.close { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.info { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 16px; }
.info .k { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.info .v { word-break: break-word; }
.tel { font-size: 17px; font-weight: 700; text-decoration: none; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; background: #fdfbfa; }
.panel h4 { margin: 0; font-size: 14px; }
.act-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.act-row label { flex: 1 1 190px; }
.notebox { background: var(--warn-soft); border-radius: 8px; padding: 8px 12px; }
.timeline { display: grid; gap: 8px; max-height: 260px; overflow-y: auto; }
.timeline .ev { border-left: 3px solid var(--line); padding-left: 10px; }
.timeline .ev .when { font-size: 12px; color: var(--muted); }

/* Dispatch */
.dispatch { display: grid; grid-template-columns: 1fr 290px; gap: 16px; align-items: start; }
.agents { position: sticky; top: 12px; }
.agent { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); font-weight: 400; cursor: pointer; grid-template-columns: none; }
.agent:last-of-type { border-bottom: 0; }
.agent .nm { flex: 1; font-weight: 600; }
.agent .ld { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* Import */
.map-table select { min-width: 150px; }
.drop { border: 2px dashed #cfc8c4; border-radius: var(--radius); padding: 28px; text-align: center; background: #fdfbfa; }

/* Graphiques */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--primary); }
.chart .bar:hover, .chart .hit:hover + .bar { fill: var(--primary-dark); }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart-total { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-tip { position: fixed; z-index: 80; pointer-events: none; background: #221c1b; color: #fff; padding: 5px 9px; border-radius: 6px; font-size: 12px; white-space: nowrap; }
.meter { height: 6px; border-radius: 3px; background: var(--grey-soft); min-width: 60px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--primary); border-radius: 3px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; }
.toast { background: #221c1b; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90vw; }
.toast.err { background: var(--bad); }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .icon-btn { display: inline-grid; place-items: center; }
  .topbar { padding: 12px 14px 2px; } main { padding: 12px 14px 40px; }
  .dispatch { grid-template-columns: 1fr; } .agents { position: static; }
  .grid2 { grid-template-columns: 1fr; }
}

/* Paramètres */
td.center, th.center { text-align: center; }
td.center input[type=checkbox] { vertical-align: middle; }
.group-row { background: #faf8f7; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
