:root {
  --navy: #12335c; --blue: #1766d6; --green: #16934a; --yellow: #f2a007;
  --red: #e02b35; --gray: #8a97a8; --text: #14233b; --line: #dbe4f0; --bg: #eef3fa;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
body { font: 14px/1.4 "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
ul { list-style: none; }

header { display: flex; align-items: center; gap: 14px; padding: 10px 18px; background: var(--navy); color: #fff; flex-wrap: wrap; }
.logo { width: 60px; height: 45px; }
.title { flex: 1; min-width: 220px; }
h1 { font-size: 20px; }
.title p { font-size: 12px; opacity: .85; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button { color: #fff; padding: 9px 15px; border-radius: 6px; font-weight: 600; }
nav button.active, nav button:hover { background: var(--blue); }
.conn { display: flex; align-items: center; gap: 7px; font-weight: 600; }
.conn i { width: 10px; height: 10px; border-radius: 50%; background: #2fd36b; }
.conn.off i { background: var(--red); }
#demoBanner { background: #fff1c2; color: #6b4a00; text-align: center; padding: 5px; font-weight: 700; }

main { display: grid; gap: 10px; padding: 10px; grid-template-columns: 1.45fr 1fr 1.05fr; align-items: stretch; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-width: 0; }
h2 { font-size: 15px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
h3 { font-size: 13px; }

#mapCard { grid-column: 1 / 3; position: relative; padding: 0; overflow: hidden; min-height: 470px; isolation: isolate; }
#map { position: absolute; inset: 0; background: #e4ebe2; }
.map-error { padding: 80px 20px; text-align: center; }
.search { position: absolute; top: 10px; left: 10px; width: min(250px, 70%); z-index: 1000; }
.search input { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 2px 8px #0002; }
.search ul { background: #fff; border-radius: 8px; margin-top: 4px; box-shadow: 0 4px 12px #0003; max-height: 220px; overflow: auto; }
.search li button { width: 100%; text-align: left; padding: 8px 12px; }
.search li button:hover { background: var(--bg); }
.leaflet-top.leaflet-left { top: 52px; }
#fit { position: absolute; top: 138px; left: 10px; z-index: 1000; width: 34px; height: 34px; background: #fff; border: 2px solid #0003; border-radius: 4px; font-size: 20px; line-height: 1; }
.pin { filter: drop-shadow(0 2px 2px #0006); }
.pin.selected { transform-origin: bottom; scale: 1.25; }
.pop b.name { display: block; margin-bottom: 4px; font-size: 14px; }
.pop div { margin: 2px 0; }
.pop .warn { margin-top: 6px; padding: 5px 8px; border-radius: 5px; font-weight: 700; }

.normal { --c: var(--green); --soft: #e5f6ea; }
.yellow { --c: #c77c00; --soft: #fff3da; }
.red    { --c: var(--red); --soft: #fde6e8; }
.offline{ --c: var(--gray); --soft: #edf0f4; }

#detail { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--navy); color: #fff; padding: 11px 13px; border-radius: 9px; font-weight: 700; font-size: 15px; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 6px; background: var(--soft); color: var(--c); white-space: nowrap; }
.head .badge { background: var(--c); color: #fff; }
.water { display: grid; grid-template-columns: 1fr 105px; gap: 10px; }
.big { font-size: 38px; font-weight: 800; color: var(--c); line-height: 1.2; }
.bar { height: 9px; border-radius: 5px; background: var(--line); overflow: hidden; margin: 4px 0; }
.bar span { display: block; height: 100%; background: var(--c); }
.rain { background: #eaf3ff; border-radius: 9px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; color: var(--blue); }
.rain em { font-size: 34px; font-style: normal; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { background: var(--soft, #eef5fd); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; }
.tile b { display: block; font-size: 22px; color: var(--c, var(--text)); }
.tempwarn { background: var(--soft); color: var(--c); border: 1px solid var(--c); border-radius: 8px; padding: 8px 12px; font-weight: 700; }
.guide { border: 1px solid #f5c4c8; border-radius: 9px; overflow: hidden; background: #fff; }
.guide h3 { background: #fde6e8; padding: 8px 12px; font-size: 14px; }
.guide .row { display: grid; grid-template-columns: 62px 1fr; gap: 8px; align-items: center; padding: 7px 10px; margin: 4px; border-radius: 7px; background: var(--soft); opacity: .6; font-size: 12px; border: 2px solid transparent; }
.guide .row.active { opacity: 1; border-color: var(--c); }
.guide .row span { font-size: 20px; text-align: center; }
.guide .row b { display: block; color: var(--c); }
.updated { font-size: 12px; color: var(--gray); text-align: right; }

#counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.count { background: var(--soft, #eaf3ff); color: var(--c, var(--blue)); border-radius: 8px; padding: 7px 4px; text-align: center; font-size: 11px; font-weight: 600; }
.count b { display: block; font-size: 22px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 8px; flex-wrap: wrap; }
#metricTabs button { font-size: 12px; padding: 3px 9px; border-radius: 5px; border: 1px solid var(--line); }
#metricTabs button.active { background: var(--blue); color: #fff; }
#chart svg { width: 100%; height: auto; display: block; font-size: 11px; }
.empty { color: var(--gray); text-align: center; padding: 28px 6px; }

#list li button { width: 100%; display: flex; align-items: center; gap: 9px; padding: 11px 8px; border-bottom: 1px solid var(--line); text-align: left; border-radius: 6px; }
#list li button.selected { background: var(--soft); }
#list .name { flex: 1; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--c); flex: none; }
.link { color: var(--blue); font-size: 12px; font-weight: 600; }
#alerts { max-height: 250px; overflow: auto; }
#alerts li { display: grid; grid-template-columns: 11px 44px 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
#alerts li .dot { margin-top: 3px; }
#alerts b { display: block; font-size: 13px; }

#settings, #about { display: none; grid-column: 1 / -1; }
form { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; align-items: end; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; }
form button { background: var(--blue); color: #fff; border-radius: 6px; padding: 9px; font-weight: 700; }
form button:disabled { background: var(--gray); }
#about p { margin-bottom: 8px; max-width: 70ch; }

/* Cac trang tren thanh menu */
body[data-view="map"] main > :not(#mapCard):not(#detail) { display: none; }
body[data-view="map"] #mapCard { min-height: calc(100vh - 100px); }
body[data-view="stats"] main > :not(#overview):not(#listCard) { display: none; }
body[data-view="stats"] #overview { grid-column: 1 / 3; }
body[data-view="alerts"] main > :not(#alertCard):not(#settings) { display: none; }
body[data-view="alerts"] #alertCard { grid-column: 1 / -1; }
body[data-view="alerts"] #alerts { max-height: 55vh; }
body[data-view="alerts"] #settings { display: block; }
body[data-view="about"] main > :not(#about) { display: none; }
body[data-view="about"] #about { display: block; }

/* Dien thoai */
@media (max-width: 900px) {
  main { grid-template-columns: minmax(0, 1fr); }
  main > * { grid-column: 1 / -1 !important; }
  #mapCard { min-height: 380px; }
  nav { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; }
  nav button { white-space: nowrap; padding: 7px 10px; }
  h1 { font-size: 17px; }
  .logo { width: 44px; height: 33px; }
  .title { min-width: 150px; }
}
