:root {
  --bg: #f3f5f8; --panel: #fff; --text: #1b2430; --muted: #6b7686; --line: #dfe4ea;
  --brand: #1d5fd6; --brand-ink: #fff; --ok: #1a8f3c; --warn: #d98a00; --bad: #c62828; --off: #7b8794;
  --shadow: 0 1px 6px rgba(0,0,0,.18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --panel: #1b222b; --text: #e6ebf1; --muted: #98a3b1; --line: #2b3541;
    --brand: #5b95f5; --brand-ink: #0b1220; --shadow: 0 1px 6px rgba(0,0,0,.6);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 5px 10px; }
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--bad); }
button.sm { padding: 2px 7px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; max-width: 100%; }
textarea { width: 100%; min-height: 80px; }

#login { display: grid; place-items: center; height: 100%; }
#login form { background: var(--panel); padding: 28px; border-radius: 10px; box-shadow: var(--shadow); width: min(340px, 92vw); display: grid; gap: 12px; }
#login h1 { margin: 0 0 4px; font-size: 20px; }
.err { color: var(--bad); min-height: 1.3em; font-size: 13px; }

#app { display: grid; grid-template-columns: 200px 1fr; height: 100%; }
#nav { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 10px; gap: 4px; overflow: auto; }
#nav .brand { font-weight: 700; font-size: 16px; padding: 4px 8px 10px; }
#nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 6px; color: inherit; text-decoration: none; cursor: pointer; }
#nav a:hover { background: var(--bg); }
#nav a.on { background: var(--brand); color: var(--brand-ink); }
#nav .who { margin-top: auto; font-size: 12px; color: var(--muted); padding: 8px; border-top: 1px solid var(--line); }
#nav .who button { margin-top: 6px; width: 100%; }
.badge { background: var(--bad); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; }
.badge:empty, .badge.zero { display: none; }
#main { position: relative; overflow: auto; min-width: 0; }
.page { padding: 16px; }
.page h2 { margin: 0 0 12px; font-size: 18px; }
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.bar .grow { flex: 1; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; }
.tabs button.on { border-bottom-color: var(--brand); font-weight: 600; }
.card { background: var(--panel); border-radius: 8px; box-shadow: var(--shadow); overflow: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); position: sticky; top: 0; background: var(--panel); }
td .act { display: flex; gap: 4px; flex-wrap: wrap; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--line); }
.pill.ok { background: var(--ok); color: #fff; } .pill.warn { background: var(--warn); color: #fff; }
.pill.bad { background: var(--bad); color: #fff; } .pill.off { background: var(--off); color: #fff; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); margin-right: 6px; }
.dot.ok { background: var(--ok); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { background: var(--panel); border-radius: 8px; padding: 6px 12px; box-shadow: var(--shadow); }

/* mapa */
#mapwrap { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; }
.floating { position: absolute; z-index: 1000; background: var(--panel); border-radius: 8px; box-shadow: var(--shadow); padding: 8px 10px; }
#mapbar { top: 10px; left: 56px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; max-width: calc(100% - 80px); }
#mapbar input[type=search] { width: 150px; }
#drawbar { top: 56px; left: 56px; display: none; gap: 6px; align-items: center; }
#drawbar.on { display: flex; }
#playback { bottom: 18px; left: 56px; right: 18px; display: none; }
#playback.on { display: block; }
#playback .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
#playback input[type=range] { flex: 1; min-width: 160px; }
.pin { width: 22px; height: 22px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.pin::after { content: ""; position: absolute; left: 6px; top: 6px; width: 6px; height: 6px; border-radius: 50%; background: #fff; }
.popup h4 { margin: 0 0 4px; }
.popup .kv { color: #444; font-size: 13px; }
.popup button { margin-top: 6px; margin-right: 4px; }

/* modal + toasts */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; place-items: center; z-index: 5000; }
#modal.on { display: grid; }
#modal .box { background: var(--panel); border-radius: 10px; padding: 18px; width: min(460px, 94vw); max-height: 90vh; overflow: auto; box-shadow: var(--shadow); }
#modal h3 { margin: 0 0 12px; }
#modal label { display: grid; gap: 3px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
#modal label.chk { display: flex; gap: 8px; align-items: center; color: var(--text); }
#modal input:not([type=checkbox]), #modal select, #modal textarea { width: 100%; color: var(--text); }
#modal .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
#toasts { position: fixed; right: 14px; bottom: 14px; z-index: 6000; display: grid; gap: 8px; }
.toast { background: var(--panel); border-left: 5px solid var(--brand); padding: 10px 14px; border-radius: 6px; box-shadow: var(--shadow); max-width: 320px; }
.toast.alarm { border-left-color: var(--bad); } .toast.ok { border-left-color: var(--ok); }
pre.small { font-size: 12px; white-space: pre-wrap; word-break: break-word; margin: 0; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #nav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; }
  #nav .brand, #nav .who span { display: none; }
  #nav .who { margin: 0; border: 0; padding: 0; }
  #mapbar { left: 10px; top: 8px; max-width: calc(100% - 20px); }
  #drawbar { left: 10px; top: 96px; }
  #playback { left: 10px; right: 10px; }
}

.livebox { display: flex; align-items: center; gap: 6px; padding: 0 10px 8px; font-size: 12px; color: var(--muted); }

.pin.person { border-radius: 50%; transform: none; width: 20px; height: 20px; }
.pin.person::after { left: 5px; top: 5px; }
.navhead { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 10px 10px 2px; letter-spacing: .04em; }
#modalBox.wide { width: min(960px, 96vw); }
.multi { display: flex; flex-wrap: wrap; gap: 4px 12px; max-height: 150px; overflow: auto; padding: 4px; border: 1px solid var(--line); border-radius: 6px; }
.coords { display: flex; gap: 6px; } .coords input { flex: 1; }
.kvs { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 8px 0; }
.kvs dt { color: var(--muted); } .kvs dd { margin: 0; word-break: break-word; }
.sec { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.timeline { list-style: none; margin: 0; padding: 0; } .timeline li { padding: 3px 0; border-left: 2px solid var(--line); padding-left: 10px; font-size: 13px; }
.pcards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; margin-bottom: 14px; }
.profcard { background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 14px; cursor: pointer; text-align: left; }
.profcard.on { border-color: var(--brand); } .profcard h4 { margin: 0 0 6px; } .profcard p { margin: 0; color: var(--muted); font-size: 13px; }
.notice { background: var(--panel); border-left: 5px solid var(--warn); padding: 10px 14px; border-radius: 6px; box-shadow: var(--shadow); margin-bottom: 12px; }
.chatwrap { display: grid; grid-template-columns: 260px 1fr; gap: 12px; height: calc(100vh - 90px); }
.threads { overflow: auto; } .threads .t { padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.threads .t.on { background: var(--bg); } .threads .t small { color: var(--muted); display: block; }
.chat { display: flex; flex-direction: column; min-height: 0; } .msgs { flex: 1; overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 75%; padding: 6px 10px; border-radius: 10px; background: var(--line); align-self: flex-start; white-space: pre-wrap; word-break: break-word; }
.msg.me { align-self: flex-end; background: var(--brand); color: var(--brand-ink); } .msg small { display: block; opacity: .7; font-size: 11px; }
.msg a { color: inherit; text-decoration: underline; cursor: pointer; }
.composer { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); } .composer textarea { min-height: 38px; height: 38px; flex: 1; }
@media (max-width: 760px) { .chatwrap { grid-template-columns: 1fr; height: auto; } }
.flink { cursor: pointer; color: var(--brand); text-decoration: underline; }

#nearbar { bottom: 18px; left: 56px; width: min(620px, calc(100% - 80px)); max-height: 46%; overflow: auto; display: none; }
#nearbar.on { display: block; }
.stepsol { margin: 6px 0 6px 18px; padding: 0; } .stepsol li { margin-bottom: 6px; }
.qr { width: 160px; height: 160px; background: #fff; padding: 6px; border-radius: 6px; } .qr svg { width: 100%; height: 100%; }
@media (max-width: 760px) { #nearbar { left: 10px; width: calc(100% - 20px); } }

.basesel{background:var(--panel,#fff);color:var(--fg,#1b2430);border:1px solid var(--line,#c9d1da);border-radius:8px;padding:4px;display:flex;gap:4px;align-items:center;box-shadow:0 1px 4px rgba(0,0,0,.25);font-size:12px}
.basesel span{padding:0 4px;opacity:.7}
.basesel button{padding:4px 8px;border-radius:6px;border:1px solid transparent;background:transparent;color:inherit;cursor:pointer;font-size:12px}
.basesel button.on{background:#1d5fd6;color:#fff}
.basesel button:disabled{opacity:.4;cursor:not-allowed}
@media(max-width:520px){.basesel span{display:none}.basesel button{padding:4px 6px}}

.trk .trkbar{flex-wrap:wrap}
#trkmap{height:min(52vh,480px);border-radius:8px;border:1px solid var(--line,#c9d1da);margin:8px 0}
.trkcards{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:8px;margin:8px 0}
.trkcard{background:var(--panel,#fff);border:1px solid var(--line,#c9d1da);border-radius:8px;padding:8px 10px;display:flex;flex-direction:column}
.trkcard b{font-size:17px}.trkcard span{font-size:12px;opacity:.7}
.stopn{width:22px;height:22px;border-radius:50%;background:#d98a00;color:#fff;font-weight:700;font-size:12px;display:flex;align-items:center;justify-content:center;border:2px solid #fff;box-shadow:0 1px 3px rgba(0,0,0,.4)}
@media print{.trkprint{display:block!important}#nav,.trkbar,.bar,#toasts,.basesel,.leaflet-control-zoom{display:none!important}body,#main,.page{overflow:visible!important;height:auto!important}#trkmap{height:380px}}

.trkprint{display:none}.trkprint h3{margin:0 0 4px}
.trkfilt{align-items:center;gap:12px}
.evn{width:24px;height:24px;border-radius:50%;color:#fff;font-size:12px;display:flex;align-items:center;justify-content:center;border:2px solid #fff;box-shadow:0 0 3px #0008}
.evn.in{background:#1a8f3c}.evn.out{background:#d9480f}
