:root {
  --navy: #1d3557;
  --accent: #e76f51;
  --bg: #ffffff;
  --fg: #1b1b1b;
  --muted: #6b7280;
  --line: #e5e7eb;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--fg); }
#map { position: absolute; inset: 0; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--fg);
  border-radius: 10px; padding: 8px 12px; font-size: 15px; cursor: pointer;
}
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.danger { background: #c1121f; color: #fff; border-color: #c1121f; }
.btn.small { padding: 4px 8px; font-size: 13px; }
.btn:disabled { opacity: .5; }

#toolbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: var(--navy); padding-bottom: var(--safe-b);
}
#toolbar button {
  flex: 1; background: none; border: 0; color: #fff; font-size: 20px;
  padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
#toolbar button span { font-size: 11px; }
#toolbar button.active { background: rgba(255,255,255,.15); }

#panel {
  position: absolute; left: 0; right: 0; bottom: calc(56px + var(--safe-b)); z-index: 6;
  max-height: 60vh; background: var(--bg); border-radius: 14px 14px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,.2); display: flex; flex-direction: column;
}
#panel header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); }
#panel h2 { margin: 0; font-size: 17px; }
#panel-body { overflow-y: auto; padding: 10px 14px 16px; }

.row { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 10px; }
.empty { color: var(--muted); padding: 10px 0; }
.toggle { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.toggle input { width: 22px; height: 22px; }
.toggle .sub { color: var(--muted); font-size: 12px; }
.modes { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.modes button { padding: 12px 6px; }
h4 { margin: 14px 0 6px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.note { color: var(--muted); font-size: 12px; margin-top: 10px; }

#recbar, #drawbar, #placebar {
  position: absolute; top: 10px; left: 10px; right: 60px; z-index: 5;
  display: flex; align-items: center; gap: 8px; background: #fff; padding: 8px 10px;
  border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,.2); font-size: 14px;
}
#recbar span#rec-info, #drawbar #draw-info, #placebar span { flex: 1; }
#rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #c1121f; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

#searchbox {
  position: absolute; top: 10px; left: 10px; right: 56px; z-index: 5; display: flex; align-items: center;
  background: #fff; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,.2); padding: 0 6px 0 10px;
}
#searchbox input { flex: 1; border: 0; outline: 0; font-size: 16px; padding: 11px 6px; background: none; min-width: 0; }
#searchbox input::-webkit-search-cancel-button { display: none; }
#searchbox button { border: 0; background: none; font-size: 16px; padding: 6px; color: var(--muted); }
#recbar:not([hidden]) ~ #searchbox, #drawbar:not([hidden]) ~ #searchbox, #placebar:not([hidden]) ~ #searchbox,
#recbar:not([hidden]) ~ #results, #drawbar:not([hidden]) ~ #results, #placebar:not([hidden]) ~ #results { display: none !important; }
#results {
  position: absolute; top: 58px; left: 10px; right: 56px; z-index: 7; max-height: 55vh; overflow-y: auto;
  background: #fff; border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
#results .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 12px 2px; }
#results .res { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-top: 1px solid var(--line); cursor: pointer; }
#results .res:active, #results .res:hover { background: #f3f4f6; }
#results .res .ico { font-size: 20px; width: 26px; text-align: center; flex: none; }
#results .res .t { font-weight: 600; font-size: 15px; }
#results .res .s { color: var(--muted); font-size: 12px; }
#results .msg { padding: 10px 12px; color: var(--muted); font-size: 13px; }
.search-pin { font-size: 30px; line-height: 1; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }

#navbar {
  position: absolute; top: 10px; left: 10px; right: 56px; z-index: 6; display: flex; align-items: center; gap: 12px;
  background: #0b3d91; color: #fff; border-radius: 14px; padding: 10px 14px; box-shadow: 0 3px 12px rgba(0,0,0,.3);
}
#navbar .grow { flex: 1; min-width: 0; }
#nav-icon { font-size: 34px; line-height: 1; }
#nav-dist { font-size: 24px; font-weight: 700; }
#nav-text { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#navfoot {
  position: absolute; left: 0; right: 0; bottom: calc(56px + var(--safe-b)); z-index: 6; display: flex; align-items: center; gap: 8px;
  background: #fff; padding: 10px 12px; box-shadow: 0 -3px 12px rgba(0,0,0,.2); border-radius: 14px 14px 0 0;
}
#navfoot .grow { flex: 1; min-width: 0; }
#nav-eta { font-weight: 700; font-size: 16px; }
#navfoot .sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#crosshair {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 4;
  font-size: 40px; color: var(--accent); pointer-events: none; text-shadow: 0 0 3px #fff; line-height: 1;
}

dialog { border: 0; border-radius: 14px; padding: 0; width: min(92vw, 420px); }
dialog form { padding: 16px; }
dialog h3 { margin: 0 0 12px; }
dialog label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
dialog input, dialog textarea, dialog select { width: 100%; font-size: 16px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 16px 0 0; }

#toast {
  position: absolute; left: 50%; bottom: calc(70px + var(--safe-b)); transform: translateX(-50%); z-index: 10;
  background: rgba(0,0,0,.8); color: #fff; padding: 8px 14px; border-radius: 20px; font-size: 14px; max-width: 90vw;
}

.maplibregl-popup-content { padding: 10px 12px; max-width: 320px; }
.popup h3 { margin: 0 0 4px; font-size: 15px; }
.popup .sub { color: var(--muted); font-size: 12px; }
.popup .cams { display: flex; overflow-x: auto; gap: 6px; scroll-snap-type: x mandatory; margin-top: 6px; }
.popup .cams img { width: 260px; flex: none; border-radius: 6px; scroll-snap-align: start; background: #eee; min-height: 146px; }
.popup table { font-size: 13px; border-collapse: collapse; }
.popup td { padding: 1px 6px 1px 0; vertical-align: top; }
.popup td:first-child { color: var(--muted); }
