/* Taiwan Housing Price Index – Main Stylesheet */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary:    #1a3a5c;
  --secondary:  #2980b9;
  --accent:     #e74c3c;
  --bg:         #f0f4f8;
  --card:       #ffffff;
  --border:     #dde3ec;
  --text:       #2c3e50;
  --muted:      #7f8c9b;
  --success:    #27ae60;
  --warning:    #e67e22;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:  0 4px 16px rgba(0,0,0,.09), 0 1px 4px rgba(0,0,0,.05);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.06);
  --radius:     12px;
  --transition: .18s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Navigation ──────────────────────────────────────────────────── */
nav {
  background: var(--primary);
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 12px rgba(0,0,0,.3);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 62px;
  gap: 2rem;
}
.nav-brand {
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.nav-brand::after {
  content: '';
  display: block;
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,.2);
  margin-left: .75rem;
}
.nav-links {
  display: flex;
  gap: 0.15rem;
  list-style: none;
  flex-wrap: wrap;
}
.nav-links a {
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  transition: background var(--transition), color var(--transition);
  letter-spacing: .01em;
}
.nav-links a:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-links a.active {
  background: rgba(255,255,255,.18);
  color: #fff;
  font-weight: 600;
}

/* ── Hero ────────────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(140deg, #0f2942 0%, #1a3a5c 50%, #1e4d82 100%);
  color: #fff;
  padding: 4rem 2rem 3.5rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}
/* Subtle dot-grid overlay */
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,.07) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
}
/* Soft bottom fade */
.hero::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: linear-gradient(to bottom, transparent, rgba(15,41,66,.4));
  pointer-events: none;
}
.hero-content { position: relative; z-index: 1; }
.hero h1 {
  font-size: clamp(1.6rem, 3.2vw, 2.6rem);
  font-weight: 700;
  margin-bottom: .6rem;
  letter-spacing: -.01em;
}
.hero p {
  color: rgba(255,255,255,.78);
  font-size: 1rem;
  max-width: 660px;
  margin: 0 auto 2rem;
  line-height: 1.7;
}

/* Hero stats strip */
.hero-stats {
  display: flex;
  justify-content: center;
  gap: 0;
  flex-wrap: wrap;
  max-width: 640px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}
.hero-stat {
  flex: 1;
  min-width: 120px;
  padding: 1rem 1.25rem;
  border-right: 1px solid rgba(255,255,255,.15);
  text-align: center;
}
.hero-stat:last-child { border-right: none; }
.hero-stat-num {
  font-size: 1.9rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  letter-spacing: -.02em;
}
.hero-stat-lbl {
  font-size: .75rem;
  color: rgba(255,255,255,.65);
  margin-top: .3rem;
  font-weight: 500;
  letter-spacing: .03em;
  text-transform: uppercase;
}

/* ── Layout ──────────────────────────────────────────────────────── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem;
}

/* ── Cards ───────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.6rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
}
.card:hover {
  box-shadow: var(--shadow-md);
}
.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1.1rem;
  padding-bottom: .65rem;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: .5rem;
  letter-spacing: -.01em;
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.1rem;
  border-radius: 7px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all var(--transition);
  letter-spacing: .01em;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
  background: var(--secondary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(41,128,185,.35);
}
.btn-primary:hover { box-shadow: 0 4px 14px rgba(41,128,185,.45); }
.btn-success {
  background: var(--success);
  color: #fff;
  box-shadow: 0 2px 8px rgba(39,174,96,.3);
}
.btn-success:hover { box-shadow: 0 4px 14px rgba(39,174,96,.4); }
.btn-outline {
  background: #fff;
  border: 1.5px solid var(--secondary);
  color: var(--secondary);
}
.btn-outline:hover { background: #eaf4fb; }
.btn-sm { padding: .3rem .75rem; font-size: .8rem; }

/* ── Chart controls ──────────────────────────────────────────────── */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  margin-bottom: 1rem;
}
.freq-toggle {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.freq-toggle button {
  padding: .35rem 1rem;
  font-size: .84rem;
  font-weight: 500;
  background: #fff;
  border: none;
  cursor: pointer;
  color: var(--muted);
  transition: background var(--transition), color var(--transition);
  font-family: inherit;
}
.freq-toggle button.active {
  background: var(--secondary);
  color: #fff;
  font-weight: 600;
}
.freq-toggle button:not(.active):hover { background: #f0f4f8; }

/* ── City selector ───────────────────────────────────────────────── */
.city-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: 1rem;
}
.city-chip {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .28rem .75rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all var(--transition);
  user-select: none;
}
.city-chip .swatch {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.city-chip.active  { opacity: 1; border-color: currentColor; box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.city-chip.inactive{ opacity: 0.38; }
.city-chip:hover   { opacity: .85; transform: scale(1.04); }

/* ── Chart container ─────────────────────────────────────────────── */
.chart-wrap    { position: relative; height: 420px; }
.chart-wrap-lg { height: 520px; }

/* ── Download bar ────────────────────────────────────────────────── */
.download-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  align-items: center;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, #eaf3fb 0%, #f0f7ff 100%);
  border: 1px solid #c5ddf0;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.download-bar span {
  font-size: .875rem;
  color: var(--primary);
  font-weight: 600;
  margin-right: .25rem;
}

/* ── Stats table ─────────────────────────────────────────────────── */
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
.stats-table thead tr {
  background: linear-gradient(135deg, #eaf3fb, #f4f8fc);
  color: var(--primary);
}
.stats-table th {
  padding: .7rem .9rem;
  font-weight: 600;
  font-size: .82rem;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.stats-table td { padding: .6rem .9rem; border-bottom: 1px solid #f0f4f8; }
.stats-table tbody tr:last-child td { border-bottom: none; }
.stats-table tbody tr:hover td { background: #f7fafd; }

/* ── Map ─────────────────────────────────────────────────────────── */
#map { height: 580px; border-radius: 10px; }
.map-info-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  min-height: 200px;
}
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: .65rem;
  margin-top: .75rem;
}
.stat-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem .5rem;
  text-align: center;
}
.stat-box .val {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -.02em;
}
.stat-box .lbl { font-size: .72rem; color: var(--muted); margin-top: .2rem; line-height: 1.4; }
.positive { color: var(--accent)   !important; }
.negative { color: var(--success)  !important; }

/* ── Methodology page ────────────────────────────────────────────── */
.method-section { margin-bottom: 2.5rem; }
.method-section h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: .8rem;
  padding-bottom: .45rem;
  border-bottom: 2px solid var(--secondary);
  letter-spacing: -.01em;
}
.method-section h3 {
  font-size: .97rem;
  font-weight: 600;
  color: var(--text);
  margin: 1.1rem 0 .4rem;
}
.method-section p  { line-height: 1.78; color: #3d4f60; margin-bottom: .75rem; }
.method-section ul { padding-left: 1.4rem; line-height: 1.9; color: #3d4f60; }

.advantage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.advantage-card {
  background: linear-gradient(135deg, #eaf3fb 0%, #f4f9ff 100%);
  border: 1px solid #c5ddf0;
  border-radius: 10px;
  padding: 1.15rem 1.3rem;
  transition: box-shadow var(--transition), transform var(--transition);
}
.advantage-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.advantage-card h4 { color: var(--primary); font-size: .93rem; font-weight: 600; margin-bottom: .4rem; }
.advantage-card p  { font-size: .84rem; color: #4a6278; line-height: 1.65; margin: 0; }

/* ── Comparison index cards ──────────────────────────────────────── */
.index-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .85rem;
  margin-top: 1rem;
}
.index-card {
  border-radius: 10px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: var(--card);
  padding: 1rem 1.1rem;
  transition: box-shadow var(--transition), transform var(--transition);
}
.index-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.index-card h4 { font-size: .9rem; font-weight: 600; color: var(--primary); }
.index-card p  { font-size: .78rem; color: var(--muted); line-height: 1.55; margin-top: .3rem; }

/* ── Tooltip ─────────────────────────────────────────────────────── */
.custom-tooltip {
  background: rgba(15,25,45,.93);
  color: #fff;
  border-radius: 8px;
  padding: .6rem .9rem;
  font-size: .82rem;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.35);
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .hero-stats { gap: 0; }
  .hero-stat  { min-width: 90px; padding: .75rem .9rem; }
  .advantage-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Mobile nav toggle ───────────────────────────────────────────── */
.nav-toggle {
  display: none;
  background: transparent;
  border: 1.5px solid rgba(255,255,255,.3);
  border-radius: 6px;
  padding: .3rem .55rem;
  cursor: pointer;
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  margin-left: auto;
  flex-shrink: 0;
}

/* Language toggle shown only inside mobile menu */
.nav-lang-inline { display: none; }
.nav-lang-inline button {
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.9);
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 6px;
  padding: .4rem 1rem;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: .04em;
  margin: .3rem .75rem;
  width: calc(100% - 1.5rem);
}

@media (max-width: 680px) {
  /* Nav */
  .nav-toggle { display: flex; align-items: center; }
  .lang-btn   { display: none; }
  .nav-inner  { flex-wrap: wrap; gap: .5rem; padding: .5rem 0; height: auto; min-height: 52px; }
  .nav-links  {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 0;
    padding: .35rem 0 .5rem;
    border-top: 1px solid rgba(255,255,255,.1);
  }
  .nav-links.open { display: flex; }
  .nav-links a    { font-size: .9rem; padding: .55rem .75rem; border-radius: 4px; }
  /* Show a language toggle inside the open menu */
  .nav-lang-inline { display: block !important; }

  /* Hero */
  .hero        { padding: 2rem 1rem 1.8rem; }
  .hero h1     { font-size: 1.5rem; }
  .hero p      { font-size: .9rem; }
  .hero-stats  { flex-wrap: wrap; }
  .hero-stat   { min-width: 80px; padding: .6rem .75rem; }
  .hero-stat-num { font-size: 1.4rem; }

  /* Layout */
  .container  { padding: .9rem; }
  .card       { padding: 1.1rem; }

  /* Charts */
  .chart-wrap    { height: 260px; }
  .chart-wrap-lg { height: 300px; }
  #map           { height: 300px; }

  /* Tables */
  .stats-table { font-size: .78rem; }
  .stats-table th, .stats-table td { padding: .45rem .5rem; }
  #latest-table, #corr-table { overflow-x: auto; }

  /* Controls */
  .controls    { gap: .35rem; }
  .freq-toggle button { padding: .3rem .7rem; font-size: .8rem; }
  .download-bar { flex-wrap: wrap; gap: .4rem; }

  /* Stat grid in map panel */
  .stat-grid   { grid-template-columns: 1fr 1fr; }

  /* Map layout */
  .map-layout  { grid-template-columns: 1fr !important; }

  /* Advantages */
  .advantage-grid { grid-template-columns: 1fr; }

  /* Method step grid */
  .step-grid   { grid-template-columns: 1fr; }

  /* Index cards */
  .index-cards { grid-template-columns: 1fr; }

  /* Math blocks */
  .math-block  { font-size: .8rem; padding: .7rem 1rem; overflow-x: auto; }
}

@media (max-width: 768px) {
  .container  { padding: 1rem; }
  .hero       { padding: 2.5rem 1.25rem 2rem; }
  .chart-wrap { height: 300px; }
  .chart-wrap-lg { height: 360px; }
  #map        { height: 360px; }
  .stat-grid  { grid-template-columns: 1fr 1fr; }
  .hero-stat-num { font-size: 1.5rem; }
}

/* ── Update badge ────────────────────────────────────────────────── */
.update-badge {
  display: inline-flex;
  align-items: center;
  background: var(--success);
  color: #fff;
  border-radius: 999px;
  padding: .15rem .65rem;
  font-size: .7rem;
  font-weight: 600;
  vertical-align: middle;
  letter-spacing: .02em;
}

/* ── Note box ────────────────────────────────────────────────────── */
.note-box {
  background: #fffbeb;
  border: 1px solid #f5d76e;
  border-left: 4px solid #f59e0b;
  border-radius: 8px;
  padding: .85rem 1.1rem;
  font-size: .85rem;
  color: #78350f;
  margin-bottom: 1.2rem;
  line-height: 1.6;
}

/* ── Footer ──────────────────────────────────────────────────────── */
footer {
  background: linear-gradient(135deg, #0f2942 0%, var(--primary) 100%);
  color: rgba(255,255,255,.62);
  text-align: center;
  padding: 2rem 1.5rem;
  font-size: .82rem;
  margin-top: 3rem;
  border-top: 1px solid rgba(255,255,255,.06);
  letter-spacing: .01em;
}
footer a { color: rgba(255,255,255,.82); }

/* ── Language toggle button ──────────────────────────────────────── */
.lang-btn {
  margin-left: auto;
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.9);
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 6px;
  padding: .28rem .7rem;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
  font-family: inherit;
  letter-spacing: .04em;
}
.lang-btn:hover {
  background: rgba(255,255,255,.22);
  border-color: rgba(255,255,255,.45);
}

/* ── Bilingual visibility ────────────────────────────────────────── */
html[lang="zh"] .lang-en { display: none !important; }
html[lang="en"] .lang-zh { display: none !important; }
