:root {
  --blue: #0047D4; --blue-2: #1E73E8; --blue-d: #0A2A6B;
  --ink: #0F1724; --mute: #5A6578; --line: #E3E8F0; --tint: #F4F6FA;
  --ochre: #C2562B; --ok: #12784A; --err: #B4232A; --white: #fff;
  --r: 12px; --shadow: 0 10px 30px rgba(15, 23, 36, .08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: "Poppins", system-ui, sans-serif; color: var(--ink); background: var(--tint); line-height: 1.5; font-size: 15px; }
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }

.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--blue); color: #fff; font-weight: 600; padding: 9px 16px; border-radius: 999px; border: 2px solid var(--blue); cursor: pointer; font-size: .9rem; }
.btn:hover { background: var(--blue-2); border-color: var(--blue-2); }
.btn-ghost { background: transparent; color: var(--blue); }
.btn-ghost:hover { background: rgba(0,71,212,.08); color: var(--blue); }
.btn-danger { background: transparent; color: var(--err); border-color: transparent; padding: 6px 10px; }
.btn-danger:hover { background: rgba(180,35,42,.08); border-color: transparent; }
.btn-sm { padding: 5px 12px; font-size: .82rem; }

input, select, textarea { padding: 9px 11px; border: 1px solid #CBD3E1; border-radius: 9px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
label { display: grid; gap: 5px; font-size: .82rem; font-weight: 600; }
.msg { font-size: .88rem; min-height: 1.3em; }
.msg.err { color: var(--err); } .msg.ok { color: var(--ok); }

/* top bar */
.top { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-in { display: flex; align-items: center; gap: 16px; height: 60px; padding: 0 20px; }
.top img { height: 32px; }
.top .who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: .88rem; color: var(--mute); }
.top .who b { color: var(--ink); font-weight: 600; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 8px 12px; border-radius: 8px; color: var(--mute); font-weight: 500; font-size: .9rem; }
.tabs a.on, .tabs a:hover { background: var(--tint); color: var(--ink); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(900px 400px at 80% 110%, #E9D5C3 0%, rgba(233,213,195,0) 60%), var(--tint); }
.login-card { width: min(400px, 100%); background: #fff; border-radius: 16px; padding: 32px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-card img { height: 46px; justify-self: start; margin-bottom: 4px; }
.login-card h1 { font-size: 1.3rem; }
.login-card p { color: var(--mute); font-size: .9rem; }

/* customer view */
.layout { display: grid; grid-template-columns: 1fr 340px; gap: 20px; padding: 20px; align-items: start; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--r); }
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-h h2 { font-size: 1rem; }
.site-h { font-size: .78rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--blue); margin: 18px 0 10px; }
.site-h:first-child { margin-top: 0; }
.site-h span { color: var(--mute); font-weight: 500; letter-spacing: 0; text-transform: none; margin-left: 6px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.tile { background: #0b1220; border-radius: 10px; overflow: hidden; cursor: pointer; position: relative; aspect-ratio: 16 / 9; border: 0; padding: 0; width: 100%; display: block; text-align: left; }
.tile:focus-visible { outline: 3px solid var(--blue-2); outline-offset: 2px; }
.tile canvas, .tile iframe { width: 100%; height: 100%; display: block; border: 0; pointer-events: none; }
.tile .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 12px 8px; background: linear-gradient(transparent, rgba(0,0,0,.7)); color: #fff; font-size: .85rem; display: flex; justify-content: space-between; gap: 8px; }
.tile .cap small { opacity: .75; }
.tile.flash { box-shadow: 0 0 0 3px var(--ochre); }
.empty { padding: 40px 20px; text-align: center; color: var(--mute); }

.feed { max-height: calc(100vh - 140px); overflow: auto; }
.ev { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; padding: 11px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ev:hover { background: var(--tint); }
.ev.new { animation: hl 3s ease-out; }
@keyframes hl { from { background: #FCEBDD; } to { background: transparent; } }
.ev .dot { grid-row: span 2; width: 10px; height: 10px; border-radius: 50%; background: var(--ochre); margin-top: 7px; }
.ev .dot.vehicle { background: var(--blue); }
.ev b { font-size: .9rem; }
.ev small { color: var(--mute); font-size: .8rem; }
.ev.has-thumb { grid-template-columns: auto 1fr 72px; }
.ev .thumb { grid-column: 3; grid-row: 1 / span 2; width: 72px; height: 41px; object-fit: cover; border-radius: 6px; background: #000; align-self: center; }
.modal-v img.still { width: 100%; height: 100%; object-fit: contain; display: block; }
.btn.light { color: #fff; border-color: rgba(255,255,255,.5); }
.btn.light:hover { background: rgba(255,255,255,.12); color: #fff; }
.pill { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--tint); color: var(--mute); margin-left: 4px; text-transform: capitalize; }
.live-dot { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--mute); }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #9aa5b8; }
.live-dot.on::before { background: #1DB954; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(5,10,20,.85); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-box { width: min(1280px, 100%); }
.modal-h { display: flex; justify-content: space-between; align-items: center; color: #fff; margin-bottom: 10px; gap: 10px; }
.modal-h small { opacity: .7; }
.modal-v { background: #000; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; }
.modal-v canvas, .modal-v iframe { width: 100%; height: 100%; display: block; border: 0; }

/* pan / tilt / zoom controls under the full-screen video */
.modal { overflow-y: auto; }
.modal-box:has(.ptz:not([hidden])) { width: min(1280px, 100%, calc((100vh - 250px) * 16 / 9)); min-width: min(100%, 560px); }
.ptz { display: flex; flex-wrap: wrap; gap: 18px 28px; align-items: center; justify-content: center; margin-top: 12px; color: #fff; }
.ptz-pad { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); gap: 6px; }
.ptz-b { width: 48px; height: 48px; border-radius: 12px; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.1); color: #fff; font-size: 1.35rem; line-height: 1; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.ptz-b:hover { background: rgba(255,255,255,.18); }
.ptz-b.on, .ptz-b:active { background: var(--blue); border-color: var(--blue); }
.ptz-b.home { font-size: 1.1rem; background: rgba(255,255,255,.05); }
.ptz-b:focus-visible { outline: 3px solid var(--blue-2); outline-offset: 2px; }
.ptz-zoom { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: .78rem; opacity: .95; }
.ptz-side { display: grid; gap: 10px; min-width: 200px; max-width: 280px; }
.ptz-side label { color: #fff; font-weight: 500; }
.ptz-side select { padding: 6px 9px; }
.ptz-msg { font-size: .8rem; opacity: .75; min-height: 1.2em; }
.ptz-msg.err { color: #FFB4B4; opacity: 1; }

/* arming: per-site badge + settings dialog */
.site-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 18px 0 10px; }
.site-row:first-child { margin-top: 0; }
.site-row .site-h { margin: 0; }
.site-arm { display: flex; gap: 6px; flex-wrap: wrap; }
.arm-badge { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px; font-size: .8rem; font-weight: 600; cursor: pointer; color: var(--ink); }
.arm-badge .link { color: var(--blue); font-weight: 500; margin-left: 4px; }
.arm-badge:hover { border-color: var(--blue); }
.arm-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--mute); }
.arm-badge.on .arm-dot { background: var(--ok); }
.arm-badge.off .arm-dot { background: var(--err); }
.arm-badge.sched .arm-dot { background: #D99A1E; }
.arm-card { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; }
.arm-now { font-weight: 600; }
.arm-now.on { color: var(--ok); } .arm-now.off { color: var(--err); } .arm-now.sched { color: #A86F00; }
.arm-modes { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; display: grid; gap: 6px; }
.arm-modes legend { font-size: .82rem; font-weight: 600; padding: 0 4px; }
label.radio, label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: .9rem; }
label.radio input, label.check input { width: auto; }
table.sched { margin: 8px 0; }
table.sched td, table.sched th { padding: 5px 6px; }
table.sched input[type=time] { padding: 5px 7px; }
.btn-row.wrap { flex-wrap: wrap; align-items: center; }
.small { font-size: .8rem; }
.ev.disarmed { opacity: .55; }
.ev.disarmed .dot { background: var(--mute); }
.pill.off { background: var(--tint); color: var(--mute); }

#notifBtn.on { background: rgba(18,120,74,.1); color: var(--ok); border-color: var(--ok); }

.net-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #c9c9d1; margin-right: 7px; vertical-align: middle; }
.net-dot.on { background: var(--ok); } .net-dot.off { background: var(--err); }

/* activity log */
.act-card { width: min(720px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; }
.act-list { max-height: 60vh; overflow-y: auto; }
table.act td { padding: 7px 8px; font-size: .85rem; vertical-align: top; }
table.act td:first-child { white-space: nowrap; }
.act-filter { display: flex; gap: 10px; align-items: end; padding: 16px; border-bottom: 1px solid var(--line); background: #FBFCFE; flex-wrap: wrap; }
.act-filter label { min-width: 220px; }

/* admin: unit health + map */
.health { display: grid; gap: 14px; padding: 16px; }
.health-sum { display: flex; gap: 10px; flex-wrap: wrap; }
.health-chip { display: flex; align-items: baseline; gap: 8px; padding: 10px 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; font-size: .85rem; color: var(--mute); }
.health-chip b { font-size: 1.4rem; color: var(--ink); }
.health-chip.on b { color: var(--ok); } .health-chip.off b { color: var(--err); } .health-chip.warn b { color: #A86F00; }
.health-map { height: 380px; border-radius: 12px; border: 1px solid var(--line); z-index: 0; }
.health-map.picking { cursor: crosshair; outline: 3px solid var(--blue); }
.health-map.picking .leaflet-container, .health-map.picking .leaflet-grab { cursor: crosshair; }
.status.warn { background: #FFF4DC; color: #A86F00; }
.map-label { font: 600 12px Poppins, sans-serif; background: rgba(255,255,255,.9); border: 0; box-shadow: 0 1px 4px rgba(0,0,0,.2); padding: 1px 6px; }
.health .help { padding: 0; }

/* admin: alarm zone editor */
.zone-wrap { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); gap: 18px; padding: 16px; }
@media (max-width: 900px) { .zone-wrap { grid-template-columns: 1fr; } }
.zone-left { display: grid; gap: 10px; align-content: start; }
.zone-stage { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; user-select: none; }
.zone-img, .zone-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.zone-img { object-fit: fill; }
.zone-svg { cursor: crosshair; touch-action: none; }
.zshape { stroke-width: 5; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.zshape.area { fill: rgba(18,170,90,.22); stroke: #19c26b; }
.zshape.line { fill: none; stroke: #ffb020; stroke-width: 6; }
.zshape.ignore { fill: rgba(160,160,170,.35); stroke: #d8d8de; stroke-dasharray: 10 8; }
.zshape.other { opacity: .45; }
.zshape.other.area { fill: rgba(255,255,255,.08); stroke: #fff; }
.zshape.active { stroke-width: 7; }
.zpt { fill: #fff; stroke: #0047D4; stroke-width: 6; cursor: grab; }
.zpt:hover { fill: #cfe0ff; }
.zarrow { stroke: #ffb020; stroke-width: 6; stroke-dasharray: 14 10; }
.zarrow-head { fill: #ffb020; }
.legend { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--mute); margin-left: auto; }
.legend i { width: 14px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 8px; }
.legend i.area { background: #19c26b; } .legend i.line { background: #ffb020; } .legend i.ignore { background: #c9c9d1; }
.zone-right { display: grid; gap: 14px; align-content: start; }
.zone-list { display: grid; gap: 6px; }
.zone-list-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.zone-item { display: grid; grid-template-columns: auto 1fr; gap: 0 10px; text-align: left; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font: inherit; }
.zone-item.on, .zone-item:hover { border-color: var(--blue); }
.zone-item small { grid-column: 2; color: var(--mute); font-size: .78rem; }
.zone-swatch { grid-row: span 2; width: 12px; height: 12px; border-radius: 3px; margin-top: 5px; background: #19c26b; }
.zone-swatch.line { background: #ffb020; }
.zone-form { display: grid; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.zone-objs { display: flex; gap: 14px; align-items: center; }
.zone-objs .lbl, .zone-edit-h { font-size: .82rem; font-weight: 600; }

/* admin: camera control settings */
details.ctl summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
details.ctl summary::-webkit-details-marker { display: none; }
details.ctl .link { color: var(--blue); font-size: .8rem; font-weight: 500; }
.ctl-form { display: grid; gap: 8px; margin-top: 10px; min-width: 220px; }
.ctl-form .check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.ctl-form .check input { width: auto; }

/* admin */
.admin { padding: 20px; display: grid; gap: 20px; max-width: 1280px; margin: 0 auto; }
.admin .panel { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; color: var(--mute); font-weight: 600; background: var(--tint); }
td code { font-size: .78rem; background: var(--tint); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; padding: 16px; align-items: end; border-bottom: 1px solid var(--line); background: #FBFCFE; }
.muted { color: var(--mute); }
.status { font-size: .78rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.status.active { background: #E3F5EC; color: var(--ok); }
.status.future { background: #E8F0FE; color: var(--blue); }
.status.ended { background: var(--tint); color: var(--mute); }
.status.off { background: #FBE9EA; color: var(--err); }
.help { padding: 12px 16px; font-size: .84rem; color: var(--mute); }
.help code { background: var(--tint); padding: 1px 6px; border-radius: 5px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .feed { max-height: 50vh; }
  .top-in { padding: 0 12px; gap: 10px; }
  .top .who span { display: none; }
  .admin { padding: 12px; }
  .tabs { overflow-x: auto; }
}
@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .top img { height: 26px; }
}
.pad { padding: 16px; }
.pad-sm { padding: 12px 16px; }
.filter-bar { padding: 10px 16px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.health-issue { color: #A86F00; font-size: .8rem; }
.btn-row { display: flex; gap: 8px; }
.form-row .msg { grid-column: 1 / -1; }
.btn { white-space: nowrap; }
@media (max-width: 560px) { .top .who b { display: none; } .top .who { gap: 6px; } }
