:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel2: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #f59e0b;
  --green: #16a34a;
  --red: #dc2626;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid #0b1220;
}
.brand {
  font-weight: 700;
  font-size: 18px;
}
.brand .tag {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 8px;
}
.tabs {
  margin-left: auto;
  display: flex;
  gap: 6px;
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--panel2);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.tab.active {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
  font-weight: 600;
}
.panel {
  flex: 1;
  position: relative;
  display: none;
}
.panel.active {
  display: block;
}
#map,
#map-route {
  position: absolute;
  inset: 0;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 20px;
  background: var(--panel);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12px;
  z-index: 5;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.legend-title {
  font-weight: 600;
  margin-bottom: 6px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  padding: 2px 0;
}
.sw {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
}
.hint {
  color: var(--muted);
  margin-top: 6px;
  font-size: 11px;
}

.popup-card {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 300px;
  max-height: 80%;
  overflow: auto;
  background: var(--panel);
  border-radius: 12px;
  padding: 14px;
  z-index: 6;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.popup-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
}
.popup-card .addr {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 10px;
}
.price-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  font-size: 13px;
  margin-bottom: 10px;
}
.price-grid .ft {
  color: var(--muted);
}
.price-grid .pv {
  font-weight: 600;
}
.popup-close {
  position: absolute;
  right: 8px;
  top: 6px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
}
.mini-btn {
  background: var(--panel2);
  color: var(--text);
  border: none;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.mini-btn:hover {
  background: #475569;
}

.route-side {
  position: absolute;
  left: 12px;
  top: 12px;
  width: 320px;
  max-height: 88%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 6;
}
.route-form {
  background: var(--panel);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.route-form h3 {
  margin: 0 0 8px;
}
.route-form label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0 2px;
}
.route-form select,
.route-form input {
  width: 100%;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid #475569;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}
.btn {
  width: 100%;
  margin-top: 10px;
  background: var(--accent);
  color: #111;
  border: none;
  border-radius: 8px;
  padding: 9px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.status {
  font-size: 12px;
  margin-top: 8px;
  color: var(--muted);
  min-height: 16px;
}
.cand-list {
  background: var(--panel);
  border-radius: 12px;
  overflow: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  flex: 1;
  min-height: 0;
}
.cand-head {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--panel2);
}
.cand {
  padding: 10px 12px;
  border-bottom: 1px solid var(--panel2);
  cursor: pointer;
}
.cand:hover {
  background: var(--panel2);
}
.cand .rank {
  font-weight: 800;
  color: var(--accent);
  font-size: 15px;
}
.cand .nm {
  font-weight: 600;
}
.cand .add {
  font-size: 12px;
  color: var(--muted);
}
.cand .row2 {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-top: 4px;
}
.cand .save {
  color: var(--green);
  font-weight: 700;
}
.cand .acts {
  margin-top: 6px;
  display: flex;
  gap: 6px;
}

.trend-panel {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 340px;
  background: var(--panel);
  border-radius: 12px;
  padding: 14px;
  z-index: 7;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.trend-panel h3 {
  margin: 0 0 6px;
  font-size: 15px;
}
.trend-advice {
  font-size: 13px;
  background: var(--panel2);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
#trend-chart {
  width: 100%;
  height: 160px;
  background: var(--panel2);
  border-radius: 8px;
}

.banner {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 24px;
  background: #7f1d1d;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  z-index: 50;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.banner.ok {
  background: #14532d;
}
.hidden {
  display: none !important;
}
.maplibregl-popup-content {
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
}
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip {
  border-top-color: var(--panel);
}
.maplibregl-popup-anchor-top .maplibregl-popup-tip {
  border-bottom-color: var(--panel);
}
