:root {
  --bg: #000;
  --panel: #0a0a0a;
  --card: #141414;
  --line: #262626;
  --text: #fff;
  --muted: #9a9a9a;
  --orange: #ff9500;
  --red: #ff3b30;
  --alert-bg: #b3261e;
  --green: #34c759;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: 'Roboto Condensed', 'Arial Narrow', system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; }
[hidden] { display: none !important; }

.app { display: grid; grid-template-columns: minmax(0, 1fr) 380px; height: 100vh; height: 100dvh; }
.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #0d0d0d; }

/* Bandeau du haut sur la carte */
.top { position: absolute; top: 12px; left: 12px; z-index: 500; display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; background: rgba(0, 0, 0, .85); border: 1px solid var(--line); border-radius: 12px; }
.brand { font-weight: 700; color: var(--orange); font-size: 18px; }
.code { font-weight: 700; font-size: 18px; }
.live { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.live i { width: 9px; height: 9px; border-radius: 50%; background: #555; }
.live.on i { background: var(--green); box-shadow: 0 0 0 4px rgba(52, 199, 89, .2); }
.live.off i { background: var(--red); }

/* Qui parle */
.talk { position: absolute; top: 12px; right: 12px; z-index: 500; display: flex; align-items: center; gap: 8px;
  padding: 8px 14px 8px 10px; background: #5a3500; border: 2px solid var(--orange); border-radius: 999px; font-weight: 700; font-size: 17px; }
.talk svg { width: 22px; height: 22px; fill: #fff; animation: beat 1s ease-in-out infinite; }
@keyframes beat { 50% { transform: scale(1.15); } }

/* Alerte (chute, décrochage, panne) */
.alert { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); z-index: 600; display: flex; align-items: center; gap: 12px;
  width: max-content; max-width: calc(100% - 24px); padding: 10px 10px 10px 14px; background: var(--alert-bg); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .55); }
.alert > svg { width: 28px; height: 28px; fill: #fff; flex: none; }
.alert-text { min-width: 0; }
.alert-text b { display: block; font-size: 19px; }
.alert-text span { font-size: 14px; opacity: .85; }
.alert button { flex: none; background: #000; color: #fff; border: 2px solid var(--orange); border-radius: 10px; padding: 8px 14px; font-weight: 700; cursor: pointer; }
.alert button.icon { padding: 6px; display: grid; place-items: center; }
.alert button.icon svg { width: 20px; height: 20px; fill: var(--orange); }

/* Boutons de la carte */
.mapbtns { position: absolute; left: 12px; bottom: 26px; z-index: 500; display: flex; gap: 8px; }
.mapbtns button { background: rgba(0, 0, 0, .88); color: #fff; border: 2px solid var(--orange); border-radius: 10px;
  padding: 10px 14px; font-weight: 700; font-size: 15px; cursor: pointer; }
.mapbtns button[aria-pressed="true"] { background: var(--orange); color: #000; }

/* Panneau */
.panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 20px; }
h2 { margin: 0 0 6px; font-size: 15px; color: var(--orange); font-weight: 700; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stats .wide { grid-column: span 2; }
.stats > div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.label { display: block; color: var(--muted); font-size: 13px; }
.stats b { display: block; font-size: 27px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats small { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.riders, .log { list-style: none; margin: 0; padding: 0; }
.riders li { display: grid; grid-template-columns: 6px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 9px 8px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 8px; }
.riders li:hover { background: #131313; }
.riders .bar { width: 6px; height: 36px; border-radius: 3px; background: var(--c); }
.riders .who { min-width: 0; }
.riders .name { font-weight: 700; font-size: 18px; }
.riders .role { color: var(--orange); font-size: 13px; font-weight: 700; margin-left: 6px; }
.riders .sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.riders .speed { font-weight: 700; font-size: 24px; text-align: right; line-height: 1; }
.riders .speed small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.riders li.is-alert { background: rgba(255, 59, 48, .16); }
.riders li.is-alert .sub { color: #ff9b93; }
.riders li.is-stale .bar { background: #555; }
.riders li.is-stale .name, .riders li.is-stale .speed { color: #9a9a9a; }

.log li { display: grid; grid-template-columns: 42px 8px minmax(0, 1fr); gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid #1a1a1a; font-size: 15px; }
.log time { color: var(--muted); font-size: 13px; }
.log .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #777); }
.log li.is-alert { color: #ff9b93; font-weight: 700; }
.riders li.empty, .log li.empty { display: block; color: var(--muted); font-size: 14px; padding: 6px 0; border: 0; cursor: default; }
.foot { margin-top: auto; color: #6b6b6b; font-size: 12px; }

/* Marqueurs de la carte */
.rider-icon { position: relative; width: 28px; height: 28px; }
.rider-icon svg { position: absolute; inset: 0; width: 28px; height: 28px; transition: transform .9s linear;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .9)); }
.rider-icon svg path { fill: var(--c); stroke: #000; stroke-width: 1.4; }
.rider-icon.is-lead svg { inset: -4px; width: 36px; height: 36px; }
.rider-icon.is-lead svg path { stroke: #fff; stroke-width: 1.5; }
.rider-icon.is-stale svg path { fill: #6b6b6b; }
.rider-icon .lbl { position: absolute; top: 31px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-weight: 700; font-size: 13px;
  color: var(--c); text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 2px #000; }
.rider-icon.is-stale .lbl { color: #9a9a9a; }
.rider-icon.is-alert::before { content: ''; position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px;
  border-radius: 50%; border: 3px solid var(--red); animation: pulse 1.2s ease-out infinite; }
@keyframes pulse { from { transform: scale(.55); opacity: 1; } to { transform: scale(1.45); opacity: 0; } }
.dest-icon svg { width: 34px; height: 34px; filter: drop-shadow(0 1px 2px #000); }

/* Écran d'accueil ou d'erreur */
.screen { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .94); }
.card { max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px; text-align: center; }
.card h1 { margin: 8px 0; font-size: 26px; }
.card p { margin: 0 0 16px; color: #cfcfcf; font-size: 16px; line-height: 1.45; }
.card button { background: var(--orange); color: #000; border: 0; border-radius: 10px; padding: 12px 18px; font-weight: 700; font-size: 16px; cursor: pointer; }

/* Leaflet en sombre */
.leaflet-container { background: #0d0d0d; font-family: inherit; }
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.82) contrast(.92) saturate(.55); }
.leaflet-control-zoom a { background: #000 !important; color: #fff !important; border-color: var(--line) !important; }
.leaflet-control-attribution { background: rgba(0, 0, 0, .65) !important; color: #8a8a8a !important; }
.leaflet-control-attribution a { color: #b0b0b0 !important; }
.leaflet-div-icon { background: none; border: 0; }

/* Choix Carte / Vidéo */
.views { display: inline-flex; border: 2px solid var(--orange); border-radius: 10px; overflow: hidden; margin-left: 4px; }
.views button { background: #000; color: #fff; border: 0; padding: 6px 12px; font-weight: 700; font-size: 15px; cursor: pointer; }
.views button[aria-pressed="true"] { background: var(--orange); color: #000; }

/* Vue Vidéo (VMS) */
.vms { position: absolute; inset: 0; z-index: 450; display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr); gap: 8px; padding: 68px 10px 10px; background: #050505; }
.vms.is-empty::after { content: 'En attente des motards'; color: var(--muted); place-self: center; grid-column: 1 / -1; }
.is-video .mapbtns, .is-video .leaflet-control-container { display: none; }
.tile { position: relative; min-height: 0; background: #0d0d0d; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: zoom-in; }
.tile.is-focus { cursor: zoom-out; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.tile-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: linear-gradient(rgba(0, 0, 0, .75), transparent); }
.tile-top .bar { width: 5px; height: 20px; border-radius: 3px; background: var(--c); }
.tile-top .tname { font-size: 17px; }
.tile-top .trole { color: var(--orange); font-size: 13px; font-weight: 700; }
.tile-top .tspeed { margin-left: auto; font-weight: 700; font-size: 16px; }
.tile-status { position: absolute; left: 10px; bottom: 10px; display: flex; align-items: center; gap: 6px; max-width: calc(100% - 150px);
  padding: 4px 10px; background: rgba(0, 0, 0, .78); border-radius: 999px; font-size: 13px; color: #cfcfcf; }
.tile-status i { width: 8px; height: 8px; border-radius: 50%; background: #666; flex: none; }
.tile-status span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-status.is-live { color: #fff; font-weight: 700; }
.tile-status.is-live i { background: var(--red); box-shadow: 0 0 0 3px rgba(255, 59, 48, .3); }
.tile-cams { position: absolute; right: 10px; bottom: 10px; display: inline-flex; border: 2px solid var(--orange); border-radius: 9px; overflow: hidden; }
.tile-cams button { background: rgba(0, 0, 0, .85); color: #fff; border: 0; padding: 6px 10px; font-weight: 700; font-size: 13px; cursor: pointer; }
.tile-cams button[aria-pressed="true"] { background: var(--orange); color: #000; }

/* Téléphone : carte en haut, panneau dessous */
@media (max-width: 760px) {
  html, body { height: auto; }
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; }
  .mapwrap { height: 60vh; height: 60svh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .top { top: 8px; left: 8px; right: 8px; gap: 10px; }
  .live { margin-left: auto; }
  .talk { top: auto; bottom: 26px; right: 8px; font-size: 15px; }
  .alert { top: 62px; width: calc(100% - 16px); }
  .alert-text b { font-size: 17px; }
  .mapbtns { left: 8px; }
  .mapbtns button { padding: 9px 11px; font-size: 14px; }
  .top { flex-wrap: wrap; }
  .views button { padding: 5px 10px; font-size: 14px; }
  .vms { padding-top: 96px; gap: 6px; padding-left: 6px; padding-right: 6px; }
}
