:root {
  --bg: #0b1520; --bg2: #122233; --bg3: #1a3048; --fg: #dde7f0; --muted: #8aa1b5;
  --acc: #29b6f6; --danger: #e53935; --border: #24405c;
  --top: 52px; --side: 310px; --panel: 430px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font-family: "Segoe UI", Roboto, Arial, sans-serif; font-size: 14px; overflow: hidden; }
button, .btn { background: var(--bg3); color: var(--fg); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; cursor: pointer; font-size: 13px; display: inline-block; }
button:hover, .btn:hover { border-color: var(--acc); }
button.primary { background: #0277bd; border-color: #0288d1; }
button.danger { background: #5a1a1a; border-color: #8e2a2a; }
button.active-mode { background: #e65100; }
input, select, textarea { background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  border-radius: 5px; padding: 6px 8px; font: inherit; width: 100%; }
.muted { color: var(--muted); font-size: 12px; }

#topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--top); display: flex; align-items: center;
  justify-content: space-between; padding: 0 14px; background: linear-gradient(90deg, #08121b, #13283d);
  border-bottom: 1px solid var(--border); z-index: 1000; }
.brand { font-weight: 700; letter-spacing: 1px; color: #fff; }
.brand .sub { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 8px; letter-spacing: 0; }
.actions { display: flex; gap: 6px; align-items: center; }
#clock { font-family: monospace; color: var(--acc); margin-left: 8px; }

#sidebar { position: fixed; top: var(--top); left: 0; bottom: 0; width: var(--side); background: var(--bg2);
  border-right: 1px solid var(--border); padding: 10px; display: flex; flex-direction: column; gap: 8px; z-index: 900; }
.filters { display: flex; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 11px; padding: 3px 7px; border-radius: 12px; border: 1px solid var(--border); cursor: pointer;
  display: flex; align-items: center; gap: 4px; user-select: none; }
.chip.off { opacity: .35; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1px solid #0006; flex: none; }
#stats { font-size: 12px; color: var(--muted); }
#list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#list li { padding: 7px 8px; border-bottom: 1px solid #1c3349; cursor: pointer; display: flex; gap: 8px; align-items: center; }
#list li:hover, #list li.sel { background: var(--bg3); }
#list li .t { flex: 1; }
#list li .t small { display: block; color: var(--muted); font-size: 11px; }
#list .grp { padding: 6px 4px; font-weight: 700; color: var(--acc); background: transparent; cursor: default; font-size: 12px; text-transform: uppercase; }

#map { position: fixed; top: var(--top); left: var(--side); right: 0; bottom: 0; }
#map.picking { cursor: crosshair; }
#map.picking .leaflet-interactive { cursor: crosshair; }

#panel, #newsPanel { position: fixed; top: calc(var(--top) + 10px); right: 10px; bottom: 34px; width: var(--panel);
  background: rgba(14, 28, 42, .97); border: 1px solid var(--border); border-radius: 10px; z-index: 950;
  display: flex; flex-direction: column; box-shadow: 0 6px 30px #000a; }
#panel.hidden, #newsPanel.hidden, .hidden { display: none !important; }
.panel-head { display: flex; justify-content: space-between; padding: 12px 14px 6px; gap: 8px; }
.panel-head h2 { margin: 0; font-size: 18px; }
.panel-btns { display: flex; gap: 6px; align-items: flex-start; }
.tabs { display: flex; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs button { border: none; border-radius: 6px 6px 0 0; background: transparent; padding: 7px 9px; color: var(--muted); }
.tabs button.active { background: var(--bg3); color: #fff; }
#pBody { padding: 12px 14px; overflow-y: auto; flex: 1; }
table.kv { width: 100%; border-collapse: collapse; }
table.kv td { padding: 6px 4px; border-bottom: 1px solid #1c3349; vertical-align: top; }
table.kv td:first-child { color: var(--muted); width: 38%; }
.badge { display: inline-flex; gap: 5px; align-items: center; padding: 2px 8px; border-radius: 10px; background: var(--bg3); font-size: 12px; }
.warn { background: #3a2c0a; border: 1px solid #6d5313; color: #ffd54f; padding: 6px 8px; border-radius: 6px; font-size: 12px; margin-top: 10px; }
#miniMap { height: 230px; border-radius: 8px; border: 1px solid var(--border); margin: 8px 0; }
.gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.gallery figure { margin: 0; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.gallery img { width: 100%; height: 130px; object-fit: cover; display: block; cursor: zoom-in; }
.gallery figcaption { font-size: 11px; padding: 4px 6px; color: var(--muted); }
.links a { color: var(--acc); display: inline-block; margin: 3px 8px 3px 0; font-size: 12px; }
.hist { list-style: none; padding: 0; margin: 0; }
.hist li { border-left: 2px solid var(--acc); padding: 4px 10px; margin-bottom: 8px; }
.hist time { color: var(--acc); font-size: 11px; display: block; }

#coordbar { position: fixed; bottom: 6px; left: 50%; transform: translateX(-50%); background: #000a; padding: 3px 10px;
  border-radius: 4px; font-family: monospace; font-size: 12px; z-index: 800; }
#toast { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); background: #0277bd; padding: 8px 16px;
  border-radius: 6px; z-index: 3000; opacity: 0; transition: opacity .3s; pointer-events: none; }
#toast.show { opacity: 1; }

.mk { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 6px #000; }
.mk.sq { border-radius: 2px; transform: rotate(45deg); width: 12px; height: 12px; }
.mk.sel { box-shadow: 0 0 0 4px #29b6f6aa, 0 0 12px #29b6f6; }
.leaflet-touch .leaflet-bar a { width: 36px; height: 36px; line-height: 36px; }
.leaflet-tooltip.lbl { background: #000b; color: #fff; border: none; box-shadow: none; font-size: 11px; padding: 1px 5px; }
.leaflet-tooltip.lbl::before { display: none; }
.area-label { color: #fff; font-weight: 700; font-size: 15px; text-shadow: 0 0 4px #000, 0 0 8px #000; white-space: nowrap; letter-spacing: 2px; }
.legend { background: #0b1520e6; padding: 8px 10px; border-radius: 6px; color: var(--fg); font-size: 12px; line-height: 1.7; }

dialog { background: var(--bg2); color: var(--fg); border: 1px solid var(--border); border-radius: 10px; width: min(760px, 95vw); max-height: 92vh; padding: 0; }
dialog::backdrop { background: #000a; }
#editForm { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
#editForm h3 { margin: 0 0 4px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#editForm label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
#editForm label.inline { flex-direction: row; align-items: center; gap: 8px; margin-top: 6px; }
#editForm label.inline input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 8px; }
legend { color: var(--acc); font-size: 12px; padding: 0 4px; }
.dlg-btns { display: flex; gap: 8px; margin-top: 6px; }

#lightbox { position: fixed; inset: 0; background: #000e; z-index: 4000; display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
#lightbox img { max-width: 94vw; max-height: 94vh; }

#btnMenu { display: none; font-size: 16px; padding: 4px 10px; margin-right: 6px; }
#list li { min-height: 44px; }

/* iPad / máy tính bảng */
@media (max-width: 1180px) {
  .brand .sub, #clock { display: none; }
  .actions .txt { display: none; }
  .actions button, .actions .btn { font-size: 16px; padding: 6px 12px; }
  #coordbar { display: none; }
}
/* iPad dọc / điện thoại: danh sách thành ngăn kéo, bảng thông tin thành tấm trượt dưới */
@media (max-width: 900px) {
  :root { --side: 0px; }
  #btnMenu { display: inline-block; }
  #sidebar { width: min(340px, 88vw); transform: translateX(-100%); transition: transform .25s; box-shadow: 4px 0 20px #000a; z-index: 1100; }
  #sidebar.open { transform: none; }
  #panel, #newsPanel { top: auto; left: 6px; right: 6px; bottom: 6px; width: auto; height: 56vh; }
  .tabs button { padding: 9px 10px; font-size: 14px; }
  #editForm .grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) { .brand { font-size: 13px; letter-spacing: 0; } }

/* ---- Tin tức ---- */
#btnNews { position: relative; }
.nbadge { position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff; border-radius: 10px;
  font-size: 10px; padding: 1px 5px; font-weight: 700; }
.news-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.news-filters input[type=search] { flex: 1 1 100%; }
.news-filters select { flex: 1; width: auto; }
.news-filters .chk { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); flex: 1 1 100%; }
.news-filters .chk input { width: auto; }
#newsStats { padding: 6px 14px; }
ul.arts { list-style: none; margin: 0; padding: 0 14px 12px; overflow-y: auto; flex: 1; }
#pBody ul.arts { padding: 0; overflow: visible; }
.arts li { padding: 9px 0; border-bottom: 1px solid #1c3349; }
.arts a.ttl { color: #fff; text-decoration: none; font-weight: 600; line-height: 1.35; display: block; }
.arts a.ttl:hover { color: var(--acc); }
.arts .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.arts .meta .new { color: #ff7043; font-weight: 700; }
.arts .sum { font-size: 12px; color: #b8c7d4; margin-top: 3px; }
.arts .tags { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 4px; }
.arts .tags .chip { font-size: 11px; }
.nb { font-size: 10px; background: #5d2b0a; color: #ffab91; border-radius: 8px; padding: 1px 6px; white-space: nowrap; }
.mk.hot { animation: hotpulse 1.6s infinite; }
@keyframes hotpulse { 0% { box-shadow: 0 0 0 0 #ff7043cc, 0 0 6px #000; } 70% { box-shadow: 0 0 0 12px #ff704300, 0 0 6px #000; } 100% { box-shadow: 0 0 0 0 #ff704300, 0 0 6px #000; } }
details summary { cursor: pointer; padding: 8px 0; color: var(--acc); }
.mk.ring { width: 20px; height: 20px; background: transparent; border: 3px dashed #fff; }
