/* vote.ysw.kr — 9회 지선 여론조사. 샤프한 선거 톤. 팔레트 토큰은 common.css :root. */

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Pretendard', system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  font-feature-settings: 'tnum' 1, 'ss01' 1;
  -webkit-font-smoothing: antialiased;
}
body { line-height: 1.5; }

a { color: inherit; }

/* 헤더·.page·푸터 chrome → common.css (전 페이지 공통) */

.intro {
  margin-bottom: 24px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: end;
}
.intro h1 {
  font-size: clamp(24px, 3.2vw, 38px);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0 0 6px;
  line-height: 1.1;
}
.intro .lede {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.6;
  margin: 0;
  max-width: 660px;
}
.legal-banner {
  grid-column: 1 / -1;
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--ink);
  color: #fff;
  border-radius: 3px;
  font-size: 12px;
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.legal-banner strong { font-weight: 700; }
.legal-banner span { opacity: 0.75; }

/* === 컨트롤 === */
.controls {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rule);
}
.seg {
  display: inline-flex;
}
/* 가로 스크롤 시 "더 있다" 페이드 — JS(setupSegFades)가 스크롤 위치로 클래스 토글 */
.seg.fade-right {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
          mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
}
.seg.fade-left {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 24px);
          mask-image: linear-gradient(to right, transparent, #000 24px);
}
.seg.fade-left.fade-right {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 24px, #000 calc(100% - 24px), transparent);
          mask-image: linear-gradient(to right, transparent, #000 24px, #000 calc(100% - 24px), transparent);
}
.seg-btn {
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--rule-strong);
  border-right: none;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.seg-btn:first-child { border-radius: 3px 0 0 3px; }
.seg-btn:last-child  { border-radius: 0 3px 3px 0; border-right: 1px solid var(--rule-strong); }
.seg-btn.is-active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.seg-btn:hover:not(.is-active) {
  background: var(--bg2);
  color: var(--ink);
}
.time-anchor {
  margin-left: auto;
  font-size: 12px;
  color: var(--ink-soft);
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.time-anchor .label { text-transform: uppercase; letter-spacing: 0.06em; font-size: 11px; }
.time-anchor .value {
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* === 시각화 레이아웃 (flex) === */
.viz {
  display: flex;
  gap: 18px;
  position: relative;
  min-height: 600px;
}
.map-pane, .hex-pane {
  flex: 1 1 0;
  min-width: 0;
  height: 680px;
  background: #fff;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  position: relative;
  display: block;
}
.map-pane { padding: 0; overflow: hidden; }
.hex-pane { padding: 16px; }

/* viz-main: hex/map pane들을 감싼 wrapper — view-toggle overlay 위치 기준 */
.viz-main {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
}
.viz-main > .map-pane,
.viz-main > .hex-pane { flex: unset; width: 100%; }

/* view 토글 오버레이 — viz-main 우측 상단 (지도/격자 영역 안) */
.view-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 600;
  background: #fff;
  box-shadow: 0 2px 8px rgba(10,14,26,0.12);
  border-radius: 4px;
}
.view-toggle .seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.view-toggle .seg-btn:not(.is-active) { background: #fff; }
.view-toggle .seg-btn svg { opacity: 0.85; }
.view-toggle .seg-btn.is-active svg { opacity: 1; }
.detail-pane { flex: 0 0 420px; }

.leaflet-container { background: var(--bg2) !important; }

.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(250,251,252,0.95);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
  font-size: 13px; color: var(--ink-soft);
}
.spin {
  display: inline-block;
  width: 12px; height: 12px;
  margin-right: 10px;
  border: 2px solid var(--ink-soft);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === 디테일 패널 === */
.detail-pane {
  background: #fff;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  height: 680px;
  overflow-y: auto;
  padding: 18px 20px 24px;
}
.detail-empty {
  color: var(--ink-mute);
  font-size: 13px;
  line-height: 1.6;
  padding: 24px 8px;
}
.detail-hdr {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--ink);
}
.detail-hdr h2 {
  font-size: 22px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
}
.detail-hdr .count {
  font-size: 12px;
  color: var(--ink-mute);
  letter-spacing: 0.04em;
}

.scatter-wrap {
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 8px;
  margin: 14px 0 4px;
}
.scatter-wrap svg { display: block; }

.latest-label {
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 14px 0 8px;
}

/* 카드 (각 조사) */
.poll-card {
  border: 1px solid var(--rule);
  border-left: 3px solid var(--ink);
  border-radius: 0;
  padding: 10px 14px 12px;
  margin-bottom: 10px;
  background: #fff;
}
.poll-card .pc-hdr {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.poll-card .pc-period {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.poll-card .pc-office {
  font-size: 10px;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.poll-card .pc-agency {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 8px;
}
.poll-card .pc-bars {
  display: grid;
  gap: 5px;
  margin: 8px 0;
}
.poll-card .pc-bar-row {
  display: grid;
  grid-template-columns: 64px 1fr 40px;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}
.poll-card .pc-bar-row .name {
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.poll-card .pc-bar {
  display: block;
  height: 6px;
  background: var(--bg2);
  position: relative;
  overflow: hidden;
  border-radius: 1px;
}
.poll-card .pc-bar-fill { display: block; height: 100%; }
.poll-card .pc-bar-row .pct {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.poll-card .pc-meta {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--rule);
  font-size: 10px;
  color: var(--ink-soft);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 12px;
  font-variant-numeric: tabular-nums;
}
.poll-card .pc-meta span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.poll-card .pc-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 11px;
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px solid var(--rule-strong);
  letter-spacing: 0.02em;
}
.poll-card .pc-link:hover { color: var(--ink); border-color: var(--ink); }

.poll-card .pc-legal {
  margin-top: 8px;
  font-size: 10px;
  color: var(--ink-mute);
  line-height: 1.5;
}
.poll-card .pc-legal a {
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px solid var(--rule-strong);
}
.poll-card .pc-legal a:hover { color: var(--ink); border-color: var(--ink); }

/* === Hex grid === */
.hex-pane .hex-cell {
  cursor: pointer;
  transition: opacity .12s;
}
.hex-pane .hex-cell:hover { opacity: 0.85; }
/* 선택 셀 — 흰 테두리 + 글로우 halo. 권역(시도) 다크 경계선과 헷갈리지 않게 확연히 구분. */
.hex-pane .hex-cell.is-selected {
  stroke: #fff;
  stroke-width: 3;
  paint-order: stroke;
  filter: drop-shadow(0 0 3.5px rgba(0, 0, 0, 0.85));
}
.hex-pane .hex-cell.no-data {
  fill: var(--bg2);
  stroke: var(--rule-strong);
  stroke-width: 1;
  cursor: default;
}
.hex-pane .hex-label {
  font-size: 13px;
  font-weight: 700;
  fill: var(--ink);
  text-anchor: middle;
  pointer-events: none;
  letter-spacing: -0.01em;
}
.hex-pane .hex-pct {
  font-size: 11px;
  font-weight: 600;
  fill: var(--ink);
  text-anchor: middle;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.hex-pane .hex-cell.has-data + .hex-label,
.hex-pane .hex-cell.has-data + .hex-label + .hex-pct { fill: #fff; }

/* === 색 범례 (지도/격자 아래) === */
.poll-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  font-size: 12.5px;
  color: var(--ink-soft);
}
.poll-legend .leg-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.poll-legend .leg-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }

/* .foot chrome → common.css */

/* === 반응형 (모바일·태블릿) === */
@media (max-width: 900px) {
  /* 헤더·.page 반응형 chrome → common.css */
  /* 인트로 */
  .intro { grid-template-columns: 1fr; gap: 8px; }
  .intro h1 { font-size: clamp(20px, 6vw, 28px); }
  .intro .lede { font-size: 13px; }

  /* 컨트롤 segmented — 가로 스크롤 (한 줄 유지) */
  .controls { gap: 10px; }
  .seg {
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .seg::-webkit-scrollbar { display: none; }
  .seg-btn { flex-shrink: 0; padding: 6px 10px; font-size: 12px; }
  .time-anchor { margin-left: 0; font-size: 11px; }

  /* viz — column layout (hex/map 위, detail 아래) */
  .viz {
    flex-direction: column;
    min-height: 0;
    gap: 14px;
  }
  .map-pane, .hex-pane {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1.05;
    min-height: 360px;
    max-height: 70vh;
  }
  .map-pane { padding: 0; }
  .hex-pane { padding: 8px; }
  .detail-pane {
    flex: none;
    width: 100%;
    height: auto;
    max-height: none;
    padding: 14px 16px 20px;
  }

}

/* 매우 좁은 화면 (≤480px) */
@media (max-width: 480px) {
  .map-pane, .hex-pane { aspect-ratio: 1 / 1.15; min-height: 320px; }
}

/* === 재·보궐선거 (byelection.html) === */
.byelection-viz { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.byelection-viz #boe-map { width: 100%; height: 600px; border: 1px solid var(--line, rgba(27,34,55,0.18)); border-radius: 8px; background: #eef1f6; }
.byelection-viz .detail-pane { max-height: 600px; overflow-y: auto; }
.boe-district { margin-bottom: 18px; padding: 8px; border-radius: 8px; transition: background .2s; }
.boe-district.is-selected { background: rgba(90,110,156,0.12); outline: 2px solid rgba(90,110,156,0.4); }
.boe-dist-hdr { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; border-bottom: 2px solid var(--ink, #1b2237); padding-bottom: 4px; }
.boe-dist-name { font-weight: 800; font-size: 1.05rem; color: var(--ink, #1b2237); }
.boe-dist-meta { font-size: 0.8rem; color: var(--ink-soft, #4d5570); }
@media (max-width: 860px) {
  .byelection-viz { grid-template-columns: 1fr; }
  .byelection-viz #boe-map { height: 380px; }
}
.seg-wrap { flex-wrap: wrap; gap: 6px; }
.boe-chip { font-size: 0.82rem; }
/* 재보궐 지도 상시 라벨 */
.boe-label { background: rgba(255,255,255,0.9); border: 1px solid rgba(27,34,55,0.25); border-radius: 4px;
  font-size: 11px; font-weight: 700; color: #1b2237; padding: 1px 5px; box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  font-family: Pretendard, system-ui, sans-serif; }
.boe-label::before { display: none; }  /* leaflet tooltip 화살표 제거 */
