:root {
  --blue: #0aa2c0;
  --blue-d: #0b7f97;
  --blue-dd: #075366;
  --navy: #0e2a36;
  --ink: #12333f;
  --bg: #f4f8fa;
  --card: #ffffff;
  --line: #e2ebef;
  --muted: #6c8592;
  --green: #17a673;
  --red: #e0533d;
  --amber: #e39a1c;
  --shadow: 0 1px 3px rgba(14,42,54,.08), 0 6px 20px rgba(14,42,54,.06);
  --radius: 14px;
  font-synthesis: none;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; cursor: pointer; border: none; }
input, select, textarea { font: inherit; }

/* ---------- LOGIN ---------- */
.login-screen {
  min-height: 100dvh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(120% 120% at 50% 0%, #0aa2c0 0%, #075366 60%, #06323f 100%);
}
.login-card {
  background: var(--card); border-radius: 20px; padding: 32px 26px; width: 100%; max-width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-logo { height: 62px; width: auto; margin: 0 auto 4px; display: block; }
.login-card h1 { color: var(--navy); font-size: 26px; }
.login-card label { text-align: left; display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
.login-card input {
  padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px; font-size: 15px; color: var(--ink);
}
.login-card input:focus { outline: none; border-color: var(--blue); }
.login-card button[type=submit] {
  margin-top: 8px; background: var(--blue); color: #fff; padding: 13px; border-radius: 10px; font-weight: 700; font-size: 15px;
}
.login-card button:hover { background: var(--blue-d); }
.error { color: var(--red); font-size: 13px; min-height: 18px; }

/* ---------- LAYOUT ---------- */
.app { display: flex; min-height: 100dvh; }
.sidebar {
  width: 236px; background: var(--navy); color: #cfe6ed; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; font-weight: 800; font-size: 19px; color: #fff; letter-spacing: .3px; }
.brand-logo { height: 34px; width: auto; background: #fff; padding: 6px 10px; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
#nav { flex: 1; overflow-y: auto; padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px; border-radius: 10px;
  color: #b6d4de; background: transparent; text-align: left; width: 100%; font-size: 14.5px; font-weight: 600;
}
.nav-item .ic { width: 20px; text-align: center; font-size: 16px; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--blue); color: #fff; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: #6b96a5; padding: 12px 14px 4px; }
.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.user-badge { font-size: 13px; margin-bottom: 8px; }
.user-badge b { color: #fff; display: block; }
.btn-ghost { background: rgba(255,255,255,.08); color: #cfe6ed; padding: 9px; border-radius: 8px; width: 100%; font-weight: 600; }
.btn-ghost:hover { background: rgba(255,255,255,.16); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.9); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); padding: 14px 22px; display: flex; align-items: center; gap: 14px;
}
.topbar h2 { font-size: 19px; color: var(--navy); flex: 1; }
.topbar-date { color: var(--muted); font-size: 13px; }
.net-badge { font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 20px; white-space: nowrap; }
.net-badge.off { background: #fdeae6; color: var(--red); }
.net-badge.pending { background: #fdf2dd; color: var(--amber); }
.icon-btn { background: none; font-size: 20px; color: var(--ink); padding: 4px; display: none; }
.view { padding: 22px; max-width: 1200px; width: 100%; }

/* ---------- CARDS / KPI ---------- */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.kpi {
  background: var(--card); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); border: 1px solid var(--line);
}
.kpi .label { font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.kpi .value { font-size: 25px; font-weight: 800; color: var(--navy); margin-top: 6px; line-height: 1.1; }
.kpi .value small { font-size: 14px; font-weight: 600; color: var(--muted); }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.kpi.accent { background: linear-gradient(135deg, var(--blue) 0%, var(--blue-d) 100%); border: none; }
.kpi.accent .label, .kpi.accent .value, .kpi.accent .sub { color: #fff; }
.kpi.accent .value small { color: rgba(255,255,255,.8); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card-head h3 { font-size: 15px; color: var(--navy); flex: 1; }
.card-body { padding: 16px 18px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; margin: 22px 0 10px; }

/* ---------- BADGES / ALERTS ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge.green { background: #e2f6ee; color: var(--green); }
.badge.red { background: #fdeae6; color: var(--red); }
.badge.amber { background: #fdf2dd; color: var(--amber); }
.badge.blue { background: #e2f4f8; color: var(--blue-d); }
.badge.gray { background: #eef3f5; color: var(--muted); }
/* Bloc (pas flex) : en flex, chaque <b> devenait une colonne et le texte s'éclatait sur mobile. */
.alert-row { display: block; padding: 11px 14px; border-radius: 10px; margin-bottom: 8px; font-size: 14px; line-height: 1.55; }
.alert-row.red { background: #fdeae6; color: #a3311f; }
.alert-row.amber { background: #fdf2dd; color: #8a5e0f; }
.alert-row.blue { background: #e4f4f9; color: #0b5f74; }

/* ---------- TABLES ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 480px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 700; background: #fafcfd; }
tbody tr:hover { background: #f7fbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--green); font-weight: 700; }
.neg { color: var(--red); font-weight: 700; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- BUTTONS / FORMS ---------- */
.btn { background: var(--blue); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; gap: 7px; }
.btn:hover { background: var(--blue-d); }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.btn.gray { background: #eef3f5; color: var(--ink); }
.btn.gray:hover { background: #e2ebef; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 9px; font-size: 15px; color: var(--ink); background: #fff; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--blue); }
.field.full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }
.calc-hint { font-size: 13px; color: var(--muted); background: #f0f7f9; padding: 8px 12px; border-radius: 8px; }
.calc-hint b { color: var(--navy); }

/* ---------- MODAL ---------- */
.modal { position: fixed; inset: 0; background: rgba(14,42,54,.5); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal-box { background: #fff; border-radius: 16px; width: 100%; max-width: 560px; max-height: 90dvh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.modal-head h3 { flex: 1; color: var(--navy); font-size: 17px; }
.modal-head .icon-btn { display: block; }
#modal-body { padding: 20px; }

/* ---------- TOAST ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 20px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 200; box-shadow: var(--shadow); }
.toast.ok { background: var(--green); } .toast.err { background: var(--red); }

.page-actions { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.page-actions .spacer { flex: 1; }
.filter-input { padding: 9px 12px; border: 1.5px solid var(--line); border-radius: 9px; font-size: 14px; }
.overlay { position: fixed; inset: 0; background: rgba(14,42,54,.4); z-index: 25; }

/* ---------- RAPPORT / IMPRESSION ---------- */
.report-head { display: flex; align-items: center; gap: 14px; border-bottom: 2px solid var(--blue); padding-bottom: 12px; }
@media print {
  .sidebar, .topbar, .no-print, #overlay { display: none !important; }
  body { background: #fff; }
  .app, .main, .view { display: block; padding: 0; margin: 0; max-width: 100%; }
  .print-area { box-shadow: none; border: none; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .kpi { border: 1px solid #ccc; box-shadow: none; }
  @page { margin: 1.4cm; }
}

/* ---------- CARTES CHAUFFEURS ---------- */
.driver-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 12px; }
.driver-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 12px; text-align: center; cursor: pointer; transition: transform .15s ease, box-shadow .15s ease; animation: fadeUp .4s ease both; }
.driver-card:hover { transform: translateY(-3px); box-shadow: 0 8px 26px rgba(14,42,54,.14); }
.dc-name { font-weight: 700; color: var(--navy); margin-top: 8px; }
.dc-stat { font-size: 13px; color: var(--muted); margin-top: 2px; }
.dc-stat span { font-weight: 800; color: var(--ink); font-size: 15px; }
.dc-reliquat { font-size: 13px; font-weight: 700; margin-top: 6px; }
.dc-sub { font-size: 11.5px; margin-top: 4px; }

/* ---------- MODE LECTURE SEULE (PDG) ---------- */
.readonly .page-actions .btn:not(.gray),
.readonly [data-del], .readonly [data-edit], .readonly [data-maint], .readonly [data-photo], .readonly [data-reg],
.readonly #add, .readonly [id^="add"] { display: none !important; }

/* ---------- BANDEAU DE MOTIVATION ---------- */
.motiv {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dd) 100%);
  border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px; color: #fff;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  box-shadow: 0 8px 30px rgba(10,162,192,.25); animation: fadeUp .4s ease both;
}
.motiv-txt { flex: 1; min-width: 240px; }
.motiv-txt h2 { font-size: 21px; margin-bottom: 4px; }
.motiv-txt p { font-size: 14px; opacity: .92; line-height: 1.5; }
.motiv-txt p b { color: #fff; }
.motiv-chips { display: flex; gap: 10px; flex-wrap: wrap; }
.motiv-chip {
  background: rgba(255,255,255,.16); border-radius: 12px; padding: 10px 14px;
  display: flex; align-items: center; gap: 9px; backdrop-filter: blur(4px);
}
.motiv-chip span { font-size: 20px; }
.motiv-chip small { display: block; font-size: 11px; opacity: .85; }
.motiv-chip b { font-size: 15px; }

/* ---------- CALENDRIER CHAUFFEUR ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-grid.head { margin-bottom: 6px; }
.cal-dow { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.cal-cell {
  min-height: 62px; border: 1px solid var(--line); border-radius: 9px; padding: 5px 6px;
  background: #fafcfd; transition: transform .12s, box-shadow .12s;
}
.cal-cell.vide { border: none; background: transparent; }
.cal-cell.actif { background: #e2f4f8; border-color: var(--blue); }
.cal-cell.actif:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.cal-cell.today { outline: 2px solid var(--amber); }
.cal-num { font-size: 11px; color: var(--muted); font-weight: 700; }
.cal-packs { font-size: 15px; font-weight: 800; color: var(--navy); line-height: 1.2; }
.cal-rev { font-size: 10.5px; color: var(--green); font-weight: 700; }
.cal-cmd { font-size: 10px; color: var(--blue-d); }

/* ---------- COMMANDES (carte OSM) ---------- */
.cmd-card { animation: fadeUp .4s ease both; }
.cmd-map { width: 100%; height: 160px; border: 1px solid var(--line); border-radius: 10px; margin-top: 10px; display: block; }

/* ---------- BLOCS STOCK / MAINTENANCE (équipements) ---------- */
.equip-bloc { margin-top: 10px; padding: 9px 11px; background: #f7fbfc; border: 1px solid var(--line); border-radius: 10px; }
.equip-bloc-t { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 5px; }
.equip-lignes { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 13px; align-items: center; }
.equip-lignes span { color: var(--muted); }
.equip-lignes b { text-align: right; }

/* ---------- CARTES ÉQUIPEMENT ---------- */
.equip-card { overflow: hidden; padding: 0; animation: fadeUp .4s ease both; }
.equip-photo { height: 150px; background: linear-gradient(135deg, #e2f4f8, #eef3f5); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.equip-photo img { width: 100%; height: 100%; object-fit: cover; }
.equip-ph { font-size: 46px; opacity: .45; }

/* ---------- AVATARS ---------- */
.avatar { border-radius: 50%; object-fit: cover; display: inline-block; vertical-align: middle; flex-shrink: 0; }
.avatar-initial { background: linear-gradient(135deg, var(--blue), var(--blue-d)); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
#open-profile { border: none; border-radius: 10px; padding: 8px; margin-bottom: 8px; transition: background .15s; }
#open-profile:hover { background: rgba(255,255,255,.08); }
.welcome { font-size: 22px; font-weight: 800; color: var(--navy); margin-bottom: 16px; }

/* ---------- GUIDE ---------- */
.guide h1 { font-size: 23px; color: var(--navy); margin-bottom: 12px; }
.guide h2 { font-size: 18px; color: var(--blue-d); margin: 24px 0 10px; border-bottom: 2px solid var(--line); padding-bottom: 6px; }
.guide h3 { font-size: 16px; color: var(--navy); margin: 18px 0 6px; }
.guide h4 { font-size: 14.5px; color: var(--navy); margin: 14px 0 4px; }
.guide p, .guide li { line-height: 1.65; margin-bottom: 6px; }
.guide ul, .guide ol { margin: 6px 0 14px 22px; }
.guide strong { color: var(--navy); }

/* ---------- ANIMATIONS ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: scale(.94) translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
.view > * { animation: fadeUp .32s ease both; }
.kpi { animation: fadeUp .4s ease both; }
.modal-box { animation: popIn .24s cubic-bezier(.2,.8,.3,1.1) both; }
.modal { animation: fadeUp .18s ease both; }
.toast { animation: popIn .22s ease both; }
.btn, .nav-item, .icon-btn { transition: background .15s, color .15s, transform .08s, box-shadow .15s; }
.btn:active, .nav-item:active { transform: translateY(1px) scale(.99); }
.kpi, .card { transition: box-shadow .2s ease, transform .2s ease; }
.kpi:hover { transform: translateY(-3px); box-shadow: 0 8px 26px rgba(14,42,54,.12); }
.alert-row { animation: fadeUp .3s ease both; }
.loader { display: inline-block; width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .7s linear infinite; }
@media (prefers-reduced-motion: reduce) { *, .view > *, .kpi, .modal-box { animation: none !important; transition: none !important; } }

/* ---------- INFOBULLE AU SURVOL ---------- */
.tip {
  position: fixed; z-index: 90; pointer-events: none;
  background: var(--navy); color: #fff; padding: 8px 11px; border-radius: 9px;
  font-size: 12.5px; line-height: 1.45; white-space: nowrap;
  box-shadow: 0 8px 24px rgba(14,42,54,.28);
  opacity: 0; transform: translateY(3px); transition: opacity .12s ease, transform .12s ease;
}
.tip.on { opacity: 1; transform: translateY(0); }
.tip b { color: #9fe6f5; }
svg .bar, svg .pt { cursor: pointer; }
svg .bar:hover .bar-r { filter: brightness(1.12); }
svg .pt:hover circle { r: 5.5; }

/* ---------- CALENDRIER DU SOLDE ---------- */
.cal-head { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 12px; font-size: 15px; }
.cal-head .btn.sm { padding: 4px 12px; font-size: 14px; }
.cal-jours { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.cal-jours div { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-c {
  min-height: 64px; border: 1px solid var(--line); border-radius: 10px; padding: 5px 6px;
  display: flex; flex-direction: column; gap: 1px; background: #fff;
  transition: transform .12s ease, box-shadow .12s ease;
}
.cal-c.vide { border: 0; background: transparent; }
.cal-c.hors { background: #fbfdfe; opacity: .5; }
.cal-c.up { background: #f2fbf7; border-color: #cceede; }
.cal-c.down { background: #fdf4f2; border-color: #f6d9d2; }
.cal-c.auj { outline: 2px solid var(--blue); outline-offset: -1px; }
.cal-c[data-tip]:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(14,42,54,.12); cursor: pointer; }
.cal-j { font-size: 11px; font-weight: 700; color: var(--muted); }
.cal-s { font-size: 12.5px; font-weight: 800; color: var(--navy); }
.cal-v { font-size: 10.5px; font-weight: 700; }

.amber-t { color: var(--amber); font-weight: 700; }

/* ---------- MESSAGERIE INTERNE ---------- */
.msg-layout { display: grid; grid-template-columns: 260px 1fr; gap: 14px; align-items: start; }
.msg-contacts { display: flex; flex-direction: column; gap: 6px; }
.msg-contact { display: flex; align-items: center; gap: 10px; text-align: left; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  cursor: pointer; font-family: inherit; transition: background .12s ease; }
.msg-contact:hover { background: #f6fbfc; }
.msg-contact.on { border-color: var(--blue); box-shadow: 0 0 0 1.5px var(--blue) inset; }
.msg-ava { width: 38px; height: 38px; font-size: 13px; flex: none; overflow: hidden; }
.msg-ava img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.msg-c-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.msg-c-txt b { font-size: 14.5px; color: var(--ink); }
.msg-c-txt small { font-size: 11.5px; color: var(--muted); }
.msg-c-txt i { font-size: 12px; color: var(--muted); font-style: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-pastille { flex: none; }

.msg-thread-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.msg-entete { padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 15px; }
.msg-thread { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; height: 46vh; min-height: 260px; overflow-y: auto; background: #f7fafc; }
.msg-ligne { display: flex; align-items: center; gap: 6px; }
.msg-ligne.moi { justify-content: flex-end; }
.msg-bulle { max-width: 78%; padding: 9px 13px; border-radius: 14px; font-size: 14.5px; line-height: 1.5; position: relative; }
.msg-ligne.lui .msg-bulle { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg-ligne.moi .msg-bulle { background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.msg-h { display: block; font-size: 10.5px; margin-top: 4px; opacity: .75; }
.msg-ligne.lui .msg-h { color: var(--muted); }
.msg-suppr { order: -1; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; opacity: 0; transition: opacity .12s; }
.msg-ligne:hover .msg-suppr { opacity: 1; }
.msg-saisie { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); align-items: flex-end; }
.msg-saisie textarea { flex: 1; border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 12px;
  font-family: inherit; font-size: 14.5px; resize: none; color: var(--ink); }
.msg-saisie textarea:focus { outline: none; border-color: var(--blue); }
@media (max-width: 860px) {
  .msg-layout { grid-template-columns: 1fr; }
  .msg-contacts { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .msg-contact { min-width: 190px; }
  .msg-thread { height: 52vh; }
}

/* ---------- OPPORTUNITÉS ---------- */
.opp-list { display: flex; flex-direction: column; gap: 10px; }
.opp-card { display: flex; gap: 14px; align-items: flex-start; background: var(--card); border: 1px solid var(--line);
  border-left: 5px solid var(--muted); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); transition: transform .12s ease, box-shadow .12s ease; }
.opp-card[data-fiche] { cursor: pointer; }
.opp-card[data-fiche]:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(14,42,54,.12); }
.opp-card.ton-pos { border-left-color: var(--green); }
.opp-card.ton-neg { border-left-color: var(--red); }
.opp-card.ton-neu { border-left-color: var(--blue); }
.opp-card.p3 { border-left-color: var(--red); }
.opp-card.p2 { border-left-color: var(--amber); }
.opp-card.p1 { border-left-color: var(--muted); }
.opp-ic { font-size: 26px; line-height: 1; }
.opp-body { flex: 1; }
.opp-t { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 15px; }
.opp-a { margin-top: 6px; font-size: 13.5px; font-weight: 700; color: var(--blue-d); }

/* ---------- AGENDA DU JOUR ---------- */
.agenda-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.agenda-bloc { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.agenda-h { display: flex; justify-content: space-between; align-items: center; font-weight: 800; font-size: 15px; margin-bottom: 8px; }
.agenda-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 4px; border-bottom: 1px solid #f0f5f7; font-size: 14px; }
.agenda-item:last-child { border-bottom: 0; }
.agenda-item[data-fiche] { cursor: pointer; }
.agenda-item[data-fiche]:hover { background: #f6fbfc; border-radius: 8px; }
.agenda-item.ok { opacity: .6; }
.agenda-item.ok b { text-decoration: line-through; }
@media (max-width: 720px) { .agenda-grid { grid-template-columns: 1fr; } }

/* ---------- CARTE COMMERCIALE ---------- */
.lmap { height: 460px; width: 100%; border-radius: 14px; border: 1px solid var(--line); background: #e8eef1; z-index: 1; }
.carte-legende { display: flex; flex-wrap: wrap; gap: 14px; margin: 12px 0 10px; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.cov-bar { display: inline-block; width: 90px; height: 8px; background: #eef3f5; border-radius: 6px; overflow: hidden; vertical-align: middle; margin-right: 6px; }
.cov-fill { height: 100%; background: linear-gradient(90deg, var(--green), var(--blue)); border-radius: 6px; }
.leaflet-popup-content { font-family: inherit; font-size: 13px; line-height: 1.5; }
@media (max-width: 860px) { .lmap { height: 340px; } }

/* ---------- PIPELINE PROSPECTION ---------- */
.pipeline { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; margin-bottom: 8px; }
.pipe-step { border: 1.5px solid var(--line); border-top: 4px solid var(--pc, var(--blue)); background: #fff; border-radius: 12px;
  padding: 12px 8px; text-align: center; cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; font-family: inherit; }
.pipe-step:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.pipe-step.on { background: #f2fafc; box-shadow: 0 0 0 2px var(--pc, var(--blue)) inset; }
.pipe-n { font-size: 24px; font-weight: 800; color: var(--navy); line-height: 1; }
.pipe-l { font-size: 11.5px; color: var(--muted); margin-top: 5px; font-weight: 600; }
@media (max-width: 860px) { .pipeline { grid-template-columns: repeat(3, 1fr); } .pipe-n { font-size: 20px; } }

/* ---------- MOBILE ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .22s ease; box-shadow: 6px 0 30px rgba(0,0,0,.3); }
  .sidebar.open { transform: translateX(0); }
  .icon-btn { display: block; }
  .topbar-date { display: none; }
  .view { padding: 16px; }
  .kpi .value { font-size: 22px; }
  .cal-grid { gap: 3px; }
  .cal-c { min-height: 52px; padding: 3px 4px; border-radius: 7px; }
  .cal-s { font-size: 10.5px; }
  .cal-v { font-size: 9px; }
  .tip { white-space: normal; max-width: 62vw; }
}

/* ---------- TÉLÉPHONE (usage terrain) ---------- */
@media (max-width: 640px) {
  .view { padding: 12px; }
  .kpis { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 20px; }
  .alert-row { font-size: 13.5px; padding: 12px 14px; }
  /* Boutons pleine largeur : plus faciles à toucher, plus de bouton coupé */
  .page-actions { gap: 8px; }
  .page-actions > .btn { flex: 1 1 100%; justify-content: center; }
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .field input, .field select, .field textarea { font-size: 16px; }   /* 16px = pas de zoom auto iOS */
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; justify-content: center; }
  #modal-body { padding: 16px; }
  .modal { padding: 8px; align-items: end; }
  .modal-box { max-height: 94dvh; }
  table { font-size: 13.5px; }
  th, td { padding: 9px 10px; }
  .section-title { font-size: 15px; }

  /* Tableaux marqués .tbl-m : une ligne = une carte lisible, sans scroll horizontal */
  .tbl-m { min-width: 0; }
  .tbl-m thead { display: none; }
  .tbl-m, .tbl-m tbody, .tbl-m tr, .tbl-m td { display: block; width: 100%; }
  .tbl-m tr { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; background: #fff; }
  .tbl-m tr:hover { background: #fff; }
  .tbl-m td { border: 0; padding: 4px 0; white-space: normal; text-align: left; display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
  .tbl-m td.num { text-align: right; }
  .tbl-m td[data-l]::before { content: attr(data-l); color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; flex: 0 0 auto; }
  .tbl-m td[data-l=""]::before { content: none; }
  .tbl-m td[data-l=""] { justify-content: flex-end; gap: 8px; padding-top: 8px; margin-top: 4px; border-top: 1px solid var(--line); }
  .tbl-m td[data-l=""] .btn { flex: 1; justify-content: center; }
  .tbl-m tfoot { display: block; }
  .tbl-m tfoot tr { background: #f7fbfc; font-weight: 800; }
  .tbl-m tfoot td { display: flex; }
}

/* ---------- Classement chauffeurs (gamification) ---------- */
.podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
@media (max-width: 560px) { .podium { grid-template-columns: 1fr; } }
.pod {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 14px; text-align: center; box-shadow: var(--shadow); position: relative;
}
.pod.gold { border-color: #e6c15a; box-shadow: 0 6px 22px rgba(201,138,26,.18); }
.pod.moi { outline: 2px solid var(--blue); outline-offset: -2px; }
.pod-med { font-size: 30px; line-height: 1; }
.pod-nom { font-weight: 800; color: var(--navy); margin-top: 6px; font-size: 15px; }
.pod-niv { font-size: 12px; font-weight: 700; margin-top: 2px; }
.pod-pts { font-size: 22px; font-weight: 800; color: var(--navy); margin-top: 8px; }
.pod-pts small { font-size: 12px; font-weight: 600; color: var(--muted); }
.pod-prime { font-size: 12.5px; font-weight: 700; color: var(--green); margin-top: 4px; min-height: 16px; }
.niv-bar { width: 130px; max-width: 100%; height: 6px; background: #eef3f5; border-radius: 6px; overflow: hidden; margin-top: 5px; }
.niv-fill { height: 100%; border-radius: 6px; }
tr.ligne-moi { background: #eef7fb; }
.pts-detail { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 12.5px; font-weight: 700; color: var(--navy); }
.pts-detail span { white-space: nowrap; }

/* ---------- Carte de fidélité (fiche client) ---------- */
.fid-card {
  background: linear-gradient(135deg, #f3fbf7, #eef6fb);
  border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
}
.fid-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fid-rule { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.fid-msg { font-size: 14.5px; color: var(--navy); }
.fid-msg b { color: var(--green); }
.fid-foot { font-size: 12px; margin-top: 4px; }

/* ---------- Badges (gamification) ---------- */
.badge-row { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 5px; }
.badge-jeton {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; font-size: 14px;
  background: var(--gold-soft, #f5e9d2); border: 1px solid #e6d3a8; cursor: help;
}
.pod .badge-row { justify-content: center; margin-top: 8px; }

/* ---------- Ventes accessoires (activité annexe) ---------- */
.acc-vig { width: 46px; height: 46px; border-radius: 9px; object-fit: cover; cursor: zoom-in; display: block; border: 1px solid var(--line); }
.acc-vig-vide { width: 46px; height: 46px; border-radius: 9px; background: #eef4f8; display: flex; align-items: center; justify-content: center; font-size: 24px; cursor: pointer; border: 1px solid var(--line); }

/* ---------- Boutique accessoires (shop) ---------- */
.acc-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 16px; border-bottom: 1px solid var(--line); }
.acc-tab { border: none; background: none; padding: 9px 14px; font-size: 14px; font-weight: 700; color: var(--muted); cursor: pointer; border-bottom: 2.5px solid transparent; font-family: inherit; }
.acc-tab.on { color: var(--navy); border-bottom-color: var(--blue); }
.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.acc-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.acc-card.epuise { opacity: .6; }
.acc-card-img { width: 100%; height: 130px; object-fit: cover; display: block; cursor: zoom-in; background: #eef4f8; }
.acc-card-vide { display: flex; align-items: center; justify-content: center; font-size: 40px; cursor: pointer; }
.acc-card-b { padding: 10px 11px 12px; display: flex; flex-direction: column; gap: 3px; }
.acc-card-nom { font-weight: 750; font-size: 14px; color: var(--navy); line-height: 1.25; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; min-height: 35px; }
.acc-card-meta { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--navy); }
.acc-card-stock { font-size: 12.5px; }
.acc-card-stock.pos { color: var(--green); } .acc-card-stock.neg { color: var(--red); } .acc-card-stock.amber-t { color: var(--amber); }

/* ---------- Stats boutique ---------- */
.grid.two { display: grid; gap: 16px; }
@media (min-width: 720px) { .grid.two { grid-template-columns: 1fr 1fr; } }
.stat-row { display: grid; grid-template-columns: 130px 1fr auto; align-items: center; gap: 10px; padding: 5px 0; }
.stat-lbl { font-size: 13px; font-weight: 650; color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-bar { height: 10px; background: #eef3f5; border-radius: 6px; overflow: hidden; }
.stat-fill { height: 100%; border-radius: 6px; min-width: 2px; }
.stat-val { font-size: 13px; font-weight: 750; color: var(--navy); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Assistant interne (bot) ---------- */
.bot-wrap { display: flex; flex-direction: column; height: calc(100vh - 150px); max-height: 720px; }
.bot-log { flex: 1; overflow-y: auto; padding: 6px 2px; display: flex; flex-direction: column; gap: 10px; }
.bot-ligne { display: flex; }
.bot-ligne.moi { justify-content: flex-end; }
.bot-bulle { background: var(--card); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 11px 14px; max-width: 82%; font-size: 14.5px; line-height: 1.55; box-shadow: var(--shadow); white-space: normal; }
.bot-bulle.moi { background: var(--navy); color: #eaf4f9; border-radius: 14px 14px 4px 14px; border-color: var(--navy); }
.bot-props { margin-top: 10px; display: grid; gap: 5px; }
.bot-prop { background: #f2f8fb; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 13px; font-weight: 650; }
.bot-saisie { display: flex; gap: 8px; margin-top: 10px; }
.bot-saisie textarea { flex: 1; border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 13px; font-size: 15px; font-family: inherit; resize: none; }
