:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1d2733;
  --muted: #6b7a8d;
  --line: #e3e8ef;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --danger: #d1242f;
  --ok: #1a7f37;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

code { background: #eef1f6; padding: 1px 5px; border-radius: 4px; font-size: .85em; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: #101827; color: #fff; padding: 16px 24px;
}
.topbar h1 { margin: 0; font-size: 19px; }
.subtitle { margin: 4px 0 0; color: #9fb0c6; font-size: 13px; }
.subtitle code { background: #1e2a3d; color: #cfe0ff; }
.pill {
  background: #17324f; border: 1px solid #2d4d73; color: #9fd0ff;
  padding: 5px 12px; border-radius: 999px; font-size: 12px;
}

main { padding: 20px 24px 40px; max-width: 1500px; margin: 0 auto; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; display: flex; flex-direction: column; gap: 4px;
}
.card-num { font-size: 28px; font-weight: 700; color: var(--accent); }
.card-label { font-size: 13px; color: var(--muted); }

.controls { display: flex; gap: 10px; margin: 18px 0 12px; flex-wrap: wrap; }
.controls input[type="search"] {
  flex: 1 1 320px; padding: 9px 14px; border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 14px;
}
.controls select {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); font-size: 14px;
}
.controls button {
  padding: 9px 18px; border: none; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); font-size: 14px; cursor: pointer;
}
.controls button:hover { filter: brightness(1.08); }

.table-wrap {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 11px 12px; background: #f8fafc;
  border-bottom: 2px solid var(--line); color: var(--muted);
  font-weight: 600; white-space: nowrap; position: sticky; top: 0;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f2f7ff; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }

.thumb {
  width: 96px; height: 56px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--line); background: #000; display: block;
}
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge.cat-sport { background: #fff3e0; color: #b26a00; }
.badge.cat-mpv   { background: #e7f1ff; color: #1254a8; }
.badge.cat-bus   { background: #ede7ff; color: #5b3df5; }
.badge.cat-other { background: #eceff3; color: #5b6775; }
.badge.plate     { background: #101827; color: #ffe066; font-family: Consolas, monospace; letter-spacing: .5px; }
.badge.flag      { background: #ffebe9; color: var(--danger); }
.badge.ok        { background: #e6f4ea; color: var(--ok); }
.muted { color: var(--muted); font-size: 12px; }
.th-sub { font-weight: 400; font-size: 10.5px; color: #9aa8b8; }

/* Tracking state badges (phase_1 state machine) */
.badge.st-init       { background: #eceff3; color: #5b6775; }
.badge.st-stationary { background: #fff4e0; color: #b26a00; }
.badge.st-ready      { background: #e7f1ff; color: #1254a8; }
.badge.st-departed   { background: #e6f4ea; color: var(--ok); }
.badge.visit         { background: #f3e8ff; color: #6b2fd6; }
.ellip {
  max-width: 340px; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(10, 16, 26, .55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 24px;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--panel); border-radius: 14px; max-width: 980px; width: 100%;
  max-height: 88vh; overflow-y: auto; padding: 22px 26px; position: relative;
}
.modal-close {
  position: absolute; top: 10px; right: 14px; border: none; background: none;
  font-size: 26px; cursor: pointer; color: var(--muted);
}
.modal h2 { margin: 0 0 4px; font-size: 20px; }
.detail-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px 18px; margin: 14px 0 6px;
}
.detail-grid .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.detail-grid .v { font-size: 14.5px; margin-top: 2px; }
.gallery { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.gallery figure { margin: 0; width: 150px; }
.gallery img {
  width: 150px; height: 94px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--line); background: #000;
}
.gallery figcaption { font-size: 11px; color: var(--muted); text-align: center; margin-top: 3px; }

footer { padding: 14px 24px 26px; color: var(--muted); font-size: 12.5px; text-align: center; }

/* ---------- Live Monitor ---------- */
.hidden { display: none !important; }

.monitor {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); margin-top: 18px; overflow: hidden;
}
.mon-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 14px; flex-wrap: wrap; padding: 14px 18px;
  border-bottom: 1px solid var(--line); background: #fbfcfe;
}
.mon-head h2 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 10px; }
.pill.mon-on  { background: #0f3d21; border-color: #1f7a42; color: #7ff0aa; }
.pill.mon-off { background: #3a2426; border-color: #7a3a3f; color: #ff9d9d; }

.mon-controls { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.mon-field { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--muted); }
.mon-field input, .mon-field select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); font-size: 13.5px; color: var(--ink); min-width: 170px;
}
.mon-field input[type="number"] { min-width: 80px; }
#mon-start, #mon-stop {
  padding: 9px 20px; border: none; border-radius: var(--radius);
  font-size: 14px; cursor: pointer; color: #fff;
}
#mon-start { background: var(--ok); }
#mon-stop  { background: var(--danger); }
#mon-start:disabled, #mon-stop:disabled { opacity: .45; cursor: not-allowed; }
.upload-btn {
  display: inline-block; margin-top: 18px; padding: 8px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); border-radius: 8px; font-size: 13px;
}

.mon-body { display: grid; grid-template-columns: minmax(280px, 460px) 1fr; gap: 16px; padding: 16px 18px; }
.mon-snap {
  background: #0c1220; border-radius: 10px; min-height: 220px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.mon-snap img { width: 100%; display: block; }
.mon-snap .empty { color: #7f8ea3; padding: 20px; }
.mon-side { min-width: 0; }
.mon-metrics { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.mon-error {
  background: #ffebe9; color: var(--danger); border: 1px solid #ffc9c5;
  padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 8px;
}
.track-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.track-list li {
  background: #eef3fb; border: 1px solid #d7e2f3; border-radius: 999px;
  padding: 4px 12px; font-size: 12.5px;
}
.mon-feed-title { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 6px 0; }
.events { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.events li {
  display: flex; gap: 10px; align-items: baseline; padding: 7px 12px;
  border-bottom: 1px solid var(--line); font-size: 13px;
}
.events li:last-child { border-bottom: none; }
.events .ev-time { color: var(--muted); font-family: Consolas, monospace; font-size: 12px; min-width: 62px; }
.events .badge.ev-det       { background: #e7f1ff; color: #1254a8; }
.events .badge.ev-match     { background: #f3e8ff; color: #6b2fd6; }
.events .badge.ev-flag      { background: #ffebe9; color: var(--danger); font-weight: 700; }
.events .badge.ev-error     { background: #fff3e0; color: #b26a00; }
.events .badge.ev-start, .events .badge.ev-stop { background: #eceff3; color: #5b6775; }
.events li.ev-flag { background: #fff6f5; }

@media (max-width: 980px) {
  .mon-body { grid-template-columns: 1fr; }
}

/* Banner mode statis (versi online) */
.static-banner {
  margin: 14px 18px 0;
  padding: 10px 14px;
  border: 1px solid #f0c36d;
  background: #fff8e8;
  color: #7a5b00;
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.5;
}
.static-banner code { background: #f5e9c8; padding: 1px 5px; border-radius: 4px; }
