:root {
  --bg: #ffffff; --fg: #1d2330; --muted: #6b7280; --line: #e5e7eb; --panel: rgba(255,255,255,.96);
  --quad: #f08c2e; --x4: #3d7fd9; --stale: #9aa0a6; --sos: #e5383b; --ok: #2f9e44; --accent: #c2410c;
  --shadow: 0 6px 24px rgba(0,0,0,.18);
}
body.night {
  --bg: #12161f; --fg: #e8ecf3; --muted: #9aa4b5; --line: #2a3140; --panel: rgba(20,25,35,.95);
  --shadow: 0 6px 24px rgba(0,0,0,.6);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--fg); background: var(--bg); -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- carte */
#map { position: fixed; inset: 0; background: #1b1f27; }
.topbar { position: fixed; top: env(safe-area-inset-top, 0); left: 0; right: 0; z-index: 1000; display: flex; gap: 8px; align-items: center; padding: 10px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.brand { background: var(--panel); border-radius: 12px; padding: 8px 12px; box-shadow: var(--shadow); font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand small { font-weight: 500; color: var(--muted); font-size: 11px; display: flex; align-items: center; gap: 4px; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(47,158,68,.6); animation: pulse 2s infinite; }
.dot-live.off { background: var(--sos); animation: none; }
.spacer { flex: 1; }
.seg { display: flex; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.seg button { border: 0; background: none; padding: 8px 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--accent); color: #fff; }

.sos-banner { position: fixed; top: calc(env(safe-area-inset-top, 0) + 60px); left: 10px; right: 10px; z-index: 1001; display: flex; flex-direction: column; gap: 6px; }
.sos-item { background: var(--sos); color: #fff; border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px; font-weight: 600; animation: blink 1.6s infinite; }
.sos-item button { margin-left: auto; background: #fff; color: var(--sos); border: 0; border-radius: 8px; padding: 6px 10px; font-weight: 700; }

.fab { position: fixed; right: 12px; z-index: 1000; width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--panel); box-shadow: var(--shadow); font-size: 20px; }
#btnLocate { bottom: calc(env(safe-area-inset-bottom, 0) + 134px); }
#btnLayers { bottom: calc(env(safe-area-inset-bottom, 0) + 188px); }
.layers { position: fixed; right: 66px; bottom: calc(env(safe-area-inset-bottom, 0) + 178px); z-index: 1001; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: none; flex-direction: column; }
.layers.open { display: flex; }
.layers button { border: 0; background: none; text-align: left; padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.layers button.on { background: var(--accent); color: #fff; }

/* ---------- panneau bas (liste) */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; background: var(--panel); border-radius: 18px 18px 0 0; box-shadow: var(--shadow); max-height: 70vh; display: flex; flex-direction: column; transform: translateY(calc(100% - 124px - env(safe-area-inset-bottom, 0))); transition: transform .25s ease; padding-bottom: env(safe-area-inset-bottom, 0); }
.sheet.open { transform: none; }
.sheet-head { padding: 8px 14px 10px; cursor: pointer; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.sheet-title { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.counts { margin-left: auto; display: flex; gap: 6px; font-size: 12px; font-weight: 600; }
.pill { padding: 3px 8px; border-radius: 99px; background: var(--line); color: var(--fg); }
.pill.red { background: var(--sos); color: #fff; }
.pill.grey { background: var(--stale); color: #fff; }
.tabs { display: flex; flex: none; gap: 6px; padding: 0 14px 10px; overflow-x: auto; white-space: nowrap; }
.tabs button { flex: none; }
.sheet-head { flex: none; }
.tabs button { border: 1px solid var(--line); background: none; border-radius: 99px; padding: 5px 12px; font-size: 13px; }
.tabs button.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.list { overflow-y: auto; padding: 0 8px 12px; -webkit-overflow-scrolling: touch; }
.row { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 10px; }
.row:active { background: var(--line); }
.badge { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px; flex: none; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.badge.quad { background: var(--quad); } .badge.x4 { background: var(--x4); } .badge.stale { background: var(--stale); } .badge.sos { background: var(--sos); }
.row .info { flex: 1; min-width: 0; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 12px; color: var(--muted); }
.row .icons { font-size: 14px; display: flex; gap: 4px; }
.wp-row .emoji { width: 34px; text-align: center; font-size: 22px; }

/* ---------- marqueurs */
.crew-marker { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 12px; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.45); }
.crew-marker.quad { background: var(--quad); } .crew-marker.x4 { background: var(--x4); }
.crew-marker.stale { background: var(--stale); opacity: .85; }
.crew-marker.sos { background: var(--sos); animation: sosring 1.2s infinite; }
.wp-marker { font-size: 22px; line-height: 30px; text-align: center; width: 34px; height: 34px; background: rgba(255,255,255,.92); border-radius: 50%; box-shadow: 0 2px 6px rgba(0,0,0,.4); border: 2px solid #222; }
.me-marker { width: 16px; height: 16px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(26,115,232,.25); }

.leaflet-popup-content-wrapper { border-radius: 12px; }
body.night .leaflet-popup-content-wrapper, body.night .leaflet-popup-tip { background: #1d2330; color: #e8ecf3; }
.pop h3 { margin: 0 0 4px; font-size: 16px; }
.pop .meta { font-size: 13px; color: #667; margin-bottom: 8px; line-height: 1.5; }
body.night .pop .meta { color: #aab; }
.pop .alert { font-size: 12px; font-weight: 700; color: var(--sos); margin-bottom: 6px; }
.pop .btns { display: flex; flex-wrap: wrap; gap: 6px; }
.pop .btns a, .pop .btns button { border: 0; border-radius: 8px; padding: 7px 10px; font-size: 13px; font-weight: 600; background: #eef0f3; color: #1d2330; text-decoration: none; }
.pop .btns .w3w { background: #e11f26; color: #fff; }
.w3w-out { margin-top: 8px; font-family: ui-monospace, Menlo, monospace; font-size: 15px; font-weight: 700; color: #e11f26; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.w3w-out button { font-family: inherit; font-size: 12px; border: 1px solid #ccc; background: none; border-radius: 6px; padding: 3px 8px; }

.toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 2000; background: #1d2330; color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; }

@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(47,158,68,.6); } 70% { box-shadow: 0 0 0 8px rgba(47,158,68,0); } 100% { box-shadow: 0 0 0 0 rgba(47,158,68,0); } }
@keyframes sosring { 0% { box-shadow: 0 0 0 0 rgba(229,56,59,.8); } 100% { box-shadow: 0 0 0 16px rgba(229,56,59,0); } }
@keyframes blink { 50% { filter: brightness(1.15); } }

/* ---------- page équipage */
.page { max-width: 520px; margin: 0 auto; padding: calc(env(safe-area-inset-top, 0) + 16px) 16px 40px; }
.page header { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.page header h1 { font-size: 20px; margin: 0; flex: 1; }
.big { display: block; width: 100%; border: 0; border-radius: 18px; padding: 24px 16px; font-size: 22px; font-weight: 800; color: #fff; margin-bottom: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.big:disabled { opacity: .6; }
.big.send { background: var(--ok); }
.big.sos { background: var(--sos); padding: 30px 16px; font-size: 28px; }
.status { text-align: center; font-size: 14px; color: var(--muted); min-height: 20px; margin: -4px 0 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.card h2 { font-size: 16px; margin: 0 0 10px; }
.kv { display: grid; grid-template-columns: 1fr; gap: 8px; font-size: 14px; }
.kv div { display: flex; flex-direction: column; gap: 2px; }
.kv span { color: var(--muted); font-size: 12px; }
.kv code { font-family: ui-monospace, Menlo, monospace; background: var(--line); border-radius: 6px; padding: 6px 8px; display: flex; justify-content: space-between; align-items: center; gap: 6px; word-break: break-all; }
.kv code button { border: 0; background: var(--fg); color: var(--bg); border-radius: 6px; padding: 3px 8px; font-size: 12px; flex: none; }
.tips { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.7; }
.link-btn { display: block; text-align: center; padding: 14px; border-radius: 14px; background: var(--fg); color: var(--bg); text-decoration: none; font-weight: 700; margin-bottom: 14px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 3000; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal.open { display: flex; }
.modal .box { background: var(--bg); border-radius: 18px; padding: 20px; width: 100%; max-width: 420px; }
.modal h2 { margin: 0 0 8px; }
.modal textarea { width: 100%; min-height: 70px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; font: inherit; background: var(--bg); color: var(--fg); margin: 10px 0; }
.modal .row2 { display: flex; gap: 10px; }
.modal .row2 button { flex: 1; border: 0; border-radius: 12px; padding: 14px; font-weight: 700; }
.btn-red { background: var(--sos); color: #fff; } .btn-grey { background: var(--line); }
.sos-result { text-align: center; }
.sos-result .words { font-family: ui-monospace, Menlo, monospace; font-size: 26px; font-weight: 800; color: #e11f26; margin: 6px 0; word-break: break-word; }
.sos-result .coords { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.sos-result a { display: block; padding: 14px; border-radius: 12px; text-decoration: none; font-weight: 700; margin-top: 8px; }
.sos-result .c112 { background: var(--sos); color: #fff; } .sos-result .corga { background: var(--fg); color: var(--bg); }

.wp-list { display: flex; flex-direction: column; gap: 4px; }
.wp-item { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-radius: 10px; font-size: 14px; }
.wp-item.done { background: rgba(47,158,68,.12); }
.wp-e { font-size: 20px; width: 26px; text-align: center; }
.wp-n { flex: 1; }
.wp-s { font-weight: 700; color: var(--ok); white-space: nowrap; }
