/* RONC – tema Angkatan Pertahanan Awam Malaysia (biru & oren) */
:root {
  --navy: #0B2A6F;
  --navy-2: #123B8F;
  --blue: #1565D8;
  --blue-soft: #E8F0FC;
  --orange: #F26A10;
  --orange-soft: #FFF1E6;
  --red: #D62828;
  --red-soft: #FDE8E8;
  --amber: #E8A100;
  --amber-soft: #FFF6DB;
  --green: #2B8A3E;
  --ink: #1B2333;
  --muted: #6B7385;
  --line: #DFE4EE;
  --bg: #F3F5F9;
  --card: #FFFFFF;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Bar atas ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px; padding: 8px 16px;
  background: linear-gradient(90deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #fff; border-bottom: 4px solid var(--orange); min-height: 62px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { height: 46px; width: auto; background: #fff; border-radius: 50%; padding: 3px; }
.brand-title { font-weight: 800; letter-spacing: .3px; font-size: 15px; line-height: 1.15; }
.brand-sub { font-size: 12px; opacity: .85; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a { color: #fff; text-decoration: none; padding: 8px 12px; border-radius: 6px; font-weight: 600; opacity: .85; }
.nav a:hover { background: rgba(255,255,255,.1); opacity: 1; }
.nav a.on { background: var(--orange); opacity: 1; }
.nav-out { border: 1px solid rgba(255,255,255,.35); }
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #999; display: inline-block; }
.dot.ok { background: #3DDC84; box-shadow: 0 0 0 3px rgba(61,220,132,.25); }
.dot.bad { background: #FF6B6B; box-shadow: 0 0 0 3px rgba(255,107,107,.25); }
.clock { font-variant-numeric: tabular-nums; font-weight: 700; padding-left: 8px; border-left: 1px solid rgba(255,255,255,.3); }

/* ---------- Banner SOS ---------- */
.sos-banner {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--red); color: #fff; font-weight: 700; animation: sosflash 1s infinite alternate;
}
.sos-icon { background: #fff; color: var(--red); padding: 2px 8px; border-radius: 4px; font-weight: 900; }
.sos-banner button { margin-left: auto; background: #fff; color: var(--red); border: 0; border-radius: 6px; padding: 6px 14px; font-weight: 800; cursor: pointer; }
@keyframes sosflash { from { background: #D62828; } to { background: #A01010; } }

/* ---------- Susun atur utama ---------- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.main { flex: 1; display: grid; grid-template-columns: 300px 1fr 320px; min-height: 0; }
.panel { background: var(--card); display: flex; flex-direction: column; min-height: 0; }
.panel-units { border-right: 1px solid var(--line); }
.panel-msgs { border-left: 1px solid var(--line); }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 15px; color: var(--navy); text-transform: uppercase; letter-spacing: .5px; }
.panel-head .count { background: var(--blue); color: #fff; border-radius: 10px; padding: 1px 8px; font-size: 12px; font-weight: 700; }
.panel-head .hint { margin-left: auto; font-size: 12px; color: var(--muted); }
.unit-list, .msg-list { overflow-y: auto; flex: 1; padding: 8px; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }

/* ---------- Kad unit ---------- */
.unit { border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 10px; margin-bottom: 8px; cursor: pointer; background: #fff; transition: box-shadow .15s; }
.unit:hover { box-shadow: 0 2px 10px rgba(11,42,111,.12); }
.unit.u-b { border-left: 4px solid var(--navy); }
.unit.u-lost { background: var(--amber-soft); border-color: #F0D48A; }
.unit.u-sos { background: var(--red-soft); border-color: var(--red); border-left: 4px solid var(--red); }
.u-row { display: flex; align-items: center; gap: 6px; }
.u-cs { font-weight: 800; font-size: 15px; border-bottom: 3px solid; line-height: 1.2; }
.u-bat { margin-left: auto; font-weight: 700; font-size: 12px; }
.u-nm { font-size: 13px; margin: 3px 0 2px; }
.u-meta, .u-pos { font-size: 12px; color: var(--muted); }
.u-pos { font-variant-numeric: tabular-nums; }
.u-base { font-size: 12px; margin-top: 4px; color: var(--navy); background: var(--blue-soft); border-radius: 5px; padding: 3px 6px; }
.lost-txt { color: #9A6B00; }
.bat-ok { color: var(--green); } .bat-mid { color: #B07800; } .bat-low { color: var(--red); }

.tag { font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 4px; letter-spacing: .4px; }
.tag-b { background: var(--navy); color: #fff; }
.tag-t { background: var(--orange-soft); color: #B24A00; }
.tag-sos { background: var(--red); color: #fff; }

/* ---------- Mesej ---------- */
.msg { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 8px; background: #fff; cursor: pointer; }
.msg-urgent { border-left: 4px solid var(--red); background: #FFF8F8; }
.msg-head { display: flex; gap: 6px; align-items: baseline; font-size: 13px; }
.msg-time { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.msg-txt { font-size: 14px; margin: 4px 0; white-space: pre-wrap; word-break: break-word; }
.msg-urgent .msg-txt { font-weight: 700; color: #A01010; }
.msg-foot { display: flex; gap: 10px; font-size: 11px; color: var(--muted); }
.ack { color: var(--green); font-weight: 700; }

/* ---------- Peta ---------- */
.map-wrap { position: relative; min-width: 0; min-height: 0; }
#map { position: absolute; inset: 0; }
.map-tools { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; align-items: center; background: #fff; padding: 6px 8px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.15); font-size: 13px; z-index: 2; }
.map-tools select, .map-tools button { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; background: #fff; cursor: pointer; }
.map-tools button { background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 600; }
.legend { position: absolute; bottom: 30px; right: 10px; background: rgba(255,255,255,.95); padding: 6px 10px; border-radius: 8px; font-size: 12px; display: flex; gap: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.12); z-index: 2; }
.lg { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; border: 2px solid #fff; box-shadow: 0 0 0 1px #999; }
.lg-b { background: var(--navy); border-radius: 2px; }
.lg-t { background: var(--orange); }
.lg-lost { background: #9AA1AE; }
.lg-sos { background: var(--red); }

/* Penanda unit */
.mk { cursor: pointer; }
.mk-dot { width: 20px; height: 20px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.45); background: var(--orange); position: relative; }
.mk-b .mk-dot { background: var(--navy); border-radius: 4px; width: 22px; height: 22px; }
.mk-lost .mk-dot { background: #9AA1AE; }
.mk-sos .mk-dot { background: var(--red); animation: sospulse 1s infinite; }
@keyframes sospulse { 0% { box-shadow: 0 0 0 0 rgba(214,40,40,.7); } 100% { box-shadow: 0 0 0 18px rgba(214,40,40,0); } }
.mk-arrow { position: absolute; left: 50%; top: 50%; width: 0; height: 0; margin: -17px 0 0 -5px; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 8px solid var(--ink); transform-origin: 5px 17px; display: none; }
.mk-label { position: absolute; left: 26px; top: 0; white-space: nowrap; font-weight: 800; font-size: 12px; background: rgba(255,255,255,.92); padding: 1px 5px; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.25); color: var(--ink); }
.mk-lost .mk-label { color: #8A5A00; }
.mk-sos .mk-label { background: var(--red); color: #fff; }

/* Popup */
.maplibregl-popup-content { padding: 0; border-radius: var(--radius); overflow: hidden; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.maplibregl-popup-close-button { color: #fff; font-size: 20px; padding: 2px 8px; }
.pp { font-size: 13px; min-width: 270px; }
.pp-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: var(--orange); color: #fff; }
.pp-head.pp-b { background: var(--navy); }
.pp-head.pp-sos { background: var(--red); }
.pp-head .tag { margin-right: 22px; background: rgba(255,255,255,.2); color: #fff; }
.pp-cs { font-weight: 900; font-size: 17px; }
.pp-nm { font-size: 12px; opacity: .95; }
.pp-alert { background: var(--red-soft); color: var(--red); font-weight: 800; padding: 6px 12px; }
.pp-lost { background: var(--amber-soft); color: #7A5200; padding: 6px 12px; font-size: 12px; }
.pp-tbl, .pp-near { width: 100%; border-collapse: collapse; }
.pp-tbl th { text-align: left; color: var(--muted); font-weight: 600; padding: 3px 12px; width: 38%; vertical-align: top; }
.pp-tbl td { padding: 3px 12px 3px 0; font-variant-numeric: tabular-nums; }
.pp-sub { background: var(--blue-soft); color: var(--navy); font-weight: 700; font-size: 12px; padding: 6px 12px; margin-top: 6px; }
.pp-near td { padding: 4px 12px; border-bottom: 1px solid var(--line); }
.pp-near td.num { padding-left: 0; }

/* ---------- Tab telefon ---------- */
.tabbar { display: none; }
.badge { background: var(--red); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 4px; }

@media (max-width: 1200px) { .main { grid-template-columns: 260px 1fr 280px; } }
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .brand img { height: 38px; }
  .brand-title { font-size: 12px; }
  .brand-sub { font-size: 11px; }
  .nav { order: 3; width: 100%; margin: 0; overflow-x: auto; }
  .nav a { padding: 6px 10px; font-size: 13px; }
  .status { margin-left: auto; font-size: 12px; }
  .main { grid-template-columns: 1fr; }
  .panel-units, .panel-msgs, .map-wrap { display: none; border: 0; }
  body[data-tab="map"] .map-wrap { display: block; }
  body[data-tab="units"] .panel-units { display: flex; }
  body[data-tab="msgs"] .panel-msgs { display: flex; }
  .legend { bottom: 34px; right: 6px; gap: 6px; font-size: 11px; flex-wrap: wrap; max-width: 60%; }
  .tabbar { display: flex; border-top: 1px solid var(--line); background: #fff; padding-bottom: env(safe-area-inset-bottom); }
  .tabbar button { flex: 1; padding: 12px 0; border: 0; background: none; font-weight: 700; color: var(--muted); border-top: 3px solid transparent; }
  .tabbar button.on { color: var(--navy); border-top-color: var(--orange); }
}

/* ---------- Log masuk ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 60%, var(--blue) 100%); padding: 16px; }
.login-card { background: #fff; width: 100%; max-width: 380px; border-radius: 14px; padding: 28px 26px; box-shadow: 0 20px 60px rgba(0,0,0,.35); border-top: 6px solid var(--orange); text-align: center; }
.login-card img { height: 110px; }
.login-card h1 { font-size: 17px; color: var(--navy); margin: 12px 0 4px; line-height: 1.3; letter-spacing: .3px; }
.login-sub { color: var(--muted); font-size: 12px; margin-bottom: 18px; }
.login-card label { display: block; text-align: left; font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.login-card input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 14px; }
.login-card input:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
.login-card button { width: 100%; padding: 12px; background: var(--orange); color: #fff; border: 0; border-radius: 8px; font-weight: 800; cursor: pointer; font-size: 15px; }
.login-card button:hover { background: #D85A08; }
.login-foot { margin-top: 16px; font-size: 11px; color: var(--muted); }
.alert { background: var(--red-soft); color: var(--red); padding: 8px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }

/* ---------- Halaman biasa (laporan / gateway) ---------- */
.page { display: flex; flex-direction: column; min-height: 100vh; }
.content { max-width: 1200px; width: 100%; margin: 0 auto; padding: 18px 16px 40px; }
.content h1 { color: var(--navy); font-size: 20px; margin: 0 0 4px; }
.content .lead { color: var(--muted); margin: 0 0 16px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 15px; color: var(--navy); margin: 0 0 12px; text-transform: uppercase; letter-spacing: .4px; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.form-row label { display: flex; flex-direction: column; font-size: 12px; font-weight: 700; color: var(--muted); gap: 4px; }
.form-row input, .form-row select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; min-width: 150px; }
.btn { display: inline-block; padding: 9px 16px; border-radius: 7px; border: 0; cursor: pointer; font-weight: 700; text-decoration: none; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-orange { background: var(--orange); color: #fff; }
.btn-line { background: #fff; color: var(--navy); border: 1px solid var(--navy); }
.btn:disabled { opacity: .5; cursor: default; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { background: var(--navy); color: #fff; text-align: left; padding: 8px; font-weight: 700; }
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:nth-child(even) td { background: #FAFBFD; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--orange); border-radius: 8px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; color: var(--navy); }
.stat span { font-size: 12px; color: var(--muted); }
#rmap { height: 460px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.log { background: #0E1626; color: #CFE3FF; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; padding: 10px; border-radius: 8px; height: 320px; overflow-y: auto; white-space: pre-wrap; }
.gw-state { display: flex; gap: 16px; flex-wrap: wrap; margin: 12px 0; font-weight: 700; }
.gw-state span { background: var(--blue-soft); color: var(--navy); padding: 6px 10px; border-radius: 6px; }
.report-head { display: none; }

@media print {
  .topbar, .no-print, .maplibregl-ctrl { display: none !important; }
  body { background: #fff; }
  .content { max-width: none; padding: 0; }
  .card { border: 0; padding: 0; break-inside: avoid; }
  .report-head { display: flex; align-items: center; gap: 12px; border-bottom: 3px solid var(--orange); padding-bottom: 8px; margin-bottom: 12px; }
  .report-head img { height: 60px; }
  #rmap { height: 420px; }
}
.maplibregl-popup-content .pp { max-height: 62vh; overflow-y: auto; }
.pp-tbl tr.grid td b { color: var(--navy); font-size: 14px; letter-spacing: .3px; }
.pp-near tr.pp-nh td { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; background: #FAFBFD; }
.u-pos b { color: var(--navy); font-weight: 700; letter-spacing: .2px; }
.msg-grid { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: var(--navy); font-weight: 700; margin-bottom: 2px; }
