/* Bản đồ trạm sạc — trang /ban-do.
   Token canonical từ tokens.css (DESIGN.md). KHÔNG hardcode hex/spacing/radius.
   Brand = xanh lá (var(--accent)). Trạng thái: available=brand · busy=warning ·
   full=danger · offline=xám(faint). Mobile-first → split panel|map từ lg.
   Nạp CHỈ ở trang này (cùng leaflet.css), KHÔNG ở base.templ. */

/* ===== Trạng thái trạm → biến màu dùng chung (chấm/pin/chú thích) ===== */
.st-available { --st: var(--accent); }
.st-busy { --st: var(--warning); }
.st-full { --st: var(--danger); }
.st-offline { --st: var(--faint); }

/* ===== Khung full-height: cột [bộ lọc | thân] =====
   --map-offset: chiều cao chrome bao quanh (header/bottom-nav) để map vừa màn.
   Mặc định 0 → lấp đầy viewport động; layout bọc ngoài có thể đặt lại. */
.map-shell {
  --map-offset: 0px;
  --map-r-tile: 10px; /* bo góc nhỏ (icon trạm/legend/điều khiển bản đồ) — khớp reference rounded-[10px] */
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--map-offset));
  min-height: 0;
  background: var(--bg);
}

/* ===== Bộ lọc (cuộn ngang khi hẹp) ===== */
.map-filters {
  flex: none;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.map-filters::-webkit-scrollbar { display: none; }
.map-filters-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--space-lg, 16px);
  width: max-content;
}
.map-filters-lead {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  flex: none;
  margin-right: 2px;
}

.fchip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur, .15s) ease, border-color var(--dur, .15s) ease, color var(--dur, .15s) ease;
}
.fchip .fa-icon { width: 14px; height: 14px; }
.fchip:hover { background: var(--surface-2); }
.fchip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fchip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ===== Thân: bản đồ + panel ===== */
.map-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

/* ===== Panel danh sách ===== */
.map-panel { display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.map-aside {
  display: none; /* mobile: dùng bottom-sheet thay panel */
  width: 392px;
  flex: none;
  border-right: 1px solid var(--border);
}
.map-panel-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 18px 8px;
}
.map-panel-title { font-size: 15px; font-weight: 600; color: var(--text); margin: 0; }
.map-count { font-variant-numeric: tabular-nums; }

/* Nút sắp xếp (chỉ panel desktop) — khớp reference "Gần nhất" */
.map-sort {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--dur, .15s) ease;
}
.map-sort:hover { background: var(--surface-2); }
.map-sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.map-sort .fa-icon { width: 14px; height: 14px; }

.map-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.map-empty { padding: 16px; color: var(--muted); font-size: 14px; text-align: center; }

/* ===== Card trạm ===== */
.scard {
  display: flex;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--dur, .15s) ease, background-color var(--dur, .15s) ease;
}
.scard:hover { background: var(--surface-2); }
.scard:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.scard[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }

.scard-ico {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--map-r-tile);
  background: var(--accent-soft);
  color: var(--accent);
}
.scard-ico .fa-icon { width: 18px; height: 18px; }

.scard-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.scard-name {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scard-meta { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.scard-dist { font-size: 12.5px; }

.scard-conns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.scard-conn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.scard-conn-type { font-weight: 600; color: var(--muted); }
.scard-conn-pow { font-size: 11px; font-weight: 600; color: var(--muted); }

.scard-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}
.scard-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--st);
}
.scard-dot-st { width: 7px; height: 7px; border-radius: var(--r-pill); background: var(--st); flex: none; }
.scard-price { font-size: 13px; font-weight: 600; color: var(--text); }

/* ===== Vùng bản đồ ===== */
.map-stage { position: relative; flex: 1; min-width: 0; min-height: 0; }
.map-canvas { position: absolute; inset: 0; background: var(--surface-2); }

/* Nút "về vị trí của tôi" */
.map-locate {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 500;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--map-r-tile);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.map-locate .fa-icon { width: 18px; height: 18px; }
.map-locate:hover { background: var(--surface-2); }
.map-locate:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Chú thích trạng thái */
.map-legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 500;
  display: none; /* mobile: ẩn để nhường bottom-sheet */
  gap: 14px;
  margin: 0;
  padding: 10px 14px;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--map-r-tile);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow-sm);
  font-size: 12px;
  color: var(--muted);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.map-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.map-legend .scard-dot-st { width: 10px; height: 10px; }

/* ===== Bottom-sheet (mobile) ===== */
.map-sheet {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  z-index: 600;
  display: flex;
  flex-direction: column;
  height: 240px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  transition: height .3s cubic-bezier(.16, 1, .3, 1);
}
.map-sheet[data-open="true"] { height: 78%; }
.map-sheet-handle {
  flex: none;
  display: grid;
  place-items: center;
  padding: 10px 0 6px;
  background: none;
  border: 0;
  cursor: grab;
  touch-action: none;
}
.map-sheet-grip { width: 40px; height: 5px; border-radius: var(--r-pill); background: var(--border-strong); }
.map-sheet-list { flex: 1; min-height: 0; }
.map-sheet-list .map-panel-head { padding-top: 4px; }

/* ===== Pin bản đồ (L.divIcon: html do map.js dựng) ===== */
.map-pin {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid var(--surface);
  border-radius: var(--r-pill) var(--r-pill) var(--r-pill) 2px;
  background: var(--st, var(--accent));
  box-shadow: var(--shadow-lg);
  transform: rotate(45deg);
  transition: width .15s ease, height .15s ease;
}
.map-pin .fa-icon { width: 14px; height: 14px; color: #fff; transform: rotate(-45deg); }
.map-pin-active { width: 34px; height: 34px; z-index: 1000; }

/* ===== Popup Leaflet (override khung mặc định theo token) ===== */
.leaflet-popup-content-wrapper {
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.leaflet-popup-content { margin: 12px 14px; font: inherit; }
.leaflet-popup-tip { background: var(--surface); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-container { font: inherit; background: var(--surface-2); }
/* Nhóm zoom +/- góc trên-phải, NẰM DƯỚI nút định vị (map-locate ~42px + 14px lề) */
.leaflet-top.leaflet-right { top: 56px; right: 4px; }
.leaflet-control-zoom.leaflet-bar {
  border: 1px solid var(--border);
  border-radius: var(--map-r-tile);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.leaflet-control-zoom a {
  width: 42px;
  height: 42px;
  line-height: 42px;
  font-size: 20px;
  background: var(--surface);
  color: var(--text);
  border: 0;
}
.leaflet-control-zoom a.leaflet-control-zoom-in { border-bottom: 1px solid var(--border); }
.leaflet-control-zoom a:hover { background: var(--surface-2); }
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--muted);
}
.leaflet-control-attribution a { color: var(--accent); }

.mpop-name { font-size: 14px; font-weight: 600; color: var(--text); margin: 0 0 2px; }
.mpop-op { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.mpop-conns { display: flex; flex-direction: column; gap: 4px; margin: 0 0 8px; }
.mpop-conn { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; }
.mpop-conn-type { color: var(--muted); }
.mpop-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--st); }

/* ===== Desktop: panel trái cố định, ẩn bottom-sheet ===== */
@media (min-width: 1024px) {
  .map-aside { display: flex; }
  .map-legend { display: flex; }
  .map-sheet { display: none; }
}
