/* ============ HQ Map styles — mobile-first, themeable ============ */
:root {
  --bg: #ffffff;
  --bg-soft: #f4f6f8;
  --bg-card: #ffffff;
  --text: #1a1d21;
  --text-dim: #5b6470;
  --border: #e2e6ea;
  --accent: #2563eb;
  --accent-soft: #dbe7ff;
  --chip-bg: #eef1f5;
  --shadow: 0 4px 18px rgba(0,0,0,.12);
  --radius: 12px;
  --appbar-h: 56px;
}
html[data-theme="dark"] {
  --bg: #101418;
  --bg-soft: #171c22;
  --bg-card: #1b2129;
  --text: #e8ecf1;
  --text-dim: #9aa5b1;
  --border: #2a323c;
  --accent: #6b9bff;
  --accent-soft: #22345c;
  --chip-bg: #232b35;
  --shadow: 0 4px 18px rgba(0,0,0,.5);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
#app { height: 100dvh; display: flex; flex-direction: column; }
.view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.hidden { display: none !important; }
a { color: var(--accent); }

/* ---------- theme toggle ---------- */
.theme-toggle {
  background: var(--chip-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  width: 40px; height: 40px;
  font-size: 18px;
  cursor: pointer;
  flex: none;
}
.theme-toggle:hover { border-color: var(--accent); }

/* ---------- landing ---------- */
#view-landing { overflow-y: auto; }
.landing-hero {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
  padding: 56px 20px 44px;
  position: relative;
}
.landing-hero .theme-toggle { position: absolute; top: 16px; right: 16px; background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.3); color: #fff; }
.landing-hero-inner { max-width: 720px; margin: 0 auto; }
.landing-hero h1 { margin: 0 0 8px; font-size: clamp(40px, 8vw, 64px); letter-spacing: -1px; }
.tagline { font-size: clamp(18px, 3.5vw, 24px); margin: 0 0 12px; opacity: .95; }
.sub { margin: 0; opacity: .85; line-height: 1.5; }
.sub strong { color: #fff; }
.landing-main { max-width: 860px; margin: 0 auto; padding: 28px 20px 40px; width: 100%; }
.landing-main h2 { margin: 0 0 4px; font-size: 22px; }
.region-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); margin: 26px 0 10px; }
.index-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.index-card {
  display: block; text-decoration: none; color: var(--text);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.index-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.index-card.disabled { opacity: .45; cursor: default; }
.index-card.disabled:hover { transform: none; box-shadow: none; border-color: var(--border); }
.index-card .idx-name { font-weight: 700; font-size: 17px; }
.index-card .idx-meta { color: var(--text-dim); font-size: 13px; margin-top: 6px; line-height: 1.45; }
.index-card .idx-cta { color: var(--accent); font-size: 13px; font-weight: 600; margin-top: 10px; display: inline-block; }
.landing-note { color: var(--text-dim); font-size: 13px; margin-top: 34px; line-height: 1.6; }
.landing-foot {
  margin-top: auto; padding: 18px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; color: var(--text-dim); font-size: 13px;
}

/* ---------- app bar ---------- */
.appbar {
  height: var(--appbar-h); flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px; border-bottom: 1px solid var(--border);
  background: var(--bg); z-index: 30;
}
.brand { text-decoration: none; color: var(--text); font-weight: 700; font-size: 16px; white-space: nowrap; }
.appbar-title { font-weight: 600; font-size: 15px; }
.appbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.btn-ghost {
  background: var(--chip-bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 8px 16px; font-size: 14px; cursor: pointer;
}
.btn-ghost:hover { border-color: var(--accent); }
.index-chips {
  display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px;
  scrollbar-width: none; flex: 1; min-width: 0;
}
.index-chips::-webkit-scrollbar { display: none; }
.index-chips .chip { flex: none; }

/* ---------- chips ---------- */
.chip {
  background: var(--chip-bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 7px 13px; font-size: 13px; cursor: pointer;
  min-height: 36px;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- map layout ---------- */
.map-layout { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar {
  width: 280px; flex: none; overflow-y: auto;
  border-right: 1px solid var(--border); background: var(--bg);
  padding: 16px; z-index: 20;
}
.sidebar h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-dim); }
.filter-block { margin-bottom: 20px; }
.radio-row { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 6px 0; cursor: pointer; }
.ccy-hint { color: var(--text-dim); font-size: 12px; cursor: help; }
.stats-line { font-size: 14px; color: var(--text-dim); line-height: 1.5; }
.search-wrap { position: relative; margin-bottom: 20px; }
#search {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-soft); color: var(--text);
}
#search:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 300px; overflow-y: auto; z-index: 40;
}
.search-results button {
  display: block; width: 100%; text-align: left; padding: 10px 12px;
  background: none; border: none; color: var(--text); font-size: 14px; cursor: pointer;
  border-bottom: 1px solid var(--border); min-height: 44px;
}
.search-results button:last-child { border-bottom: none; }
.search-results button:hover { background: var(--bg-soft); }
.search-results .sr-ticker { color: var(--text-dim); font-size: 12px; margin-left: 6px; }
.sidebar-close { display: none; }

.map-wrap { flex: 1; position: relative; min-width: 0; }
.map { position: absolute; inset: 0; }
.fab {
  display: none; position: absolute; left: 12px; top: 12px; z-index: 15;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  font-size: 20px; cursor: pointer; box-shadow: var(--shadow);
}

/* ---------- detail panel / bottom sheet ---------- */
.detail {
  position: absolute; z-index: 25;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 340px; max-height: calc(100% - 32px);
  right: 16px; top: 16px; overflow-y: auto; padding: 20px;
}
.detail-close {
  position: absolute; top: 10px; right: 10px;
  background: var(--chip-bg); border: 1px solid var(--border); color: var(--text);
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 14px;
}
.detail h2 { margin: 0 24px 2px 0; font-size: 20px; }
.detail .d-ticker { color: var(--text-dim); font-size: 13px; margin-bottom: 12px; }
.d-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 14px; }
.d-row .k { color: var(--text-dim); flex: none; }
.d-row .v { text-align: right; }
.d-ceo { margin-top: 14px; background: var(--bg-soft); border-radius: 10px; padding: 12px; font-size: 14px; line-height: 1.55; }
.d-ceo .ceo-name { font-weight: 700; }
.d-pay-note { font-size: 13px; color: var(--text-dim); margin-top: 6px; }
.d-moves { margin-top: 14px; font-size: 14px; }
.d-moves h5 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-dim); }
.d-moves li { margin-bottom: 6px; line-height: 1.45; }
.d-src { margin-top: 12px; font-size: 12px; color: var(--text-dim); line-height: 1.5; }

/* ---------- breakdown view ---------- */
.breakdown-main { max-width: 720px; margin: 0 auto; padding: 24px 20px 48px; width: 100%; overflow-y: auto; }
.breakdown-section { margin-bottom: 36px; }
.breakdown-section h3 { margin: 0 0 12px; font-size: 18px; }
.breakdown-sub { font-weight: 400; color: var(--text-dim); font-size: 13px; }
.bar-list { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 64px; gap: 10px; align-items: center; font-size: 14px; }
.bar-row .bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--bg-soft); border-radius: 6px; height: 22px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 6px; min-width: 2px; transition: width .4s ease; }
.bar-row .bar-val { text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.bar-clickable { cursor: pointer; border-radius: 6px; }
.bar-clickable:hover .bar-label, .bar-clickable:focus .bar-label { text-decoration: underline; color: var(--accent); }
.bar-clickable:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
/* inline expandable company list under a bar row */
.group-list { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
  margin: 2px 0 6px; padding: 6px; background: var(--bg-soft); border-radius: 8px; }
.group-item { display: flex; gap: 10px; align-items: baseline; text-align: left; background: none;
  border: none; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text);
  flex-wrap: wrap; }
.group-item:hover { background: var(--chip-bg); }
.group-ticker { font-weight: 600; min-width: 72px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.group-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-meta { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
/* ---------- landing global stats ---------- */
.global-stats { display: flex; gap: 12px; flex-wrap: wrap; margin: 20px 0 8px; }
.gstat { flex: 1 1 140px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.gstat strong { font-size: 24px; font-variant-numeric: tabular-nums; }
.gstat span { font-size: 13px; color: var(--text-dim); }
.gstat-cities { flex: 2 1 220px; }

/* ---------- tablet ---------- */
@media (max-width: 1023px) {
  .sidebar {
    position: absolute; left: 0; top: 0; bottom: 0;
    transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: var(--shadow); width: 300px;
  }
  .sidebar.open { transform: none; }
  .sidebar-close { display: block; position: absolute; top: 10px; right: 10px; }
  .fab { display: block; }
}

/* ---------- phone ---------- */
@media (max-width: 639px) {
  .appbar { padding: 0 8px; gap: 6px; flex-wrap: wrap; height: auto; min-height: var(--appbar-h); padding-top: 6px; padding-bottom: 6px; }
  .brand { font-size: 14px; }
  .index-chips { order: 3; flex-basis: 100%; padding-bottom: 2px; }
  .index-chips .chip { font-size: 13px; padding: 6px 12px; }
  .btn-ghost { padding: 7px 12px; font-size: 13px; }
  .detail {
    left: 0; right: 0; top: auto; bottom: 0; width: auto;
    max-height: 62dvh; border-radius: 18px 18px 0 0;
    border-left: none; border-right: none; border-bottom: none;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  .bar-row { grid-template-columns: 110px 1fr 52px; font-size: 13px; }
  .index-cards { grid-template-columns: 1fr 1fr; }
  .landing-hero { padding: 44px 16px 32px; }
}

/* SEO pre-rendered content (removed by JS on app boot) */
.seo-static .seo-table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14px; }
.seo-static .seo-table th, .seo-static .seo-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border, #e5e7eb); }
.seo-static .seo-table th { font-weight: 600; opacity: .7; }
.group-sort { display: flex; gap: 8px; align-items: center; padding: 8px; font-size: 12px; color: var(--text-dim); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); }
.group-sort button { background: none; border: 1px solid var(--border); border-radius: 4px; padding: 3px 8px; font-size: 12px; color: var(--text); cursor: pointer; }
.group-sort button.active { background: var(--chip-bg); font-weight: 600; }
