:root {
  --bg: #0c1218;
  --bg-elev: #141c26;
  --panel: rgba(16, 24, 34, 0.94);
  --panel-border: rgba(86, 170, 200, 0.28);
  --accent: #4eb3d4;
  --accent-dim: #2a7a96;
  --medical: #3db88a;
  --dental: #5b8def;
  --mixed: #c9a227;
  --text: #e6eef4;
  --muted: #8fa3b3;
  --danger: #e07a6a;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --sidebar-w: min(380px, 92vw);
  --font: "Noto Sans TC", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font-family: inherit; color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

#app {
  position: relative; height: 100%;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  overflow: hidden;
}
#app.collapsed {
  grid-template-columns: 0 1fr;
}

.sidebar {
  position: relative; z-index: 700;
  display: flex; flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  backdrop-filter: blur(12px);
  min-width: 0;
  overflow: hidden;
}
#app.collapsed .sidebar { border-right: none; pointer-events: none; }

.side-head {
  display: flex; align-items: flex-start; gap: 0.5rem;
  padding: 0.9rem 1rem 0.55rem;
  border-bottom: 1px solid var(--panel-border);
}
.brand h1 {
  margin: 0; font-size: 1.25rem; font-weight: 700;
  letter-spacing: 0.02em; color: var(--accent);
}
.subtitle { margin: 0.2rem 0 0; font-size: 0.72rem; color: var(--muted); line-height: 1.35; }
.side-head .btn.icon { margin-left: auto; }

.btn {
  appearance: none; border: 1px solid var(--panel-border);
  background: var(--bg-elev); color: var(--text);
  padding: 0.45rem 0.85rem; border-radius: 999px;
  cursor: pointer; font-size: 0.85rem;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--accent); background: #1a2834; }
.btn.ghost { background: transparent; }
.btn.icon {
  width: 2rem; height: 2rem; padding: 0; border-radius: 50%;
  font-size: 1.2rem; line-height: 1; flex-shrink: 0;
}

.filters { padding: 0.75rem 1rem; border-bottom: 1px solid var(--panel-border); }
#search-input, #filter-district {
  width: 100%; padding: 0.55rem 0.85rem;
  border-radius: 10px; border: 1px solid var(--panel-border);
  background: var(--bg-elev); outline: none;
}
#search-input:focus, #filter-district:focus { border-color: var(--accent); }
.filter-row {
  display: grid; grid-template-columns: 1fr; gap: 0.5rem; margin-top: 0.55rem;
}
.practice-toggles { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.28rem 0.65rem; border-radius: 999px;
  border: 1px solid var(--panel-border); background: var(--bg-elev);
  font-size: 0.8rem; cursor: pointer; user-select: none;
}
.chip.subtle { background: transparent; color: var(--muted); }
.chip input { accent-color: var(--accent); }
.filter-meta {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; margin-top: 0.55rem; font-size: 0.78rem; color: var(--muted);
}
#result-count { font-variant-numeric: tabular-nums; }

.clinic-list {
  list-style: none; margin: 0; padding: 0.35rem;
  overflow: auto; flex: 1; min-height: 0;
}
.clinic-list li {
  padding: 0.65rem 0.75rem; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent;
}
.clinic-list li:hover, .clinic-list li.active {
  background: rgba(78, 179, 212, 0.12);
  border-color: rgba(78, 179, 212, 0.25);
}
.clinic-list .name { font-weight: 600; font-size: 0.92rem; }
.clinic-list .addr { color: var(--muted); font-size: 0.75rem; margin-top: 0.2rem; line-height: 1.35; }
.clinic-list .tags { margin-top: 0.3rem; display: flex; gap: 0.3rem; flex-wrap: wrap; }
.tag {
  font-size: 0.68rem; padding: 0.1rem 0.4rem; border-radius: 999px;
  background: rgba(255,255,255,0.06); color: var(--muted);
}
.tag.medical { color: var(--medical); background: rgba(61,184,138,0.12); }
.tag.dental { color: var(--dental); background: rgba(91,141,239,0.12); }
.tag.mixed { color: var(--mixed); background: rgba(201,162,39,0.12); }
.tag.approx { color: var(--danger); }

.side-foot {
  padding: 0.65rem 1rem; border-top: 1px solid var(--panel-border);
  font-size: 0.68rem; color: var(--muted); line-height: 1.45;
}
.side-foot p { margin: 0; }

.map-pane { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #0a1016; }
#map.map-ready { background: #0a1016; }

.status-pill {
  position: absolute; left: 50%; bottom: 1.1rem; transform: translateX(-50%) translateY(12px);
  z-index: 650; padding: 0.4rem 0.9rem; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--panel-border);
  color: var(--muted); font-size: 0.78rem; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; white-space: nowrap; max-width: 90vw;
  overflow: hidden; text-overflow: ellipsis;
}
.status-pill.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.status-pill.error { color: var(--danger); }

.map-legend {
  position: absolute; right: 0.75rem; bottom: 0.75rem; z-index: 640;
  display: flex; gap: 0.65rem; align-items: center; flex-wrap: wrap;
  padding: 0.4rem 0.7rem; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--panel-border);
  font-size: 0.72rem; color: var(--muted);
}
.dot {
  display: inline-block; width: 0.55rem; height: 0.55rem;
  border-radius: 50%; margin-right: 0.2rem; vertical-align: middle;
}
.dot.medical { background: var(--medical); }
.dot.dental { background: var(--dental); }
.dot.mixed { background: var(--mixed); }

.fab {
  position: absolute; left: 0.75rem; top: 0.75rem; z-index: 720;
  border: 1px solid var(--panel-border); background: var(--panel);
  color: var(--text); border-radius: 999px; padding: 0.5rem 0.95rem;
  cursor: pointer; box-shadow: var(--shadow); font-size: 0.85rem;
}
#app.collapsed .fab { display: inline-flex; }
.fab[hidden] { display: none !important; }

.detail {
  position: absolute; right: 0.75rem; top: 0.75rem; bottom: 0.75rem;
  width: min(340px, calc(100vw - 1.5rem)); z-index: 750;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; backdrop-filter: blur(12px);
}
.detail[hidden] { display: none !important; }
.detail-head { padding: 0.75rem 1rem 0.4rem; position: relative; }
.detail-head .btn.icon { position: absolute; right: 0.55rem; top: 0.55rem; }
#detail-name {
  margin: 0 2rem 0.35rem 0; font-size: 1.05rem; font-weight: 700; line-height: 1.35;
}
.badge {
  display: inline-block; margin: 0; padding: 0.15rem 0.55rem;
  border-radius: 999px; font-size: 0.72rem;
  background: rgba(78,179,212,0.15); color: var(--accent);
}
.badge.medical { color: var(--medical); background: rgba(61,184,138,0.15); }
.badge.dental { color: var(--dental); background: rgba(91,141,239,0.15); }
.badge.mixed { color: var(--mixed); background: rgba(201,162,39,0.15); }

.viewer3d {
  height: 180px; margin: 0.35rem 0.75rem;
  border-radius: 12px; overflow: hidden;
  background: linear-gradient(160deg, #0e1822, #1a2c3a 55%, #122018);
  border: 1px solid var(--panel-border);
  touch-action: none;
}
.viewer3d canvas { display: block; width: 100% !important; height: 100% !important; }
.viewer-hint {
  margin: 0 1rem 0.4rem; font-size: 0.68rem; color: var(--muted); text-align: center;
}

.detail-meta {
  margin: 0; padding: 0.2rem 1rem 0.5rem;
  overflow: auto; flex: 1; min-height: 0;
}
.detail-meta > div {
  display: grid; grid-template-columns: 3.2rem 1fr; gap: 0.45rem;
  padding: 0.35rem 0; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.detail-meta dt { margin: 0; color: var(--muted); font-size: 0.75rem; }
.detail-meta dd { margin: 0; font-size: 0.85rem; line-height: 1.4; word-break: break-word; }
.approx-note {
  margin: 0 1rem 0.5rem; padding: 0.45rem 0.6rem;
  border-radius: 8px; background: rgba(224,122,106,0.1);
  color: #e8b0a6; font-size: 0.72rem; line-height: 1.4;
}
.detail-actions {
  display: flex; gap: 0.45rem; padding: 0.65rem 1rem 0.9rem;
  border-top: 1px solid var(--panel-border);
}

/* Leaflet cluster theming */
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large {
  background-color: rgba(78, 179, 212, 0.28) !important;
}
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div {
  background-color: rgba(42, 122, 150, 0.9) !important;
  color: #eaf6fb !important; font-weight: 600;
}
.clinic-pin {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.85);
  box-shadow: 0 1px 4px rgba(0,0,0,0.45);
}
.clinic-pin.medical { background: var(--medical); }
.clinic-pin.dental { background: var(--dental); }
.clinic-pin.mixed { background: var(--mixed); }
.clinic-pin.selected {
  width: 18px; height: 18px; border-width: 3px;
  box-shadow: 0 0 0 4px rgba(78,179,212,0.35);
}

/* CSS2D clinic label */
.clinic-label {
  padding: 0.2rem 0.5rem; border-radius: 6px;
  background: rgba(12, 18, 24, 0.85); color: #eaf6fb;
  border: 1px solid rgba(78,179,212,0.45);
  font-size: 11px; font-weight: 600; white-space: nowrap;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none; user-select: none;
  font-family: var(--font);
}

@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; }
  .sidebar {
    position: absolute; inset: 0 auto 0 0; width: var(--sidebar-w);
    max-width: 100%; box-shadow: var(--shadow);
  }
  #app.collapsed .sidebar { transform: translateX(-105%); }
  .detail {
    left: 0.5rem; right: 0.5rem; width: auto;
    top: auto; bottom: 0.5rem; max-height: 55vh;
  }
  .viewer3d { height: 140px; }
}
