:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #697586;
  --line: #d9e0dc;
  --green: #2f8f5b;
  --blue: #2d6cdf;
  --amber: #c77900;
  --red: #cf3f35;
  --gray: #707985;
  --zone-child: #2563eb;
  --zone-senior: #be185d;
  --zone-disabled: #0891b2;
}

/* Local Leaflet essentials. This keeps the map correct even if CDN CSS is blocked. */
.leaflet-container {
  overflow: hidden;
  background: #ddd;
  outline-offset: 1px;
  touch-action: none;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-container img,
.leaflet-container svg {
  max-width: none;
  max-height: none;
}

.leaflet-tile {
  visibility: hidden;
  user-select: none;
}

.leaflet-tile-loaded {
  visibility: inherit;
}

.leaflet-map-pane {
  z-index: auto;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control-zoom {
  margin: 10px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.18);
}

.leaflet-control-zoom a {
  display: block;
  width: 28px;
  height: 28px;
  color: #222;
  font: bold 18px/28px Arial, Helvetica, sans-serif;
  text-align: center;
  text-decoration: none;
}

.leaflet-control-zoom a + a {
  border-top: 1px solid #d6d6d6;
}

.leaflet-interactive {
  cursor: pointer;
}

.leaflet-grab {
  cursor: grab;
}

.leaflet-dragging .leaflet-grab {
  cursor: move;
}

.leaflet-popup {
  position: absolute;
  margin-bottom: 20px;
  text-align: center;
}

.leaflet-popup-content-wrapper {
  padding: 1px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.25);
}

.leaflet-popup-content {
  min-width: 180px;
  margin: 12px 14px;
  line-height: 1.45;
  text-align: left;
}

.leaflet-popup-tip-container {
  position: absolute;
  left: 50%;
  width: 40px;
  height: 20px;
  margin-left: -20px;
  overflow: hidden;
  pointer-events: none;
}

.leaflet-popup-tip {
  width: 17px;
  height: 17px;
  margin: -10px auto 0;
  transform: rotate(45deg);
  background: #fff;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.25);
}

.leaflet-popup-close-button {
  position: absolute;
  top: 0;
  right: 0;
  width: 24px;
  height: 24px;
  color: #666;
  text-align: center;
  text-decoration: none;
  font: 16px/24px Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Segoe UI",
    "Noto Sans KR",
    system-ui,
    sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  min-height: 0;
  padding: 20px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.panel-header h1 {
  margin: 4px 0 6px;
  font-size: 26px;
  line-height: 1.25;
}

.eyebrow,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.eyebrow {
  color: var(--green);
  font-weight: 700;
  text-transform: uppercase;
}

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

.metric {
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

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

.toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  background: #fbfcfa;
}

input,
select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  font: inherit;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 0;
  accent-color: var(--blue);
}

.activity-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  flex: 1 1 auto;
  gap: 10px;
}

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

.activity-tab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfa;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.activity-tab span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.activity-tab.active {
  border-color: #9fb8aa;
  color: var(--text);
  background: #ffffff;
  box-shadow: inset 0 -3px 0 var(--green);
}

.activity-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  gap: 10px;
}

.activity-panel[hidden] {
  display: none;
}

.filters {
  display: grid;
  gap: 8px;
}

.list-section {
  min-height: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.section-title h2 {
  margin: 0;
  font-size: 16px;
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
}

.event-list,
.run-list {
  display: grid;
  align-content: start;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
  min-height: 0;
}

.event-item,
.run-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.event-item:hover,
.run-item:hover {
  border-color: #9fb8aa;
}

.event-item.selected {
  border-color: var(--green);
  box-shadow: inset 3px 0 0 var(--green);
}

.event-topline,
.run-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.event-title,
.run-title {
  min-width: 0;
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  flex: 0 0 auto;
  padding: 3px 7px;
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.badge.NEW {
  background: var(--green);
}

.badge.DELETED {
  background: var(--red);
}

.badge.MISSING {
  background: var(--gray);
}

.badge.ATTRIBUTE_CHANGED,
.badge.GEOMETRY_CHANGED,
.badge.GEOMETRY_ATTRIBUTE_CHANGED,
.badge.POINT_CHANGED,
.badge.POINT_ATTRIBUTE_CHANGED {
  background: var(--amber);
}

.event-meta,
.run-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.run-error {
  display: inline-block;
  margin: 4px 0 2px;
  color: var(--red);
  font-weight: 700;
}

.timeline-summary {
  color: var(--text);
  font-weight: 700;
}

.zone-type {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text);
  font-weight: 700;
}

.zone-type::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--zone-type-color, var(--gray));
}

.popup-timeline {
  margin: 8px 0;
  padding: 8px 0 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.popup-timeline strong {
  display: block;
  margin-bottom: 4px;
}

.popup-timeline ol {
  display: grid;
  gap: 2px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.map-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.legend {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 500;
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: 8px 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 30px rgba(31, 41, 51, 0.14);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.zone-child {
  background: var(--zone-child);
}

.zone-senior {
  background: var(--zone-senior);
}

.zone-disabled {
  background: var(--zone-disabled);
}

.zone-other {
  background: var(--gray);
}

.change-new {
  background: var(--green);
}

.change-updated {
  background: var(--amber);
}

.change-deleted {
  background: var(--red);
}

.change-missing {
  background: var(--gray);
}

@media (max-width: 900px) {
  .app-shell {
    display: block;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .side-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    gap: 12px;
    max-height: min(58vh, 560px);
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
    overflow: auto;
    border-top: 1px solid var(--line);
    border-right: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -12px 36px rgba(31, 41, 51, 0.2);
  }

  .map-panel {
    height: 100%;
  }

  .panel-header h1 {
    margin-bottom: 4px;
    font-size: 24px;
  }

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

  .metric {
    min-height: 72px;
    padding: 10px;
  }

  .metric strong {
    font-size: 23px;
  }

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

  .toolbar label,
  .activity-tab {
    min-height: 40px;
  }

  .activity-shell {
    overflow: visible;
  }

  .activity-panel {
    min-height: 260px;
  }

  .event-list,
  .run-list {
    max-height: 40vh;
  }

  .legend {
    top: calc(12px + env(safe-area-inset-top));
    right: 12px;
    bottom: auto;
    grid-template-columns: repeat(2, max-content);
    padding: 10px;
  }

  .leaflet-control-zoom {
    margin-top: calc(10px + env(safe-area-inset-top));
  }
}

@media (max-width: 520px) {
  .side-panel {
    max-height: 52vh;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
  }

  .panel-header h1 {
    font-size: 23px;
  }

  .eyebrow,
  .muted {
    font-size: 12px;
  }

  .metrics {
    gap: 8px;
  }

  .metric {
    min-height: 66px;
    padding: 9px;
  }

  .metric strong {
    margin-top: 6px;
    font-size: 22px;
  }

  .toolbar label {
    padding: 8px;
  }

  input[type="checkbox"] {
    width: 17px;
    height: 17px;
  }

  .activity-tabs {
    gap: 6px;
  }

  .activity-tab {
    padding: 8px 10px;
  }

  .legend {
    max-width: calc(100vw - 78px);
    grid-template-columns: repeat(2, max-content);
    gap: 6px 10px;
    font-size: 11px;
  }
}
