:root {
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --accent-soft: #dbe5fb;
  --bg: #f3f5f9;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e3e7ee;
  --navy: #0f1b33;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 27, 51, .06), 0 4px 16px rgba(15, 27, 51, .06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

/* ---------- header */
.topbar {
  background: var(--navy); color: #fff; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 4px solid var(--accent); position: sticky; top: 0; z-index: 500;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; }
.brand .seal {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 12px; font-weight: 800; border: 2px solid rgba(255,255,255,.7);
}
.brand small { display: block; font-weight: 500; opacity: .75; font-size: 12px; }
.topbar .btn { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.2); }

/* ---------- buttons & inputs */
.btn {
  border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 9px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-weight: 600; font-size: 14px; text-decoration: none; color: var(--ink);
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 9px; font-size: 13px; border-radius: 7px; }
.btn.lg { padding: 13px 18px; font-size: 16px; border-radius: 11px; }
.btn.block { width: 100%; justify-content: center; }
.icon-btn { width: 34px; height: 34px; padding: 0; justify-content: center; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=tel], input[type=date], input[type=time],
input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 80px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- panels */
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 2px 8px;
  border-radius: 99px; background: #eef1f6; color: var(--muted);
}
.badge.on { background: #dcfce7; color: var(--ok); }
.badge.duty { background: var(--accent-soft); color: var(--accent); }
.badge.off { background: #fee2e2; color: var(--bad); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; display: inline-block; }
.dot.on { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.count { background: var(--bad); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 6px; font-weight: 700; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #f8f9fc; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
tr:hover td { background: #fafbfd; }

/* ---------- login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--navy), #1e2d4f 60%, var(--accent)); }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { color: var(--ink); margin-bottom: 18px; }
.login-card .brand small { color: var(--muted); opacity: 1; }
.error { color: var(--bad); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }

/* ---------- tabs */
.tabs { display: flex; gap: 4px; background: var(--panel); padding: 6px 12px 0; border-bottom: 1px solid var(--line); overflow-x: auto; position: sticky; top: 60px; z-index: 400; }
.tab { border: 0; background: transparent; padding: 10px 14px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
main.page { padding: 16px; max-width: 1400px; margin: 0 auto; }

/* ---------- toast */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 9999; display: grid; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--navy); color: #fff; padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; animation: pop .2s ease; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,27,51,.55); display: grid; place-items: center; z-index: 2000; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; padding: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; margin-bottom: 14px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* ---------- chat */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; background: #f7f8fb; border-radius: 10px; min-height: 200px; }
.msg { max-width: 78%; padding: 8px 11px; border-radius: 12px; background: #fff; border: 1px solid var(--line); align-self: flex-start; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.msg time { display: block; font-size: 11px; opacity: .7; margin-top: 2px; }
.chat-form { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- color picker */
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch.sel { box-shadow: 0 0 0 3px var(--ink); }
input[type=color] { width: 44px; height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: #fff; cursor: pointer; }

/* ---------- call overlay */
.call-ui { position: fixed; inset: 0; background: #0b1324; z-index: 5000; color: #fff; display: flex; flex-direction: column; }
.call-ui video.remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #0b1324; }
.call-ui video.local { position: absolute; right: 14px; top: 14px; width: 28vw; max-width: 200px; aspect-ratio: 3/4; object-fit: cover; border-radius: 12px; border: 2px solid rgba(255,255,255,.5); z-index: 2; background: #000; transform: scaleX(-1); }
.call-info { position: relative; z-index: 2; text-align: center; padding: 60px 20px 0; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.call-info .avatar { width: 96px; height: 96px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 36px; font-weight: 800; margin: 0 auto 16px; }
.call-info h2 { font-size: 24px; }
.call-actions { position: relative; z-index: 2; margin-top: auto; display: flex; justify-content: center; gap: 18px; padding: 30px; }
.call-actions .btn { width: 64px; height: 64px; border-radius: 50%; justify-content: center; font-size: 13px; padding: 0; border: 0; background: rgba(255,255,255,.18); color: #fff; flex-direction: column; gap: 2px; }
.call-actions .btn.danger { background: var(--bad); }
.call-actions .btn.ok { background: #16a34a; }
.call-actions .btn.off { background: #fff; color: #0b1324; }
.call-actions .btn svg { width: 24px; height: 24px; }

/* ---------- alarm overlay */
.alarm-ui { position: fixed; inset: 0; z-index: 6000; display: grid; place-items: center; text-align: center; color: #fff; padding: 24px; animation: flash .6s infinite alternate; }
@keyframes flash { from { background: #7f1d1d; } to { background: #ef4444; } }
.alarm-ui h1 { font-size: 40px; letter-spacing: 2px; }
.alarm-ui p { font-size: 20px; max-width: 520px; margin: 12px auto 28px; }
.alarm-ui .btn { background: #fff; color: #7f1d1d; font-size: 18px; padding: 16px 28px; border: 0; }

/* ---------- map */
.leaflet-container { font: inherit; border-radius: 10px; }
.pin { width: 34px; height: 34px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); display: grid; place-items: center; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.pin span { transform: rotate(45deg); color: #fff; font-size: 11px; font-weight: 800; }
.pin.stale { filter: grayscale(1) opacity(.7); }
.pin.report { width: 22px; height: 22px; border-width: 2px; }
/* Police Trainee posting points */
.tbox { width: 14px; height: 14px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.45); }
.tlabel i.sq { border-radius: 2px; }
.tlabel { display: inline-flex; align-items: center; gap: 6px; }
.tlabel i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.leaflet-control-layers { color: #111; }

/* ---------- photos */
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; background: #eef1f6; }
.thumb.more { display: grid; place-items: center; font-weight: 700; color: var(--muted); }
.pick { position: relative; display: inline-block; }
.pick img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.pick button { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--bad); color: #fff; font-weight: 700; cursor: pointer; line-height: 1; }
.viewer { background: rgba(0,0,0,.88); }
.viewer-box { max-width: 92vw; text-align: center; }
.viewer-box img { max-width: 100%; max-height: 80vh; border-radius: 8px; display: block; margin: 0 auto; }
.drive-tag { font-size: 12px; font-weight: 600; }
.drive-tag.ok { color: var(--ok); }
.drive-tag.wait { color: var(--warn); }
code.block { display: block; background: #0f1b33; color: #e5e7eb; padding: 10px; border-radius: 8px; font-size: 12px; max-height: 160px; overflow: auto; white-space: pre; }
ol.steps { padding-left: 20px; margin: 8px 0; }
ol.steps li { margin-bottom: 6px; }

svg.i { width: 18px; height: 18px; flex: none; }
