*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  min-height: 100vh;
  line-height: 1.6;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

h1 { font-size: 1.75rem; font-weight: 700; color: #f8fafc; }
h2 { font-size: 1rem; font-weight: 600; color: #94a3b8; }

.updated-at { font-size: 0.8rem; color: #64748b; }

/* ── 總覽卡片 ─────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: #1e2130;
  border: 1px solid #2d3348;
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
}

.card-label { font-size: 0.78rem; color: #64748b; margin-bottom: 0.4rem; }
.card-value { font-size: 1.5rem; font-weight: 700; color: #f8fafc; }
.card-sub   { font-size: 0.85rem; margin-top: 0.2rem; color: #94a3b8; }

/* ── 通用區塊 ────────────────────────────── */
.chart-section > h2 { margin-bottom: 1rem; }

.chart-section {
  background: #1e2130;
  border: 1px solid #2d3348;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.controls { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ── Toggle / Range 按鈕 ─────────────────── */
.toggle-group {
  display: flex;
  gap: 0.2rem;
  background: #0f1117;
  border-radius: 8px;
  padding: 3px;
}

.toggle-btn, .range-btn {
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 0.78rem;
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.toggle-btn.active, .range-btn.active {
  background: #2d3348;
  color: #e2e8f0;
}

.toggle-btn:focus-visible, .range-btn:focus-visible,
.tab-btn:focus-visible, .fv-row-header:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
  border-radius: 6px;
}

/* ── 資産走勢圖 ──────────────────────────── */
.history-chart-wrapper {
  position: relative;
  height: 300px;
}

.empty-msg {
  text-align: center;
  padding: 3rem;
  color: #4a5568;
  font-size: 0.9rem;
  font-style: italic;
}

/* ── 圓餅圖 ──────────────────────────────── */
.chart-wrapper {
  max-width: 340px;
  margin: 0.5rem auto 0;
}

/* ── 資產配置並排 ─────────────────────────── */
.allocation-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
  margin-top: 1rem;
}

.sub-chart-title {
  font-size: 0.78rem;
  color: #64748b;
  text-align: center;
  margin-bottom: 0.5rem;
}

/* ── 兩欄並排 ────────────────────────────── */
.two-col-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.two-col-grid .chart-section { margin-bottom: 0; }

/* ── 十大持股圖 ──────────────────────────── */
.top10-wrapper {
  position: relative;
  height: 320px;
}

/* ── 損益貢獻圖 ──────────────────────────── */
.contribution-wrapper {
  position: relative;
  height: 340px;
}

/* ── Treemap ─────────────────────────────── */
.treemap-section {
  background: #1e2130;
  border: 1px solid #2d3348;
  border-radius: 12px;
  padding: 1.5rem;
}

.treemap {
  position: relative;
  width: 100%;
  height: 520px;
  overflow: hidden;
}

.tm-industry {
  position: absolute;
  border: 1px solid #0f1117;
  border-radius: 4px;
  overflow: hidden;
}

.tm-label {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 22px;
  line-height: 22px;
  padding: 0 6px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #94a3b8;
  background: rgba(15,17,23,0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 1;
}

.tm-tile {
  position: absolute;
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: default;
  overflow: hidden;
  transition: filter 0.1s;
}

.tm-tile:hover { filter: brightness(1.2); }

.tm-code { font-size: 0.8rem; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.5); white-space: nowrap; }
.tm-pct  { font-size: 0.7rem; color: rgba(255,255,255,0.85); text-shadow: 0 1px 2px rgba(0,0,0,0.5); }

/* ── Tooltip ─────────────────────────────── */
.tooltip {
  position: fixed;
  z-index: 1000;
  background: #1e2130;
  border: 1px solid #3d4460;
  border-radius: 10px;
  padding: 0.875rem 1rem;
  min-width: 200px;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.tt-header { font-size: 1rem; margin-bottom: 0.6rem; display: flex; align-items: baseline; gap: 0.5rem; }
.tt-industry { font-size: 0.75rem; color: #64748b; }
.tt-row { display: flex; justify-content: space-between; gap: 1.5rem; font-size: 0.8rem; padding: 0.15rem 0; }
.tt-row span:first-child { color: #64748b; }
.tt-row span:last-child  { font-weight: 500; }
.tt-divider { border-top: 1px solid #2d3348; margin: 0.4rem 0; }

/* ── 顏色 ────────────────────────────────── */
.positive { color: #4ade80; }
.negative { color: #f87171; }
.neutral  { color: #94a3b8; }

/* ── 狀態 ────────────────────────────────── */
.loading { text-align: center; padding: 4rem; color: #64748b; }
.error   { background: #2d1b1b; border: 1px solid #7f1d1d; border-radius: 8px; padding: 1rem 1.5rem; color: #fca5a5; margin-bottom: 1rem; }
.hidden  { display: none; }

/* ── Tab 導覽 ────────────────────────────── */
.tab-nav {
  display: flex;
  border-bottom: 1px solid #2d3348;
  margin-bottom: 1.5rem;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: #64748b;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.6rem 1.25rem;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: -1px;
}

.tab-btn.active {
  color: #e2e8f0;
  border-bottom-color: #6366f1;
}

.tab-btn:hover:not(.active) { color: #94a3b8; }

/* ── 合理價工具列 ─────────────────────────── */
.fv-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.fv-search {
  flex: 1;
  min-width: 160px;
  background: #1e2130;
  border: 1px solid #2d3348;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 0.85rem;
  padding: 0.45rem 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.fv-search::placeholder { color: #4a5568; }
.fv-search:focus { border-color: #6366f1; }

.fv-filters {
  display: flex;
  gap: 0.4rem;
}

/* ── 摘要 Chips ──────────────────────────── */
.fv-chips {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.fv-chip {
  font-size: 0.75rem;
  color: #64748b;
  background: #1e2130;
  border: 1px solid #2d3348;
  border-radius: 20px;
  padding: 0.2rem 0.75rem;
}

.fv-chip--green { color: #4ade80; border-color: #1a3d2b; background: #0f2318; }

/* ── 合理價表格 ──────────────────────────── */
.fv-loading-msg {
  text-align: center;
  padding: 3rem;
  color: #4a5568;
  font-size: 0.9rem;
}

.fv-table {
  background: #1e2130;
  border: 1px solid #2d3348;
  border-radius: 12px;
  overflow: hidden;
}

.fv-thead {
  display: grid;
  grid-template-columns: 80px 1fr 70px 90px 28px;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  background: #161b27;
  font-size: 0.72rem;
  color: #4a5568;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.fv-row { border-top: 1px solid #2d3348; }
.fv-row:first-child { border-top: none; }

.fv-row-header {
  display: grid;
  grid-template-columns: 80px 1fr 70px 90px 28px;
  gap: 0.5rem;
  align-items: center;
  padding: 0.85rem 1.25rem;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}

.fv-row-header:hover { background: rgba(99,102,241,0.06); }

.fv-cell { font-size: 0.85rem; color: #e2e8f0; }

.fv-code { font-weight: 700; font-size: 0.9rem; color: #f8fafc; }

.fv-score {
  font-weight: 700;
  font-size: 0.9rem;
}

.fv-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 20px;
  background: #1a3d2b;
  color: #4ade80;
  border: 1px solid #2a5c40;
}

.fv-badge--na { background: transparent; color: #4a5568; border: none; }

.fv-chevron {
  color: #4a5568;
  font-size: 1rem;
  text-align: center;
  transition: transform 0.2s;
}

.fv-chevron--open { transform: rotate(90deg); }

.fv-empty {
  padding: 3rem;
  text-align: center;
  color: #4a5568;
  font-size: 0.9rem;
}

/* ── 展開明細 ────────────────────────────── */
.fv-detail {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.28s ease;
}

.fv-detail--open { max-height: 500px; }

.fv-methods {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
  padding: 1rem 1.25rem 1.25rem;
  background: #161b27;
}

/* ── 估值方法卡片 ─────────────────────────── */
.method-card {
  background: #1e2130;
  border: 1px solid #2d3348;
  border-left: 3px solid #2d3348;
  border-radius: 8px;
  padding: 0.85rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.method-card--positive { border-left-color: #4ade80; }
.method-card--negative { border-left-color: #f87171; }
.method-card--na       { opacity: 0.35; }

.method-name {
  font-size: 0.68rem;
  color: #64748b;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.method-fair-value {
  font-size: 1rem;
  font-weight: 700;
  color: #f8fafc;
  margin-top: 0.1rem;
}

.method-margin {
  font-size: 0.82rem;
  font-weight: 600;
}

.method-prereq {
  font-size: 0.7rem;
  margin-top: 0.2rem;
}

.method-prereq--ok   { color: #4ade80; }
.method-prereq--warn { color: #f59e0b; }
.method-prereq--na   { color: #4a5568; }

/* ── 合理價表格水平捲動保護 ──────────────── */
#fv-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.fv-table      { min-width: 440px; }

/* ── 無障礙：減少動態 ───────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── RWD ─────────────────────────────────── */
@media (max-width: 900px) {
  .summary-grid    { grid-template-columns: repeat(3, 1fr); }
  .two-col-grid    { grid-template-columns: 1fr; }
  .allocation-grid { grid-template-columns: 1fr; }
  .fv-methods      { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 560px) {
  .container       { padding: 1rem; }
  h1               { font-size: 1.35rem; }
  .summary-grid    { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
  .card            { padding: 1rem 1rem; }
  .card-value      { font-size: 1.15rem; }
  .chart-section   { padding: 1rem; }
  .treemap-section { padding: 1rem; }
  .section-header  { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .controls        { width: 100%; }
  .treemap         { height: 380px; }
  .top10-wrapper   { height: 260px; }
  .contribution-wrapper { height: 280px; }
  .history-chart-wrapper { height: 220px; }
  .fv-methods      { grid-template-columns: repeat(2, 1fr); }
  .fv-thead        { grid-template-columns: 60px 1fr 54px 72px 24px; padding: 0.5rem 0.85rem; }
  .fv-row-header   { grid-template-columns: 60px 1fr 54px 72px 24px; padding: 0.75rem 0.85rem; min-height: 52px; }
  .fv-toolbar      { gap: 0.5rem; }
  .toggle-btn, .range-btn { min-height: 36px; padding: 0.4rem 0.75rem; }
  .tab-btn         { min-height: 40px; padding: 0.5rem 1rem; }
}
