/* Khung app: sân khấu 3D, thanh trên, thẻ KPI, nút bản đồ, chú thích, nhãn nổi trên nhà. */
.app { position: fixed; inset: 0; overflow: hidden; }
.stage { position: absolute; inset: 0; z-index: 0; isolation: isolate; }
.stage canvas { display: block; outline: none; }
.label-layer { position: absolute; inset: 0; pointer-events: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card, .topbar, .kpi, .map-tools, .detail, .journey, .tables, .legend {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card);
  box-shadow: var(--shadow); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}

/* Thanh trên */
.topbar {
  position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); left: 16px; right: 16px; height: 58px;
  display: flex; align-items: center; gap: 14px; padding-inline: 14px; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: none; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.bm-side { fill: var(--accent); } .bm-top { fill: var(--roof-2); } .bm-front { fill: var(--door); }
.brand b { display: block; font-family: var(--font-display); font-size: 17px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.brand span { display: block; font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.search {
  position: relative; flex: 1 1 auto; min-width: 120px; max-width: 520px; display: flex; align-items: center; gap: 8px;
  height: 38px; padding-inline: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card-solid);
}
.search svg { width: 17px; height: 17px; fill: none; stroke: var(--ink-3); stroke-width: 1.8; flex: none; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink); font: 13.5px var(--font-ui); outline: none; }
.search input::placeholder { color: var(--ink-3); }
.search kbd { font: 11px var(--font-mono); color: var(--ink-3); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.search-results {
  position: absolute; top: 44px; left: 0; right: 0; max-height: 340px; overflow-y: auto; z-index: 8;
  background: var(--card-solid); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.search-results button {
  display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 10px; width: 100%;
  text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.search-results button:hover, .search-results button[aria-selected="true"] { background: var(--hover); }
.search-results small { color: var(--ink-3); font: 11.5px var(--font-mono); }
.search-results .empty { padding: 10px; color: var(--ink-3); font-size: 13px; }
.district-pick {
  display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 6px 0 6px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card-solid); min-width: 0;
}
.district-badge {
  font: 600 10.5px var(--font-mono); letter-spacing: 0.04em; color: var(--on-accent); background: var(--accent);
  border-radius: 7px; padding: 4px 6px;
}
.district-pick select { border: 0; background: transparent; color: var(--ink); font: 500 13px var(--font-ui); outline: none; max-width: 230px; cursor: pointer; }
.live {
  display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px; border-radius: var(--r-pill);
  background: var(--unknown-soft); color: var(--ink-2); font: 500 12.5px var(--font-ui); white-space: nowrap; margin-left: auto;
}
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--unknown); }
.live.is-live { background: var(--ok-soft); color: var(--ok); }
.live.is-live i { background: var(--ok); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); } 50% { box-shadow: 0 0 0 6px transparent; } }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--card-solid); cursor: pointer; position: relative; flex: none;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: var(--ink-2); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.icon-btn[aria-pressed="true"] svg { stroke: var(--accent); }
.alerts-btn b {
  position: absolute; top: -6px; right: -6px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
  background: var(--down); color: #fff; font: 600 11px/19px var(--font-ui); text-align: center;
}
.alerts-btn b:empty, .alerts-btn b[data-zero] { display: none; }

/* Thẻ KPI */
.kpis { position: absolute; top: calc(82px + env(safe-area-inset-top, 0px)); left: 16px; display: flex; gap: 10px; z-index: 4; max-width: calc(100% - 32px); }
.kpi { display: flex; gap: 11px; align-items: flex-start; padding: 11px 14px 11px 11px; min-width: 0; width: 196px; }
.kpi-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); flex: none; }
.kpi-icon svg { width: 18px; height: 18px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.kpi-label { font-size: 11.5px; font-weight: 600; color: var(--ink-2); }
.kpi-value { font: 600 22px/1.15 var(--font-display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi-value small { font: 500 12px var(--font-ui); color: var(--ink-3); letter-spacing: 0; }
.kpi-sub { font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.kpi-sub .up { color: var(--down); font-weight: 600; } .kpi-sub .good { color: var(--ok); font-weight: 600; }

/* Chú thích màu */
.legend {
  position: absolute; top: calc(160px + env(safe-area-inset-top, 0px)); left: 16px; display: flex; flex-wrap: wrap; gap: 4px 12px;
  padding: 8px 12px; font-size: 11.5px; color: var(--ink-2); z-index: 3; max-width: 430px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend i { width: 9px; height: 9px; border-radius: 50%; }
.legend .walker { width: 7px; height: 11px; border-radius: 4px; background: var(--accent); }

/* Nút bản đồ */
.map-tools { position: absolute; top: calc(82px + env(safe-area-inset-top, 0px)); right: 16px; display: flex; flex-direction: column; gap: 6px; padding: 6px; z-index: 4; }
.map-tools .icon-btn { width: 34px; height: 34px; border-radius: 9px; }

/* Chấm và nhãn trạng thái dùng chung */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: var(--unknown); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: var(--r-pill);
  font: 600 11.5px var(--font-ui); white-space: nowrap; background: var(--unknown-soft); color: var(--unknown);
}
[data-state="ok"] { --st: var(--ok); --st-soft: var(--ok-soft); }
[data-state="slow"] { --st: var(--slow); --st-soft: var(--slow-soft); }
[data-state="warn"] { --st: var(--warn); --st-soft: var(--warn-soft); }
[data-state="down"] { --st: var(--down); --st-soft: var(--down-soft); }
[data-state="unknown"] { --st: var(--unknown); --st-soft: var(--unknown-soft); }
[data-state="idle"] { --st: var(--idle); --st-soft: var(--unknown-soft); }
[data-state="retired"] { --st: var(--retired); --st-soft: var(--unknown-soft); }
.pill[data-state] { background: var(--st-soft); color: var(--st); }
.dot[data-state] { background: var(--st); }

/* Nhãn nổi trên nhà (CSS2D) */
.lbl {
  pointer-events: auto; cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 4px 9px 4px 7px;
  background: var(--card-solid); border: 1.5px solid var(--line); border-radius: 9px; box-shadow: var(--shadow);
  font: 600 11.5px var(--font-ui); color: var(--ink); white-space: nowrap; transform: translateY(-4px);
  transition: opacity 0.18s ease;
}
.lbl[data-state="warn"], .lbl[data-state="down"], .lbl[data-state="slow"] { border-color: var(--st); }
.lbl.is-selected { border-color: var(--accent); }
.lbl .nm { max-width: 190px; overflow: hidden; text-overflow: ellipsis; }
.lbl em { font-style: normal; font-weight: 600; color: var(--st, var(--ink-3)); padding-left: 6px; border-left: 1px solid var(--line); }
.lbl-district {
  pointer-events: auto; cursor: pointer; display: flex; flex-direction: column; gap: 1px; padding: 6px 10px; border-radius: 10px;
  background: var(--card-solid); border: 1px solid var(--line); box-shadow: var(--shadow); transform: translate(50%, -50%);
}
.lbl-district b { font: 600 11px var(--font-display); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); white-space: nowrap; }
.lbl-district span { font: 500 11px var(--font-ui); color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.lbl-hidden { opacity: 0; pointer-events: none; }

.tooltip {
  position: absolute; z-index: 9; pointer-events: none; padding: 8px 10px; border-radius: 10px; max-width: 280px;
  background: var(--card-solid); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 12px; color: var(--ink-2);
}
.tooltip b { display: block; color: var(--ink); font-size: 12.5px; }

.boot { position: absolute; inset: 0; display: grid; place-items: center; z-index: 20; background: var(--bg); transition: opacity 0.4s ease; }
.boot.is-done { opacity: 0; pointer-events: none; }
.boot-card { display: grid; gap: 4px; text-align: center; }
.boot-card b { font: 600 18px var(--font-display); }
.boot-card span { color: var(--ink-3); font-size: 13px; }
.boot.is-error .boot-card span { color: var(--down); }

@media (prefers-reduced-motion: reduce) { .live.is-live i { animation: none; } }
