* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: #1f2430;
  background: #f5f6f8;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* 모바일 브라우저 주소창 높이를 뺀 실제 화면 높이 */
}

#topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: #1f2430;
  color: #fff;
  flex-wrap: wrap;
  position: relative;
  z-index: 20; /* 검색 목록이 광고·지도 위로 펼쳐지게 */
}

#topbar h1 {
  font-size: 18px;
  margin: 0;
  white-space: nowrap;
}

#search-form {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 280px;
}

#search-box {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
}

#address-input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #444a5a;
  font-size: 14px;
}

/* 장소·주소 검색 목록 */
#search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: min(60vh, 440px);
  overflow-y: auto;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: #fff;
  color: #1f2430;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

#search-results.hidden {
  display: none;
}

.search-item {
  padding: 9px 14px;
  border-bottom: 1px solid #f0f1f4;
  cursor: pointer;
}

.search-item:last-child {
  border-bottom: none;
}

.search-item:hover,
.search-item.active {
  background: #fff6d6;
}

.si-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.si-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.si-cat {
  flex-shrink: 0;
  font-size: 12px;
  color: #8a90a0;
}

.si-cat-address {
  padding: 0 6px;
  border-radius: 4px;
  background: #eef1f6;
  color: #4a5266;
}

.si-sub {
  margin-top: 2px;
  font-size: 12px;
  color: #5a6070;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-empty {
  padding: 12px 14px;
  font-size: 13px;
  color: #8a90a0;
}

#search-form button {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: #ffd23f;
  color: #1f2430;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

#search-form button:hover {
  background: #ffdb63;
}

#search-form button:disabled {
  background: #9a9a9a;
  cursor: default;
}

#layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

#sidebar {
  width: 340px;
  min-width: 340px;
  background: #fff;
  border-right: 1px solid #e2e4ea;
  overflow-y: auto;
  padding: 16px;
}

#layer-toggles h2 {
  font-size: 13px;
  color: #666;
  margin: 0 0 10px;
  font-weight: 600;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  font-size: 14px;
  cursor: pointer;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.dot-onstreet { background: #e74c3c; }
.dot-offstreet { background: #3498db; }
.dot-attached { background: #2ecc71; }
.dot-resident { background: #9b59b6; }
.dot-ev { background: #00b894; }
.dot-building { background: #636e72; }

.hint {
  font-size: 12px;
  color: #8a8f9c;
  line-height: 1.5;
}

.layer-note {
  margin: -2px 0 6px 24px;
  color: #a8760a;
  background: #fff8e6;
  border: 1px solid #ffe8a3;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11px;
}

#result-panel {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #eee;
}

#result-panel.empty {
  color: #8a8f9c;
}

.ad-slot-sidebar {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid #eee;
}

.ad-label {
  font-size: 10px;
  color: #b0b4bd;
  letter-spacing: 0.05em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

.ad-container {
  height: 250px;
  overflow: hidden;
  border-radius: 6px;
}

.ad-slot-top-banner {
  padding: 8px 20px;
  background: #fff;
  border-bottom: 1px solid #e2e4ea;
}

.ad-slot-top-banner .ad-label {
  text-align: center;
}

.ad-slot-top-banner .ad-container {
  height: 90px;
}

.mock-ad {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  border: 1px dashed #d5d8df;
  border-radius: 6px;
  color: #b0b4bd;
  font-size: 12px;
}

.result-title {
  font-size: 13px;
  color: #666;
  margin: 0 0 4px;
}

.result-region {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px;
}

.result-place {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 2px;
}

.result-place + .result-region {
  font-size: 13px;
  font-weight: 400;
  color: #555;
}

.result-category {
  font-size: 12px;
  font-weight: 400;
  color: #8a90a0;
}

.result-total {
  background: #fff8e6;
  border: 1px solid #ffe8a3;
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  margin-bottom: 14px;
}

.result-total .num {
  font-size: 32px;
  font-weight: 800;
  color: #b8860b;
  line-height: 1.2;
}

.result-total .label {
  font-size: 12px;
  color: #8a7440;
  margin-top: 2px;
}

.result-method {
  font-size: 11px;
  color: #a08a4a;
  margin-top: 6px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.kakao-map-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 6px;
  background: #fee500; /* 카카오 노랑 */
  color: #191919;
  text-decoration: none;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.kakao-map-link:hover {
  background: #f5dc00;
}

.kakao-map-link img {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.dest-route {
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.dest-route .kakao-map-link {
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
}

.dest-route .kakao-map-link img {
  width: 18px;
  height: 18px;
  border-radius: 4px;
}

.nearby-section {
  margin-bottom: 16px;
}

.nearby-title {
  font-size: 12px;
  font-weight: 600;
  color: #666;
  margin: 0 0 8px;
}

.nearby-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid #eee;
  border-radius: 8px;
  margin-bottom: 6px;
}

.nearby-info {
  min-width: 0;
}

.nearby-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nearby-dist {
  font-size: 11px;
  color: #8a8f9c;
  margin-top: 2px;
}

.nearby-item .kakao-map-link {
  margin-top: 0;
  flex-shrink: 0;
}

.building-card {
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 12.5px;
  line-height: 1.7;
}

.building-card .bld-name {
  font-weight: 700;
  font-size: 13.5px;
  margin-bottom: 4px;
}

.building-card table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
}

.building-card td {
  padding: 2px 0;
  font-size: 12px;
  color: #444;
}

.building-card td.k {
  color: #8a8f9c;
  width: 40%;
}

.error-box {
  background: #fdeceb;
  border: 1px solid #f5b7ae;
  color: #a8352a;
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.6;
}

#map-wrap {
  flex: 1;
  position: relative;
  isolation: isolate; /* 카카오 지도 안쪽 요소의 z-index 가 검색 목록을 덮지 않게 */
}

#map {
  width: 100%;
  height: 100%;
}

#kakao-key-banner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: #f5f6f8;
  color: #555;
  font-size: 14px;
  line-height: 1.8;
  padding: 20px;
}

#kakao-key-banner.hidden {
  display: none;
}

#kakao-key-banner code {
  background: #e7e9ee;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12.5px;
}

#locate-btn {
  position: absolute;
  right: 12px;
  bottom: 28px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px 8px 11px;
  border: 1px solid #d5d8de;
  border-radius: 20px;
  background: #fff;
  color: #1f2430;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  cursor: pointer;
}

#locate-btn:hover {
  background: #f5f6f8;
}

#locate-btn.hidden {
  display: none;
}

#locate-btn.active svg {
  color: #1a73e8;
}

#locate-btn.locating svg {
  animation: locate-blink 1s ease-in-out infinite;
}

@keyframes locate-blink {
  50% { opacity: 0.3; }
}

/* 지도 위 내 위치 표시: 파란 점 + 퍼지는 테두리 (정확도 범위는 kakao.maps.Circle로 따로 그린다) */
.my-location-dot {
  position: relative;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1a73e8;
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.my-location-dot::after {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  background: rgba(26, 115, 232, 0.3);
  animation: my-location-pulse 2s ease-out infinite;
  z-index: -1;
}

@keyframes my-location-pulse {
  from { transform: scale(0.4); opacity: 1; }
  to { transform: scale(1.4); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .my-location-dot::after,
  #locate-btn.locating svg {
    animation: none;
  }
}

#map-toast {
  position: absolute;
  left: 50%;
  bottom: 80px;
  z-index: 6;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(31, 36, 48, 0.92);
  color: #fff;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

#map-toast.hidden {
  display: none;
}

.kakao-info-window {
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.6;
  width: 230px;
  box-sizing: border-box;
}

.kakao-info-window .title {
  font-weight: 700;
  margin-bottom: 2px;
}

.roadview-link {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  background: #2d3e50;
  color: #fff;
  border: none;
  text-decoration: none;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
}

.roadview-link:hover {
  background: #1c2733;
}

.dest-route .roadview-link {
  padding: 8px 14px;
  font-size: 13px;
}

#roadview-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#roadview-modal.hidden {
  display: none;
}

#roadview-modal-inner {
  position: relative;
  width: min(1000px, 92vw);
  height: min(650px, 82vh);
  background: #111;
  border-radius: 10px;
  overflow: hidden;
}

#roadview-container {
  width: 100%;
  height: 100%;
}

#roadview-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: #fff;
  color: #191919;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

#roadview-close:hover {
  background: #eee;
}

#roadview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  margin: 0;
  background: #111;
}

#roadview-empty.hidden {
  display: none;
}

/* ---------- 반응형 ---------- */

/* 태블릿: 사이드바를 좁혀 지도를 넓힌다 */
@media (max-width: 1024px) {
  #topbar {
    gap: 16px;
    padding: 10px 16px;
  }

  #sidebar {
    width: 280px;
    min-width: 280px;
    padding: 14px;
  }

  .ad-slot-top-banner {
    padding: 8px 16px;
  }
}

/* 휴대폰: 지도를 위에 크게 두고 레이어 선택·조회 결과·광고는 그 아래로. 페이지 전체가 스크롤된다 */
@media (max-width: 768px) {
  #app {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  #topbar {
    gap: 8px;
    padding: 10px 12px;
  }

  #topbar h1 {
    font-size: 16px;
  }

  #search-form {
    flex-basis: 100%;
    min-width: 0;
  }

  #address-input {
    min-width: 0;
    font-size: 16px; /* 16px보다 작으면 iOS가 입력할 때 화면을 확대한다 */
  }

  .search-item {
    padding: 11px 14px; /* 손가락으로 누르기 쉽게 */
  }

  #search-form button {
    padding: 8px 12px;
  }

  .ad-slot-top-banner {
    padding: 6px 12px;
  }

  .ad-slot-top-banner .ad-container {
    height: 50px; /* 모바일 배너(320x50) 높이 */
  }

  #layout {
    flex-direction: column;
  }

  #map-wrap {
    order: -1;
    flex: none;
    height: 62vh;
    height: 62svh;
    min-height: 320px;
  }

  #sidebar {
    display: flex;
    flex-direction: column;
    width: auto;
    min-width: 0;
    border-right: none;
    border-top: 1px solid #e2e4ea;
    overflow: visible;
    padding: 14px 12px 24px;
  }

  #layer-toggles {
    order: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  #result-panel {
    order: 2;
    scroll-margin-top: 8px;
  }

  .ad-slot-sidebar {
    order: 3;
  }

  /* 광고 두 개가 연달아 붙지 않도록 휴대폰에서는 아래쪽 광고를 뺀다 */
  .ad-slot-sidebar[data-ad-key="sidebar_bottom"] {
    display: none;
  }

  #layer-toggles h2,
  #layer-toggles .hint {
    flex-basis: 100%;
    margin: 0;
  }

  #layer-toggles h2 {
    margin-bottom: 2px;
  }

  #viewport-note:empty {
    display: none;
  }

  /* 레이어 선택을 줄바꿈되는 칩 모양으로 */
  .layer-item {
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid #e2e4ea;
    border-radius: 16px;
    font-size: 13px;
  }

  .layer-item input {
    margin: 0;
  }
}

/* 마우스가 없는 터치 기기에서는 우클릭 안내를 숨긴다 */
@media (hover: none) {
  .hint-rightclick {
    display: none;
  }
}
