:root {
  --red: #d71f27; --red-dark: #a8151c; --orange: #f39200; --ink: #1d1d1f; --ink-2: #4a4a50; --muted: #7a7a82;
  --line: #e4e4e8; --bg: #f4f4f6; --card: #ffffff; --green: #1a8f4c; --green-bg: #e3f5ea; --blue: #1f6fd1; --blue-bg: #e5effb;
  --amber-bg: #fff3dc; --red-bg: #fde8e8; --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; min-height: 100dvh; font-size: 15px; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.boot { display: grid; place-items: center; height: 100vh; } .boot img { width: 240px; opacity: .9; }

/* ---------- boutons & champs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: #fff;
  border-radius: 10px; padding: 10px 16px; font-weight: 600; cursor: pointer; min-height: 42px; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { background: #fafafa; } .btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; } .btn.primary:hover { background: var(--red-dark); }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--red); }
.btn.big { min-height: 58px; font-size: 18px; border-radius: 14px; width: 100%; }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 14px; }
label.field { display: block; margin-bottom: 12px; } label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
input, select, textarea { width: 100%; border: 1px solid #d4d4da; border-radius: 10px; padding: 10px 12px; background: #fff; min-height: 44px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(215,31,39,.25); border-color: var(--red); }
.row { display: flex; gap: 12px; } .row > * { flex: 1; min-width: 0; }
.grow { flex: 1; } .muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }
.hide { display: none !important; }

/* ---------- connexion */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: linear-gradient(160deg, #fff 0%, #fff 55%, #fdeceb 100%); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 28px 24px; border: 1px solid var(--line); }
.login-card img { width: 100%; max-width: 300px; display: block; margin: 0 auto 18px; }
.login-card h1 { font-size: 20px; margin: 0 0 18px; text-align: center; }
.error { background: var(--red-bg); color: var(--red-dark); padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }

/* ---------- entête */
.topbar { position: sticky; top: 0; z-index: 1000; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center;
  gap: 16px; padding: 8px 20px; padding-top: max(8px, env(safe-area-inset-top)); }
.topbar .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.topbar .brand img { height: 38px; } .topbar .brand b { font-size: 15px; border-left: 1px solid var(--line); padding-left: 10px; color: var(--red); }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; } .nav::-webkit-scrollbar { display: none; }
.nav a { padding: 9px 14px; border-radius: 9px; text-decoration: none; color: var(--ink-2); font-weight: 600; white-space: nowrap; }
.nav a.on { background: var(--red-bg); color: var(--red); } .nav a:hover:not(.on) { background: var(--bg); }
.userchip { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
main.page { padding: 20px; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; flex: 1; }

/* ---------- cartes / tableaux */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; } .card h3 { margin: 0 0 12px; font-size: 16px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; } .kpi .v { font-size: 28px; font-weight: 800; letter-spacing: -.5px; } .kpi .l { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi.accent { border-left: 4px solid var(--red); }
.dash { display: grid; grid-template-columns: 1fr 380px; gap: 16px; }
.map { height: 560px; border-radius: var(--radius); overflow: hidden; z-index: 1; }
.map.small { height: 240px; } .map.medium { height: 360px; }
.list { display: flex; flex-direction: column; } .list > * + * { border-top: 1px solid var(--line); }
.driver-row { display: flex; gap: 10px; padding: 12px 14px; align-items: center; cursor: pointer; } .driver-row:hover { background: #fafafa; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #c4c4ca; flex: none; } .dot.on { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.dot.stale { background: var(--orange); }
table.tbl { width: 100%; border-collapse: collapse; } .tbl th, .tbl td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #fafafb; position: sticky; top: 0; }
.tbl tbody tr { cursor: pointer; } .tbl tbody tr:hover { background: #fbfbfc; }
.tbl-wrap { overflow-x: auto; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.s-a_faire { background: #eef0f3; color: #4a5160; } .s-en_route { background: var(--blue-bg); color: var(--blue); }
.s-arrivee { background: var(--amber-bg); color: #9a5b00; } .s-livree { background: var(--green-bg); color: var(--green); }
.s-echec { background: var(--red-bg); color: var(--red-dark); } .s-annulee { background: #f0f0f0; color: #888; text-decoration: line-through; }
.urgent { background: var(--red); color: #fff; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; } .chip { border: 1px solid var(--line); background: #fff; padding: 7px 12px; border-radius: 99px; cursor: pointer; font-weight: 600; font-size: 13px; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 160px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- fenêtre modale / panneau */
.overlay { position: fixed; inset: 0; background: rgba(20,20,25,.45); z-index: 2000; display: flex; justify-content: flex-end; animation: fade .15s; }
.overlay.centered { justify-content: center; align-items: center; padding: 16px; }
.panel { background: #fff; width: 100%; max-width: 560px; height: 100%; overflow-y: auto; box-shadow: -10px 0 30px rgba(0,0,0,.15); animation: slide .2s; }
.overlay.centered .panel { height: auto; max-height: 92dvh; border-radius: 16px; max-width: 520px; animation: pop .15s; }
.panel-head { position: sticky; top: 0; background: #fff; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-size: 18px; flex: 1; } .panel-body { padding: 18px; } .panel-foot { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding: 12px 18px; display: flex; gap: 10px; justify-content: flex-end; }
@keyframes fade { from { opacity: 0; } } @keyframes slide { from { transform: translateX(40px); opacity: 0; } } @keyframes pop { from { transform: scale(.97); opacity: 0; } }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 14px; margin-bottom: 16px; } .kv dt { color: var(--muted); font-weight: 600; } .kv dd { margin: 0; white-space: pre-wrap; }
.timeline { list-style: none; padding: 0; margin: 0; } .timeline li { position: relative; padding: 0 0 14px 22px; font-size: 14px; }
.timeline li::before { content: ''; position: absolute; left: 4px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--red); }
.timeline li::after { content: ''; position: absolute; left: 8px; top: 18px; bottom: 0; width: 1px; background: var(--line); } .timeline li:last-child::after { display: none; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photos figure { margin: 0; } .photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; cursor: zoom-in; border: 1px solid var(--line); background: #f4f4f4; }
.photos figcaption { font-size: 11px; color: var(--muted); margin-top: 3px; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 3000; display: grid; place-items: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }
.suggest { border: 1px solid var(--line); border-radius: 10px; margin: -6px 0 12px; overflow: hidden; } .suggest button { display: block; width: 100%; text-align: left; border: 0; background: #fff; padding: 10px 12px; cursor: pointer; font-size: 14px; }
.suggest button + button { border-top: 1px solid var(--line); } .suggest button:hover { background: var(--bg); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; margin: 18px 0 8px; }
#toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff;
  padding: 12px 18px; border-radius: 12px; font-weight: 600; opacity: 0; transition: .2s; z-index: 4000; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); } #toast.err { background: var(--red-dark); }
.map-marker { background: var(--ink); color: #fff; border-radius: 99px; padding: 3px 8px; font-weight: 700; font-size: 12px; white-space: nowrap; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); transform: translate(-50%, -50%); display: inline-block; }
.map-marker.on { background: var(--green); } .map-marker.stale { background: var(--orange); }
.pin { width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--red); border: 2px solid #fff; box-shadow: 0 2px 5px rgba(0,0,0,.3); }
.pin.urgent { background: #7a0d12; } .pin.done { background: var(--green); }

/* ---------- interface livreur (mobile) */
.driver { max-width: 640px; margin: 0 auto; padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
.d-top { position: sticky; top: 0; z-index: 1000; background: #fff; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.d-top img { height: 34px; } .d-top .grow { min-width: 0; }
.shift { margin: 14px 16px; padding: 16px; border-radius: 16px; background: var(--ink); color: #fff; display: flex; align-items: center; gap: 12px; }
.shift.on { background: linear-gradient(135deg, #12753d, #1a8f4c); }
.shift .t { font-weight: 800; font-size: 17px; } .shift .s { font-size: 13px; opacity: .85; }
.shift .btn { background: #fff; color: var(--ink); border: 0; }
.d-tabs { display: flex; margin: 0 16px 10px; background: #e9e9ed; border-radius: 12px; padding: 4px; }
.d-tabs button { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 9px; font-weight: 700; color: var(--ink-2); }
.d-tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.job { margin: 0 16px 10px; padding: 14px 16px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); cursor: pointer; display: block; width: calc(100% - 32px); text-align: left; }
.job.active { border: 2px solid var(--blue); }
.job .top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; } .job .name { font-weight: 800; font-size: 17px; flex: 1; }
.job .addr { color: var(--ink-2); } .job .meta { display: flex; gap: 12px; margin-top: 8px; font-size: 13px; color: var(--muted); font-weight: 600; flex-wrap: wrap; }
.d-detail .head { padding: 16px; background: #fff; border-bottom: 1px solid var(--line); }
.d-detail h2 { margin: 6px 0 2px; font-size: 22px; } .d-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px 16px; }
.d-actions .btn { min-height: 54px; }
.d-main { padding: 0 16px; } .d-main .btn.big + .btn.big { margin-top: 10px; }
.info-block { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin: 0 16px 12px; }
.info-block .lbl { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; } .info-block .val { white-space: pre-wrap; margin-top: 2px; }
.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); z-index: 1500; }
.bottom-bar .inner { max-width: 608px; margin: 0 auto; display: flex; gap: 10px; }
.photo-pick { border: 2px dashed #cfcfd6; border-radius: 14px; padding: 18px; text-align: center; cursor: pointer; background: #fafafb; display: block; margin-bottom: 12px; }
.photo-pick img { max-width: 100%; max-height: 260px; border-radius: 10px; display: block; margin: 0 auto; }
.photo-pick .big-ico { font-size: 34px; }
.sig { width: 100%; height: 160px; border: 1px solid #d4d4da; border-radius: 10px; background: #fff; touch-action: none; display: block; }
.gps { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 99px; background: #eee; color: var(--ink-2); }
.gps.ok { background: var(--green-bg); color: var(--green); } .gps.err { background: var(--red-bg); color: var(--red-dark); }
.reasons { display: grid; gap: 8px; margin-bottom: 12px; } .reasons label { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-weight: 600; }
.reasons input { width: 20px; min-height: 20px; height: 20px; accent-color: var(--red); }

@media (max-width: 1100px) { .dash { grid-template-columns: 1fr; } .map { height: 420px; } }
@media (max-width: 760px) {
  .kpis { grid-template-columns: 1fr 1fr; } .topbar { padding: 8px 12px; flex-wrap: wrap; gap: 8px; } .topbar .brand b { display: none; }
  .nav { order: 3; flex-basis: 100%; } .userchip .uname { display: none; } main.page { padding: 14px 12px; }
  .row { flex-direction: column; gap: 0; } .filters input, .filters select { flex: 1; min-width: 0; }
  .tbl .hide-sm { display: none; } .kv { grid-template-columns: 100px 1fr; }
}

.depot-marker { position: absolute; transform: translate(-50%, calc(-100% - 10px)); background: #fff; border-radius: 10px; padding: 5px 8px;
  box-shadow: 0 3px 10px rgba(0,0,0,.28); border: 2px solid var(--red); white-space: nowrap; }
.depot-marker img { height: 30px; display: block; }
.depot-marker::after { content: ''; position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%); border: 8px solid transparent; border-top-color: var(--red); border-bottom: 0; }

.install-banner { position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 3500; background: #fff;
  border: 1px solid var(--line); border-left: 4px solid var(--red); border-radius: 14px; box-shadow: 0 8px 28px rgba(0,0,0,.18);
  padding: 12px; display: flex; gap: 10px; align-items: center; animation: pop .2s; max-width: 600px; margin: 0 auto; }
.install-banner img { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); flex: none; }
.install-banner .small { color: var(--ink-2); margin-top: 2px; }
.ios-share { display: inline-block; border: 1px solid #999; border-radius: 4px; padding: 0 4px; font-size: 12px; }

.truck-marker { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.truck-badge { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: #8a8a92; border: 3px solid #fff; box-shadow: 0 3px 10px rgba(0,0,0,.35); }
.truck-marker.on .truck-badge { background: var(--green); box-shadow: 0 0 0 5px rgba(26,143,76,.25), 0 3px 10px rgba(0,0,0,.35); }
.truck-marker.stale .truck-badge { background: var(--orange); }
.truck-name { margin-top: 3px; background: #fff; color: var(--ink); font-weight: 800; font-size: 12px; padding: 1px 7px; border-radius: 99px; box-shadow: 0 1px 4px rgba(0,0,0,.25); white-space: nowrap; }
.driver-tip, .driver-pop .leaflet-popup-content-wrapper { border-radius: 12px; padding: 0; box-shadow: 0 8px 24px rgba(0,0,0,.2); border: 0; }
.driver-tip { padding: 10px 12px; width: 250px; white-space: normal; }
.driver-pop .leaflet-popup-content { margin: 12px; width: 250px !important; }
.tip-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; } .tip-head b { font-size: 15px; }
.tip-row { padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; line-height: 1.4; }
.tip-actions { display: flex; gap: 6px; margin-top: 8px; } .tip-actions .btn { flex: 1; color: var(--ink); }
