/* ===== 지도 페이지 ===== */

/* --- 헤더 --- */
.map-header {
  margin-bottom: 16px;
}

.map-title-row {
  margin-bottom: 12px;
}

.map-page-title {
  margin-bottom: 0 !important;
}

.map-controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

/* 시대 선택 */
.era-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.era-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-right: 4px;
}

.era-btn {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.era-btn:hover {
  background: var(--bg-hover);
  border-color: var(--gold-dim);
  color: var(--text-primary);
}

.era-btn.active {
  background: var(--navy);
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 600;
}

/* 검색 */
.map-search-wrap {
  position: relative;
  flex: 1;
  min-width: 180px;
  max-width: 320px;
}

.map-search {
  width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.map-search:focus {
  border-color: var(--gold-dim);
}

.map-search::placeholder {
  color: var(--text-muted);
}

.map-search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0 0 6px 6px;
  max-height: 260px;
  overflow-y: auto;
  z-index: 1000;
}

.map-search-results.visible {
  display: block;
}

.search-result-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.search-result-name {
  color: var(--text-primary);
  font-size: 0.9rem;
}

.search-result-hanja {
  color: var(--gold-dim);
  font-size: 0.8rem;
}

.search-result-type {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-left: auto;
  padding: 2px 6px;
  background: var(--bg-card);
  border-radius: 3px;
}

.search-no-result {
  padding: 12px;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.85rem;
}

/* 필터 */
.map-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 4px;
}

.filter-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s;
}

.filter-label:hover {
  color: var(--text-primary);
}

.filter-label input[type="checkbox"] {
  accent-color: var(--gold);
  width: 14px;
  height: 14px;
}

/* --- 지도 + 패널 래퍼 --- */
.map-page-wrapper {
  position: relative;
  display: flex;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-card);
}

/* Leaflet 지도 컨테이너 */
.map-leaflet {
  width: 100%;
  height: calc(100vh - 240px);
  min-height: 500px;
  max-height: 800px;
}

/* --- Leaflet 다크 테마 오버라이드 --- */
.leaflet-control-zoom a {
  background: var(--bg-secondary) !important;
  color: var(--gold) !important;
  border-color: var(--border) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-hover) !important;
}

.leaflet-control-attribution {
  background: rgba(10, 10, 15, 0.7) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--gold-dim) !important;
}

/* 툴팁 */
.map-tooltip {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  font-size: 12px !important;
  padding: 3px 8px !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5) !important;
}

.map-tooltip-province {
  font-family: var(--font-serif) !important;
  font-size: 13px !important;
  font-weight: 700 !important;
  color: var(--gold-light) !important;
  background: rgba(17, 17, 24, 0.9) !important;
  border-color: var(--gold-dim) !important;
}

.leaflet-tooltip-top:before {
  border-top-color: var(--border) !important;
}

.leaflet-tooltip-bottom:before {
  border-bottom-color: var(--border) !important;
}

/* 마커 아이콘 */
.pass-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: none !important;
  border: none !important;
}

.terrain-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: none !important;
  border: none !important;
}

.terrain-mountain {
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8));
}

.terrain-river {
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8));
  color: #5599dd;
}

/* --- 범례 --- */
.map-legend {
  background: rgba(17, 17, 24, 0.92) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  padding: 10px 14px !important;
  color: var(--text-primary) !important;
  font-size: 11px;
  min-width: 140px;
  max-height: 350px;
  overflow-y: auto;
}

.legend-title {
  font-weight: 700;
  color: var(--gold);
  font-size: 12px;
  margin-bottom: 6px;
  font-family: var(--font-serif);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  color: var(--text-secondary);
}

.legend-color {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-marker {
  display: inline-block;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.legend-marker-lg {
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
}

.legend-marker-md {
  width: 10px;
  height: 10px;
}

.legend-marker-sm {
  width: 6px;
  height: 6px;
}

.legend-icon {
  font-size: 14px;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.legend-divider {
  border-top: 1px solid var(--border);
  margin: 6px 0;
}

/* --- 상세 패널 --- */
.region-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 340px;
  height: 100%;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  padding: 0;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  z-index: 800;
}

.region-panel.open {
  transform: translateX(0);
}

.detail-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  z-index: 10;
}

.detail-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--gold-dim);
}

.detail-header {
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.detail-name-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.detail-hanja {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  color: var(--gold);
  font-weight: 700;
}

.detail-name {
  font-size: 1.1rem;
  color: var(--text-primary);
}

.detail-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.detail-type-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border: 1px solid;
  border-radius: 4px;
}

.detail-subtype {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 3px;
}

.detail-pinyin {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

.detail-section {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.detail-section-title {
  font-family: var(--font-serif);
  font-size: 0.9rem;
  color: var(--gold);
  margin-bottom: 8px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}

.detail-row-tags {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.detail-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.detail-value {
  font-size: 0.85rem;
  color: var(--text-primary);
  text-align: right;
}

.detail-link {
  cursor: pointer;
  color: var(--gold-dim) !important;
  text-decoration: underline;
  transition: color 0.15s;
}

.detail-link:hover {
  color: var(--gold) !important;
}

.detail-faction-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* 바 차트 */
.detail-bar-group {
  margin: 6px 0;
}

.detail-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.detail-bar-track {
  width: 100%;
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
}

.detail-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* 태그 */
.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.detail-tag {
  font-size: 0.75rem;
  padding: 2px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
}

.detail-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* 시대별 세력 변화 */
.detail-era-timeline {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.era-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.15s;
}

.era-row-current {
  background: var(--bg-card);
}

.era-row-year {
  font-size: 0.8rem;
  color: var(--text-muted);
  width: 50px;
  flex-shrink: 0;
}

.era-row-faction {
  font-size: 0.85rem;
}

/* --- 모바일 반응형 --- */
@media (max-width: 768px) {
  .map-controls-row {
    flex-direction: column;
    align-items: stretch;
  }

  .map-search-wrap {
    max-width: none;
  }

  .era-group {
    flex-wrap: wrap;
  }

  .map-leaflet {
    height: calc(100vh - 300px);
    min-height: 350px;
  }

  /* 상세 패널 → 하단 시트 */
  .region-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60vh;
    max-height: 60vh;
    transform: translateY(100%);
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    z-index: 1100;
  }

  .region-panel.open {
    transform: translateY(0);
  }

  .region-panel::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    margin: 10px auto 0;
  }

  .map-legend {
    max-height: 200px !important;
    font-size: 10px !important;
    padding: 8px 10px !important;
    min-width: 120px !important;
  }

  .map-filters {
    gap: 8px;
  }

  .filter-label {
    font-size: 0.75rem;
  }
}

@media (max-width: 480px) {
  .era-btn {
    padding: 4px 10px;
    font-size: 0.8rem;
  }

  .map-leaflet {
    height: calc(100vh - 340px);
    min-height: 280px;
  }
}
