:root {
  --bg: #f4f5f2; --card: #fff; --ink: #1d2420; --muted: #5d6862; --line: #dfe3dd;
  --brand: #1f5f3f; --brand-2: #2e7d55; --warn: #c77700; --bad: #b3261e; --ok: #2e7d32; --info: #1565c0;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; }
a { color: var(--brand-2); }
header { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand small { display: block; opacity: .8; font-size: 12px; }
.logo { width: 34px; height: 34px; border-radius: 8px; background: #fff; color: var(--brand); display: grid; place-items: center; font-weight: 800; }
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
nav a { color: #fff; text-decoration: none; padding: 6px 12px; border-radius: 6px; white-space: nowrap; opacity: .85; }
nav a.on, nav a:hover { background: rgba(255,255,255,.16); opacity: 1; }
.who { display: flex; gap: 10px; align-items: center; font-size: 13px; white-space: nowrap; }
.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; padding: 0; }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }
main.full { padding: 0; max-width: none; height: calc(100vh - 52px); }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi b { display: block; font-size: 28px; line-height: 1.1; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi.bad b { color: var(--bad); } .kpi.warn b { color: var(--warn); } .kpi.ok b { color: var(--ok); }
.two { grid-template-columns: 1.4fr 1fr; }
@media (max-width: 900px) { .two { grid-template-columns: 1fr; } }
.btn { border: 1px solid var(--brand-2); background: var(--brand-2); color: #fff; padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.btn.ghost { background: #fff; color: var(--brand-2); }
.btn.bad { background: var(--bad); border-color: var(--bad); }
.btn.big { width: 100%; padding: 14px; font-size: 17px; margin: 6px 0; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters { margin-bottom: 12px; }
.filters select, .filters input, .form select, .form input, .form textarea { padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.form label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 3px; }
.form textarea { width: 100%; min-height: 64px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbf9; position: sticky; top: 0; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover { background: #f1f6f2; }
.tablewrap { max-height: calc(100vh - 230px); overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; }
.st-moi { background: #d32f2f; } .st-dang_ra_soat { background: #ef6c00; } .st-da_giao { background: #f9a825; color: #222; }
.st-da_kiem_tra { background: #1565c0; } .st-vi_pham { background: #6a1b9a; } .st-khong_vi_pham { background: #2e7d32; } .st-loai_bo { background: #757575; }
.src { font-size: 12px; padding: 2px 6px; border-radius: 4px; background: #e8efe9; color: var(--brand); white-space: nowrap; }
.src.camera { background: #fde7e7; color: var(--bad); }
.over { color: var(--bad); font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; }
.pri { display: inline-block; min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: #e9ece8; border-radius: 3px; overflow: hidden; width: 60px; display: inline-block; vertical-align: middle; margin-left: 6px; }
.bar i { display: block; height: 100%; background: var(--warn); }
/* login */
.login { max-width: 380px; margin: 10vh auto; }
.login h1 { text-align: center; }
.login input { width: 100%; padding: 11px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 8px; }
.err { color: var(--bad); min-height: 20px; }
/* map */
.mapwrap { position: relative; height: 100%; }
#map, #map2 { position: absolute; inset: 0; }
#map2 { z-index: 2; }
.panel { position: absolute; z-index: 5; top: 10px; left: 10px; width: 290px; max-height: calc(100% - 20px); overflow: auto; background: rgba(255,255,255,.97); border-radius: var(--radius); box-shadow: 0 2px 12px rgba(0,0,0,.18); padding: 12px; font-size: 14px; }
.panel h3 { font-size: 13px; text-transform: uppercase; color: var(--muted); margin: 12px 0 6px; letter-spacing: .03em; }
.panel h3:first-child { margin-top: 0; }
.panel label { display: flex; gap: 8px; align-items: center; padding: 3px 0; cursor: pointer; }
.panel select { width: 100%; padding: 6px; }
.panel .toggle { position: absolute; top: 8px; right: 8px; }
.panel.min { width: auto; } .panel.min > :not(.toggle):not(h3:first-child) { display: none; }
.swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; flex: none; }
.legend div { display: flex; gap: 6px; align-items: center; font-size: 12px; }
.swipe { position: absolute; z-index: 4; top: 0; bottom: 0; width: 4px; background: #fff; box-shadow: 0 0 4px rgba(0,0,0,.5); cursor: ew-resize; touch-action: none; }
.swipe::after { content: "⇆"; position: absolute; top: 50%; left: -16px; width: 36px; height: 36px; border-radius: 50%; background: #fff; display: grid; place-items: center; box-shadow: 0 1px 5px rgba(0,0,0,.4); transform: translateY(-50%); font-weight: 700; }
.swipe-label { position: absolute; z-index: 4; top: 10px; background: rgba(0,0,0,.65); color: #fff; padding: 3px 8px; border-radius: 5px; font-size: 13px; }
.maplibregl-popup-content { padding: 10px 12px; max-width: 280px; }
.popcard img { width: 100%; border-radius: 6px; margin: 6px 0; image-rendering: pixelated; }
.popcard b { font-size: 15px; }
/* compare slider in detail */
.cmp { position: relative; width: 100%; aspect-ratio: 1; max-width: 520px; border-radius: 8px; overflow: hidden; background: #222; touch-action: pan-y; user-select: none; }
.cmp img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.cmp .top { clip-path: inset(0 0 0 50%); }
.cmp input { position: absolute; inset: auto 0 8px 0; width: 90%; margin: 0 5%; z-index: 3; }
.cmp .lbl { position: absolute; top: 8px; z-index: 3; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.cmp .line { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; z-index: 2; left: 50%; pointer-events: none; }
.detail { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 900px) { .detail { grid-template-columns: 1fr; } .detail.field > :last-child { order: -1; } main { padding: 10px; } }
dl.info { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; }
dl.info dt { color: var(--muted); font-size: 13px; } dl.info dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-left: 3px solid var(--line); padding: 4px 0 10px 12px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 8px; width: 11px; height: 11px; border-radius: 50%; background: var(--brand-2); }
.timeline .t { font-size: 12px; color: var(--muted); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.photos figure { margin: 0; font-size: 12px; color: var(--muted); }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }
.minimap { height: 260px; border-radius: 8px; overflow: hidden; position: relative; }
.chart svg { width: 100%; height: 220px; }
.chart text { font-size: 11px; fill: var(--muted); }
#toast { position: fixed; z-index: 50; right: 16px; bottom: 16px; background: #222; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.3); max-width: 360px; cursor: pointer; }
#toast.alarm { background: var(--bad); }
.jobs pre { background: #111; color: #cfe; padding: 10px; border-radius: 8px; max-height: 260px; overflow: auto; font-size: 12px; white-space: pre-wrap; }
.note { background: #fff8e1; border: 1px solid #f3d98b; padding: 10px 12px; border-radius: 8px; font-size: 13px; }
/* field officer mobile */
.task { display: block; text-decoration: none; color: inherit; margin-bottom: 10px; }
.task .row { justify-content: space-between; }
@media (max-width: 640px) {
  header { flex-wrap: wrap; gap: 6px 12px; padding: 8px 10px; }
  nav { order: 3; flex-basis: 100%; }
  .brand small { display: none; }
  main.full { height: calc(100vh - 92px); }
  .panel { width: calc(100% - 20px); max-height: 45%; }
  th:nth-child(n+6), td:nth-child(n+6) { display: none; }
}

/* bản đồ dự phòng (Leaflet) */
.mapwrap #map { z-index: 0; }
.leaflet-image-layer.px { image-rendering: pixelated; }
.lite-note { position: absolute; z-index: 5; bottom: 28px; left: 50%; transform: translateX(-50%); background: rgba(255,248,225,.95); border: 1px solid #f3d98b; padding: 4px 10px; border-radius: 6px; font-size: 12px; max-width: 90%; }
.leaflet-popup-content { margin: 10px 12px; }
