:root {
  --sidebar-width: 430px;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #eef4f8;
  --text: #13202f;
  --muted: #647487;
  --line: #dce5ee;
  --primary: #04746d;
  --primary-strong: #075e59;
  --blue: #2563eb;
  --orange: #ea6b16;
  --danger: #dc2626;
  --overlay: rgba(255, 255, 255, 0.94);
  --danger-line: #ef9a9a;
  --shadow: 0 14px 38px rgba(15, 23, 42, 0.16);
  --radius: 8px;
}

[data-theme="dark"] {
  --bg: #101820;
  --surface: #16212b;
  --surface-soft: #1e2b36;
  --text: #e9f1f8;
  --muted: #a7b6c6;
  --line: #2d3e4d;
  --primary: #20b2a6;
  --primary-strong: #14a095;
  --blue: #60a5fa;
  --orange: #fb923c;
  --overlay: rgba(22, 33, 43, 0.94);
  --danger-line: #8f3d3d;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Sarabun", "Noto Sans Thai", system-ui, sans-serif;
  overflow: hidden;
}

body.is-resizing-sidebar {
  cursor: col-resize;
  user-select: none;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: clamp(340px, var(--sidebar-width), min(430px, 42vw)) 1fr;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}

.sidebar {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface);
  transition: opacity 0.18s ease, visibility 0.18s ease;
}

.sidebar-resizer {
  position: absolute;
  top: 0;
  right: -5px;
  z-index: 700;
  width: 10px;
  height: 100%;
  border: 0;
  background: transparent;
  cursor: col-resize;
  padding: 0;
}

.sidebar-resizer::after {
  position: absolute;
  top: 50%;
  left: 3px;
  width: 4px;
  height: 56px;
  border-radius: 999px;
  background: rgba(4, 116, 109, 0.42);
  content: "";
  transform: translateY(-50%);
}

.sidebar-resizer:hover::after,
.sidebar-resizer:focus-visible::after {
  background: var(--primary);
}

.sidebar-collapsed .sidebar {
  width: 0;
  min-width: 0;
  border-right: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.brand {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  background: linear-gradient(135deg, #04746d, #11a89d 60%, #2b7fbd);
  color: #ffffff;
}

.brand h1 {
  margin: 2px 0 6px;
  font-size: 30px;
  line-height: 1.05;
  letter-spacing: 0;
}

.brand p {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  opacity: 0.92;
}

.brand .eyebrow {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  cursor: pointer;
}

.toolbar {
  display: grid;
  flex: 0 0 auto;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.field {
  display: grid;
  gap: 5px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(4, 116, 109, 0.16);
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.button,
.action-link,
.quick-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  padding: 9px 10px;
  color: #ffffff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
  text-decoration: none;
  transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.16s ease;
}

.button:hover,
.action-link:hover,
.quick-action:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.14);
}

.leaflet-popup-content a.action-link,
.leaflet-popup-content a.action-link:visited,
.leaflet-popup-content a.action-link:hover,
.leaflet-popup-content a.action-link:focus {
  color: #ffffff;
  text-decoration: none;
}

.leaflet-popup-content a.action-link span {
  color: inherit;
}

.primary,
.green {
  background: var(--primary);
}

.ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.blue {
  background: var(--blue);
}

.orange,
.call {
  background: var(--orange);
}

.status-strip {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 46px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.status-strip strong {
  color: var(--text);
}

.district-list {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px 22px;
  scrollbar-gutter: stable;
}

.district-group {
  overflow: hidden;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}

.district-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  cursor: pointer;
  list-style: none;
  background: var(--surface-soft);
  font-weight: 900;
}

.district-group summary::-webkit-details-marker {
  display: none;
}

.district-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.dot {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border-radius: 50%;
}

.badge {
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  padding: 4px 8px;
}

.place-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.marker-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.28);
}

.place-name {
  margin-bottom: 1px;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.28;
}

.place-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 116px;
  gap: 10px;
  align-items: start;
}

.place-copy {
  min-width: 0;
  padding-top: 1px;
}

.inline-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  justify-self: end;
  width: 116px;
}

.quick-action {
  min-height: 28px;
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  font-size: 11px;
  font-weight: 900;
  gap: 5px;
  line-height: 1;
  padding: 6px 8px;
  text-decoration: none;
}

.quick-action span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.place-meta,
.popup-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.director-card {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 8px;
  font-size: 12px;
  line-height: 1.55;
}

.director-line,
.phone-line,
.info-row {
  display: flex;
  align-items: flex-start;
  gap: 7px;
}

.phone-line {
  margin-top: 3px;
  color: var(--muted);
}

/* ตารางรายชื่อ รพ.สต. */
.place-table {
  display: grid;
  grid-template-columns: 40px minmax(200px, 1fr) minmax(160px, 1fr) 100px;
  gap: 0;
  border-top: 1px solid var(--line);
}

.table-header {
  display: contents;
}

.table-header > div {
  padding: 10px 12px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  line-height: 1.2;
}

.table-header > div:last-child {
  border-right: none;
}

.place-row {
  display: contents;
}

.place-row > div {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  line-height: 1.4;
}

.place-row > div:last-child {
  border-right: none;
}

.cell-number {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 14px;
  color: #ffffff;
}

.place-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 2px solid #ffffff;
  padding: 0;
  font-weight: 900;
  font-size: 14px;
  color: #ffffff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.18);
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}

.place-number:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.22);
}

.place-number:focus {
  outline: 3px solid rgba(4, 116, 109, 0.14);
  outline-offset: 4px;
}

.cell-name {
  min-width: 0;
}

.place-name {
  font-size: 13px;
  font-weight: 900;
  margin-bottom: 2px;
  line-height: 1.3;
  background: transparent;
  border: none;
  padding: 0;
  text-align: left;
  width: 100%;
  cursor: pointer;
  color: var(--text);
  display: inline-block;
}

.place-name:focus {
  outline: 3px solid rgba(4, 116, 109, 0.14);
  outline-offset: 2px;
  border-radius: 6px;
}

.place-code {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
}

.cell-director {
  min-width: 0;
}

.director-name {
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 2px;
  line-height: 1.3;
}

.director-phone {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
}

.director-phone a {
  color: var(--primary);
  text-decoration: none;
}

.director-phone a:hover {
  text-decoration: underline;
}

.cell-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  padding: 0;
  text-decoration: none;
  transition: all 0.16s ease;
}

.icon-btn:hover {
  border-color: var(--primary);
  background: var(--surface-soft);
  color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.14);
}

.icon-btn:active {
  transform: translateY(0);
}

/* Responsive: บน mobile เปลี่ยนเป็น card layout */
@media (max-width: 768px) {
  .place-table {
    display: block;
  }

  .table-header {
    display: none;
  }

  .place-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 0;
  }

  .place-row > div {
    padding: 0;
    border-bottom: none;
    border-right: none;
  }

  .cell-number {
    grid-column: 1;
    grid-row: 1 / 4;
    width: 36px;
    height: 36px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.28);
    font-size: 12px;
  }

  /* reduce place-number size on small screens to match layout */
  .place-number {
    width: 36px;
    height: 36px;
    font-size: 13px;
    border-width: 2px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.16);
  }

  .cell-name {
    grid-column: 2;
    grid-row: 1;
    border-bottom: 8px solid transparent;
  }

  .cell-director {
    grid-column: 2;
    grid-row: 2;
    border-bottom: 8px solid transparent;
  }

  .cell-actions {
    grid-column: 2;
    grid-row: 3;
    justify-content: flex-start;
  }

  .icon-btn {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
}


.phone-line a {
  color: inherit;
  font-weight: 800;
  text-decoration: none;
}

.popup-info {
  display: grid;
  gap: 5px;
  margin-top: 8px;
  color: #475569;
  font-size: 12px;
  line-height: 1.55;
}

.card-actions,
.popup-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 9px;
}

.card-actions.three,
.popup-actions.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.map-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
}

.sidebar-toggle {
  position: absolute;
  top: 50%;
  left: 0;
  z-index: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  width: 42px;
  height: 96px;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--overlay);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  padding: 8px 6px;
  transform: translateY(-50%);
}

/* Header variant of the sidebar toggle (inline in .brand) */
.brand .sidebar-toggle {
  position: relative;
  top: auto;
  left: auto;
  width: auto;
  height: auto;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  line-height: 1;
}

.brand .sidebar-toggle .sidebar-toggle-icon {
  font-size: 16px;
}

.brand .sidebar-toggle:hover {
  box-shadow: var(--shadow);
}

.sidebar-toggle:hover {
  filter: brightness(1.03);
}

.sidebar-toggle-icon {
  font-size: 22px;
  line-height: 1;
}

.sidebar-collapsed .sidebar-toggle-icon {
  transform: rotate(180deg);
}

#map {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at top left, rgba(239, 246, 250, 0.95), rgba(217, 228, 236, 0.96));
}

.map-title,
.legend {
  position: absolute;
  z-index: 500;
  border: 1px solid rgba(220, 229, 238, 0.84);
  border-radius: var(--radius);
  background: var(--overlay);
  box-shadow: var(--shadow);
}

.map-title {
  top: 16px;
  left: 78px;
  max-width: min(520px, calc(100% - 94px));
  padding: 13px 15px;
}

.map-title p,
.map-title h2,
.map-title span {
  margin: 0;
}

.map-title p {
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
}

.map-title h2 {
  margin-top: 3px;
  font-size: 18px;
  line-height: 1.35;
}

.map-title span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.legend {
  right: 16px;
  bottom: 20px;
  max-width: 280px;
  padding: 13px 15px;
}

.legend h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.legend-note {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  font-size: 13px;
}

.number-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 3px solid #ffffff;
  border-radius: 50%;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.38);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.34);
}

.number-marker.active {
  animation: markerPulse 0.78s ease-in-out infinite alternate;
  outline: 4px solid rgba(250, 204, 21, 0.86);
}

.district-label {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #13202f;
  padding: 3px 8px;
  font-weight: 900;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.16);
}

.popup-card {
  min-width: 250px;
  max-width: 310px;
}

.popup-head {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.popup-title {
  color: #13202f;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.35;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.24);
}

.leaflet-popup-content {
  margin: 14px 14px 13px;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(0px);
  transition: opacity 0.3s ease, backdrop-filter 0.3s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(0px);
}

.loading-container {
  text-align: center;
  max-width: 280px;
}

.loading-spinner {
  position: relative;
  width: 60px;
  height: 60px;
  margin: 0 auto 20px;
}

.spinner-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  border: 3px solid transparent;
  border-top-color: var(--primary);
  border-right-color: var(--primary);
  border-radius: 50%;
  transform: translate(-50%, -50%) rotate(0deg);
  animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

.spinner-ring:nth-child(2) {
  border-color: transparent;
  border-top-color: var(--primary);
  border-right-color: var(--primary);
  animation-delay: -0.4s;
}

.spinner-ring:nth-child(3) {
  border-color: transparent;
  border-top-color: var(--primary);
  border-right-color: var(--primary);
  animation-delay: -0.2s;
}

@keyframes spin {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

.loading-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  line-height: 1.4;
}

.loading-card,
.error-card,
.empty-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted);
  padding: 14px;
  font-size: 14px;
  line-height: 1.6;
}

.error-card {
  border-color: var(--danger-line);
  color: var(--danger);
}

@keyframes markerPulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.34);
  }
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 52vh 48vh;
    min-height: 0;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: 100vh 0;
    grid-template-rows: 100dvh 0;
  }

  .map-panel {
    grid-row: 1;
    height: 52vh;
    height: 52dvh;
  }

  .sidebar-collapsed .map-panel {
    height: 100vh;
    height: 100dvh;
  }

  .sidebar {
    grid-row: 2;
    min-height: 0;
    height: 48vh;
    height: 48dvh;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .sidebar-resizer {
    display: none;
  }

  .sidebar-collapsed .sidebar {
    height: 0;
    border-top: 0;
  }

  .brand {
    padding: 12px 16px;
  }

  .brand h1 {
    font-size: 23px;
  }

  .brand p {
    font-size: 12px;
  }

  .toolbar {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 12px;
  }

  .map-title {
    display: none;
  }
}

@media (max-width: 720px) {
  .app-shell,
  .app-shell.sidebar-collapsed {
    display: block;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }

  .map-panel,
  .sidebar-collapsed .map-panel {
    height: 100vh;
    height: 100dvh;
  }

  .sidebar {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 620;
    width: 100%;
    height: min(78vh, 680px);
    height: min(78dvh, 680px);
    border-top: 1px solid var(--line);
    border-right: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -16px 40px rgba(15, 23, 42, 0.2);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateY(0);
    transition: transform 0.22s ease, opacity 0.18s ease, visibility 0.18s ease;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-collapsed .sidebar {
    width: 100%;
    height: min(78vh, 680px);
    height: min(78dvh, 680px);
    border-top: 1px solid var(--line);
    opacity: 0;
    pointer-events: none;
    transform: translateY(100%);
    visibility: hidden;
  }

  .brand {
    align-items: center;
    padding: 10px 18px;
  }

  .brand h1 {
    margin: 0;
    font-size: clamp(21px, 6vw, 28px);
  }

  .brand p {
    display: none;
  }

  .brand .eyebrow {
    margin-bottom: 2px;
    font-size: 11px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .toolbar {
    gap: 7px;
    padding: 9px 12px;
  }

  .field {
    gap: 3px;
  }

  .field span {
    font-size: 11px;
  }

  .field input,
  .field select {
    min-height: 39px;
    padding: 8px 10px;
    font-size: 14px;
  }

  .actions {
    gap: 7px;
  }

  .button {
    min-height: 38px;
    padding: 7px 8px;
    font-size: 12px;
  }

  .status-strip {
    min-height: 38px;
    padding: 8px 12px;
    font-size: 12px;
  }

  .district-list {
    flex: 0 0 auto;
    min-height: auto;
    overflow: visible;
    padding: 10px 10px 18px;
  }

  .district-group {
    margin-bottom: 10px;
  }

  .district-group summary {
    padding: 10px;
  }

  .place-card {
    gap: 8px;
    padding: 10px;
  }

  .place-head {
    grid-template-columns: minmax(0, 1fr) 96px;
    gap: 8px;
  }

  .inline-actions {
    width: 96px;
  }

  .quick-action {
    min-height: 27px;
    font-size: 10px;
    padding: 5px 7px;
  }

  .director-card {
    margin-top: 6px;
    padding: 7px;
  }

  .sidebar-toggle {
    top: auto;
    bottom: 18px;
    left: 0;
    height: 88px;
    transform: none;
  }

  .sidebar-collapsed .sidebar-toggle {
    bottom: 22px;
  }

  .legend {
    display: none;
  }

  .leaflet-control-zoom {
    margin-top: 12px;
  }

  .leaflet-popup {
    max-width: calc(100vw - 28px);
  }

  .popup-card {
    min-width: 230px;
    max-width: calc(100vw - 58px);
  }
}

@media (max-width: 560px) {
  .actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-actions,
  .card-actions.three {
    grid-template-columns: 1fr;
  }

  .legend {
    right: 10px;
    bottom: 10px;
    max-width: calc(100% - 20px);
  }
}

@media (max-width: 420px) {
  .sidebar {
    height: min(84vh, 720px);
    height: min(84dvh, 720px);
  }

  .sidebar-collapsed .sidebar {
    height: min(84vh, 720px);
    height: min(84dvh, 720px);
  }

  .actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
