/* 터널 파인더 — 프론트 스타일 (빌드 도구 없음, 순수 CSS) */

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e2e6ee;
  --text: #1f2430;
  --text-muted: #6b7280;
  --primary: #2f6fed;
  --primary-dark: #1f4fbd;
  --primary-soft: #eaf1ff;
  --accent: #ff5a36;
  --accent-soft: #ffe9e2;
  --recommend: #16a06a;
  --recommend-soft: #e3f7ee;
  --danger: #d64545;
  --danger-soft: #fdeceb;
  --approx: #b45309;
  --approx-soft: #fdf1dc;
  --avoid: #7c3aed;
  --avoid-soft: #efe7fd;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Apple SD Gothic Neo", "Malgun Gothic", Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p,
ol,
ul {
  margin: 0;
}

button {
  font-family: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
}

/* ---------- 상단 검색바 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
}

.brand {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--primary-dark);
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.field {
  position: relative;
  flex: 1 1 220px;
}

.field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder {
  color: var(--text-muted);
}

.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.field-start input {
  padding-right: 74px;
}

.field-goal input {
  padding-right: 40px;
}

.locate-btn {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.locate-btn:hover {
  background: var(--primary-soft);
}

.locate-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* 즐겨찾기(⭐) 토글 버튼 — locate-btn과 동일 패턴. 출발지 입력창은 📍와 겹치지
   않도록 오프셋(right)만 다르게 준다. */
.fav-btn {
  position: absolute;
  top: 5px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.fav-btn:hover {
  background: var(--primary-soft);
}

.fav-btn-start {
  right: 39px; /* locate-btn(right:5, width:30) 왼쪽에 4px 간격을 두고 배치 */
}

.fav-btn-goal {
  right: 5px;
}

.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  list-style: none;
  padding: 6px;
  max-height: 260px;
  overflow-y: auto;
  z-index: 60;
}

.suggestion-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}

.suggestion-item:hover,
.suggestion-item.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.suggestion-icon {
  flex: 0 0 auto;
  font-size: 12.5px;
  opacity: 0.8;
}

.suggestion-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 즐겨찾기 드롭다운(.suggestions 마크업 재사용) ---------- */

.fav-action-item .suggestion-label {
  font-weight: 600;
  color: var(--primary-dark);
}

.fav-action-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.fav-empty-item {
  cursor: default;
  color: var(--text-muted);
}

.fav-empty-item:hover {
  background: transparent;
}

.fav-item-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2px;
}

.fav-action-btn {
  border: none;
  background: transparent;
  padding: 3px 5px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}

.fav-action-btn:hover {
  background: var(--primary-soft);
}

.primary-btn {
  flex: 0 0 auto;
  padding: 11px 20px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.primary-btn:active {
  transform: translateY(1px);
}

.primary-btn:disabled {
  background: #a9bce8;
  cursor: not-allowed;
}

.form-error {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 500;
}

/* ---------- 경유지 UI ---------- */

.via-section {
  flex: 1 1 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.via-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.via-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 500;
  max-width: 220px;
}

.via-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.via-chip-remove {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--primary-dark);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 50%;
}

.via-chip-remove:hover {
  background: rgba(47, 111, 237, 0.18);
}

/* "＋ 경유지" 클릭 시 임시로 끼워 넣는 자동완성 입력창. .suggestions 클래스를 그대로
   재사용하므로 위치 기준(position: relative)만 여기서 잡아준다. */
.via-input-item {
  position: relative;
  min-width: 180px;
}

.via-input-item .via-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
}

.via-input-item .via-input:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.via-actions {
  display: flex;
  gap: 8px;
}

.via-add-btn,
.via-pick-btn {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.via-add-btn:hover,
.via-pick-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.via-add-btn:disabled,
.via-pick-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* "📍 지도에서 찍기" 모드 켜짐 표시 — 회피 배지와 같은 계열 대신 accent(주황) 톤으로
   "지금 클릭을 기다리는 중" 상태를 눈에 띄게 구분. */
.via-pick-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- 네이버 지도 URL 붙여넣기 (road-search-form과 동일 패턴 재사용) ---------- */

.naver-url-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.naver-url-form input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.naver-url-form input::placeholder {
  color: var(--text-muted);
}

.naver-url-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.naver-url-btn {
  flex: 0 0 auto;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.naver-url-btn:hover {
  background: var(--primary-dark);
}

.naver-url-btn:active {
  transform: translateY(1px);
}

.naver-url-btn:disabled {
  background: #a9bce8;
  cursor: wait;
}

.naver-url-notice {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
}

@media (max-width: 480px) {
  .search-form {
    flex-direction: column;
  }
  .field,
  .primary-btn {
    flex: 1 1 auto;
    width: 100%;
  }
}

.toast {
  margin: 10px 16px 0;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 500;
}

/* ---------- 결과 영역 (2단 레이아웃) ---------- */

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 16px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.panel-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
}

.placeholder {
  color: var(--text-muted);
  font-size: 13.5px;
  padding: 6px 2px;
}

.panel-right {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 360px 1fr;
  }
  .panel-cards {
    max-height: calc(100vh - 130px);
    overflow-y: auto;
    position: sticky;
    top: 106px;
  }
  .panel-tunnels {
    max-height: 240px;
    overflow-y: auto;
  }
}

/* ---------- 경로 후보 카드 ---------- */

.route-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.route-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

.route-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.route-card:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.route-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: var(--shadow-md);
}

.route-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.option-name {
  font-weight: 700;
  font-size: 14.5px;
  color: var(--text);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.badge-recommend {
  background: var(--recommend-soft);
  color: var(--recommend);
}

/* 좌표 근사(축퇴/불가능 비율 원본 데이터를 length_m 기준으로 걸어 추정) 매칭 표시.
   추천(초록)·터널강조(주황)와 겹치지 않도록 별도 톤(호박색) 사용. */
.badge-approx {
  background: var(--approx-soft);
  color: var(--approx);
}

.route-card-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.metric-value {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
}

.metric-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* 경로 카드 "간단 설명"(도로 체인 · 긴 터널) — 작은 회색 글씨, border-left 없이
   여백만으로 구분(전역 컨벤션: border-left 금지). 둘 다 없으면 app.js가 블록 자체를 생략. */
.route-card-desc {
  margin-bottom: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.route-card-desc-line {
  overflow-wrap: break-word;
}

.route-card-desc-line + .route-card-desc-line {
  margin-top: 2px;
}

.route-card-tunnels {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}

.nav-hint {
  margin-top: 6px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-muted);
  text-align: center;
}

/* "터널 회피" 카드 전용 — 비교 문구(예: "터널 15개→2개 · +23분"). border-left 대신
   배지·배경색 톤(--avoid)만으로 강조(전역 컨벤션: border-left 금지). */
.route-card-comparison {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--avoid);
  background: var(--avoid-soft);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}

.badge-avoid {
  background: var(--avoid-soft);
  color: var(--avoid);
}

/* 경로 카드 "위치 미확인 터널" 정직 고지(2026-07-15 추가) — has_coords=0(좌표 없음) 터널이
   이 경로의 도로에 있을 수 있다는 경고 한 줄. 좌표 근사(--approx)와 같은 톤 재사용(둘 다
   "위치 정보가 불확실"이라는 동일 계열 의미) — border-left 대신 배경·글자색 톤만으로 구분
   (전역 컨벤션: border-left 금지). unlocated_tunnels가 있을 때만 app.js가 블록을 만든다. */
.route-card-unlocated {
  margin-top: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--approx);
  background: var(--approx-soft);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  line-height: 1.4;
}

/* ---------- 터널 회피 경로 찾기 패널 (경로 후보 카드 영역 하단) ---------- */

.avoid-panel {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.avoid-btn {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--avoid);
  border-radius: var(--radius-md);
  background: var(--avoid-soft);
  color: var(--avoid);
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.avoid-btn:hover {
  background: var(--avoid);
  color: #fff;
}

.avoid-btn:active {
  transform: translateY(1px);
}

.avoid-btn:disabled {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}

.avoid-status {
  margin-top: 8px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--avoid-soft);
  color: var(--avoid);
  font-size: 13px;
  font-weight: 500;
}

.avoid-status-fail {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- 터널 리스트 ---------- */

.tunnel-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tunnel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.tunnel-item:hover {
  background: var(--bg);
}

.tunnel-item:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.tunnel-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.tunnel-order {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 지하차도는 진짜 터널과 구분: 원형(터널) 대신 각진 사각형 + 무채색(회색)으로 표시.
   통계 집계에는 그대로 포함되고, 표시만 다르다. */
.tunnel-order-underpass {
  border-radius: var(--radius-sm);
  background: var(--text-muted);
}

.tunnel-name {
  flex: 1 1 auto;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.tunnel-length {
  flex: 0 0 auto;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

/* ---------- 도로별 터널 조회 ---------- */

.road-search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.road-search-form input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.road-search-form input::placeholder {
  color: var(--text-muted);
}

.road-search-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.road-search-btn {
  flex: 0 0 auto;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.road-search-btn:hover {
  background: var(--primary-dark);
}

.road-search-btn:active {
  transform: translateY(1px);
}

.road-search-btn:disabled {
  background: #a9bce8;
  cursor: wait;
}

.road-result-head {
  margin-bottom: 8px;
}

.road-result-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  overflow-wrap: break-word;
}

/* roads가 여러 개 매칭되거나 결과가 캡핑됐을 때의 보조 문구 — 여백만으로 구분
   (전역 컨벤션: border-left 금지). */
.road-result-sub {
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-muted);
  overflow-wrap: break-word;
}

.road-tunnel-list {
  max-height: 320px;
  overflow-y: auto;
}

/* length_m >= 2000m 터널 강조 — 이름·길이만 굵게, 색은 그대로(과한 강조 방지). */
.tunnel-item-strong .tunnel-name,
.tunnel-item-strong .tunnel-length {
  font-weight: 700;
}

/* ---------- 지도 ---------- */

.panel-map {
  position: relative;
  min-height: 320px;
  flex: 1 1 380px;
  padding: 0;
  overflow: hidden;
}

@media (min-width: 900px) {
  .panel-map {
    min-height: 460px;
  }
}

.map {
  width: 100%;
  height: 100%;
  min-height: 320px;
  background: #e7ebf2;
}

@media (min-width: 900px) {
  .map {
    min-height: 460px;
  }
}

.map-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
  background: #eef1f7;
  color: var(--text-muted);
}

.map-fallback-icon {
  color: var(--primary);
  opacity: 0.75;
  margin-bottom: 4px;
}

.map-fallback-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.map-fallback-sub {
  font-size: 13px;
  max-width: 320px;
}

/* 네이버 지도 위 터널 강조 마커 (JS에서 icon.content로 삽입) */
.tunnel-marker-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

/* 지하차도 마커: 터널(원형)과 구분되는 각진 사각형 + 무채색. 지도 위 폴리라인도
   JS에서 점선으로 함께 그린다(strokeStyle: shortdash). */
.tunnel-marker-dot-underpass {
  border-radius: 3px;
  background: var(--text-muted);
}

/* 네이버 지도 InfoWindow 내부 콘텐츠 (JS에서 innerHTML로 삽입) */
.tunnel-infowindow {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
}

.tunnel-infowindow strong {
  font-size: 13.5px;
  color: var(--text);
}

.tunnel-infowindow span {
  color: var(--text-muted);
}
