:root {
  --bg: #f4f1ea;
  --panel: #fffcf7;
  --ink: #1c1917;
  --muted: #57534e;
  --line: #e7e0d6;
  --teal: #0f766e;
  --teal-ink: #134e4a;
  --amber: #c2410c;
  --indigo: #3730a3;
  --ok: #15803d;
  --bad: #b91c1c;
  --shadow: 0 8px 28px rgba(28, 25, 23, 0.12);
  --radius: 14px;
  --header-h: 64px;
  --panel-w: 360px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Noto Sans TC", "PingFang TC", "Hiragino Sans CNS", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}
button, input, select { font: inherit; }
a { color: var(--teal-ink); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

#app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  min-height: var(--header-h);
  padding: calc(8px + var(--safe-top)) 14px 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fffdf9;
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(145deg, #0f766e, #115e59);
  color: #fff; display: grid; place-items: center;
  font-weight: 700; letter-spacing: 0.02em;
}
.brand-text h1 {
  margin: 0; font-size: 16px; font-weight: 700; line-height: 1.2;
}
.tagline { margin: 0; font-size: 11px; color: var(--muted); }

.search-wrap { flex: 1 1 220px; min-width: 140px; }
.search-wrap input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  outline: none;
}
.search-wrap input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }

.top-actions { display: flex; align-items: center; gap: 8px; }
.btn, .lang-toggle button, .map-chip, .layer-switch button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  cursor: pointer;
}
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 10px;
}
.icon-btn:hover, .lang-toggle button:hover, .map-chip:hover { background: #f5f0e8; }
.icon-btn:disabled { opacity: .65; cursor: wait; }
.icon-btn.is-busy .refresh-icon { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.lang-toggle {
  display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
}
.lang-toggle button {
  border: 0; border-radius: 0; padding: 6px 10px; font-size: 12px; font-weight: 600;
}
.lang-toggle button.is-active { background: var(--ink); color: #fff; }

.workspace { flex: 1; display: flex; min-height: 0; position: relative; }
.panel {
  width: var(--panel-w);
  flex: 0 0 var(--panel-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
  z-index: 15;
}
.panel-handle { display: none; }
.layer-switch {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 6px; padding: 12px 14px 8px;
}
.layer-switch button {
  padding: 8px 6px; font-size: 13px; font-weight: 600; border-radius: 10px;
}
.layer-switch button.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }

.filters {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px 10px; padding: 4px 14px 8px;
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.filters select {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; background: #fff; color: var(--ink);
}
.check {
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px 10px; font-size: 13px;
}
.list-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 4px 14px; border-top: 1px solid var(--line);
}
.list-head h2 { margin: 0; font-size: 13px; font-weight: 700; }
.muted { color: var(--muted); font-size: 12px; }

.place-list { flex: 1; overflow: auto; padding: 0 8px 8px; }
.place-item {
  display: grid; grid-template-columns: auto 1fr auto;
  gap: 10px; align-items: start;
  width: 100%; text-align: left;
  border: 0; background: transparent;
  padding: 10px 8px; border-radius: 10px; cursor: pointer;
}
.place-item:hover { background: #f3eee6; }
.place-item.is-active { background: #ecf8f6; box-shadow: inset 0 0 0 1px #99f6e4; }
.place-item .badge {
  width: 28px; height: 28px; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff; flex: none;
}
.place-item .meta { min-width: 0; }
.place-item h3 {
  margin: 0 0 2px; font-size: 13.5px; font-weight: 650; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.place-item p { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.35; }
.place-item .status { font-size: 11px; font-weight: 650; white-space: nowrap; }
.status.ok { color: var(--ok); }
.status.full { color: var(--bad); }
.status.unknown { color: var(--muted); }
.empty-list { padding: 24px 16px; color: var(--muted); font-size: 13px; text-align: center; }

.panel-foot {
  border-top: 1px solid var(--line);
  padding: 10px 14px calc(10px + var(--safe-bottom));
}
.panel-foot .attr { font-size: 11px; line-height: 1.5; color: var(--muted); margin: 6px 0 0; }

.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { height: 100%; width: 100%; background: #dbe4dc; }
.map-chip {
  position: absolute; top: 12px; right: 12px; z-index: 500;
  padding: 7px 12px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow);
}
.toast {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 600; background: #1c1917; color: #fff;
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
  box-shadow: var(--shadow); max-width: min(90%, 420px);
}

/* Markers: colour + shape + letter */
.mk {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 12px; line-height: 1;
  border: 2px solid #fff;
  box-shadow: 0 1px 5px rgba(0,0,0,.35);
}
.mk-ev { background: var(--teal); border-radius: 50%; }
.mk-meter { background: var(--amber); border-radius: 5px; }
.mk-park { background: var(--indigo); border-radius: 4px 4px 12px 12px; }
.mk.is-vacant { box-shadow: 0 0 0 2px #16a34a, 0 1px 5px rgba(0,0,0,.35); }
.mk.is-full { opacity: 0.82; }
.badge.ev { background: var(--teal); border-radius: 50%; }
.badge.metered { background: var(--amber); border-radius: 5px; }
.badge.carpark { background: var(--indigo); border-radius: 4px 4px 8px 8px; }

.leaflet-popup-content-wrapper {
  border-radius: 12px; box-shadow: var(--shadow);
  font-family: inherit;
}
.leaflet-popup-content { margin: 12px 14px; min-width: 220px; max-width: 280px; }
.pop h3 { margin: 0 0 4px; font-size: 15px; line-height: 1.3; }
.pop .addr { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); }
.pop dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12.5px; }
.pop dt { color: var(--muted); }
.pop dd { margin: 0; }
.pop .links { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.pop .links a {
  display: inline-block; padding: 5px 9px; border-radius: 999px;
  background: #ecf8f6; text-decoration: none; font-size: 12px; font-weight: 600;
}
.pop .kind-pill {
  display: inline-block; font-size: 10px; font-weight: 700;
  letter-spacing: .04em; padding: 2px 7px; border-radius: 999px;
  margin-bottom: 6px; color: #fff;
}
.pop .kind-pill.ev { background: var(--teal); }
.pop .kind-pill.metered { background: var(--amber); }
.pop .kind-pill.carpark { background: var(--indigo); }

.marker-cluster-ev { background: rgba(15,118,110,.25); }
.marker-cluster-ev div { background: var(--teal); color: #fff; }
.marker-cluster-park { background: rgba(55,48,163,.22); }
.marker-cluster-park div { background: var(--indigo); color: #fff; }
.marker-cluster-mixed { background: rgba(28,25,23,.18); }
.marker-cluster-mixed div { background: #1c1917; color: #fff; }

#app.panel-collapsed .panel { display: none; }
#app.panel-collapsed .panel-toggle { background: var(--ink); color: #fff; }

@media (max-width: 800px) {
  .tagline, .btn-label { display: none; }
  .brand-text h1 { font-size: 15px; }
  .workspace { flex-direction: column; }
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0;
    width: auto; flex-basis: auto;
    height: 46%; max-height: 70%;
    border-right: 0; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 24px rgba(28,25,23,.12);
  }
  .panel-handle {
    display: block; width: 40px; height: 4px; border-radius: 4px;
    background: #d6d3d1; margin: 8px auto 0;
  }
  .map-chip { top: auto; bottom: calc(46% + 12px); right: 10px; }
  #app.panel-collapsed .panel { display: none; }
  #app.panel-collapsed .map-chip { bottom: 16px; }
  .filters { grid-template-columns: 1fr 1fr; }
}
