:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e4e7ec;
  --text: #1a2233;
  --sub: #5b6577;
  --muted: #8a93a3;
  --navy: #17233f;
  --commercial: #2f6fed;
  --commercial-soft: #e8f0fe;
  --land: #17935f;
  --land-soft: #e4f5ec;
  --accent: var(--commercial);
  --accent-soft: var(--commercial-soft);
  --warn-bg: #fff6e0;
  --warn-text: #8a5a00;
  --radius: 10px;
  --shadow: 0 4px 18px rgba(20, 30, 50, 0.12);
}
body.type-land { --accent: var(--land); --accent-soft: var(--land-soft); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
input { font: inherit; }
h3 { font-size: 13px; font-weight: 700; margin: 0 0 10px; color: var(--text); }
.muted { color: var(--muted); font-weight: 500; }

/* 상단바 */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  background: var(--navy);
  color: #fff;
  flex-shrink: 0;
  z-index: 1001;
}
.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, #5d8cff, #2f6fed 55%, #17935f);
}
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: -0.3px; }
.brand-tag { font-size: 11px; color: #9fb0d0; border: 1px solid #3a4a6e; border-radius: 4px; padding: 1px 5px; }

.search { position: relative; flex: 1; max-width: 420px; }
.search input {
  width: 100%; height: 36px; border-radius: 8px; border: 0;
  padding: 0 12px; background: #24335a; color: #fff; outline: none;
}
.search input::placeholder { color: #9fb0d0; }
.search input:focus { background: #fff; color: var(--text); }
.search-results {
  position: absolute; top: 42px; left: 0; right: 0;
  margin: 0; padding: 6px; list-style: none;
  background: #fff; color: var(--text); border-radius: 8px; box-shadow: var(--shadow);
}
.search-results li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; }
.search-results li:hover, .search-results li.active { background: var(--bg); }
.search-results li span { color: var(--muted); font-size: 12px; }

.btn-ghost { background: transparent; border: 0; color: inherit; padding: 6px 10px; border-radius: 6px; }
.btn-ghost:hover { background: rgba(127, 127, 127, 0.12); }
.filter-toggle { display: none; margin-left: auto; border: 1px solid #3a4a6e; }

.sample-banner {
  background: var(--warn-bg); color: var(--warn-text);
  font-size: 12px; font-weight: 600; text-align: center; padding: 6px 12px; flex-shrink: 0;
}

/* 레이아웃 */
.layout { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar {
  width: 300px; flex-shrink: 0; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 16px;
}
.map-area { flex: 1; position: relative; min-width: 0; }
#map { width: 100%; height: 100%; background: #e9ecef; } /* 네이버지도가 position을 relative로 덮어쓰므로 inset 대신 크기 지정 */

/* 사이드바 필터 */
.type-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 8px; padding: 4px; margin-bottom: 18px; }
.tab { border: 0; background: transparent; padding: 9px 0; border-radius: 6px; font-weight: 700; color: var(--sub); }
.tab.active { background: #fff; color: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

.filter-group { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--sub);
  border-radius: 999px; padding: 5px 12px; font-size: 13px;
}
.chip.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.range-inputs { display: flex; align-items: center; gap: 8px; }
.range-inputs input {
  width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 6px; padding: 0 10px; outline: none;
}
.range-inputs input:focus { border-color: var(--accent); }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--sub); cursor: pointer; }
.filter-group > .check + .check { margin-top: 8px; }
.check input { accent-color: var(--accent); }

.ranking { border-bottom: 0; }
.ranking ol { list-style: none; margin: 0; padding: 0; }
.ranking li {
  display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 8px;
  padding: 8px 6px; border-radius: 6px; cursor: pointer;
}
.ranking li:hover, .ranking li.active { background: var(--accent-soft); }
.ranking .rank { color: var(--muted); font-size: 12px; font-weight: 700; }
.ranking .name { font-weight: 600; }
.ranking .meta { font-size: 12px; color: var(--sub); text-align: right; }
.ranking .meta b { color: var(--text); }
.note { font-size: 11.5px; line-height: 1.55; color: var(--muted); margin: 0; }

/* 지도 마커 */
.marker-wrap { background: none; border: 0; }
.dong-marker {
  transform: translate(-50%, -100%);
  display: inline-flex; flex-direction: column; align-items: center;
  cursor: pointer; white-space: nowrap; user-select: none;
}
.dong-marker .bubble {
  background: #fff; border: 2px solid var(--accent); border-radius: 10px;
  padding: 4px 9px 5px; box-shadow: 0 2px 8px rgba(0,0,0,.15);
  text-align: center; line-height: 1.25;
}
.dong-marker .bubble .n {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px;
  border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
}
.dong-marker .bubble .t { font-size: 12px; font-weight: 700; color: var(--text); }
.dong-marker .bubble .p { font-size: 11px; color: var(--accent); font-weight: 700; }
.dong-marker .tail {
  width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-top: 7px solid var(--accent);
}
.dong-marker.active .bubble { background: var(--accent); }
.dong-marker.active .bubble .t, .dong-marker.active .bubble .p { color: #fff; }
.dong-marker.active .bubble .n { background: #fff; color: var(--accent); }
.dong-marker.empty .bubble { border-color: #b9c0cc; }
.dong-marker.empty .tail { border-top-color: #b9c0cc; }
.dong-marker.empty .bubble .p { color: var(--muted); }

.legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 500;
  background: rgba(255,255,255,.95); border-radius: 8px; box-shadow: var(--shadow);
  padding: 7px 12px; font-size: 11.5px; color: var(--sub); display: flex; gap: 12px;
}

/* 상세 패널 */
.detail {
  position: absolute; top: 12px; right: 12px; bottom: 12px; width: 400px; z-index: 900;
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
  overflow-y: auto; padding: 18px;
}
.detail[hidden] { display: none; }
.sheet-handle { display: none; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.detail-head h2 { margin: 2px 0 0; font-size: 22px; letter-spacing: -0.4px; }
.detail-sub { margin: 0; font-size: 12px; font-weight: 700; color: var(--accent); }
.detail-head .btn-ghost { color: var(--sub); font-size: 16px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
.stat { background: var(--bg); border-radius: var(--radius); padding: 10px 12px; }
.stat .label { font-size: 11.5px; color: var(--sub); }
.stat .value { font-size: 17px; font-weight: 800; margin-top: 2px; letter-spacing: -0.3px; }
.stat .value small { font-size: 12px; font-weight: 600; color: var(--sub); }

.chart-box { margin-bottom: 18px; }
#chart svg { display: block; width: 100%; height: auto; }
#chart .bar { fill: var(--accent); opacity: .85; }
#chart .bar:hover { opacity: 1; }
#chart text { font-size: 10px; fill: var(--muted); font-family: inherit; }
#chart .val { fill: var(--text); font-weight: 700; }
.empty-msg { color: var(--muted); font-size: 13px; padding: 16px 0; text-align: center; }

.deal-list { list-style: none; margin: 0; padding: 0; }
.deal {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 8px;
}
.deal-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.deal-price { font-size: 17px; font-weight: 800; letter-spacing: -0.3px; }
.deal-date { font-size: 12px; color: var(--muted); }
.deal-pp { font-size: 12.5px; color: var(--accent); font-weight: 700; margin-top: 2px; }
.deal-info { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 8px 0 0; font-size: 12.5px; }
.deal-info dt { color: var(--muted); }
.deal-info dd { margin: 0; color: var(--text); }
.badges { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 4px; background: var(--bg); color: var(--sub); }
.badge.warn { background: #fdecec; color: #c0392b; }

/* 모바일 */
@media (max-width: 860px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .brand-tag { display: none; }
  .filter-toggle { display: inline-block; }
  .sidebar {
    position: absolute; top: 0; left: 0; bottom: 0; width: min(320px, 88vw); z-index: 1000;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  body.filters-open .sidebar { transform: none; }
  .legend { display: none; }
  .detail {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 72%;
    border-radius: 16px 16px 0 0; padding-top: 8px;
  }
  .sheet-handle { display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
}

/* ---------- 상단 메뉴 ---------- */
.brand { color: #fff; text-decoration: none; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a {
  color: #b8c4dc; text-decoration: none; font-weight: 600; font-size: 14px;
  padding: 7px 12px; border-radius: 7px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav a.active { color: #fff; background: #24335a; }
.badge-count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #e5484d; color: #fff;
  font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- 실거래 마커 (건물 단위) ---------- */
.deal-marker {
  transform: translate(-50%, -100%);
  display: inline-flex; flex-direction: column; align-items: center; cursor: pointer; white-space: nowrap; user-select: none;
}
.deal-marker .bubble {
  position: relative; background: #fff; border: 1.5px solid var(--accent); border-radius: 6px;
  padding: 2px 7px 3px; text-align: center; line-height: 1.2; box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.deal-marker .u { display: block; font-size: 10px; color: var(--sub); font-weight: 600; }
.deal-marker .p { font-size: 13px; font-weight: 800; color: var(--accent); letter-spacing: -0.3px; }
.deal-marker .d { font-size: 10px; color: var(--muted); }
.deal-marker .n {
  position: absolute; top: -8px; right: -8px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--navy); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px;
}
.deal-marker .tail { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid var(--accent); }
.deal-marker.active .bubble { background: var(--accent); }
.deal-marker.active .u, .deal-marker.active .p, .deal-marker.active .d { color: #fff; }

.map-notice {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 500;
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow);
}

/* 사이드바 최근 실거래 */
.recent { border-bottom: 0; }
.recent ol { list-style: none; margin: 0; padding: 0; }
.recent li { padding: 9px 8px; border-radius: 6px; cursor: pointer; border-bottom: 1px solid var(--line); }
.recent li:hover, .recent li.active { background: var(--accent-soft); }
.recent .r-top { display: flex; justify-content: space-between; align-items: baseline; }
.recent .r-top b { font-size: 14px; }
.recent .r-top span { font-size: 11.5px; color: var(--muted); }
.recent .r-sub { font-size: 12px; color: var(--sub); margin-top: 2px; }

/* 상세 패널 건물 정보 */
.detail-road { margin: 2px 0 0; font-size: 12.5px; color: var(--sub); }
.bld-info {
  display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0 0 18px; padding: 12px 14px;
  background: var(--bg); border-radius: var(--radius); font-size: 13px;
}
.bld-info:empty { display: none; }
.bld-info dt { color: var(--muted); }
.bld-info dd { margin: 0; }

/* ---------- 문서형 페이지 (건축물대장 / 검토 요청) ---------- */
body.page-doc { display: block; height: auto; min-height: 100%; }
body.page-doc .topbar { position: sticky; top: 0; }
.doc { max-width: 1240px; margin: 0 auto; padding: 24px 20px 60px; }
.doc-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.doc-head h1 { font-size: 22px; margin: 0; letter-spacing: -0.4px; }
.doc-head p { margin: 0; font-size: 13px; line-height: 1.5; }

.btn-primary { background: var(--navy); color: #fff; border: 0; border-radius: 6px; padding: 8px 18px; font-weight: 700; }
.btn-primary:hover { background: #24335a; }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-line {
  background: #fff; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 14px;
  font-weight: 600; text-decoration: none; font-size: 13px; display: inline-flex; align-items: center;
}
.btn-line:hover { border-color: var(--sub); }

.search-form {
  display: grid; grid-template-columns: 1fr 1fr; background: var(--panel);
  border-top: 2px solid var(--text); border-bottom: 1px solid var(--line);
}
.sf-row { display: flex; border-bottom: 1px solid var(--line); min-height: 48px; }
.sf-label { width: 110px; flex-shrink: 0; background: #f7f8fa; font-weight: 700; font-size: 13px; display: flex; align-items: center; padding: 0 14px; }
.sf-field { flex: 1; display: flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 13px; color: var(--sub); flex-wrap: wrap; }
.sf-field input[type=number], .sf-field input[type=search] {
  width: 110px; height: 32px; border: 1px solid var(--line); border-radius: 4px; padding: 0 8px; outline: none; color: var(--text);
}
.sf-field input:focus { border-color: var(--commercial); }
.sf-text input[type=search] { flex: 1; width: auto; min-width: 160px; }
.unit-toggle { display: inline-flex; gap: 10px; margin-left: 6px; }
.unit-toggle label { display: inline-flex; align-items: center; gap: 3px; cursor: pointer; }

.result-bar { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 8px; font-size: 13px; }
.table-wrap { overflow-x: auto; background: var(--panel); border-top: 1px solid var(--text); }
.reg-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 1100px; }
.reg-table th { font-weight: 700; padding: 12px 8px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
.reg-table td { padding: 11px 8px; border-bottom: 1px solid var(--line); text-align: center; vertical-align: top; }
.reg-table td.addr { text-align: left; white-space: nowrap; }
.reg-table td.addr a { color: var(--commercial); text-decoration: none; font-weight: 600; }
.reg-table td.num { text-align: right; white-space: nowrap; }
.reg-table tbody tr:hover { background: #fafbfc; }
.tag-deal { font-size: 10.5px; font-weight: 700; color: #fff; background: var(--commercial); border-radius: 3px; padding: 1px 5px; margin-left: 4px; }
.pager { display: flex; justify-content: center; gap: 4px; margin-top: 18px; }
.pager button { min-width: 34px; height: 32px; border: 1px solid var(--line); background: #fff; border-radius: 6px; font-size: 13px; }
.pager button.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.pager button:disabled { opacity: .4; cursor: default; }

/* 검토 요청 */
.review-tabs { margin-bottom: 16px; }
.review-tabs b { margin-left: 4px; }
.rv-item { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 12px; }
.rv-deal { margin-bottom: 12px; }
.rv-price { font-size: 19px; font-weight: 800; letter-spacing: -0.3px; }
.rv-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--sub); margin-top: 4px; }
.rv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rv-table th { text-align: left; font-weight: 700; padding: 8px; background: #fafbfc; border-bottom: 1px solid var(--line); white-space: nowrap; }
.rv-table td { padding: 9px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.rv-table input { accent-color: var(--commercial); }
.rv-manual { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.rv-manual input { height: 34px; border: 1px solid var(--line); border-radius: 6px; padding: 0 10px; width: 160px; outline: none; }
.rv-actions { display: flex; gap: 8px; margin-top: 12px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 2000;
  background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow);
}

@media (max-width: 860px) {
  .nav { margin-left: 0; }
  .nav a { padding: 6px 8px; font-size: 13px; }
  .page-map .topbar .search { display: none; }
  .search-form { grid-template-columns: 1fr; }
  .sf-label { width: 84px; padding: 0 10px; }
  .rv-item { overflow-x: auto; }
}
.rv-hint { font-size: 12px; color: var(--muted); margin: 4px 0 6px; font-weight: 600; }
.rv-manual { margin-top: 12px; }
.sf-field select { height: 32px; border: 1px solid var(--line); border-radius: 4px; padding: 0 8px; min-width: 200px; background: #fff; color: var(--text); }
.rv-pending { opacity: .55; }
.nav a[hidden], .badge-count[hidden] { display: none !important; }
