/* GeoLoc — version téléphone (activée par mobile.js : body.m) */
body:not(.m) .m-nav, body:not(.m) .m-page, body:not(.m) .m-dev, body:not(.m) .m-action-back { display: none !important; }

body.m { --mnav: calc(60px + env(safe-area-inset-bottom, 0px)); --mtop: 52px; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body.m .app { height: calc(100% - var(--mnav)); grid-template-columns: 1fr; }
body.m .panel, body.m #panelToggle, body.m .views, body.m .top-right, body.m #data, body.m #replay, body.m .follow-chip, body.m .leaflet-control-zoom { display: none !important; }
body.m .topbar { gap: 10px; }
body.m .brand { height: 30px; }
body.m .top-status { margin-left: auto; }
body.m .top-status span { display: inline; }
body.m .mapwrap { grid-column: 1; }
body.m .toast { bottom: calc(var(--mnav) + 12px); }
body.m .alert { bottom: auto; top: calc(env(safe-area-inset-top, 0px) + 6px); left: 10px; right: 10px; max-width: none; z-index: 3200; }
body.m-devopen .m-page { display: none !important; }
body.m .map-tools { top: 10px; right: 10px; }
body.m .map-tools select, body.m .map-btn { padding: 8px 10px; }
body.m.m-devopen .map-tools { display: none; }

/* Barre de navigation en bas */
.m-nav { position: fixed; left: 0; right: 0; bottom: 0; height: var(--mnav); padding-bottom: env(safe-area-inset-bottom, 0px); display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--panel); border-top: 1px solid var(--line); z-index: 1500; box-shadow: 0 -2px 10px rgba(0,0,0,.05); }
.m-nav button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11.5px; font-weight: 600; position: relative; padding: 0; }
.m-nav svg { width: 25px; height: 25px; fill: currentColor; }
.m-nav button[aria-current="page"] { color: var(--navy); }
.m-nav button[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--navy); }
.m-badge { position: absolute; top: 5px; left: calc(50% + 5px); background: var(--crit); color: #fff; border-radius: 99px; font-family: var(--f-mono); font-size: 10.5px; font-weight: 500; padding: 1px 5px; min-width: 18px; text-align: center; }

/* Pages plein écran (Engins, Alertes, Plus) */
.m-page { position: fixed; top: var(--mtop); left: 0; right: 0; bottom: var(--mnav); overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--bg); z-index: 1000; }
.m-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 6px; }
.m-head h2 { margin: 0; font-family: var(--f-disp); font-size: 24px; letter-spacing: .02em; }
.m-head .sp { flex: 1; }
.m-sub { margin: 0 14px 8px; color: var(--muted); font-size: 13px; }
.m-events .ev-list { background: var(--panel); border-top: 1px solid var(--line); }
.m-events .ev { padding: 12px 14px 12px 0; }

/* Liste des engins */
.m-list-head { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 10px 12px 6px; display: flex; flex-direction: column; gap: 8px; }
.m-list-head input { width: 100%; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 16px; }
.m-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.m-chips::-webkit-scrollbar { display: none; }
.m-chips .chip { white-space: nowrap; padding: 6px 12px; font-size: 13px; flex: none; }
.m-cards { padding: 4px 12px 16px; display: flex; flex-direction: column; gap: 12px; }

.mc { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); position: relative; }
.mc::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c); z-index: 3; }
.mc-map { position: relative; height: 132px; overflow: hidden; background: #e5e3df; cursor: pointer; }
.mm-tiles { position: absolute; left: 50%; top: 0; }
.mm-tiles img { position: absolute; width: 256px; height: 256px; max-width: none; user-select: none; }
.mc-nopos { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); }
.mc-pin { position: absolute; left: 50%; top: 56%; transform: translate(-50%, -50%); pointer-events: none; }
.mc-over { position: absolute; inset: 0 0 auto 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 8px 12px 18px 14px; background: linear-gradient(rgba(255,255,255,.95), rgba(255,255,255,.8) 55%, rgba(255,255,255,0)); }
.mc-spd { display: flex; align-items: baseline; gap: 3px; flex: none; }
.mc-spd b { font-family: var(--f-mono); font-size: 26px; font-weight: 600; line-height: 1; }
.mc-spd small { font-size: 12px; color: var(--muted); font-weight: 600; }
.mc-name { font-family: var(--f-disp); font-size: 19px; font-weight: 700; letter-spacing: .01em; text-align: right; line-height: 1.1; min-width: 0; overflow-wrap: anywhere; }
.mc-state { position: absolute; left: 12px; bottom: 8px; max-width: calc(100% - 24px); background: rgba(255,255,255,.96); border-radius: 6px; padding: 3px 8px 3px 22px; font-size: 12.5px; font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.15); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mc-state::before { content: ""; position: absolute; left: 8px; top: 50%; width: 9px; height: 9px; margin-top: -4.5px; border-radius: 50%; background: var(--c); }
.mc.st-stop .mc-state { color: #a8261d; } .mc.st-move .mc-state { color: #146c3a; } .mc.st-idle .mc-state { color: #7a6100; } .mc.st-off .mc-state { color: var(--muted); }
.mc-ind, .m-ind { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.mi { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 2px 6px; text-align: center; min-width: 0; }
.mi i { display: block; height: 18px; }
.mi i svg { width: 18px; height: 18px; fill: var(--muted); }
.mi.on i svg { fill: var(--move); }
.mi.crit i svg { fill: var(--crit); }
.mi small { font-size: 10px; color: var(--muted); line-height: 1.1; }
.mi b { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; line-height: 1.3; }
.mi .bars { height: 13px; margin-top: 2px; }
.mi .crit { color: var(--crit); }
.mc-act { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 46px; border-top: 1px solid var(--line); }
.mc-act button { border: 0; background: none; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 11px 2px; font-weight: 600; font-size: 12.5px; color: var(--navy); min-width: 0; }
.mc-act button + button { border-left: 1px solid var(--line); }
.mc-act button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mc-act svg { width: 17px; height: 17px; fill: currentColor; flex: none; }
.mc-act button:active { background: var(--hover); }

/* Page d'un engin */
.m-dev { position: fixed; top: 0; left: 0; right: 0; bottom: var(--mnav); z-index: 1100; display: flex; flex-direction: column; pointer-events: none; }
.m-dev-head { pointer-events: auto; display: flex; align-items: center; gap: 8px; padding: calc(6px + env(safe-area-inset-top, 0px)) 6px 6px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 58px; }
.m-dev-t { flex: 1; min-width: 0; }
.m-dev-t b { display: block; font-family: var(--f-disp); font-size: 20px; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-dev-t small { display: block; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-icon { border: 0; background: none; width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; color: var(--ink); flex: none; padding: 0; }
.m-icon svg { width: 24px; height: 24px; fill: currentColor; }
.m-icon:active { background: var(--hover); }
.m-dev .dev-ico { width: 38px; height: 38px; }
.m-dev .dev-ico svg { width: 30px; height: 30px; }
.m-tabs { pointer-events: auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--panel); border-bottom: 1px solid var(--line); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.m-tabs button { border: 0; background: none; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 4px; font-weight: 600; font-size: 13px; color: var(--muted); border-bottom: 3px solid transparent; min-width: 0; }
.m-tabs button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-tabs svg { display: none; }
.m-tabs button[aria-selected="true"] { color: var(--navy); border-bottom-color: var(--navy); }
.m-pane { flex: 1; position: relative; min-height: 0; }
.m-pane.m-dash { pointer-events: auto; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px; }
.m-pane.m-dash .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.m-pane.m-dash .dash-tile b { font-size: 17px; }
.m-pchips-dash, .m-pchips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.m-pchips-dash::-webkit-scrollbar, .m-pchips::-webkit-scrollbar { display: none; }
.m-pchips-dash { margin: 0 -12px; padding: 0 12px 2px; }
.m-pchips { pointer-events: auto; padding: 10px 12px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); }
.pchips button { flex: none; }
.m-daypick { position: relative; flex: none; border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 6px 12px; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; }
.m-daypick.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.m-daypick input { position: absolute; inset: 0; opacity: 0; width: 100%; }

/* Feuilles du bas (Direct, Historique) */
.m-sheet { pointer-events: auto; position: absolute; left: 0; right: 0; bottom: 0; background: var(--panel); border-radius: 16px 16px 0 0; box-shadow: 0 -6px 20px rgba(0,0,0,.15); max-height: 62%; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 8px; }
.m-grip { display: block; width: 100%; height: 18px; border: 0; background: none; position: relative; padding: 0; }
.m-grip::after { content: ""; position: absolute; left: 50%; top: 7px; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: #cfd4dc; }
.m-live-top { display: flex; gap: 12px; align-items: flex-start; padding: 0 14px 10px; }
.m-live-top .mc-spd b { font-size: 30px; }
.m-live-top > div { min-width: 0; flex: 1; }
.m-state { display: block; font-size: 14.5px; }
.m-live-top.st-stop .m-state { color: #a8261d; } .m-live-top.st-move .m-state { color: #146c3a; } .m-live-top.st-idle .m-state { color: #7a6100; } .m-live-top.st-off .m-state { color: var(--muted); }
.m-addr, .m-zone { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.m-sheet .m-ind { grid-template-columns: repeat(4, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.m-live-act { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px 4px; }
.m-live-act .btn { flex: 1 1 calc(50% - 8px); text-align: center; text-decoration: none; padding: 10px 8px; font-size: 14px; }
.m-replay { display: flex; align-items: center; gap: 10px; padding: 0 14px 8px; }
.m-play { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--navy); color: #fff; display: grid; place-items: center; padding: 0; }
.m-play svg { width: 22px; height: 22px; fill: currentColor; }
.m-replay input { flex: 1; min-width: 0; accent-color: var(--navy); height: 30px; }
.m-rp-out { flex: none; text-align: right; min-width: 74px; }
.m-rp-out b { display: block; font-family: var(--f-mono); font-size: 14px; font-weight: 500; }
.m-rp-out small { font-family: var(--f-mono); font-size: 11.5px; color: var(--muted); }
.m-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.m-kpis > div { background: var(--panel); padding: 8px 10px; min-width: 0; }
.m-kpis small { display: block; font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.m-kpis b { font-family: var(--f-mono); font-size: 15px; font-weight: 500; white-space: nowrap; }
.m-more-det { display: none; }
#mHistSheet { max-height: 46%; }
#mHistSheet.open { max-height: 78%; }
#mHistSheet.open .m-more-det { display: block; }
#mHistSheet.open .m-more-det .m-kpis { border-top: 0; }
.m-noh { padding: 12px 16px; }

/* Feuille d'actions */
.m-action-back { position: fixed; inset: 0; background: rgba(15,20,40,.45); z-index: 3500; display: flex; align-items: flex-end; }
.m-action { background: var(--panel); width: 100%; border-radius: 16px 16px 0 0; padding: 14px 12px calc(12px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; max-height: 85%; overflow-y: auto; }
.m-action h3 { margin: 2px 4px 4px; font-family: var(--f-disp); font-size: 21px; letter-spacing: .02em; }
.m-action p { margin: 0 4px 6px; line-height: 1.45; }
.m-action button { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 13px; font-size: 15px; font-weight: 600; text-align: center; }
.m-action button.danger { color: var(--crit); }
.m-action button.danger.solid { background: var(--crit); color: #fff; border-color: var(--crit); }
.m-action button.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.m-action .m-act-cancel { background: var(--raise); margin-top: 4px; }
.m-steps { margin: 0 4px 6px; padding-left: 22px; line-height: 1.6; }

/* Plus */
.m-user b { display: block; font-size: 17px; }
.m-user small { color: var(--muted); }
.m-menu { list-style: none; margin: 6px 12px 16px; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.m-menu li + li { border-top: 1px solid var(--line); }
.m-menu button { width: 100%; border: 0; background: none; text-align: left; padding: 13px 16px; display: flex; flex-direction: column; gap: 2px; position: relative; }
.m-menu button::after { content: "›"; position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 20px; }
.m-menu button b { font-weight: 600; font-size: 15px; }
.m-menu button small { color: var(--muted); font-size: 12.5px; }
.m-menu button.danger b { color: var(--crit); }
.m-menu button:active { background: var(--hover); }

/* Vues de bureau ouvertes depuis « Plus » */
body.m .rp-filters { gap: 10px; }
body.m .rp-field { flex: 1 1 140px; }
body.m .rp-devs summary { min-width: 0; }
body.m .rp-devs-box { width: min(300px, calc(100vw - 32px)); }
@media (prefers-reduced-motion: no-preference) { .m-sheet { transition: max-height .2s; } }
