:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1b1f26;
  --text-dim: #6b7280;
  --accent: #1f4b8e;
  --up: #d64545;
  --down: #2f9e44;
  --radius: 10px;
  --wrap: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116;
    --surface: #171a21;
    --border: #272b34;
    --text: #e6e8ec;
    --text-dim: #9aa1ad;
    --accent: #7aa2e0;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei",
    "PingFang TC", "Noto Sans TC", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 16px; }

/* ── header ─────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.header-inner { display: flex; align-items: center; gap: 28px; height: 56px; }
.brand {
  font-size: 19px; font-weight: 700; color: var(--text);
  text-decoration: none; letter-spacing: .02em; white-space: nowrap;
}
.nav { display: flex; gap: 4px; overflow-x: auto; }
.nav-link {
  padding: 6px 12px; border-radius: 6px; text-decoration: none;
  color: var(--text-dim); font-size: 14px; white-space: nowrap;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.is-active { color: var(--accent); font-weight: 600; background: var(--bg); }
.nav-link.is-disabled { color: var(--text-dim); opacity: .5; cursor: default; }
.nav-link.is-disabled em {
  font-style: normal; font-size: 10px; margin-left: 5px;
  border: 1px solid var(--border); border-radius: 3px; padding: 0 4px;
}
.nav-link.is-disabled:hover { background: none; color: var(--text-dim); }

.search { position: relative; margin-left: auto; }
.search input {
  width: 190px; padding: 6px 11px; font-size: 13px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text);
}
.search input:focus { outline: none; border-color: var(--accent); width: 240px; }
.search input, .search input:focus { transition: width .15s ease; }
.search-results {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 260px;
  margin: 0; padding: 4px; list-style: none; z-index: 30;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
  max-height: 340px; overflow-y: auto;
}
.search-results a {
  display: flex; align-items: baseline; gap: 8px; padding: 6px 9px;
  border-radius: 5px; text-decoration: none; color: var(--text); font-size: 13.5px;
}
.search-results a:hover { background: var(--bg); }
.sr-code { font-variant-numeric: tabular-nums; color: var(--text-dim); min-width: 46px; }
.sr-name { font-weight: 600; }
.sr-ind { margin-left: auto; font-size: 11px; color: var(--text-dim); }
.sr-empty { padding: 8px 10px; font-size: 13px; color: var(--text-dim); }

/* ── 首頁 ───────────────────────────────── */
.hero { padding: 44px 0 30px; text-align: center; }
.hero h1 { margin: 0 0 10px; font-size: 30px; font-weight: 700; letter-spacing: -.01em; }
.hero-sub {
  margin: 0 auto 22px; max-width: 660px; color: var(--text-dim); font-size: 15px;
  /* 中文沒有詞邊界，瀏覽器會在任意字元換行，把「進出」這種詞拆開 */
  text-wrap: pretty; line-break: strict;
}
.hero-search { position: relative; max-width: 460px; margin: 0 auto; }
.hero-search input {
  width: 100%; padding: 11px 16px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
.hero-search input:focus { outline: none; border-color: var(--accent); }
.hero-search .search-results { left: 0; right: 0; min-width: 0; }

.error-code {
  margin: 0 0 4px; font-size: 52px; font-weight: 700; line-height: 1;
  color: var(--border); font-variant-numeric: tabular-nums;
}
.error-back { margin-top: 18px; font-size: 14px; }
.error-back a { color: var(--accent); }

.popular-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px; margin-top: 12px;
}
.popular-item {
  display: flex; flex-direction: column; gap: 1px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  text-decoration: none; color: var(--text);
}
.popular-item:hover { border-color: var(--accent); background: var(--bg); }
.pi-code { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.pi-name { font-size: 15px; font-weight: 600; }
.pi-ind { font-size: 11px; color: var(--text-dim); }

.feature-list {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px 26px; margin: 12px 0 0;
}
.feature-list dt { font-size: 14px; font-weight: 650; margin-bottom: 2px; }
.feature-list dd { margin: 0; font-size: 13px; color: var(--text-dim); line-height: 1.6; }

/* ── stock head ─────────────────────────── */
.stock-head {
  display: flex; flex-wrap: wrap; align-items: flex-end;
  justify-content: space-between; gap: 12px; padding: 22px 0 14px;
}
.stock-title h1 { margin: 0; font-size: 24px; font-weight: 700; }
.stock-title .code { color: var(--text-dim); font-weight: 600; margin-right: 6px; }
.industry {
  display: inline-block; margin-top: 4px; font-size: 12px; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 4px; padding: 1px 7px;
}
.quote { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.price { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.delta { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.asof { font-size: 12px; color: var(--text-dim); }
.up { color: var(--up); }
.down { color: var(--down); }

.notice {
  border-radius: var(--radius); padding: 11px 15px; margin-bottom: 16px;
  font-size: 13.5px; line-height: 1.6;
}
.notice-stale {
  background: color-mix(in srgb, #e8590c 10%, var(--surface));
  border: 1px solid color-mix(in srgb, #e8590c 35%, transparent);
}

/* ── stat row ───────────────────────────── */
.stat-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 1px; background: var(--border); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; margin-bottom: 20px;
}
.stat { background: var(--surface); padding: 11px 14px; }
.stat dt { font-size: 12px; color: var(--text-dim); margin: 0; }
.stat dd {
  margin: 3px 0 0; font-size: 17px; font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.stat dd em { font-style: normal; font-size: 11px; color: var(--text-dim); font-weight: 400; }

/* ── chart ──────────────────────────────── */
.chart-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 20px;
}
.range-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.range-btn {
  border: 1px solid var(--border); background: transparent; color: var(--text-dim);
  border-radius: 6px; padding: 4px 12px; font-size: 13px; cursor: pointer;
  font-family: inherit;
}
.range-btn:hover { color: var(--text); }
.range-btn.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chart-hint { margin-left: auto; font-size: 12px; color: var(--text-dim); }
.chart { width: 100%; }

.subchart-bar {
  display: flex; align-items: center; gap: 6px; margin: 10px 0 8px;
  overflow-x: auto; scrollbar-width: none; padding-bottom: 2px;
}
.subchart-bar::-webkit-scrollbar { display: none; }
.sub-label { font-size: 12px; color: var(--text-dim); white-space: nowrap; margin-right: 2px; }
.sub-chip {
  border: 1px solid var(--border); background: transparent; color: var(--text-dim);
  border-radius: 999px; padding: 4px 13px; font-size: 12.5px; cursor: pointer;
  font-family: inherit; white-space: nowrap; flex: 0 0 auto;
}
.sub-chip:hover { color: var(--text); border-color: var(--text-dim); }
.sub-chip.is-on {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500;
}
.event-legend {
  display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px;
  font-size: 12px; color: var(--text-dim); align-items: center;
}
.event-legend .ev { display: inline-flex; align-items: center; gap: 5px; }
.event-legend .ev::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.ev-disposal::before { background: #c92a2a; }
.ev-attention::before { background: #e8590c; }
.ev-dividend::before { background: #1971c2; }
.ev-increase::before { background: #7048e8; }
.ev-short::before { background: #868e96; }
.ev-revenue::before { background: #2f9e44; }
.event-note { margin-left: auto; font-size: 11.5px; font-style: italic; }


.broker-map {
  /* 台灣是縱長的（南北 366km、東西 200km）。容器若是寬扁的，fitBounds 為了
     塞進南北向就會把東西向攤到 800km 以上，畫面一半是福建跟琉球。
     維持接近 1:1.3 的直式比例才看得到本島細節。 */
  width: 100%; max-width: 640px; height: 560px; margin: 0 auto;
  border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border); background: var(--bg);
}
.map-note { margin: 8px 0 0; font-size: 12px; color: var(--text-dim); }
.map-tiles-dark { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9); }
.map-popup h4 {
  margin: 0 0 6px; font-size: 13px; display: flex; gap: 8px;
  justify-content: space-between; align-items: baseline;
}
.map-popup table { border-collapse: collapse; font-size: 12.5px; }
.map-popup td { padding: 2px 0; }
.map-popup td:last-child { text-align: right; padding-left: 14px; font-variant-numeric: tabular-nums; }
.map-popup .more { margin: 5px 0 0; font-size: 11.5px; color: var(--text-dim); }
.leaflet-popup-content { margin: 10px 12px; }

/* ── panels ─────────────────────────────── */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 20px;
}
.panel h2 { margin: 0 0 4px; font-size: 17px; font-weight: 650; }
.panel h2 .sub { font-size: 12px; font-weight: 400; color: var(--text-dim); margin-left: 6px; }
.panel-note { margin: 0 0 12px; font-size: 12.5px; color: var(--text-dim); }

.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td {
  padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.data-table td { font-size: 14px; }
.data-table .r { text-align: right; }
.data-table .c { text-align: center; width: 26px; padding-left: 4px; padding-right: 4px; }
.broker-toggle { cursor: pointer; accent-color: var(--accent); margin: 0; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table.compact th, .data-table.compact td { padding: 5px 8px; font-size: 13px; }
.data-table .ref { font-size: 12px; color: var(--text-dim); }
.data-table tr.is-over td { background: color-mix(in srgb, var(--up) 8%, transparent); }
.data-table tr.is-over td:first-child { font-weight: 600; }
.badge {
  display: inline-block; font-size: 10.5px; line-height: 1.5; padding: 0 5px;
  border-radius: 3px; background: var(--up); color: #fff; margin-left: 3px;
}
.data-table .broker { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }

.rank-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.rank-title { margin: 0 0 6px; font-size: 14px; font-weight: 650; }
.rank-title.buy { color: var(--up); }
.rank-title.sell { color: var(--down); }

.quality ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--text-dim); }
.quality li { margin-bottom: 5px; }

/* ── footer ─────────────────────────────── */
.site-footer { border-top: 1px solid var(--border); margin-top: 12px; padding: 20px 0 40px; }
.disclaimer { font-size: 12px; color: var(--text-dim); margin: 0; line-height: 1.7; }

@media (max-width: 760px) {
  .broker-map { height: 400px; max-width: none; }
  .header-inner { gap: 12px; }
  .search input { width: 120px; }
  .search input:focus { width: 150px; }
  .search-results { min-width: 220px; }
  .rank-grid { grid-template-columns: 1fr; }
  .price { font-size: 25px; }
  .chart-hint { display: none; }
}
