/* KALORA Dashboard: konsol pelacak kawanan (hanya tampilan) */
:root {
  --rail: #12302a;
  --rail-2: #1d4a3d;
  --rail-ink: #e8f0eb;
  --rail-muted: #a9c2b6;

  --ground: #eef1ef;
  --panel: #ffffff;
  --sunk: #f5f7f6;
  --ink: #111a16;
  --muted: #56635d;
  --line: #dde3df;
  --line-2: #c3ccc6;
  --action: #12302a;
  --action-hover: #1d4a3d;
  --action-ink: #ffffff;
  --focus: #2563eb;

  --aman-fg: #14663c;   --aman-bg: #e1f3e7;   --aman-bd: #86c79c;   --aman-solid: #17713f;
  --pisah-fg: #6e4f00;  --pisah-bg: #fcf0c4;  --pisah-bd: #d9ad22;  --pisah-solid: #d4a512;
  --zona-fg: #a3231b;   --zona-bg: #fde4e0;   --zona-bd: #e08a81;   --zona-solid: #c9392f;
  --off-fg: #4d5651;    --off-bg: #e9ecea;    --off-bd: #aab3ad;    --off-solid: #5f6963;

  --r-sm: 6px; --r-md: 8px; --r-lg: 12px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --shadow: 0 1px 2px rgb(17 26 22 / .06), 0 6px 16px -6px rgb(17 26 22 / .10);
  --bar-h: 72px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 16px; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 15px/1.5 var(--font); font-variant-numeric: tabular-nums; }
::selection { background: #bfe0cf; color: var(--ink); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
* { scrollbar-color: #b5c1ba transparent; scrollbar-width: thin; }
a { color: var(--action); text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: .94rem; font-weight: 700; text-transform: none; }
h3 { font-size: .94rem; font-weight: 650; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.ico { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.muted { color: var(--muted); }
.empty { color: var(--muted); margin: 0; }
.note { color: var(--muted); font-size: .8rem; margin: 6px 0 10px; }

/* banner koneksi putus */
.banner { position: sticky; top: 0; z-index: 2000; display: flex; gap: 10px; align-items: center; padding: 12px 20px; background: var(--zona-solid); color: #fff; font-weight: 600; }
.banner[hidden] { display: none; }

/* ---------- shell: rail + area kerja ---------- */
.shell { display: grid; grid-template-columns: 76px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.rail {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 8px;
  background: var(--rail); color: var(--rail-ink);
}
.rail-logo { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: 12px; border-radius: var(--r-lg); color: #7fd6a4; background: var(--rail-2); }
.rail-logo svg { width: 30px; height: 30px; }
.rail-links { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; width: 100%; }
.rail-links a, .rail-btn {
  display: grid; justify-items: center; gap: 3px; width: 100%; padding: 9px 4px;
  border-radius: var(--r-md); color: var(--rail-muted); text-decoration: none;
  font: 600 .8rem/1.2 var(--font); transition: background-color .15s, color .15s;
}
.rail-links a:hover, .rail-btn:hover { background: var(--rail-2); color: var(--rail-ink); }
.rail-out { margin: auto 0 0; width: 100%; }
.rail-btn { border: 0; background: none; cursor: pointer; }
.rail :focus-visible { outline-color: #8ab4ff; }

.work { min-width: 0; padding: 0 24px 40px; }

/* bilah atas */
.bar { display: flex; align-items: center; gap: 16px 24px; flex-wrap: wrap; min-height: var(--bar-h); padding: 14px 0 14px; }
.bar-title { margin-right: auto; }
.bar-title p { margin: 0; color: var(--muted); font-size: .8rem; }
.filter { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.field { display: grid; gap: 3px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.field select { min-width: 200px; }
.filter-note { margin: 0; color: var(--muted); font-size: .8rem; }

.conn { align-self: flex-end; min-height: 40px; display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); font-size: .94rem; font-weight: 600; color: var(--muted); }
.conn .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off-bd); }
.conn[data-state="ok"] { color: var(--aman-fg); border-color: var(--aman-bd); background: var(--aman-bg); }
.conn[data-state="ok"] .dot { background: var(--aman-solid); box-shadow: 0 0 0 3px rgb(31 138 79 / .18); }
.conn[data-state="err"] { color: var(--zona-fg); border-color: var(--zona-bd); background: var(--zona-bg); }
.conn[data-state="err"] .dot { background: var(--zona-solid); }

/* panel */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); }

/* ---------- panggung: peta + daftar kalung ---------- */
.stage {
  display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 16px;
  height: calc(100vh - var(--bar-h) - 32px); height: calc(100dvh - var(--bar-h) - 32px); min-height: 560px;
}
.map-panel { display: flex; flex-direction: column; overflow: hidden; }
#map {
  position: relative; flex: 1; min-height: 360px; margin: 0;
  background-color: #f7faf8;
  background-image: radial-gradient(circle, #d3dcd6 1px, transparent 1.2px);
  background-size: 22px 22px;
}
#map svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#map .fence { fill: rgb(31 138 79 / .06); stroke: var(--rail); stroke-width: 2; stroke-dasharray: 8 6; }
#map .fence-lbl { font-size: 12px; font-weight: 700; fill: var(--rail); text-anchor: middle; paint-order: stroke; stroke: #f7faf8; stroke-width: 4px; }
#map .ble { fill: rgb(37 99 235 / .09); stroke: #2f6fd6; stroke-width: 1.5; }
#map .ble.far { fill: rgb(212 165 18 / .12); stroke: #b38a0b; }
#map .ble.none { fill: none; stroke: #b38a0b; stroke-dasharray: 3 4; }
#map .dot { stroke: #fff; stroke-width: 3; filter: drop-shadow(0 1px 2px rgb(17 26 22 / .35)); }
#map .lbl { font-size: 12.5px; font-weight: 700; fill: var(--ink); paint-order: stroke; stroke: #f7faf8; stroke-width: 4px; }
#map .alarm .lbl { fill: var(--zona-fg); }
#map .pulse { fill: none; stroke: var(--zona-solid); stroke-width: 2.5; animation: pulse 1.4s cubic-bezier(.16, 1, .3, 1) infinite; transform-box: fill-box; transform-origin: center; }
#map .off { opacity: .45; }
#map .dim { opacity: .15; }
@keyframes pulse { from { transform: scale(1); opacity: .9; } to { transform: scale(2.8); opacity: 0; } }
.map-empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; }
.map-note { margin: 0; padding: 10px 18px 12px; border-top: 1px solid var(--line); }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .8rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 7px; }
.lg { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.lg.fence { border: 2px dashed var(--rail); background: rgb(31 138 79 / .06); }
.lg.ble { border: 1.5px solid #2f6fd6; background: rgb(37 99 235 / .09); }
.lg.ble-none { border: 1.5px dashed #b38a0b; }

/* daftar kalung */
.roster { display: flex; flex-direction: column; overflow: hidden; }
.roster .panel-head { padding: 10px 16px; }
.nodes { flex: 1; min-height: 0; overflow-y: auto; padding: 10px; display: grid; grid-auto-rows: max-content; gap: 10px; align-content: start; overscroll-behavior: contain; }
.nodes > .empty { padding: 24px 4px; text-align: center; }

.node {
  --st-fg: var(--off-fg); --st-bg: var(--off-bg); --st-bd: var(--off-bd); --st-solid: var(--off-solid);
  border: 1px solid var(--st-bd); border-radius: var(--r-lg); background: var(--panel); overflow: hidden;
}
.node[data-status="aman"] { --st-fg: var(--aman-fg); --st-bg: var(--aman-bg); --st-bd: var(--aman-bd); --st-solid: var(--aman-solid); }
.node[data-status="terpisah_kawanan"] { --st-fg: var(--pisah-fg); --st-bg: var(--pisah-bg); --st-bd: var(--pisah-bd); --st-solid: var(--pisah-solid); }
.node[data-status="keluar_zona"] { --st-fg: var(--zona-fg); --st-bg: var(--zona-bg); --st-bd: var(--zona-bd); --st-solid: var(--zona-solid); }
.node-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; background: var(--st-bg); border-bottom: 1px solid var(--st-bd); }
.node-head h3 { margin: 0; font-size: .94rem; font-weight: 700; letter-spacing: .01em; color: var(--ink); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; border-radius: 999px; background: var(--st-solid); color: #fff; font-weight: 700; font-size: .94rem; white-space: nowrap; }
.node[data-status="terpisah_kawanan"] .chip { color: #2b1f00; }
.chip .ico { width: 18px; height: 18px; }
.node-body { padding: 10px 12px 12px; display: grid; gap: 8px; }
.reason { margin: 0; font-weight: 650; font-size: .94rem; line-height: 1.4; }
.kond { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.kond .sub { margin: 0 2px 0 0; }
.kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 12px; margin: 0; }
.kv div { min-width: 0; padding: 5px 0; border-top: 1px solid var(--line); }
.kv dt { font-size: .8rem; color: var(--muted); }
.kv dd { margin: 0; font-weight: 650; font-size: .94rem; overflow-wrap: anywhere; }
.sub { font-size: .8rem; font-weight: 600; color: var(--muted); margin: 0 0 4px; }
.ov { margin: 0; padding: 8px 10px; border-radius: var(--r-md); background: #e7eefc; color: #1c4aa6; font-size: .94rem; font-weight: 600; }

.badge { display: inline-block; padding: 1px 8px; margin-right: 4px; border-radius: 999px; font-size: .8rem; font-weight: 700; border: 1px solid; }
.badge.fix { color: var(--aman-fg); background: var(--aman-bg); border-color: var(--aman-bd); }
.badge.terakhir { color: var(--pisah-fg); background: var(--pisah-bg); border-color: var(--pisah-bd); }
.badge.simulasi { color: #3b3a7a; background: #ecebfa; border-color: #a9a7dd; border-style: dashed; }
.badge.gnss-on { color: #1c4aa6; background: #e7eefc; border-color: #9ab7ee; }
.badge.gnss-off { color: var(--muted); background: var(--sunk); border-color: var(--line-2); }

.nb { margin: 0; padding: 0; list-style: none; display: grid; }
.nb li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-top: 1px solid var(--line); font-size: .94rem; }
.ktag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .8rem; font-weight: 700; border: 1px solid; white-space: nowrap; }
.ktag[data-k="terpisah_kawanan"] { color: var(--pisah-fg); background: var(--pisah-bg); border-color: var(--pisah-bd); }
.ktag[data-k="keluar_zona"] { color: var(--zona-fg); background: var(--zona-bg); border-color: var(--zona-bd); }
.node-actions { display: grid; gap: 4px; padding-top: 8px; border-top: 1px solid var(--line); }
.node-actions .btn { width: 100%; }

/* ---------- bawah: riwayat + pengaturan ---------- */
.lower { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; margin-top: 16px; align-items: start; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: .94rem; }
th, td { text-align: left; padding: 10px 18px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 650; background: var(--sunk); position: sticky; top: 0; }
tbody tr:hover td { background: #fafbfa; }
td.t { white-space: nowrap; color: var(--muted); }
tbody td:nth-child(2) { white-space: nowrap; }
.tag { --st-fg: var(--off-fg); --st-bg: var(--off-bg); --st-bd: var(--off-bd); display: inline-block; padding: 1px 8px; border-radius: 999px; font-weight: 650; font-size: .8rem; border: 1px solid var(--st-bd); background: var(--st-bg); color: var(--st-fg); white-space: nowrap; }
.tag[data-s="aman"] { --st-fg: var(--aman-fg); --st-bg: var(--aman-bg); --st-bd: var(--aman-bd); }
.tag[data-s="terpisah_kawanan"] { --st-fg: var(--pisah-fg); --st-bg: var(--pisah-bg); --st-bd: var(--pisah-bd); }
.tag[data-s="keluar_zona"] { --st-fg: var(--zona-fg); --st-bg: var(--zona-bg); --st-bd: var(--zona-bd); }
td.empty { padding: 28px 18px; text-align: center; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 18px; flex-wrap: wrap; border-top: 1px solid var(--line); }
.pager .btn { min-height: 38px; padding: 6px 12px; display: inline-flex; align-items: center; gap: 4px; }
.pager .ico { width: 18px; height: 18px; }
#ev-info { font-size: .94rem; }

.settings form { display: grid; gap: 14px; padding: 16px 18px 18px; }
.settings label { display: grid; gap: 4px; font-weight: 600; font-size: .94rem; }
.settings small { font-weight: 400; font-size: .8rem; color: var(--muted); }
.lower-main { display: grid; gap: 16px; min-width: 0; }
/* uji buzzer: ringkas, di atas daftar kalung */
.side-col { display: flex; flex-direction: column; gap: 16px; min-height: 0; min-width: 0; }
.side-col .roster { flex: 1; min-height: 0; }
.buzz-panel { flex: none; }
.buzz-panel .panel-head { display: grid; gap: 2px; padding: 10px 16px; }
.buzz-note { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.35; }
.buzz { display: grid; padding: 2px 16px 6px; max-height: 180px; overflow-y: auto; }
.buzz > .empty { padding: 8px 0; }
.buzz-row { display: grid; grid-template-columns: 78px minmax(0, 1fr); align-items: center; gap: 2px 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.buzz-row:first-child { border-top: 0; }
.buzz-row strong { font-size: .8rem; font-weight: 700; }
.buzz-btns { display: grid; grid-template-columns: 1fr 1.25fr 1.15fr; gap: 6px; }
.buzz-btns .btn { min-height: 36px; padding: 4px 6px; font-size: .8rem; line-height: 1.15; white-space: nowrap; }
.buzz-row .buzz-state { grid-column: 1 / -1; }
.buzz-state { margin: 0; font-size: .8rem; color: #1c4aa6; font-weight: 600; min-height: 1.2em; }
.buzz-state:empty { min-height: 0; }

/* kontrol */
select, input[type=number], input[type=text], input[type=password] {
  font: inherit; font-size: .94rem; padding: 8px 10px; min-height: 40px;
  border: 1px solid var(--line-2); border-radius: var(--r-md); background: #fff; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
select:hover, input:hover { border-color: #9aa8a0; }
select:focus-visible, input:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgb(37 99 235 / .25); }
input::placeholder { color: #6b7771; }
.btn {
  font: inherit; font-weight: 650; font-size: .94rem; min-height: 44px; padding: 8px 14px;
  border-radius: var(--r-md); border: 1px solid var(--line-2); background: #fff; color: var(--ink);
  cursor: pointer; transition: background-color .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--sunk); border-color: #9aa8a0; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--action); border-color: var(--action); color: var(--action-ink); }
.btn.primary:hover { background: var(--action-hover); border-color: var(--action-hover); }
.msg { margin: 0; min-height: 1.2em; font-size: .94rem; font-weight: 600; }
.msg.ok { color: var(--aman-fg); } .msg.err { color: var(--zona-fg); }
.leaflet-container { font-family: var(--font); }

/* ---------- responsif ---------- */
@media (max-width: 1280px) {
  .stage { grid-template-columns: minmax(0, 1fr) 380px; }
  .lower { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 1024px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: sticky; top: 0; z-index: 1000; height: auto; flex-direction: row; padding: 8px 12px; gap: 6px; }
  .rail-logo { width: 40px; height: 40px; margin: 0 6px 0 0; }
  .rail-logo svg { width: 24px; height: 24px; }
  .rail-links { display: flex; width: auto; }
  .rail-links a, .rail-btn { width: auto; padding: 6px 10px; }
  .rail-out { margin: 0 0 0 auto; width: auto; }
  html { scroll-padding-top: 76px; }
  .work { padding: 0 16px 32px; }
  .stage { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 0; }
  #map { flex: none; height: 440px; }
  .nodes { overflow: visible; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
  .lower { grid-template-columns: minmax(0, 1fr); }
  .side-col { display: contents; }
  .buzz-panel { order: -1; }
}
@media (max-width: 560px) {
  .rail-links a span, .rail-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .rail-links a, .rail-btn { padding: 8px; }
  .bar { align-items: stretch; }
  .filter, .field, .field select { width: 100%; min-width: 0; }
  .filter { display: grid; grid-template-columns: 1fr 1fr; }
  #map { height: auto; min-height: 0; aspect-ratio: 16 / 11; }
  .pager #ev-info { order: -1; flex-basis: 100%; }
  .nodes { grid-template-columns: minmax(0, 1fr); padding: 10px; }
  .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .legend { display: grid; }
  #map .lbl, #map .fence-lbl { font-size: 22px; stroke-width: 6px; }
  table { min-width: 0; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tbody tr { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  tbody td { display: block; padding: 0; border: 0; }
  tbody td:nth-child(2) { white-space: nowrap; font-weight: 700; justify-self: end; }
  tbody td:nth-child(n+3), tbody td.empty { grid-column: 1 / -1; }
  tbody tr:hover td { background: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}

/* ---------- halaman login ---------- */
.login-page { min-height: 100vh; min-height: 100dvh; }
.login-shell { display: grid; grid-template-columns: minmax(320px, 5fr) 7fr; min-height: 100vh; min-height: 100dvh; }
.login-side { display: flex; flex-direction: column; justify-content: space-between; gap: 32px; padding: 40px 48px; background: var(--rail); color: var(--rail-ink); }
.login-brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 1.25rem; letter-spacing: .06em; color: #fff; }
.login-brand .logo { width: 38px; height: 38px; color: #7fd6a4; }
.login-fence { width: 100%; max-width: 420px; align-self: center; }
.lf-fence { fill: rgb(127 214 164 / .06); stroke: #7fd6a4; stroke-width: 2; stroke-dasharray: 8 6; }
.lf-ble { fill: rgb(138 180 255 / .10); stroke: #8ab4ff; stroke-width: 1.5; }
.lf-dot { stroke: var(--rail); stroke-width: 3; }
.lf-dot.ok { fill: #4cc283; }
.lf-dot.out { fill: #f0675c; }
.login-tag { margin: 0; max-width: 38ch; color: var(--rail-muted); font-size: .94rem; line-height: 1.55; }
.login-main { display: grid; place-items: center; padding: 32px 20px; }
.login-panel { width: 100%; max-width: 380px; }
.login-panel h1 { margin-bottom: 4px; }
.login-panel .note { margin: 0 0 22px; font-size: .94rem; }
.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 5px; font-weight: 600; font-size: .94rem; }
.login-form input { width: 100%; min-height: 44px; }
.login-form .btn { width: 100%; margin-top: 6px; }
.login-error { display: flex; gap: 8px; align-items: center; margin: 0 0 16px; padding: 10px 12px; border: 1px solid var(--zona-bd); border-radius: var(--r-md); background: var(--zona-bg); color: var(--zona-fg); font-weight: 600; font-size: .94rem; }
.login-error .ico { width: 20px; height: 20px; }
@media (max-width: 820px) {
  .login-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .login-side { padding: 20px 24px; gap: 12px; }
  .login-fence { display: none; }
  .login-tag { font-size: .94rem; }
}
