:root {
  --bg: #11161c; --bg2: #1a2129; --bg3: #232c36; --line: #2f3a46; --fg: #e6edf3; --mut: #8b98a5;
  --acc: #c8a64b; --ok: #3fb950; --bad: #f85149; --blue: #4493f8; --warn: #d29922;
  --r: 10px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Georgian", "BPG Arial", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden; -webkit-tap-highlight-color: transparent; }
body.night #app, body.night .gate { filter: sepia(1) saturate(6) hue-rotate(-50deg) brightness(.55); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* gate (login / enroll / unlock) */
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: auto; background: radial-gradient(circle at 50% 0, #1d2833, var(--bg)); }
.card { width: 100%; max-width: 380px; background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 22px; }
.card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: .5px; }
.card h1 small { color: var(--acc); font-size: 12px; display: block; letter-spacing: 1.5px; margin-top: 2px; }
.card p { color: var(--mut); font-size: 14px; line-height: 1.45; }
.field { display: block; margin: 12px 0; }
.field span { display: block; font-size: 12px; color: var(--mut); margin-bottom: 5px; }
.field input, .field select, .field textarea, .inp { width: 100%; padding: 11px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; outline: none; }
.field input:focus, .inp:focus, .field select:focus, .field textarea:focus { border-color: var(--acc); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--mut); margin: 10px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg3); cursor: pointer; min-height: 42px; }
.btn:hover { border-color: var(--mut); }
.btn.pri { background: var(--acc); color: #1a1405; border-color: var(--acc); font-weight: 600; }
.btn.bad { background: transparent; color: var(--bad); border-color: #6e2a28; }
.btn.full { width: 100%; }
.btn.sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; margin: 8px 0 0; }
.warnline { font-size: 11px; color: var(--warn); text-align: center; margin-top: 14px; }
.langsw { display: flex; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.langsw button { background: none; border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; font-size: 12px; cursor: pointer; color: var(--mut); }
.langsw button.on { color: var(--fg); border-color: var(--acc); }

/* app layout */
#app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; background: #0b0f13; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; pointer-events: none; z-index: 450; opacity: .7;
  background: linear-gradient(var(--acc), var(--acc)) center/2px 100% no-repeat, linear-gradient(var(--acc), var(--acc)) center/100% 2px no-repeat; }
#top { position: absolute; top: 0; left: 0; right: 0; z-index: 1000; display: flex; gap: 8px; align-items: center; padding: calc(8px + var(--safe-t)) 10px 8px;
  background: linear-gradient(var(--bg) 60%, transparent); flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: .5px; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.lock { font-size: 13px; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); display: inline-block; }
.conn.on { background: var(--ok); } .conn.off { background: var(--bad); }
#goto { flex: 1; min-width: 140px; }
#gotoIn { width: 100%; padding: 7px 10px; background: rgba(17,22,28,.85); border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.coords { font-size: 12px; line-height: 1.3; text-align: right; color: var(--fg); background: rgba(17,22,28,.85); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
.coords b { color: var(--acc); font-weight: 600; }
@media (max-width: 600px) { .coords { order: 3; width: 100%; text-align: left; } }

#tools { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1300; display: flex; justify-content: space-around; gap: 2px;
  padding: 6px 4px calc(6px + var(--safe-b)); background: var(--bg); border-top: 1px solid var(--line); overflow-x: auto; }
.tool { flex: 1 1 0; min-width: 48px; max-width: 110px; display: flex; flex-direction: column; align-items: center; gap: 2px; background: none; border: 0; padding: 5px 2px; border-radius: 8px; cursor: pointer; color: var(--mut); position: relative; font-size: 11px; }
.tool .ic { font-size: 19px; line-height: 1; color: var(--fg); }
.tool.on { background: var(--bg3); color: var(--acc); }
.tool .badge { position: absolute; top: 1px; right: 10%; background: var(--bad); color: #fff; font-size: 10px; border-radius: 8px; padding: 0 5px; min-width: 16px; }

#fabs { position: absolute; right: 12px; bottom: calc(150px + var(--safe-b)); z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.fab { width: 46px; height: 46px; border-radius: 50%; background: var(--bg2); border: 1px solid var(--line); font-size: 22px; cursor: pointer; }
.fab.on { color: var(--blue); border-color: var(--blue); }
.sos { position: absolute; right: 10px; bottom: calc(76px + var(--safe-b)); z-index: 1000; width: 64px; height: 64px; border-radius: 50%; border: 3px solid #ffb3ad;
  background: var(--bad); color: #fff; font-weight: 800; letter-spacing: 1px; cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none; overflow: hidden; }
#sosRing { position: absolute; inset: 0; border-radius: 50%; background: rgba(255,255,255,.35); transform: scale(0); }
.sos.holding #sosRing { transform: scale(1); transition: transform 1.5s linear; }
.sos.active { animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 14px rgba(248,81,73,.25); } }

.banner { position: absolute; left: 10px; right: 10px; top: calc(90px + var(--safe-t)); z-index: 1100; background: #5a1210; border: 2px solid var(--bad); border-radius: var(--r); padding: 12px; animation: pulse 1.2s infinite; }
.banner .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.modebar, .navbar { position: absolute; left: 50%; transform: translateX(-50%); z-index: 1050; background: var(--bg2); border: 1px solid var(--acc); border-radius: var(--r);
  padding: 8px 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; max-width: calc(100% - 20px); font-size: 14px; }
.modebar { bottom: calc(76px + var(--safe-b)); }
.navbar { top: calc(96px + var(--safe-t)); border-color: var(--blue); }

.panel { position: absolute; z-index: 1200; right: 0; top: 0; bottom: 0; width: min(420px, 100%); background: var(--bg2); border-left: 1px solid var(--line); display: flex; flex-direction: column; padding-top: var(--safe-t); }
@media (max-width: 819px) {
  .panel { top: auto; bottom: calc(60px + var(--safe-b)); height: min(68%, calc(100% - 170px)); width: 100%; border-left: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.5); }
  body.panel-open #fabs { display: none; }
  body.panel-open .sos { bottom: auto; top: calc(108px + var(--safe-t)); width: 52px; height: 52px; font-size: 13px; }
}
@media (min-width: 820px) {
  .panel { bottom: calc(62px + var(--safe-b)); }
  body.panel-open #fabs, body.panel-open .sos { right: 432px; }
}
.phead { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.phead h2 { margin: 0; font-size: 17px; }
.x { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--mut); padding: 6px; }
.pbody { flex: 1; overflow: auto; padding: 12px 14px calc(14px + var(--safe-b)); }
.sect { margin: 0 0 18px; }
.sect h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--mut); margin: 0 0 8px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; gap: 10px; align-items: center; padding: 9px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.item .grow { flex: 1; min-width: 0; }
.item .sub { font-size: 12px; color: var(--mut); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--mut); }
.dot.on { background: var(--ok); }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line); color: var(--mut); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; margin: 8px 0; }
.kv dt { color: var(--mut); } .kv dd { margin: 0; overflow-wrap: anywhere; }

/* chat */
.chatwrap { display: flex; flex-direction: column; height: 100%; }
.msgs { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 6px; padding-bottom: 8px; }
.msg { max-width: 85%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 14px; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: #2a2412; border-color: #5b4b1d; }
.msg .meta { font-size: 11px; color: var(--mut); margin-bottom: 2px; }
.quick { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0; }
.quick button { white-space: nowrap; }
.chatin { display: flex; gap: 6px; }

/* map symbols */
.u-ic { position: relative; width: 0; height: 0; }
.u-dot { position: absolute; left: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px #000; }
.u-hdg { position: absolute; left: -5px; top: -24px; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 10px solid #fff; transform-origin: 5px 24px; }
.u-lbl { position: absolute; left: 12px; top: -9px; white-space: nowrap; font-size: 12px; font-weight: 700; color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000; }
.u-ic.stale { opacity: .45; }
.u-ic.me .u-dot { border-color: var(--acc); }
.m-ic { position: relative; width: 0; height: 0; }
.m-ic svg { position: absolute; left: -15px; top: -15px; filter: drop-shadow(0 0 2px #000); }
.m-ic .u-lbl { left: 17px; }
.sos-ic .u-dot { background: var(--bad) !important; animation: pulse 1s infinite; }
.leaflet-container { background: #0b0f13; font: inherit; }
.leaflet-control-attribution { font-size: 9px; background: rgba(17,22,28,.7) !important; color: var(--mut); }
.leaflet-control-attribution a { color: var(--mut); }
.leaflet-control-zoom { display: none; }
.leaflet-tooltip.mtip { background: var(--bg2); color: var(--fg); border: 1px solid var(--acc); font-size: 12px; }

/* modal & toasts */
.modal { position: fixed; inset: 0; z-index: 3000; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; }
.mbox { width: 100%; max-width: 420px; max-height: 90vh; overflow: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.mbox h3 { margin: 0 0 10px; }
.types { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.types button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-size: 11px; }
.types button.on { border-color: var(--acc); background: #2a2412; }
.swatches { display: flex; gap: 6px; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatches button.on { border-color: #fff; }
.qr { background: #fff; padding: 10px; border-radius: 8px; display: grid; place-items: center; margin: 10px 0; }
.qr img { width: 100%; max-width: 260px; image-rendering: pixelated; }
#toasts { position: fixed; left: 50%; transform: translateX(-50%); top: calc(100px + var(--safe-t)); z-index: 4000; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: var(--bg3); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px; font-size: 14px; max-width: 90vw; }
.toast.bad { border-color: var(--bad); }
.small { font-size: 12px; color: var(--mut); }
.audit { font-size: 12px; }
.audit div { padding: 4px 0; border-bottom: 1px solid var(--line); }

.tool .tl { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tools[data-wide="1"] { justify-content: center; }
.fab.zf { width: 40px; height: 40px; font-size: 20px; margin-left: 3px; }
@media (pointer: coarse) { .fab.zf { display: none; } }

/* more sheet */
.moregrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.moretile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 12px; text-align: center; min-height: 84px; }
.moretile:hover { border-color: var(--acc); }
.moretile .ic { font-size: 24px; }

/* status */
.u-st { position: absolute; left: 12px; top: 6px; font-size: 10px; font-weight: 700; padding: 0 4px; border-radius: 3px; color: #000; white-space: nowrap; }
.stchips { display: flex; flex-wrap: wrap; gap: 6px; }
.stchip { padding: 7px 11px; border-radius: 18px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-size: 13px; }
.stchip::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 6px; }
.stchip.on { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); color: #fff; }
.tag.tok { color: var(--ok); border-color: #2a5b33; }
.tag.tbad { color: var(--bad); border-color: #6e2a28; }

/* map labels */
.ring-lbl { position: absolute; transform: translate(-50%, -100%); font-size: 10px; color: #ffd33d; text-shadow: 0 0 3px #000, 0 0 3px #000; white-space: nowrap; }
.grid-lbl { position: absolute; font-size: 11px; font-weight: 700; color: var(--acc); text-shadow: 0 0 3px #000, 0 0 3px #000; }
.grid-lbl.gx { transform: translate(-50%, 4px); top: 0; }
.grid-lbl.gy { transform: translate(4px, -50%); }
.navarrow { display: inline-block; font-size: 22px; color: var(--blue); transition: transform .3s; }
.navarrow.northup { opacity: .7; }

/* chat extras */
.msg.ci { max-width: 100%; align-self: stretch; border-color: var(--acc); background: #1f1c10; }
.msg.help { border-color: var(--bad); background: #3a1513; }
.msg[onclick], .msg:has(.small) { cursor: pointer; }
.cilist { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.chatimg { display: block; max-width: 100%; height: auto; max-height: 260px; border-radius: 8px; margin: 2px 0; cursor: zoom-in; background: var(--bg3); }
.msg audio { width: 230px; max-width: 100%; height: 36px; }
.imgview { display: grid; place-items: center; }
.imgview img { max-width: 100%; max-height: 82vh; border-radius: 8px; }
.btn.ib { min-width: 40px; padding: 6px; }
.btn.rec { background: var(--bad); border-color: var(--bad); animation: pulse 1s infinite; }
.chatin .inp { min-width: 0; flex: 1; }

/* briefing */
.brief .btitle { font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--fg); }
.btext { white-space: pre-wrap; line-height: 1.5; font-size: 15px; margin-bottom: 10px; }

/* command post */
.cpside { position: absolute; z-index: 1100; left: 0; top: 0; bottom: calc(62px + var(--safe-b)); width: 340px; background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
body.cp #map { left: 340px; }
body.cp #top { left: 340px; }
body.cp #crosshair { left: calc(50% + 170px); }
.demoflag { position: absolute; z-index: 1001; left: 50%; transform: translateX(-50%); top: calc(96px + var(--safe-t)); background: #a371f7; color: #000; font-weight: 800; font-size: 11px; letter-spacing: 2px; padding: 2px 10px; border-radius: 10px; }
@media (min-width: 820px) {
  body.panel-open #top, body.panel-open .banner { right: 430px; }
  body.cp .banner, body.cp .modebar, body.cp .navbar { left: 350px; }
  body.cp .modebar, body.cp .navbar { transform: none; }
}
