:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #dfe4ea;
  --text: #1c2530;
  --muted: #6b7684;
  --accent: #1a73e8;
  --up: #d32f2f;
  --down: #1558d6;
  --map-bg: #ffffff;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  /* 격자는 내용이 창보다 훨씬 크므로 body 높이를 창에 못박아야
     .layout 의 flex:1 이 '남는 높이'로 계산된다 */
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Noto Sans KR", "Malgun Gothic", -apple-system, system-ui, sans-serif;
}

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(0deg, #eef4fd 0%, var(--panel) 100%);
}
/* 제목과 출처를 한 줄에 붙여 헤더 높이를 줄인다 */
.brand { display: flex; align-items: baseline; gap: 10px; }
.topbar h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.src { margin: 0; font-size: 11px; color: var(--muted); }

/* 슬라이더 위 시점 표시 */
.wk-head { display: flex; align-items: baseline; gap: 7px; }
.wk-tag { color: var(--muted); }
.wk-head b { font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.wk-range { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- controls ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.ctl { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.ctl select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  min-width: 168px;
}
.ctl select#fontSize { min-width: 104px; }

/* .ctl select 의 min-width 를 이기도록 뒤에 선언한다 */
.playbar select.speed { width: 56px; min-width: 0; flex: none; padding: 5px 2px 5px 6px; }
.ctl.slider { flex: 1; min-width: 320px; }
.ctl.slider b { color: var(--text); font-variant-numeric: tabular-nums; }
/* 기본(주간)에서는 채움 없이 손잡이만 움직인다. "기간선택" 이 켜지면 JS 가
 * background 에 linear-gradient 를 얹어 시작점(손잡이)~현재(오른쪽 끝)를
 * 파랗게 채운다 — 그래서 트랙 자체는 net 배경(투명/회색)만 그리고, 실제
 * 채움 색은 -webkit-appearance:none 으로 지운 네이티브 트랙 대신 이 background
 * 로 대체한다. */
.ctl input[type=range] {
  flex: 1; min-width: 120px;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  outline: none;
}
.ctl input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 2px #fff;
}
.ctl input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: pointer;
}
.ctl input[type=range]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: transparent;
}

/* 재생 컨트롤 */
.playbar { display: flex; align-items: center; gap: 6px; }
.nav {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.nav:hover { background: #eef2f7; border-color: #c4ccd6; }
.nav:active { background: #e4eaf1; }
.nav.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.speed {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 2px 5px 6px;
  font-size: 12px;
  width: 56px;
  min-width: 0;
  flex: none;
}

/* 체크박스 토글 */
.ctl.toggle .chk { display: flex; align-items: center; gap: 6px; height: 30px; }
.ctl.toggle input { accent-color: var(--accent); width: 15px; height: 15px; }
.ctl.toggle label { color: var(--text); font-size: 13px; cursor: pointer; }

/* 1200~1400px 대에서 컨트롤 바가 두 줄로 밀리는 걸 막는다. select 들의
 * 고정 min-width(168px)와 슬라이더의 min-width(320px) 합이 이 폭대에서
 * 뷰포트를 넘어서는 게 원인이라, 좁아지면 다 같이 줄어들 수 있게 한다.
 * 뒤에서 각 컨트롤의 기본 flex/min-width 를 다시 정의하는 규칙들보다
 * 위에 있으면 밀려 무시되므로, 이 파일에서 그 규칙들 다음(마지막)에 둔다. */
/* 격자 보기는 이미 그 아래 별도 규칙(body[data-view="grid"] .controls 등)으로
 * 좁은 폭에 맞춰져 있으므로, 아래 규칙은 지도 보기에만 스코프한다 — 안 그러면
 * 격자 모드의 "전체 맞춤 보기"·"연도선" 등과 겹쳐 깨진다. */
@media (max-width: 1440px) {
  body[data-view="map"] .controls { gap: 8px 10px; padding: 12px 14px; }
  /* 남는 폭은 슬라이더가 가져가도록 다른 컨트롤은 grow 를 0으로 두고
   * 라벨 한 줄 폭 정도(=제 basis)에서만 움직이게 한다. basis 를 실제
   * 라벨/옵션 글자가 안 잘리는 선까지만 줄여야 내부에서 두 번째 줄바꿈이
   * 나지 않는다. 항목별로 옵션 글자 길이가 다르므로 basis 를 다르게 준다:
   * 지표·표시값·지역은 옵션 문구가 길어 넓게, 글자크기·보합은 짧아 좁게. */
  body[data-view="map"] .ctl:not(.slider) { flex: 0 1 100px; min-width: 0; }
  body[data-view="map"] .ctl:has(#kind),
  body[data-view="map"] .ctl:has(#metric),
  body[data-view="map"] .ctl:has(#sido) { flex-basis: 128px; }
  /* "지역명·변동률" 글자 폭보다 basis 가 넓으면 체크박스 뒤에 빈 공간이
   * 남아 여백처럼 보인다 — 실제 문구 폭에 맞춘다. */
  body[data-view="map"] .ctl.toggle { flex-basis: 112px; }
  body[data-view="map"] .ctl select:not(.speed) { min-width: 0; width: 100%; }
  /* 슬라이더는 절대 이보다 좁아지면 재생바(‹ ▶ › 배속 슬라이더)가 안 들어가
   * 두 줄로 깨지므로 min-width 를 넉넉히 둔다. */
  body[data-view="map"] .ctl.slider { flex: 1 1 260px; min-width: 260px; }
  body[data-view="map"] .ctl.slider input[type=range] { min-width: 60px; }
  body[data-view="map"] .ctl.flatctl { flex: 0 1 168px; }
  body[data-view="map"] .flatctl .flatrow { gap: 6px; flex-wrap: nowrap; }
  body[data-view="map"] .flatctl .chk label { white-space: nowrap; }
  body[data-view="map"] .flatctl .flatsel { min-width: 46px; flex: 1 1 46px; }
  /* 기간선택은 버튼 하나뿐이라 늘어날 필요가 없다 — 남는 폭을 슬라이더로 돌린다. */
  body[data-view="map"] .ctl.periodctl { flex: 0 1 auto; min-width: 0; }
  /* 글자크기는 옵션이 "보통"처럼 짧아 더 좁게 잡는다. select 자체의
   * min-width(104px, 위 70행)가 이 basis 보다 넓으면 상자가 그대로
   * 104px 로 뜨면서 옆 "보합" 라벨과 거의 맞닿아 침범한 것처럼 보이므로
   * select 의 min-width 자체를 줄인다. */
  body[data-view="map"] .ctl:has(#fontSize) { flex: 0 1 68px; margin-right: 8px; }
  body[data-view="map"] .ctl select#fontSize { min-width: 60px; }
}

/* ---- layout ---- */
/* 헤더·컨트롤·푸터 높이는 로고 크기나 컨트롤 줄바꿈에 따라 달라진다.
 * 고정값(132px)을 빼면 어긋나므로 body 를 세로 flex 로 두고 layout 이
 * 남는 높이를 전부 가져가게 한다. */
.layout {
  display: grid;
  grid-template-columns: 1fr var(--side-w, 340px);
  transition: grid-template-columns .22s ease;
  gap: 0;
  flex: 1;
  min-height: 0;
}
#map { width: 100%; height: 100%; background: var(--map-bg); }

/* 지도 안 시점 표시 — Leaflet 컨테이너의 형제로 띄운다 */
.mapwrap { position: relative; min-width: 0; min-height: 0; }
body[data-view="grid"] .mapwrap { display: none; }
.map-week {
  position: absolute;
  top: 16px; right: 42px;
  z-index: 450;                /* Leaflet 컨트롤(400) 위, 접기 버튼(500) 아래 */
  pointer-events: none;        /* 지도 조작을 가리지 않는다 */
  display: flex;
  align-items: baseline;
  gap: 8px;
  /* 상자를 없애고 글자에 흰 테두리만 둘렀다. 왼쪽 끝이 흔들리지 않게
   * 텍스트 자체를 고정폭(weekTextFixed/weekRangeTextFixed)으로 만들어
   * 두므로, 폭을 CSS 로 강제로 잡아둘 필요가 없다 — nowrap 만 유지. */
  white-space: nowrap;
  paint-order: stroke fill;
  -webkit-text-stroke: 5px rgba(255, 255, 255, .92);
}
.map-week b { font-size: 30px; font-weight: 700; letter-spacing: -0.02em;
              color: #1c2530; font-variant-numeric: tabular-nums; }
.map-week span { font-size: 24px; font-weight: 600; color: #3d4855;
                 font-variant-numeric: tabular-nums; }
/* 기간선택 모드일 때만 붙는 "→ 현재 2026년 8월 4주 (08.24~08.30)" 꼬리.
 * 시작 주보다는 눈에 덜 띄어야 하므로 한 단계 작게 둔다. */
/* [hidden] 은 UA 스타일(display:none)과 클래스 선택자가 동률 특정도라
 * 소스 순서로 밀린다 — [hidden] 을 명시해 항상 이기게 한다. */
.map-week-end { display: inline-flex; align-items: baseline; gap: 6px; }
.map-week-end[hidden] { display: none; }
.map-week-end .mwe-arrow { font-size: 20px; font-weight: 600; color: #6b7684; }
.map-week-end b { font-size: 22px; }
.map-week-end span:not(.mwe-arrow) { font-size: 18px; }

.map-logo {
  position: absolute;
  left: 14px; bottom: 12px;
  z-index: 450;
  height: 44px; width: auto;
  opacity: .92;
  pointer-events: none;
  filter: drop-shadow(0 0 3px #fff) drop-shadow(0 0 3px #fff) drop-shadow(0 0 6px #fff);
}

.side {
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow-x: hidden;          /* 접히는 동안 내용이 삐져나오지 않게 */
  overflow-y: auto;
  transition: padding .22s ease, border-left-width .22s ease;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 다른 컨트롤과 같은 모양: 라벨은 위, 그 아래 체크박스+셀렉트를 한 줄로.
 * .ctl 이 세로 스택이라 안쪽을 따로 가로로 묶어야 한 줄에 붙는다. */
.flatctl > .chk { display: inline-flex; align-items: center; gap: 5px; }
.flatctl .flatrow { display: flex; align-items: center; gap: 10px; }

.periodctl .period-anchor { position: relative; height: 30px; display: flex; align-items: center; }
.zbtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* 세로로 쌓지 않고 가로 한 줄짜리 안내 띠로 둔다 — 버튼 바로 아래에 붙는다. */
.period-popup {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
}
/* display:flex 가 [hidden] 의 UA display:none 과 동률 특정도라 그냥 두면
 * hidden 이어도 계속 보인다 — hidden 일 때는 확실히 꺼지도록 명시한다. */
.period-popup[hidden] { display: none; }
.period-popup .period-tip { color: var(--muted); }
.period-popup .zbtn { width: 20px; height: 20px; font-size: 11px; flex: none; }

.side > * { min-width: 312px; }   /* 340px − 좌우 패딩 */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; }

/* ---- summary tiles ---- */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
  box-shadow: var(--shadow);
}
.tile .n { font-size: 11px; color: var(--muted); }
.tile .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* ---- detail ---- */
.detail .rname { font-size: 16px; font-weight: 700; }
.detail .rpath { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.detail.empty { color: var(--muted); font-size: 13px; padding: 6px 0; }

/* 선택 지역이 없을 때 기본으로 보여주는 전국 지수 */
.rdefault {
  display: inline-block;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 8px;
}
.rows { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; }
.rows .k { color: var(--muted); }
.rows .v { text-align: right; font-variant-numeric: tabular-nums; }
.spark-wrap { position: relative; margin-top: 8px; }
#spark { width: 100%; height: 90px; display: block; cursor: crosshair; }
.spark-tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 4px);
  z-index: 5;
  background: rgba(255, 255, 255, .97);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11px;
  line-height: 1.5;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 3px 10px rgba(16, 24, 40, .12);
  font-variant-numeric: tabular-nums;
}
.spark-tip .sp-d { color: var(--muted); }

/* ---- ranks ---- */
.ranks { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ranks h3 { margin: 0 0 6px; font-size: 12px; }
.ranks h3.up { color: var(--up); }
.ranks h3.down { color: var(--down); }
.ranks ol { margin: 0; padding-left: 18px; font-size: 12px; }
.ranks li { margin-bottom: 3px; cursor: pointer; }
.ranks li:hover { color: var(--accent); }
.ranks .nm {
  display: inline-block;
  max-width: 62%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
.ranks .val { float: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---- legend ---- */
.legend {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--text);
  font-size: 11px;
  line-height: 1.5;
  box-shadow: var(--shadow);
}
.leaflet-right .legend { margin-right: 24px; }
.legend .ttl { font-weight: 600; margin-bottom: 6px; font-size: 11.5px; }
.legend .lg-row { display: flex; align-items: center; gap: 7px; }
.legend .lg-row i {
  width: 15px; height: 11px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, .07);
  flex: none;
}
.legend .lg-row span { font-variant-numeric: tabular-nums; white-space: nowrap; }
.legend .lg-row.nd { margin-top: 5px; padding-top: 5px; border-top: 1px solid var(--line); }
.legend .lg-row.nd span { color: var(--muted); }

/* ---- 지도 위 툴팁 (폴리곤이 아닌 지도 컨테이너에 하나만 둔다) ---- */
.hover-tip {
  position: absolute;
  top: 0; left: 0;
  z-index: 650;
  pointer-events: none;
  background: rgba(255, 255, 255, .5);
  border: 1px solid rgba(185, 194, 204, .5);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 12px;
  color: var(--text);
  box-shadow: 0 4px 14px rgba(16, 24, 40, .1);
  backdrop-filter: blur(3px);
  white-space: nowrap;
}
.hover-tip strong { font-size: 13px; }
.hover-tip .t-sido { color: var(--muted); font-size: 11px; }
.hover-tip .t-val { font-variant-numeric: tabular-nums; }

/* ---- 지도 라벨 ---- */
.map-label {
  background: none;
  border: none;
  white-space: nowrap;
  /* iconAnchor 로 중심을 맞추므로 여기서는 상자 안에서만 가운데 정렬한다 */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: visible;
  line-height: 1.15;
  /* 진한 폴리곤 위에서도 읽히도록 흰 테두리를 두른다 */
  paint-order: stroke fill;
  -webkit-text-stroke: 2.5px rgba(255, 255, 255, .78);
}
/* --label-scale 은 컨트롤 패널의 '글자 크기'로 조절된다 */
.map-label .lb-n {
  display: block;
  font-size: calc(10.5px * var(--label-scale, 1));
  color: #1c2530;
  font-weight: 700;
}
.map-label .lb-v {
  display: block;
  font-size: calc(10px * var(--label-scale, 1));
  color: #3d4855;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* 주차 이동 시 색이 튀지 않도록 짧은 페이드를 준다 */
.leaflet-interactive { transition: fill .16s ease-out, fill-opacity .16s ease-out; }

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 20px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.foot .keys { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.foot kbd {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  font: inherit;
  font-size: 10.5px;
  color: var(--text);
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .mapwrap { height: 60vh; }
  #map { height: 100%; }
  .side { border-left: none; border-top: 1px solid var(--line); }
  body.side-off .side { display: none; }
}

/* ---- 데이터소스 탭 + 뷰 전환 탭 묶음 ---- */
.tabgroup { display: flex; align-items: center; gap: 14px; }

/* ---- 뷰 전환 탭 ---- */
.viewtabs { display: flex; gap: 4px; }
.vt {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 7px;
  /* font: inherit 가 뒤에 오면 font-weight 를 되돌리므로 먼저 선언한다 */
  font: inherit;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
/* 이모지 대신 인라인 SVG — 단색이라 버튼 글자색(currentColor)을 그대로
 * 따라가고, 폰트에 따라 모양이 달라지지 않는다. */
.vt-ico { width: 15px; height: 15px; display: block; flex: none; }
.vt:hover { background: #eef2f7; color: var(--text); }
.vt.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- 데이터소스 토글 (부동산원 | KB) ---- */
.sourcetabs {
  display: flex;
  gap: 1px;
  padding: 2px;
  background: var(--panel-2);
  border: 1px solid #c8d0da;
  border-radius: 9px;
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, .08);
}
.st {
  padding: 6px 13px;
  background: transparent;
  color: var(--muted);
  border: none;
  font: inherit;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, color .12s ease, box-shadow .12s ease;
}
/* 그룹 바깥쪽 모서리만 둥글게, 버튼끼리 맞닿는 안쪽은 직각으로 둔다 */
.st:first-child { border-radius: 6px 0 0 6px; }
.st:last-child { border-radius: 0 6px 6px 0; }
.st:hover:not(:disabled):not(.on) { background: #e3e8ef; color: var(--text); }
.st.on,
.st.on:hover {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .25), 0 1px 1px rgba(16, 24, 40, .12);
}
.st:disabled { opacity: .4; cursor: not-allowed; }
.st-short { display: none; }

/* 격자 전용 컨트롤은 지도 모드에서 감춘다 (반대도 마찬가지) */
body[data-view="map"] .grid-only { display: none; }
body[data-view="grid"] .map-only { display: none; }
/* 격자는 세로축 전체가 시간이므로 시점 재생 컨트롤이 필요 없다 */
body[data-view="grid"] .ctl.slider { display: none; }
body[data-view="grid"] .side { display: none; }
/* 격자 모드에서는 한 칸짜리 그리드 + 행 높이를 100% 로 못박아
 * .grid-scroll 이 내용 높이만큼 늘어나 스크롤을 잃는 것을 막는다. */
body[data-view="grid"] .layout {
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  min-height: 0;
}

/* ---- 격자(히트맵) 뷰 ---- */
.gridwrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--panel);
  position: relative;
}

/* 격자 모드의 시간축·맞춤 컨트롤. controls 안에서 한 줄로 흐른다. */
.zoomctl {
  flex-direction: row !important;
  align-items: center;
  gap: 6px;
}

.zbtn {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px; line-height: 1;
  cursor: pointer;
}
.zbtn:hover { background: #eef2f7; border-color: #c4ccd6; }
.zbtn.on:hover { background: var(--accent); border-color: var(--accent); }
.zbtn.wide { width: auto; padding: 0 10px; font-size: 12px; }

/* 헤더 캔버스(지역명)는 고정, 아래 본문만 스크롤한다.
 * 헤더는 본문의 가로 스크롤만 translateX 로 따라간다(가로 넘침은 숨김). */
.grid-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.grid-head-clip { flex: none; overflow: hidden; }
#gridHead { display: block; }

.grid-scroll { flex: 1; min-height: 0; overflow: auto; position: relative; }
/* 축과 본문을 가로로 나란히 놓는다. float/sticky 조합은 두 캔버스를
 * 세로로 쌓아버리므로 inner flex 로 배치하고 축만 sticky 로 고정한다. */
.grid-inner { display: flex; align-items: flex-start; width: max-content; }
#gridAxis { position: sticky; left: 0; z-index: 2; display: block; flex: none; background: #fff; }
#gridCanvas { display: block; flex: none; }

.grid-tip {
  position: absolute;
  z-index: 10;
  display: none;
  pointer-events: none;
  background: rgba(17, 24, 39, .5);
  color: #fff;
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.45;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(16, 24, 40, .22);
}
.grid-tip b { font-size: 13px; }
.grid-tip .gt-path { color: #fff; font-size: 11px; }
.grid-tip .gt-val { font-variant-numeric: tabular-nums; }

/* hidden 속성이 display:flex/grid 에 밀리지 않게 못박는다 */
#map[hidden], .gridwrap[hidden] { display: none !important; }


.zchk { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.zchk input { accent-color: var(--accent); cursor: pointer; }
/* 가로 맞춤 상태에서는 격자가 가로로 넘치지 않는다 */
body[data-view="grid"] .grid-scroll.no-xscroll { overflow-x: hidden; }

/* 축을 잡고 끌면 확대/축소 — 커서로 조작 가능함을 알린다 */
#gridAxis { cursor: ns-resize; }
#gridHead { cursor: ew-resize; }
body.dragging-y, body.dragging-y * { cursor: ns-resize !important; user-select: none; }
body.dragging-x, body.dragging-x * { cursor: ew-resize !important; user-select: none; }
.grid-tip .gt-up, .grid-tip .gt-down { color: #fff; }

/* ---- 격자 모드: 컨트롤 바를 1열로 눕혀 높이를 줄인다 ----
 * 지도 모드는 라벨을 위에 두는 2단 배치를 그대로 쓰고,
 * 격자 모드에서만 라벨과 입력을 같은 줄에 놓는다. */
body[data-view="grid"] .controls {
  gap: 6px 8px;
  padding: 6px 14px;
  align-items: center;
}
body[data-view="grid"] .ctl {
  flex-direction: row;
  align-items: center;
  gap: 4px;
}
body[data-view="grid"] .ctl > span:first-child { white-space: nowrap; }
body[data-view="grid"] .ctl select {
  padding: 4px 8px;
  font-size: 12px;
  min-width: 0;
}
body[data-view="grid"] .zbtn { width: 24px; height: 24px; }
body[data-view="grid"] .zbtn.wide { width: auto; padding: 0 9px; height: 24px; }

/* 격자 모드에서 필요 없는 지도 전용 컨트롤은 감춘다 */
body[data-view="grid"] .ctl.toggle,
body[data-view="grid"] .ctl:has(#sido),
body[data-view="grid"] .ctl:has(#fontSize) { display: none; }

/* 격자 캔버스 바로 위 여백을 없앤다 */
body[data-view="grid"] .gridwrap { border-top: 1px solid var(--line); }

/* ---- 격자 모드: 컨트롤 바 우측 색 범례 ----
 * 구간마다 색 칸 아래에 그 구간의 값 범위를 적는다. 보합도 하나의 구간으로
 * 색 띠 안에 들어가므로 별도 칩이 없다. */
.legend-inline {
  flex-direction: row !important;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  min-width: 0;
}
.legend-inline .lg-cap {
  color: var(--muted);
  white-space: nowrap;
  font-size: 11px;
}
.legend-inline .lg-bands { display: flex; min-width: 0; }
.legend-inline .lg-band {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  flex: 0 1 auto;
}
.legend-inline .lg-band i {
  height: 10px;
  display: block;
  border: 1px solid rgba(15, 23, 42, .12);
  border-right: none;
}
.legend-inline .lg-band:last-child i { border-right: 1px solid rgba(15, 23, 42, .12); }
.legend-inline .lg-band em {
  font-style: normal;
  font-size: 8.5px;
  line-height: 1.35;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
  padding: 0 2px;
  overflow: hidden;
  text-overflow: clip;
}

/* 본문은 잡아끌어 이동할 수 있다 */
#gridCanvas { cursor: default; }
body.panning, body.panning * { cursor: grabbing !important; user-select: none; }

/* 범례가 줄바꿈되지 않도록 컨트롤 바를 한 줄로 눌러 담는다 */
body[data-view="grid"] .controls { flex-wrap: nowrap; overflow: hidden; }
body[data-view="grid"] .ctl select { max-width: 108px; }
body[data-view="grid"] .legend-inline { flex: none; }

/* zoomctl 안에서 버튼·체크박스가 두 줄로 접히지 않게 한다 */
body[data-view="grid"] .zoomctl { flex-wrap: nowrap; white-space: nowrap; }
body[data-view="grid"] .zchk span { white-space: nowrap; }

/* 범례가 오른쪽 끝에 딱 붙도록 여백을 정리한다 */
body[data-view="grid"] .controls { padding-right: 10px; }
body[data-view="grid"] .legend-inline { padding-right: 2px; }

/* 폭이 모자라면 가운데 컨트롤들이 먼저 줄어들고, 범례는 끝까지 온전히 남는다 */
body[data-view="grid"] .ctl { min-width: 0; }
body[data-view="grid"] .ctl select { flex: 1 1 auto; min-width: 60px; }

body[data-view="grid"] .legend-inline { flex: 0 1 auto; min-width: 0; }

/* 범례가 넓어져 컨트롤을 덮지 않도록 폭을 제한하고, 넘치면 라벨을 줄인다 */
/* 범례가 한 줄에 안 들어가면 다음 줄로 내린다 — 구간 수치가 잘려 읽히지
 * 않으면 범례를 넣은 의미가 없다. 표시값에 따라 범례 폭이 달라지므로
 * 고정 breakpoint 대신 실측해서 .legend-wrap 을 붙인다(app.js). */
body[data-view="grid"] .controls.legend-wrap { flex-wrap: wrap; }
body[data-view="grid"] .controls.legend-wrap .legend-inline {
  margin-left: 0;
  width: 100%;
}
/* 보합 셀렉트는 지도·격자 공용이라 뷰에 상관없이 폭을 좁게 고정한다.
 * 예전엔 격자 전용이라 grid 뷰에만 걸려 있었고, 지도에서는 일반
 * 컨트롤 폭으로 늘어났다. */
/* 폭은 가장 긴 항목('0 (변동없음)')에 맞춘다 */
select.flatsel { min-width: 0; width: 116px; padding: 3px 6px; font-size: 12px; }
body[data-view="grid"] select.flatsel { width: 108px; padding: 3px 4px; font-size: 11px; }

/* '전체 보기'는 격자에서 가장 자주 쓰는 버튼이라 조금 더 눈에 띄게 한다 */
body[data-view="grid"] #zFitAll {
  height: 26px;
  padding: 0 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  border-color: #c4ccd6;
}
body[data-view="grid"] #zFitAll:hover {
  background: #e8eef6;
  border-color: #9fb0c4;
}

/* '전체 맞춤 보기'는 토글이 아니라 별개 동작이라 왼쪽 여백을 띄운다 */
body[data-view="grid"] #zFitAll { margin-left: 14px; }

/* ---- 사이드바 접기 ---- */
.side-toggle {
  position: absolute;
  top: 50%;
  right: 340px;                /* 사이드바 폭에 맞춰 붙는다 */
  transform: translateY(-50%);
  z-index: 500;                /* Leaflet 컨트롤 위 */
  width: 18px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  border-right: none;
  border-radius: 6px 0 0 6px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  box-shadow: -1px 0 3px rgba(16, 24, 40, .06);
  transition: right .22s ease, background .12s ease, color .12s ease;
}
.side-toggle:hover { background: #eef2f7; color: var(--text); }

/* 접힌 상태: 사이드바 폭만 0 으로 줄인다. display:none 은 전환이 안 걸려
 * 툭 끊기므로, 폭을 애니메이션하고 내용은 overflow 로 잘라낸다. */
body.side-off { --side-w: 0px; }
body.side-off .side { border-left-width: 0; padding-left: 0; padding-right: 0; }
body.side-off .side-toggle { right: 0; }

/* 격자 모드에서는 사이드바 자체가 숨겨지므로 버튼도 감춘다 */
body[data-view="grid"] .side-toggle { display: none; }

/* 버튼을 layout 기준으로 앉히기 위해 위치 기준을 준다 */
.layout { position: relative; }

/* ---- 헤더 브랜드 (로고 제거, 제목만) ---- */
.brand { align-items: center; gap: 12px; }
.brand .titles { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { line-height: 1.2; }

/* 좁은 화면: 소스탭은 짧은 라벨("부동산원 | KB")로, 뷰탭은 아이콘만 */
@media (max-width: 900px) {
  .st-full { display: none; }
  .st-short { display: inline; }
  .vt-txt { display: none; }
  .vt { padding: 7px 12px; }
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .brand h1 { font-size: 18px; }
  .h1-sub { display: none; }
}

/* 즉시 뜨는 커스텀 툴팁. 브라우저 기본 title 은 1초 가까이 지연되어
   단축키 안내로는 늦다. 올리는 순간 바로 보이게 직접 그린다. */
.tip { position: relative; }
.tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 41, 59, .55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -.2px;
  padding: 6px 9px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  z-index: 60;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .16);
}
.tip::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(30, 41, 59, .55);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  z-index: 60;
}
.tip:hover::after, .tip:hover::before,
.tip:focus-visible::after, .tip:focus-visible::before { opacity: 1; visibility: visible; }
