/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red: #d32f2f;
  --red-dark: #b71c1c;
  --green: #2e7d32;
  --green-light: #4caf50;
  --green-bg: #e8f5e9;
  --gray-100: #f5f5f5;
  --gray-200: #eeeeee;
  --gray-300: #e0e0e0;
  --gray-600: #757575;
  --gray-800: #424242;
  --gray-900: #212121;
  --white: #ffffff;
  --shadow: 0 2px 8px rgba(0,0,0,0.12);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.15);
  --radius: 8px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  color: var(--gray-900);
  background: var(--gray-100);
  line-height: 1.6;
}

/* ===== HEADER ===== */
.site-header {
  background: linear-gradient(135deg, var(--red-dark), var(--red));
  color: var(--white);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon { flex-shrink: 0; }

.logo-text h1 {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.2;
}

.logo-text .subtitle {
  font-size: 0.85rem;
  opacity: 0.85;
  font-weight: 300;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-nav {
  display: flex;
  gap: 0.25rem;
}

/* ===== LANG TOGGLE ===== */
.lang-toggle {
  display: flex;
  align-items: center;
  background: rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 0.2rem 0.15rem;
  gap: 0;
}

.lang-sep {
  color: rgba(255,255,255,0.4);
  font-size: 0.85rem;
  user-select: none;
}

.lang-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.3rem 0.65rem;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

.lang-btn:hover {
  color: rgba(255,255,255,0.9);
}

.lang-btn.active {
  background: rgba(255,255,255,0.25);
  color: #ffffff;
}

.nav-link {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: all 0.2s;
}

.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,0.2);
  color: var(--white);
}

/* ===== HERO ===== */
.hero {
  background: linear-gradient(135deg, #1b5e20, #2e7d32, #388e3c);
  color: var(--white);
  padding: 2.5rem 1.5rem;
}

.hero-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2rem;
}

.avg-badge {
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  width: 180px;
  height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: transform 0.3s;
}

.avg-badge:hover { transform: scale(1.05); }

.avg-label {
  font-size: 0.75rem;
  opacity: 0.9;
  line-height: 1.3;
}

.avg-price {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1.1;
}

.avg-unit {
  font-size: 0.85rem;
  opacity: 0.8;
}

.stats-row {
  display: flex;
  gap: 2.5rem;
  flex-wrap: wrap;
}

.stat-item {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.8rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.8rem;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ===== LEVEL SELECTOR ===== */
.level-selector {
  background: var(--white);
  border-bottom: 1px solid var(--gray-300);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 56px;
  z-index: 999;
}

.level-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.level-label {
  font-weight: 600;
  color: var(--gray-800);
}

.level-buttons {
  display: flex;
  gap: 0.5rem;
}

.level-btn {
  padding: 0.5rem 1.25rem;
  border: 2px solid var(--gray-300);
  border-radius: 25px;
  background: var(--white);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--gray-800);
  transition: all 0.2s;
}

.level-btn:hover {
  border-color: var(--green);
  color: var(--green);
}

.level-btn.active {
  background: var(--green);
  border-color: var(--green);
  color: var(--white);
}

/* ===== SECTIONS ===== */
.section {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.section-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 0.5rem;
}

.section-desc {
  color: var(--gray-600);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

/* ===== MAP BREADCRUMB ===== */
.map-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--white);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.bc-link {
  background: none;
  border: none;
  color: var(--green);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: background 0.2s;
}

.bc-link:hover {
  background: var(--green-bg);
}

.bc-sep {
  color: var(--gray-600);
  font-size: 1.1rem;
}

.bc-current {
  color: var(--gray-800);
  font-weight: 500;
}

/* ===== DRILL-DOWN LOADER ===== */
.drill-loader {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 0.75rem;
  color: var(--gray-800);
  font-size: 0.9rem;
}

.loader-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--gray-300);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== MAP ===== */
#map {
  width: 100%;
  height: 550px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--white);
  z-index: 1;
}

.legend {
  background: var(--white);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 1rem;
  display: inline-block;
}

.legend h4 {
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--gray-800);
}

.legend-items {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--gray-600);
}

.legend-color {
  width: 20px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.1);
}

/* Province tooltip (hover) */
.province-tooltip {
  background: var(--white) !important;
  border: 1px solid var(--gray-300) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0.6rem 0.8rem !important;
  font-family: var(--font) !important;
}

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

/* Map info popup */
.province-popup {
  font-family: var(--font);
  line-height: 1.5;
}

.province-popup h3 {
  font-size: 1rem;
  margin-bottom: 0.4rem;
  color: var(--green);
  border-bottom: 2px solid var(--green-bg);
  padding-bottom: 0.3rem;
}

.province-popup .popup-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.85rem;
  padding: 0.15rem 0;
}

.province-popup .popup-value {
  font-weight: 600;
}

/* ===== TABLE ===== */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#ev-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  font-size: 0.92rem;
}

#ev-table thead {
  background: var(--red);
  color: var(--white);
}

#ev-table th {
  padding: 0.85rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

#ev-table th:hover { background: var(--red-dark); }

#ev-table th small {
  font-weight: 400;
  opacity: 0.85;
}

.sort-icon {
  font-size: 0.65rem;
  opacity: 0.6;
  margin-left: 0.3rem;
}

#ev-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-200);
}

#ev-table tbody tr {
  transition: background 0.15s;
}

#ev-table tbody tr:hover {
  background: var(--green-bg);
}

#ev-table tbody tr:nth-child(even) {
  background: var(--gray-100);
}

#ev-table tbody tr:nth-child(even):hover {
  background: var(--green-bg);
}

.price-cell {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.price-cell.highlight-low { color: var(--green); }
.price-cell.highlight-high { color: var(--red); }
.price-cell.na { color: var(--gray-600); font-style: italic; font-weight: 400; }

.model-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.model-fixed { background: #e3f2fd; color: #1565c0; }
.model-time { background: #fff3e0; color: #e65100; }
.model-power { background: #f3e5f5; color: #7b1fa2; }
.model-mixed { background: #e8eaf6; color: #283593; }
.model-na { background: var(--gray-200); color: var(--gray-600); }

/* ===== COMPARISON CHART ===== */
.chart-container {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  max-height: 500px;
}

#comparison-chart {
  max-height: 450px;
}

/* ===== ABOUT ===== */
.section-about {
  margin-bottom: 3rem;
}

.about-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.about-card {
  background: var(--white);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 4px solid var(--green);
}

.about-card h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: var(--green);
}

.about-card p {
  font-size: 0.9rem;
  color: var(--gray-800);
}

.last-updated {
  text-align: center;
  color: var(--gray-600);
  font-size: 0.85rem;
}

/* ===== FOOTER ===== */
.site-footer {
  background: var(--gray-900);
  color: rgba(255,255,255,0.7);
  text-align: center;
  padding: 1.5rem;
  font-size: 0.85rem;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .header-inner { flex-direction: column; align-items: flex-start; }
  .header-right { flex-direction: row; width: 100%; justify-content: space-between; }
  .hero-inner { flex-direction: column; }
  .avg-badge { width: 150px; height: 150px; }
  .avg-price { font-size: 2rem; }
  .stats-row { gap: 1.5rem; }
  #map { height: 400px; }
  .level-selector { top: 0; position: relative; }
  .about-content { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .header-nav { flex-wrap: wrap; }
  .nav-link { font-size: 0.8rem; padding: 0.3rem 0.5rem; }
  #ev-table { font-size: 0.82rem; }
  #ev-table th, #ev-table td { padding: 0.6rem 0.5rem; }
}
