:root {
  color-scheme: dark;
  --bg: #232324;
  --panel: #292b32;
  --panel-strong: #363a46;
  --line: #4a4f5d;
  --text: #fefefe;
  --muted: #aeb4c2;
  --soft: #3f414b;
  --red: #f63538;
  --green: #30cc5a;
  --accent: #2563eb;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  --panel-bg: rgba(41, 43, 50, 0.94);
  --row-hover: rgba(37, 99, 235, 0.09);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f3ee;
  --panel: #fffdfa;
  --panel-strong: #fff;
  --line: #ded8cd;
  --text: #25231f;
  --muted: #756f66;
  --soft: #ece6dc;
  --red: #c83232;
  --green: #11805f;
  --accent: #2563eb;
  --shadow: 0 18px 45px rgba(42, 37, 30, 0.1);
  --panel-bg: rgba(255, 253, 250, 0.96);
  --row-hover: rgba(37, 99, 235, 0.05);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}
button, input, select { color: inherit; font: inherit; }
button { cursor: pointer; }

.detail-shell .holdings-summary > div { height: auto; min-height: 70px; }
.holdings-summary #summaryDate { display: inline; font: inherit; }
.holdings-summary .summary-count {
  display: inline-block;
  padding: 2px 0;
  font: inherit;
  color: inherit;
}
.holdings-summary .summary-count.gain { color: var(--red); }
.holdings-summary .summary-count.loss { color: var(--green); }
.detail-shell .holdings-summary strong { overflow: visible; white-space: normal; }
.detail-shell .holdings-summary small { white-space: normal; overflow-wrap: anywhere; }
.holdings-summary #trendLeaders span { display: inline-block; font: inherit; white-space: nowrap; }

.detail-shell {
  width: min(1640px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 12px 0 24px;
}

.detail-shell .detail-header {
  min-height: 56px;
  padding: 8px 12px;
}

.detail-header,
.summary-strip,
.list-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: var(--shadow);
}

.detail-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  min-height: 68px;
  padding: 12px 14px;
}

.brand {
  color: var(--accent);
  font-size: clamp(18px, 1.8vw, 26px);
  font-weight: 850;
  text-decoration: none;
  text-transform: uppercase;
  white-space: nowrap;
}

.primary-nav,
.filter-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.nav-link,
.filter-button {
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}
.nav-link { padding: 8px 14px; }
.filter-button { min-height: 36px; padding: 0 18px; }
.nav-link.is-active,
.filter-button.is-active { color: #fff; background: var(--accent); }

.header-actions { display: flex; justify-content: flex-end; gap: 10px; }
.icon-button,
.refresh-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel-strong);
}
.icon-button { width: 46px; padding: 0; font-size: 22px; }
.refresh-button { padding: 0 16px; font-weight: 700; }
.theme-button .sun { display: none; }
:root[data-theme="light"] .theme-button .sun { display: inline; }
:root[data-theme="light"] .theme-button .moon { display: none; }

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 8px 0;
  overflow: hidden;
}
.detail-shell .summary-strip > div { min-width: 0; min-height: 74px; padding: 7px 12px; }
.summary-strip > div + div { border-left: 1px solid var(--line); }
.summary-strip span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
#todayProfitLabel { display: inline; }
.summary-strip strong { display: block; overflow: hidden; margin-top: 3px; font-size: clamp(18px, 1.25vw, 23px); text-overflow: ellipsis; white-space: nowrap; }
.summary-strip small { display: block; overflow: hidden; margin-top: 1px; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

.list-panel { overflow: hidden; }
.list-panel .list-toolbar {
  display: flex;
  align-items: end;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}
.search-box { display: grid; gap: 5px; color: var(--muted); font-size: 13px; font-weight: 700; }
.search-box { width: min(260px, 34vw); }
.search-box input {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  color: var(--text);
  background: var(--panel-strong);
}
.search-box input:focus { border-color: var(--accent); }
.list-toolbar .search-box { font-size: 12px; font-weight: 500; }
.list-toolbar .search-box input { font-size: 13px; }
.list-toolbar .filter-tabs {
  display: inline-grid;
  min-width: 210px;
  min-height: 36px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 3px;
}
.list-toolbar .filter-button { min-height: 30px; padding: 0 15px; font-size: 12px; font-weight: 500; }
.list-toolbar .filter-button.is-active {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.14);
}

.query-indicator {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 6px 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(37, 99, 235, 0.06);
  font-size: 13px;
}
.query-indicator.is-active { color: var(--text); background: rgba(37, 99, 235, 0.12); }
.query-indicator strong { color: var(--accent); font-size: 16px; }
.query-indicator span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.query-indicator-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.14);
  animation: query-dot-pulse 1.2s ease-in-out infinite;
}

@keyframes query-dot-pulse {
  0%, 100% { transform: scale(0.8); opacity: 0.62; }
  50% { transform: scale(1.25); opacity: 1; }
}

.table-scroll {
  max-height: max(320px, calc(100dvh - 220px));
  overflow: auto;
}
.fund-table { min-width: 1420px; }
.table-header,
.fund-row {
  display: grid;
  grid-template-columns: minmax(250px, 1.45fr) minmax(125px, .76fr) minmax(145px, .84fr) repeat(3, minmax(105px, .6fr)) minmax(135px, .8fr) repeat(3, minmax(120px, .7fr));
  align-items: center;
}
.table-header {
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.detail-shell .table-header { min-height: 48px; }
.column-button {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  align-self: stretch;
  padding: 0 18px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  font-weight: 750;
  text-align: right;
}
.detail-shell .column-button { padding-right: 12px; padding-left: 12px; font-size: 13px; font-weight: 650; }
.column-button.name-column { justify-content: flex-start; text-align: left; }
.column-button:hover { color: var(--text); }
.column-button.is-active { color: var(--accent); }
.column-button small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 650; }
.sort-mark {
  display: inline-grid;
  flex: 0 0 10px;
  width: 10px;
  color: var(--muted);
  font-size: 8px;
  line-height: .72;
  text-align: center;
}
.sort-mark::before { content: "▲"; opacity: .55; }
.sort-mark::after { content: "▼"; opacity: .55; }
.column-button.is-active[data-direction="asc"] .sort-mark::before,
.column-button.is-active[data-direction="desc"] .sort-mark::after { color: var(--accent); opacity: 1; }
.column-button.is-active[data-direction="asc"] .sort-mark::after,
.column-button.is-active[data-direction="desc"] .sort-mark::before { opacity: .25; }

.fund-row {
  min-height: 86px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 58%, transparent);
  cursor: pointer;
  outline: none;
  transition: background-color 160ms ease, box-shadow 160ms ease;
}
@keyframes fund-rank-change {
  0% { background-color: color-mix(in srgb, var(--accent) 20%, transparent); }
  45% { background-color: color-mix(in srgb, var(--accent) 9%, transparent); }
  100% { background-color: transparent; }
}
.fund-row.is-rank-changed { animation: fund-rank-change 760ms ease-out; }
.detail-shell .fund-row { min-height: 68px; }
.fund-row:hover,
.fund-row:focus-visible {
  background: var(--row-hover);
  box-shadow: inset 3px 0 var(--accent);
}
.fund-cell { min-width: 0; padding: 13px 18px; text-align: right; }
.detail-shell .fund-cell { padding: 6px 12px; }
.fund-cell:first-child { text-align: left; }
.fund-name { overflow: hidden; font-size: 16px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.detail-shell .fund-name { font-size: 14px; font-weight: 650; }
.fund-meta,
.cell-sub { overflow: hidden; margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.detail-shell .fund-meta,
.detail-shell .cell-sub { margin-top: 3px; font-size: 10.5px; }
.fund-code {
  display: inline-block;
  margin-right: 8px;
  padding: 2px 5px;
  border: 1px solid color-mix(in srgb, var(--accent) 56%, transparent);
  border-radius: 4px;
  color: var(--accent);
  font-weight: 750;
}
.detail-shell .fund-code { font-weight: 650; }
.fund-update-status {
  display: inline-block;
  margin-right: 8px;
  padding: 1px 5px;
  border: 1px solid currentColor;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.detail-shell .fund-update-status { font-weight: 550; }
.fund-update-status.updated { color: var(--accent); }
.fund-update-status.estimate { color: var(--accent); }
.fund-update-status.pending { color: #d69a24; }
.fund-update-status.unknown { color: var(--muted); }
.summary-status {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 6px;
  border: 1px solid currentColor;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 750;
  vertical-align: 1px;
}
.summary-status.updated { color: var(--accent); }
.summary-status.estimate { color: #d69a24; }
.summary-status.partial { color: var(--muted); }
.cell-value { display: block; overflow: hidden; font-size: 17px; font-variant-numeric: tabular-nums; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.detail-shell .cell-value { font-size: 14px; font-weight: 700; }
.gain { color: var(--red) !important; }
.loss { color: var(--green) !important; }
.neutral { color: var(--muted) !important; }
.loading-state,
.empty-state { padding: 80px 20px; color: var(--muted); text-align: center; }
.list-footer { display: flex; justify-content: space-between; gap: 16px; padding: 12px 18px; color: var(--muted); font-size: 12px; }

body.is-fund-detail-open { overflow: hidden; }

.fund-detail-backdrop {
  position: fixed;
  z-index: 1000;
  inset: 0;
  background: rgba(15, 18, 24, 0.42);
  opacity: 0;
  transition: opacity 180ms ease;
}

.fund-detail-backdrop.is-open { opacity: 1; }

.fund-detail-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: min(560px, calc(100vw - 32px));
  height: 100%;
  overflow: hidden;
  border-left: 1px solid var(--line);
  color: var(--text);
  background: var(--panel);
  box-shadow: -18px 0 48px rgba(0, 0, 0, 0.24);
  opacity: 0.72;
  transform: translateX(28px);
  transition: opacity 180ms ease, transform 220ms cubic-bezier(.2, .7, .2, 1);
}

.fund-detail-backdrop.is-open .fund-detail-drawer {
  opacity: 1;
  transform: translateX(0);
}

.fund-detail-header {
  position: relative;
  z-index: 2;
  display: flex;
  min-height: 88px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-bg);
}

.fund-detail-identity { min-width: 0; }
.fund-detail-code {
  display: inline-block;
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}
.fund-detail-identity h2 {
  overflow: hidden;
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fund-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}
.fund-detail-meta .updated { color: var(--accent); }
.fund-detail-meta .pending { color: #d69a24; }

.fund-detail-close {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: var(--panel-strong);
  font-size: 24px;
  font-weight: 300;
  line-height: 1;
  place-items: center;
}
.fund-detail-close:hover { color: var(--text); border-color: var(--accent); }

.fund-detail-content {
  height: calc(100% - 88px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.fund-detail-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}
.fund-detail-metric {
  min-width: 0;
  min-height: 61px;
  padding: 8px 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 56%, transparent);
}
.fund-detail-metric:nth-child(odd) { border-right: 1px solid color-mix(in srgb, var(--line) 56%, transparent); }
.fund-detail-metric span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fund-detail-metric strong {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fund-detail-metric small {
  display: block;
  overflow: hidden;
  margin-top: 1px;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fund-chart-section { padding: 14px 14px 10px; }
.fund-chart-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}
.fund-detail-eyebrow { color: var(--accent); font-size: 10px; font-weight: 650; }
.fund-chart-heading h3 { margin: 1px 0 0; font-size: 15px; font-weight: 650; }
.fund-detail-chart { min-height: 225px; margin-top: 10px; }
.fund-detail-chart-item + .fund-detail-chart-item {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.fund-detail-loading {
  display: grid;
  min-height: 130px;
  color: var(--muted);
  font-size: 12px;
  place-items: center;
}
.fund-detail-chart-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.fund-detail-chart-summary span { color: var(--muted); font-size: 12px; }
.fund-detail-chart-summary b { margin-left: 7px; color: var(--text); font-weight: 650; }
.fund-detail-chart-summary strong { font-size: 17px; font-variant-numeric: tabular-nums; font-weight: 650; }
.fund-detail-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.fund-detail-chart-grid { stroke: color-mix(in srgb, var(--line) 62%, transparent); stroke-width: 1; }
.fund-detail-chart-zero { stroke: color-mix(in srgb, var(--muted) 48%, transparent); stroke-width: 1; }
.fund-detail-chart-line { fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.fund-detail-chart-line.gain { stroke: var(--red); }
.fund-detail-chart-line.loss { stroke: var(--green); }
.fund-detail-chart-line.neutral { stroke: var(--muted); }
.fund-detail-chart-label { fill: var(--muted); font-size: 10px; }
.fund-detail-chart-axis {
  display: flex;
  justify-content: space-between;
  margin: 6px 3px 0 48px;
  color: var(--muted);
  font-size: 10px;
}

.fund-detail-source {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 14px 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
}

@media (max-width: 760px) {
  .detail-header { grid-template-columns: 1fr auto; }
  .primary-nav { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; }
  .nav-link { flex: 1; text-align: center; }
  .search-box { width: min(520px, 62vw); }
}

@media (max-width: 640px) {
  .detail-shell { width: 100%; padding: 0 0 18px; }
  .detail-header,
  .summary-strip,
  .list-panel { border-right: 0; border-left: 0; border-radius: 0; }
  .detail-header { min-height: 60px; border-top: 0; }
  .brand { font-size: 18px; }
  .refresh-button { width: 44px; padding: 0; font-size: 0; }
  .refresh-button span { font-size: 23px; }
  .summary-strip { grid-template-columns: 1fr 1fr; margin: 8px 0; }
  .summary-primary { grid-column: 1 / -1; border-bottom: 1px solid var(--line); }
  .summary-strip > div { padding: 9px 14px; }
  .summary-strip > div:nth-child(2) { border-left: 0; }
  .summary-strip strong { font-size: 18px; }
  .list-panel .list-toolbar { align-items: stretch; flex-direction: column; gap: 12px; padding: 14px; }
  .query-indicator { flex-wrap: wrap; }
  .query-indicator span:last-child { width: 100%; padding-left: 18px; }
  .search-box { width: 100%; }
  .filter-tabs { width: 100%; }
  .filter-button { flex: 1; }
  .fund-table { width: 100%; min-width: 1330px; }
  .table-header,
  .fund-row { grid-template-columns: 210px 130px 145px 110px 110px 110px 135px 120px 120px; }
  .column-button,
  .fund-cell { padding-right: 6px; padding-left: 6px; }
  .detail-shell .column-button,
  .detail-shell .fund-cell { padding-right: 6px; padding-left: 6px; }
  .column-button { gap: 2px; font-size: 11px; line-height: 1.2; }
  .detail-shell .fund-row { min-height: 68px; }
  .detail-shell .fund-name { font-size: 13px; }
  .fund-meta,
  .cell-sub { margin-top: 4px; font-size: 10px; }
  .detail-shell .fund-meta,
  .detail-shell .cell-sub { margin-top: 3px; font-size: 10px; }
  .fund-code { margin-right: 3px; padding: 1px 3px; }
  .fund-update-status { margin-right: 3px; padding: 1px 3px; font-size: 9px; }
  .detail-shell .cell-value { font-size: 12px; }
  .sector-name { font-size: 10px; }
  .list-footer span:last-child { display: none; }

  .fund-detail-drawer { width: 100%; border-left: 0; }
  .fund-detail-header { min-height: 84px; padding: 12px 12px 10px; }
  .fund-detail-identity h2 { font-size: 17px; }
  .fund-detail-content { height: calc(100% - 84px); }
  .fund-detail-metric { min-height: 58px; padding: 7px 11px; }
  .fund-detail-metric strong { font-size: 15px; }
  .fund-chart-section { padding: 12px 10px 10px; }
  .fund-chart-heading { align-items: stretch; flex-direction: column; gap: 10px; }
  .fund-detail-chart { min-height: 140px; margin-top: 8px; }
  .fund-detail-loading { min-height: 130px; }
  .fund-detail-source { flex-direction: column; gap: 3px; padding: 10px 12px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .fund-row.is-rank-changed { animation: none; }
  .fund-detail-backdrop,
  .fund-detail-drawer { transition: none; }
}

.list-footer:has(#dataStatus:empty) { display: none; }
html:has(body.is-holdings-fullscreen) { scrollbar-gutter: auto; overflow: hidden; }
body.is-holdings-fullscreen { overflow: hidden; }
body.is-holdings-fullscreen > .detail-shell {
  width: 100%;
  max-width: none;
  height: 100dvh;
  margin: 0;
  padding: 8px;
  box-sizing: border-box;
}
body.is-holdings-fullscreen .detail-shell > :not(.list-panel) { display: none; }
body.is-holdings-fullscreen .list-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  margin: 0;
  min-height: 0;
}
body.is-holdings-fullscreen .table-scroll { flex: 1; min-height: 0; max-height: none; }
body.is-holdings-fullscreen .list-footer { flex-shrink: 0; align-items: center; }
