/* 기본 리셋 */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
  color: #1a1a2e;
  background: #f0f2f5;
}

a {
  color: #2563eb;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* 레이아웃 */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 40px;
  position: relative;
}

/* 헤더 */
.header {
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  color: #fff;
  padding: 32px 16px;
  text-align: center;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.header .subtitle {
  font-size: 0.9rem;
  opacity: 0.85;
}

/* 통계 카드 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: -24px;
  padding: 0 4px;
}

.stat-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px 16px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: #6b7280;
  margin-bottom: 4px;
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e3a5f;
}

/* 필터 */
.filters {
  margin-top: 24px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
}

.filter-group select {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  color: #1a1a2e;
  cursor: pointer;
  width: 100%;
  max-width: 400px;
}

.filter-group select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* 차트 */
.chart-section {
  margin-top: 28px;
  background: #fff;
  border-radius: 12px;
  padding: 24px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.chart-section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: #1e3a5f;
}

.chart-wrapper {
  position: relative;
  width: 100%;
  height: 280px;
  overflow: hidden;
}

.chart-message {
  text-align: center;
  padding: 40px 16px;
  color: #6b7280;
  font-size: 0.95rem;
}

/* 테이블 */
.table-section {
  margin-top: 28px;
  background: #fff;
  border-radius: 12px;
  padding: 24px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.table-section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: #1e3a5f;
}

.search-box {
  margin-bottom: 16px;
}

.search-box input {
  width: 100%;
  max-width: 400px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.95rem;
}

.search-box input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  background: #f8fafc;
  padding: 12px 10px;
  text-align: left;
  font-weight: 600;
  color: #374151;
  border-bottom: 2px solid #e5e7eb;
  white-space: nowrap;
}

tbody td {
  padding: 10px;
  border-bottom: 1px solid #f3f4f6;
  color: #1a1a2e;
}

tbody tr:hover {
  background: #f8fafc;
}

.table-message {
  text-align: center;
  padding: 40px 16px;
  color: #6b7280;
  font-size: 0.95rem;
}

/* 로딩 */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay p {
  margin-top: 12px;
  color: #6b7280;
  font-size: 0.95rem;
}

/* 에러 */
.error-message {
  margin-top: 24px;
  padding: 16px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #991b1b;
  text-align: center;
  font-size: 0.95rem;
}

/* 헤더 네비게이션 */
.header-nav {
  margin-bottom: 8px;
}

.back-link {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.9rem;
  text-decoration: none;
}

.back-link:hover {
  color: #fff;
  text-decoration: none;
}

/* 통계 카드 상세 */
.stat-detail {
  display: block;
  font-size: 0.7rem;
  color: #6b7280;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 섹션 헤더 (타이틀 + 더보기) */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-header h2 {
  margin-bottom: 0;
}

.more-link {
  font-size: 0.85rem;
  color: #2563eb;
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}

.more-link:hover {
  text-decoration: underline;
}

/* 가격 셀 강조 */
.price-cell {
  font-weight: 600;
  color: #2563eb;
}

/* 필터 행 */
.filter-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-input {
  width: 100%;
  max-width: 400px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.95rem;
}

.search-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* 더보기 버튼 */
.load-more-wrap {
  text-align: center;
  margin-top: 16px;
}

.load-more-btn {
  padding: 10px 32px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.load-more-btn:hover {
  background: #1d4ed8;
}

/* 구별 카드 그리드 */
.district-section {
  margin-top: 28px;
}

.district-section-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.district-section-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #1e3a5f;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 물음표 툴팁 */
.tooltip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.tooltip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid #9ca3af;
  background: transparent;
  color: #9ca3af;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: default;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}

.tooltip-btn:hover {
  border-color: #2563eb;
  color: #2563eb;
}

.tooltip-box {
  display: none;
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  transform: none;
  background: #1e3a5f;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.7;
  padding: 12px 16px;
  border-radius: 8px;
  white-space: pre-line;
  min-width: 260px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  z-index: 100;
  pointer-events: none;
}

.tooltip-box::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 10px;
  transform: none;
  border: 6px solid transparent;
  border-top-color: #1e3a5f;
}

.tooltip-wrap:hover .tooltip-box,
.tooltip-btn:focus + .tooltip-box {
  display: block;
}

.sort-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.sort-label {
  font-size: 0.8rem;
  color: #6b7280;
  font-weight: 500;
  margin-right: 2px;
}

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  background: #fff;
  color: #6b7280;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.sort-btn:hover {
  border-color: #2563eb;
  color: #2563eb;
  background: #eff6ff;
}

.sort-btn.active {
  border-color: #2563eb;
  background: #2563eb;
  color: #fff;
}

.sort-btn.active svg path {
  fill: #fff;
}

.district-section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: #1e3a5f;
}

.district-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.district-card {
  display: block;
  background: #fff;
  border-radius: 12px;
  padding: 18px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  cursor: pointer;
}

.district-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  text-decoration: none;
}

.district-card-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1e3a5f;
  margin-bottom: 6px;
}

.district-card-prices {
  margin-bottom: 8px;
}

.district-card-avg {
  font-size: 1.15rem;
  font-weight: 700;
  color: #2563eb;
}

.district-card-median {
  font-size: 0.85rem;
  font-weight: 500;
  color: #059669;
  margin-top: 2px;
}

.district-card-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: #6b7280;
}

.district-card-max {
  color: #dc2626;
  font-weight: 500;
}

/* 푸터 */
.footer {
  text-align: center;
  padding: 24px 16px;
  color: #6b7280;
  font-size: 0.8rem;
  border-top: 1px solid #e5e7eb;
  margin-top: 40px;
}

.footer p {
  margin-bottom: 4px;
}

/* 구별 페이지 필터 행 */
.district-filter-row {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.district-filter-row .search-box {
  margin-bottom: 0;
}

@media (min-width: 768px) {
  .district-filter-row {
    flex-direction: row;
    align-items: flex-end;
    gap: 20px;
  }
  .district-filter-row .search-box {
    flex: 0 0 200px;
  }
  .district-filter-row .price-range-wrap {
    flex: 1;
    min-width: 0;
  }
}

/* 가격 범위 슬라이더 */
.price-range-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.price-range-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
}

.price-range-title {
  color: #6b7280;
  font-weight: 500;
}

.price-range-display {
  color: #2563eb;
  font-weight: 600;
  font-size: 0.82rem;
}

.price-range-body {
  display: flex;
  align-items: center;
  gap: 10px;
}

.price-range-edge {
  font-size: 0.72rem;
  color: #9ca3af;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 36px;
}

.range-slider-wrap {
  position: relative;
  height: 32px;
  flex: 1;
  display: flex;
  align-items: center;
}

.range-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
}

.range-fill {
  position: absolute;
  height: 4px;
  background: #2563eb;
  border-radius: 2px;
  pointer-events: none;
}

.range-thumb {
  position: absolute;
  width: 100%;
  height: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  pointer-events: none;
  outline: none;
  margin: 0;
  padding: 0;
  top: 50%;
}

.range-thumb::-webkit-slider-runnable-track {
  height: 0;
}

.range-thumb::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #2563eb;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(37,99,235,0.4);
  cursor: pointer;
  pointer-events: all;
  position: relative;
  z-index: 2;
}

.range-thumb::-moz-range-track {
  height: 0;
  border: none;
  background: transparent;
}

.range-thumb::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #2563eb;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(37,99,235,0.4);
  cursor: pointer;
  pointer-events: all;
}

.range-thumb-max {
  z-index: 1;
}

.footer-yt-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #ff0000;
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: opacity 0.15s;
}

.footer-yt-link:hover {
  opacity: 0.75;
  text-decoration: none;
}

.footer-yt-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* 차트 그리드 (2열 / 3열) */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 28px;
}

.chart-grid .chart-section {
  margin-top: 0;
}

.chart-wrapper-sm {
  height: 220px;
}

/* 데스크톱 */
@media (min-width: 768px) {
  .header h1 {
    font-size: 2rem;
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }

  .stat-value {
    font-size: 1.75rem;
  }

  .chart-section,
  .table-section {
    padding: 28px 24px;
  }

  .chart-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .chart-grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }

  .district-section-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .district-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }

  .filter-row {
    flex-direction: row;
    align-items: flex-end;
  }
}

@media (min-width: 1024px) {
  .district-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}
