@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #f4f6fb; --surface: rgba(255,255,255,.86); --surface-solid: #fff; --surface-2: #eef1f8;
    --text: #0f172a; --muted: #64748b; --border: rgba(15,23,42,.08);
    --primary: #4f46e5; --primary-2: #7c3aed; --primary-soft: rgba(79,70,229,.1);
    --ok: #059669; --warn: #d97706; --danger: #e11d48;
    --shadow: 0 10px 30px -8px rgba(15,23,42,.25), 0 2px 6px rgba(15,23,42,.06);
    --radius: 18px; --blur: saturate(180%) blur(18px);
}
:root[data-theme="dark"] {
    --bg: #0b1020; --surface: rgba(20,26,45,.82); --surface-solid: #141a2d; --surface-2: #1c2440;
    --text: #e8ecf8; --muted: #8f9bb8; --border: rgba(255,255,255,.08);
    --primary: #818cf8; --primary-2: #a78bfa; --primary-soft: rgba(129,140,248,.16);
    --ok: #34d399; --warn: #fbbf24; --danger: #fb7185;
    --shadow: 0 14px 34px -8px rgba(0,0,0,.6), 0 2px 6px rgba(0,0,0,.3);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { margin: 0; font-family: 'Inter', system-ui, -apple-system, Segoe UI, sans-serif; color: var(--text); background: var(--bg); overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }

/* Boutons & champs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px; padding: 11px 16px;
    font: 600 14px/1 inherit; font-family: inherit; color: #fff; cursor: pointer; background: linear-gradient(135deg, var(--primary), var(--primary-2));
    box-shadow: 0 6px 16px -6px var(--primary); transition: transform .12s, filter .12s; }
.btn:active { transform: scale(.96); }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--surface-2); color: var(--text); box-shadow: none; }
.btn.danger { background: linear-gradient(135deg, #f43f5e, var(--danger)); box-shadow: 0 6px 16px -6px var(--danger); }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.field { display: block; margin: 12px 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .input { width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--surface-2); color: var(--text); font: 500 15px inherit; font-family: inherit; outline: none; transition: border-color .15s, box-shadow .15s; }
.field input:focus, .field select:focus, .input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.glass { background: var(--surface); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); border: 1px solid var(--border); box-shadow: var(--shadow); }

/* Connexion */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 20px; overflow: auto;
    background: radial-gradient(900px 500px at 15% -10%, rgba(124,58,237,.35), transparent 60%),
                radial-gradient(800px 500px at 100% 110%, rgba(79,70,229,.35), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; border-radius: 26px; padding: 32px 28px; }
.logo { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 10px 24px -8px var(--primary); }
.logo svg.i { width: 28px; height: 28px; }
.login-card h1 { margin: 18px 0 4px; font-size: 28px; letter-spacing: -.02em; }
.alert { background: rgba(225,29,72,.12); color: var(--danger); padding: 10px 14px; border-radius: 12px; font-size: 14px; font-weight: 500; margin: 14px 0 0; }

/* Carte */
#map { position: fixed; inset: 0; z-index: 0; background: var(--bg); }
.leaflet-container { font-family: inherit; }
.tiles-dark { filter: invert(1) hue-rotate(200deg) brightness(.92) contrast(.88) saturate(.75); }
.leaflet-control-zoom,.leaflet-control-attribution { display: none; }
.leaflet-popup-content-wrapper { border-radius: 14px; background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }
.leaflet-popup-tip { background: var(--surface-solid); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 1.5; }
.pop-title { font-weight: 700; font-size: 14px; }
.pop-link { color: var(--danger); font-weight: 600; cursor: pointer; }

/* Marqueurs */
.pin { width: 34px; height: 34px; border-radius: 50% 50% 50% 8px; transform: rotate(-45deg); display: grid; place-items: center;
    color: #fff; box-shadow: 0 6px 14px rgba(0,0,0,.35); border: 2px solid #fff; }
.pin > span { transform: rotate(45deg); display: grid; }
.pin svg.i { width: 16px; height: 16px; stroke-width: 2.4; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font: 700 14px Inter, sans-serif;
    border: 3px solid #fff; box-shadow: 0 6px 16px rgba(0,0,0,.35); position: relative; }
.avatar.live::after { content: ''; position: absolute; inset: -9px; border-radius: 50%; border: 2px solid currentColor; opacity: 0;
    animation: pulse 2s infinite; color: inherit; }
.avatar.off { filter: grayscale(.9) brightness(.9); opacity: .85; }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #2563eb; border: 3px solid #fff; box-shadow: 0 0 0 0 rgba(37,99,235,.6); animation: ring 2s infinite; }
.vtx { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--primary); box-shadow: 0 2px 6px rgba(0,0,0,.4); }
@keyframes pulse { 0% { transform: scale(.7); opacity: .8; } 100% { transform: scale(1.5); opacity: 0; } }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(37,99,235,.55); } 100% { box-shadow: 0 0 0 20px rgba(37,99,235,0); } }

/* Page terrain */
.top { position: fixed; z-index: 500; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; gap: 10px; align-items: center; pointer-events: none; }
.top > * { pointer-events: auto; }
.pill { height: 48px; border-radius: 16px; display: flex; align-items: center; gap: 10px; padding: 0 14px; }
.pill.grow { flex: 1; min-width: 0; }
.pill select { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text); font: 600 15px Inter, sans-serif; outline: none; appearance: none; -webkit-appearance: none; text-overflow: ellipsis; }
.pill select option { color: #0f172a; }
.icon-btn { width: 48px; height: 48px; border-radius: 16px; display: grid; place-items: center; color: var(--text); cursor: pointer; border: 0; padding: 0; font-family: inherit; }
.icon-btn:active { transform: scale(.94); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 999px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px rgba(5,150,105,.2); }
.dot.bad { background: var(--danger); }
#gps { position: fixed; z-index: 500; top: calc(max(12px, env(safe-area-inset-top)) + 58px); left: 12px; }
.fabs { position: fixed; z-index: 500; right: 12px; bottom: calc(112px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.fabs .icon-btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; }

.dock { position: fixed; z-index: 500; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto;
    border-radius: 24px; padding: 8px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.dock button { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 9px 2px; border: 0; background: transparent; color: var(--muted);
    border-radius: 16px; font: 600 11px Inter, sans-serif; cursor: pointer; transition: all .15s; }
.dock button svg.i { width: 22px; height: 22px; }
.dock button:active { transform: scale(.93); }
.dock button.on { color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 8px 18px -8px var(--primary); }

.hud { position: fixed; z-index: 600; left: 12px; right: 12px; bottom: calc(100px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; border-radius: 22px;
    padding: 16px; transform: translateY(calc(100% + 140px)); opacity: 0; pointer-events: none; transition: transform .3s cubic-bezier(.2,.9,.3,1), opacity .2s; }
.hud.show { transform: none; opacity: 1; pointer-events: auto; }
.hud .big { font-size: 34px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; background: linear-gradient(135deg, var(--primary), var(--primary-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hud .row { display: flex; gap: 8px; margin-top: 12px; }
.hud .row .btn { flex: 1; padding: 11px 6px; }

.sheet { position: fixed; z-index: 700; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto; max-height: 78vh; display: flex; flex-direction: column;
    border-radius: 26px 26px 0 0; transform: translateY(105%); transition: transform .32s cubic-bezier(.2,.9,.3,1); }
.sheet.show { transform: none; }
.sheet .grab { width: 44px; height: 5px; border-radius: 9px; background: var(--border); margin: 10px auto 4px; }
.sheet-head { padding: 8px 18px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sheet-head h3 { margin: 0; font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 0 14px calc(18px + env(safe-area-inset-bottom)); }
.item { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 16px; background: var(--surface-2); margin-bottom: 8px; cursor: pointer; }
.item .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff; flex: none; }
.item .t { font-weight: 700; font-size: 14px; }
.item .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.item .v { margin-left: auto; font-weight: 700; font-size: 13px; white-space: nowrap; }
.tabs { display: flex; gap: 6px; padding: 0 14px 10px; overflow-x: auto; }
.tab { padding: 8px 14px; border-radius: 999px; border: 0; background: var(--surface-2); color: var(--muted); font: 600 13px Inter, sans-serif; cursor: pointer; white-space: nowrap; }
.tab.on { background: var(--primary); color: #fff; }

/* Modale & toasts */
.scrim { position: fixed; inset: 0; z-index: 900; background: rgba(8,12,24,.5); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.show { opacity: 1; pointer-events: auto; }
.modal { width: 100%; max-width: 400px; border-radius: 24px; padding: 24px; background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); transform: scale(.94); transition: transform .2s; }
.scrim.show .modal { transform: none; }
.modal h3 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.01em; }
.modal .row { display: flex; gap: 10px; margin-top: 16px; }
.modal .row .btn { flex: 1; }
#toasts { position: fixed; z-index: 1000; top: calc(max(12px, env(safe-area-inset-top)) + 64px); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { padding: 12px 18px; border-radius: 14px; font: 600 14px Inter, sans-serif; color: #fff; background: #111827; box-shadow: var(--shadow);
    animation: tin .3s cubic-bezier(.2,.9,.3,1); max-width: 90vw; }
.toast.ok { background: var(--ok); } .toast.err { background: var(--danger); }
@keyframes tin { from { transform: translateY(-14px); opacity: 0; } }

/* Admin */
.shell { position: fixed; inset: 0; display: grid; grid-template-columns: 420px 1fr; }
.panel { z-index: 10; display: flex; flex-direction: column; min-height: 0; background: var(--surface-solid); border-right: 1px solid var(--border); }
.panel-head { padding: 18px 18px 8px; display: flex; align-items: center; gap: 12px; }
.panel-head .logo { width: 40px; height: 40px; border-radius: 12px; }
.panel-head .logo svg.i { width: 22px; height: 22px; }
.panel-head h1 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
.panel-head .sp { flex: 1; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 8px 18px 12px; }
.kpi { border-radius: 16px; padding: 14px; background: var(--surface-2); }
.kpi b { display: block; font-size: 26px; letter-spacing: -.03em; font-weight: 800; }
.kpi span { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi.accent { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; }
.kpi.accent span { color: rgba(255,255,255,.8); }
.panel-body { flex: 1; overflow-y: auto; padding: 4px 14px 24px; min-height: 0; }
.panel .tabs { padding: 4px 14px 10px; }
.panel .btn.row-btn { margin: 6px 0 12px; }
.form-card { background: var(--surface-2); border-radius: 16px; padding: 4px 14px 14px; margin-bottom: 12px; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.badge.ok { background: rgba(5,150,105,.15); color: var(--ok); }
.badge.off { background: var(--surface); color: var(--muted); }
.shell #map { position: relative; inset: auto; }
.map-tools { position: absolute; z-index: 500; top: 12px; right: 12px; display: flex; gap: 10px; }
.mobile-toggle { display: none; }
@media (max-width: 860px) {
    .shell { grid-template-columns: 1fr; grid-template-rows: 46vh 1fr; }
    .shell #map { grid-row: 1; }
    .panel { grid-row: 2; border-right: 0; border-radius: 22px 22px 0 0; margin-top: -22px; box-shadow: var(--shadow); }
}
@media (min-width: 700px) {
    .dock { grid-template-columns: repeat(5, 1fr); }
    .dock button { flex-direction: row; justify-content: center; font-size: 13px; padding: 12px 6px; gap: 8px; }
    .dock button svg.i { width: 20px; height: 20px; }
}
