:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --line: #e3e6eb;
  --accent: #1f6feb;
  --ok: #1a7f37;
  --ok-bg: #e6f4ea;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --bad: #c62828;
  --bad-bg: #fde8e8;
  --flash: #fff1a8;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
/* atribut hidden harus menang atas display: grid/flex milik kelas (gate sempat tampil bersama app) */
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1, h2, h3, h4 { margin: 0; }
h2 { font-size: 15px; }
h4 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--accent); }
button {
  font: inherit; border: 1px solid var(--accent); background: var(--accent); color: #fff;
  border-radius: 6px; padding: 7px 14px; cursor: pointer;
}
button.ghost { background: transparent; color: var(--accent); }
button:disabled { opacity: .6; cursor: default; }
.muted { color: var(--muted); }
.error { color: var(--bad); }
.empty { padding: 12px 0; margin: 0; }

/* ---------- gate ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.gate-card { width: min(380px, 100%); padding: 24px; display: grid; gap: 10px; }
.gate-card input { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; width: 100%; }
.gate-card p { margin: 0; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2;
}
.brand { font-weight: 700; }
.status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; }
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; white-space: nowrap;
  background: #eef0f3; color: var(--muted);
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.banner { margin: 8px 16px 0; padding: 8px 12px; background: var(--bad-bg); border-radius: 6px; }

/* ---------- layout ---------- */
.layout {
  display: grid; gap: 12px; padding: 12px 16px 24px;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  grid-template-areas: "alarms detail" "devices detail";
  align-items: start;
}
.alarms { grid-area: alarms; }
.detail { grid-area: detail; position: sticky; top: 56px; max-height: calc(100vh - 68px); overflow: auto; }
.devices { grid-area: devices; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.subhead { font-size: 13px; margin: 14px 0 6px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "alarms" "detail" "devices"; }
  .detail { position: static; max-height: none; }
}

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7f9fc; }
tbody tr.selected { background: #e8f0fe; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge {
  display: inline-block; margin: 0 4px 2px 0; padding: 1px 6px; border-radius: 4px; font-size: 11px;
  background: #eef0f3; color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

@keyframes flash { from { background: var(--flash); } to { background: transparent; } }
.flash, .flash td { animation: flash 2.5s ease-out; }

/* ---------- detail ---------- */
.detail-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.detail-title h3 { font-size: 16px; }
.detail-title .small-button { margin-left: auto; padding: 3px 10px; font-size: 13px; }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.delays { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 12px 0 4px; }
.delay { border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.delay .label { font-size: 12px; color: var(--muted); }
.delay .value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.photos figure { margin: 0; }
.photos img { width: 100%; height: auto; display: block; border-radius: 6px; background: #000; }
figcaption, .file-meta { font-size: 12px; color: var(--muted); margin-top: 3px; overflow-wrap: anywhere; }
.video-card { border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-bottom: 8px; }
.video-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
video { width: 100%; max-width: 100%; display: block; border-radius: 6px; background: #000; }
.video-placeholder {
  display: grid; place-items: center; min-height: 120px; border-radius: 6px;
  background: #f1f3f6; color: var(--muted); text-align: center; padding: 12px;
}
pre { background: #f6f8fa; padding: 8px; border-radius: 6px; overflow: auto; max-height: 280px; font-size: 12px; }
details { margin-top: 12px; }
.file-list { margin: 0; padding-left: 18px; font-size: 13px; }
.file-list li { margin: 2px 0; overflow-wrap: anywhere; }
/* badge evidence boleh turun baris — status video tidak boleh terpotong di scroll horizontal */
td.evidence { white-space: normal; min-width: 120px; }
td.kind { white-space: normal; min-width: 90px; }

/* ---------- tab & halaman Device ---------- */
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 6px 12px; border-radius: 6px; color: var(--muted); text-decoration: none; font-weight: 600; }
.tabs a:hover { background: #eef0f3; }
.tabs a.active { background: #e8f0fe; color: var(--accent); }
.page-devices { display: grid; gap: 12px; padding: 12px 16px 24px; max-width: 1100px; margin: 0 auto; }
.small { font-size: 12px; }
.spacer { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button.danger { background: var(--bad); border-color: var(--bad); }
button.ghost.danger { background: transparent; color: var(--bad); }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.inline-form input { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; flex: 1 1 200px; min-width: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { background: #eef0f3; color: var(--text); border: 1px solid transparent; padding: 4px 10px; border-radius: 999px; font-size: 13px; }
.chip.active { background: #e8f0fe; color: var(--accent); border-color: #c6d8fb; }
.chip .count { font-variant-numeric: tabular-nums; color: var(--muted); }
.device-list { display: grid; gap: 6px; }
.device-item { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.device-summary {
  width: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; text-align: left;
  background: transparent; color: var(--text); border: 0; padding: 10px 12px; border-radius: 8px;
}
.device-summary:hover { background: #f7f9fc; }
.device-summary .chevron { color: var(--muted); width: 1em; }
.device-summary .dsno { font-weight: 700; font-variant-numeric: tabular-nums; }
.device-summary .badges { display: flex; flex-wrap: wrap; gap: 2px; }
.device-summary .gps-mini { margin-left: auto; font-size: 12px; }
.device-detail { border-top: 1px solid var(--line); padding: 10px 12px 12px; display: grid; gap: 10px; }
.device-info { display: grid; gap: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.device-gps h4 { margin-top: 4px; }
.talk-bar { border-color: #c6d8fb; background: #f8fbff; }
.talk-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.talk-head h2 { font-size: 15px; }
.talk-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.ptt { min-width: 180px; padding: 12px 18px; font-weight: 600; touch-action: none; user-select: none; }
.ptt.talking { background: var(--bad); border-color: var(--bad); }
button.ghost.active { background: #e8f0fe; color: var(--accent); }
.pb-volume { display: inline-flex; align-items: center; gap: 4px; }
.pb-volume input { width: 96px; accent-color: var(--accent); }
.meter { flex: 1 1 140px; min-width: 100px; height: 10px; background: #e3e6eb; border-radius: 999px; overflow: hidden; }
.meter > div { height: 100%; width: 0; background: var(--ok); transition: width 80ms linear; }
.check { display: inline-flex; gap: 6px; align-items: center; }
.dialog { padding: 20px; max-width: min(420px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(15, 20, 30, .35); }
.dialog p { margin: 0 0 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
@media (max-width: 600px) {
  .device-summary .gps-mini { margin-left: 0; width: 100%; }
  .ptt { flex: 1 1 100%; }
}
/* grid tanpa template kolom = lebar minimum item mengikuti isi (tabel GPS nowrap) -> meluap di HP */
.page-devices, .device-list, .device-detail, .device-info { grid-template-columns: minmax(0, 1fr); }
.device-item { min-width: 0; }
@media (max-width: 600px) {
  .topbar { row-gap: 6px; }
  .status { order: 3; flex-basis: 100%; }
  #st-counts { font-size: 12px; }
}

/* ---------- live view ---------- */
.live-panel { border-color: #1d2330; }
.live-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 6px 0; }
.live-grid.single { grid-template-columns: minmax(0, 1fr); }
.live-tile { position: relative; margin: 0; background: #0b0f17; border-radius: 6px; overflow: hidden; aspect-ratio: 11 / 9; min-width: 0; }
.live-grid:not(.single) .live-tile { cursor: zoom-in; }
.live-grid.single .live-tile { aspect-ratio: 4 / 3; max-height: 78vh; justify-self: center; }
.live-grid .live-tile.novideo { aspect-ratio: auto; order: 1; align-self: start; cursor: default; }
.live-tile.novideo canvas, .live-tile.novideo figcaption { display: none; }
.live-tile.novideo .live-overlay { position: static; background: none; }
.live-tile canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.live-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 12px; text-align: center;
  color: #d8dee9; font-size: 13px; background: rgba(11, 15, 23, .55);
}
.live-overlay.warn { color: #ffd479; }
.live-tile figcaption {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0; padding: 4px 8px; font-size: 12px; color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, .65)); overflow-wrap: anywhere;
}
@media (max-width: 600px) {
  .live-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- playback (POC-DESIGN §8h-4) ---------- */
.pb-panel { border-color: #1d2330; --pb-label: 22px; }
.pb-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 14px; align-items: start; }
.pb-side { display: grid; gap: 10px; min-width: 0; }
.pb-cal-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 6px; }
.pb-cal-head button { padding: 2px 10px; }
.pb-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; text-align: center; }
.pb-dow { font-size: 11px; color: var(--muted); padding: 2px 0; }
.pb-day {
  font: inherit; font-size: 13px; padding: 5px 0; border-radius: 5px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted); cursor: pointer;
}
.pb-day.has { background: #dff3e4; color: var(--ok); border-color: #b7dfc2; font-weight: 600; }
.pb-day.alarm { box-shadow: inset 0 -3px 0 #e8912d; }
.pb-day.today { outline: 1px dashed var(--muted); outline-offset: -3px; }
.pb-day.selected { background: var(--accent); border-color: var(--accent); color: #fff; }
.pb-legend { margin: 6px 0 0; }
.pb-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: #dff3e4; border: 1px solid #b7dfc2; vertical-align: -1px; }
.pb-dot.alarm { background: #fff; border-color: #e8912d; box-shadow: inset 0 -3px 0 #e8912d; }
.pb-channels { border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px 8px; margin: 0; }
.pb-channels legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.pb-chn { display: flex; flex-wrap: wrap; gap: 4px 14px; }
#pb-side-note { margin: 0; }
#pb-side-note:empty { display: none; }
.pb-main { min-width: 0; display: grid; gap: 8px; }
.pb-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pb-time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px; margin-left: 4px; }
.warn-text { color: var(--warn); }
.pb-timeline-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.pb-timeline {
  position: relative; user-select: none; touch-action: none; cursor: pointer; background: #0f141c; border-radius: 6px;
  padding: 18px 8px 6px; overflow: hidden;
}
.pb-ruler { position: relative; height: 14px; margin-left: var(--pb-label); margin-top: -14px; }
.pb-hour { position: absolute; transform: translateX(-50%); font-size: 10px; color: #8b95a7; }
.pb-hour:first-child { transform: none; }
.pb-hour:last-child { transform: translateX(-100%); }
.pb-rows { display: grid; gap: 4px; }
.pb-row { display: grid; grid-template-columns: var(--pb-label) minmax(0, 1fr); align-items: center; }
.pb-row.off { opacity: .45; }
.pb-row-label { font-size: 11px; color: #c9d1dd; }
.pb-track {
  position: relative; height: 16px; border-radius: 3px;
  background: repeating-linear-gradient(90deg, #1a212c 0 calc(100% / 24 - 1px), #253041 calc(100% / 24 - 1px) calc(100% / 24));
}
.pb-bar { position: absolute; top: 2px; bottom: 2px; background: #2ea44f; border-radius: 2px; }
.pb-bar.alarm { background: #e8912d; }
.pb-cursor { position: absolute; top: 4px; bottom: 4px; width: 2px; margin-left: 8px; background: #ff5a5f; pointer-events: none; }
.pb-hover {
  position: absolute; top: 2px; padding: 0 4px; border-radius: 3px; background: rgba(255, 255, 255, .92); color: #111;
  font-size: 11px; pointer-events: none; font-variant-numeric: tabular-nums;
}
@media (max-width: 820px) {
  .pb-layout { grid-template-columns: minmax(0, 1fr); }
  .pb-side { grid-template-columns: minmax(0, 1fr); }
}
