:root {
  color-scheme: dark;
  --bg: #232324;
  --panel: #292b32;
  --panel-strong: #363a46;
  --line: #4a4f5d;
  --text: #fefefe;
  --muted: #aeb4c2;
  --soft: #3f414b;
  --red: #f63538;
  --green: #30cc5a;
  --amber: #f2a900;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.36);
  --body-gradient: linear-gradient(135deg, rgba(38, 41, 49, 0.96), rgba(35, 35, 36, 0.98));
  --body-glow: radial-gradient(circle at top left, rgba(246, 53, 56, 0.1), transparent 30rem);
  --action-border: rgba(254, 254, 254, 0.14);
  --action-bg: #292b32;
  --action-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  --metric-bg: rgba(54, 58, 70, 0.84);
  --panel-bg: rgba(41, 43, 50, 0.92);
  --toolbar-bg: rgba(54, 58, 70, 0.72);
  --query-bg: rgba(242, 169, 0, 0.08);
  --query-active-bg: rgba(242, 169, 0, 0.16);
  --query-accent: #ffca5a;
  --query-dot-shadow: 0 0 0 4px rgba(242, 169, 0, 0.18);
  --control-active-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
  --treemap-bg: #262931;
  --treemap-group-border: rgba(74, 79, 93, 0.88);
  --treemap-group-bg: rgba(63, 65, 75, 0.46);
  --treemap-group-label: rgba(254, 254, 254, 0.62);
  --tile-border: rgba(38, 41, 49, 0.92);
  --tile-neutral: #414554;
  --tile-shadow: 0 16px 30px rgba(0, 0, 0, 0.38);
  --tile-detail: rgba(254, 254, 254, 0.78);
  --tile-text-on-fill: #fefefe;
  --tile-text-muted-on-fill: rgba(254, 254, 254, 0.72);
  --detail-cell-bg: rgba(63, 65, 75, 0.72);
  --rank-bg: rgba(63, 65, 75, 0.58);
  --selected-border: rgba(254, 254, 254, 0.32);
  --focus-border: rgba(254, 254, 254, 0.36);
  --dialog-backdrop: rgba(0, 0, 0, 0.56);
  --tooltip-bg: rgba(35, 35, 36, 0.97);
  --tooltip-border: rgba(74, 79, 93, 0.92);
  --tooltip-shadow: 0 16px 36px rgba(0, 0, 0, 0.42);
  --tooltip-text: #fff;
  --tooltip-muted-1: rgba(255, 255, 255, 0.76);
  --tooltip-muted-2: rgba(255, 255, 255, 0.58);
  --tooltip-muted-3: rgba(255, 255, 255, 0.7);
  --tooltip-muted-4: rgba(255, 255, 255, 0.92);
  --tooltip-muted-5: rgba(255, 255, 255, 0.42);
  --tooltip-muted-6: rgba(255, 255, 255, 0.52);
  --tooltip-divider-strong: rgba(255, 255, 255, 0.16);
  --tooltip-divider: rgba(255, 255, 255, 0.12);
  --chart-grid: rgba(255, 255, 255, 0.1);
  --chart-axis: rgba(255, 255, 255, 0.2);
  --chart-zero: rgba(255, 255, 255, 0.3);
  --chart-label: rgba(255, 255, 255, 0.5);
  --chart-line: rgba(255, 255, 255, 0.8);
  --chart-gain: #ff7073;
  --chart-loss: #55dc79;
  --reduced-query-bg: rgba(242, 169, 0, 0.14);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f3ee;
  --panel: #fffdfa;
  --panel-strong: #ffffff;
  --line: #ded8cd;
  --text: #25231f;
  --muted: #756f66;
  --soft: #ece6dc;
  --red: #c83232;
  --green: #11805f;
  --amber: #9b6a17;
  --shadow: 0 18px 45px rgba(42, 37, 30, 0.12);
  --body-gradient: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(236, 230, 220, 0.74));
  --body-glow: radial-gradient(circle at top left, rgba(200, 50, 50, 0.12), transparent 30rem);
  --action-border: rgba(37, 35, 31, 0.16);
  --action-bg: #25231f;
  --action-shadow: 0 10px 24px rgba(37, 35, 31, 0.18);
  --metric-bg: rgba(255, 253, 250, 0.86);
  --panel-bg: rgba(255, 253, 250, 0.92);
  --toolbar-bg: rgba(255, 255, 255, 0.6);
  --query-bg: rgba(155, 106, 23, 0.06);
  --query-active-bg: rgba(155, 106, 23, 0.12);
  --query-accent: #7b5010;
  --query-dot-shadow: 0 0 0 4px rgba(177, 120, 24, 0.14);
  --control-active-shadow: 0 3px 10px rgba(37, 35, 31, 0.1);
  --treemap-bg: #eee8df;
  --treemap-group-border: rgba(117, 111, 102, 0.48);
  --treemap-group-bg: rgba(255, 253, 250, 0.52);
  --treemap-group-label: rgba(37, 35, 31, 0.72);
  --tile-border: rgba(255, 253, 250, 0.86);
  --tile-neutral: #d8d1c6;
  --tile-shadow: 0 16px 30px rgba(37, 35, 31, 0.24);
  --tile-detail: rgba(37, 35, 31, 0.78);
  --tile-text-on-fill: #25231f;
  --tile-text-muted-on-fill: rgba(37, 35, 31, 0.72);
  --detail-cell-bg: rgba(255, 255, 255, 0.62);
  --rank-bg: rgba(255, 255, 255, 0.58);
  --selected-border: rgba(37, 35, 31, 0.42);
  --focus-border: rgba(37, 35, 31, 0.42);
  --dialog-backdrop: rgba(37, 35, 31, 0.46);
  --tooltip-bg: rgba(255, 253, 250, 0.97);
  --tooltip-border: rgba(117, 111, 102, 0.38);
  --tooltip-shadow: 0 16px 36px rgba(37, 35, 31, 0.22);
  --tooltip-text: #25231f;
  --tooltip-muted-1: rgba(37, 35, 31, 0.76);
  --tooltip-muted-2: rgba(37, 35, 31, 0.58);
  --tooltip-muted-3: rgba(37, 35, 31, 0.7);
  --tooltip-muted-4: rgba(37, 35, 31, 0.92);
  --tooltip-muted-5: rgba(37, 35, 31, 0.48);
  --tooltip-muted-6: rgba(37, 35, 31, 0.56);
  --tooltip-divider-strong: rgba(37, 35, 31, 0.16);
  --tooltip-divider: rgba(37, 35, 31, 0.12);
  --chart-grid: rgba(37, 35, 31, 0.1);
  --chart-axis: rgba(37, 35, 31, 0.22);
  --chart-zero: rgba(37, 35, 31, 0.3);
  --chart-label: rgba(37, 35, 31, 0.56);
  --chart-line: rgba(37, 35, 31, 0.78);
  --chart-gain: #c83232;
  --chart-loss: #11805f;
  --reduced-query-bg: rgba(155, 106, 23, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    var(--body-gradient),
    var(--body-glow),
    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 {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: var(--shadow);
}

.topbar > div:first-child {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 14px;
}

.eyebrow {
  margin: 0;
  color: var(--amber);
  font-size: clamp(18px, 1.8vw, 26px);
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  overflow: hidden;
  font-size: clamp(24px, 2.2vw, 36px);
  line-height: 1;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

h2 {
  font-size: 16px;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--action-border);
  border-radius: 8px;
  color: #fff;
  background: var(--action-bg);
  box-shadow: var(--action-shadow);
}

.primary-action:disabled {
  cursor: progress;
  opacity: 0.68;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fullscreen-action {
  width: 42px;
  justify-content: center;
  padding: 0;
  font-size: 20px;
}

.theme-toggle {
  display: inline-flex;
  width: 72px;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--action-border);
  border-radius: 999px;
  color: var(--text);
  background: var(--action-bg);
  box-shadow: var(--action-shadow);
}

.theme-toggle-track {
  position: relative;
  display: grid;
  width: 60px;
  height: 30px;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
}

.theme-toggle-icon {
  position: relative;
  z-index: 2;
  display: grid;
  min-width: 0;
  place-items: center;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
}

.theme-toggle-thumb {
  position: absolute;
  z-index: 1;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
  transition:
    transform 160ms ease,
    background-color 160ms ease;
}

:root[data-theme="dark"] .theme-toggle-thumb {
  transform: translateX(30px);
}

:root[data-theme="light"] .theme-toggle-sun,
:root[data-theme="dark"] .theme-toggle-moon {
  color: #fff;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.metric {
  min-width: 0;
  position: relative;
  min-height: 86px;
  padding: 12px 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--metric-bg);
}

.metric::before {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 2px;
  content: "";
  background: linear-gradient(90deg, var(--amber), transparent 72%);
  opacity: 0.72;
}

.metric-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong {
  display: block;
  min-height: 0;
  overflow-wrap: anywhere;
  font-size: clamp(19px, 1.7vw, 30px);
  line-height: 1.2;
}

.metric-detail {
  display: block;
  min-height: 18px;
  margin-top: 5px;
  font-size: 12px;
  line-height: 1.35;
}

.reserve-section {
  display: grid;
  grid-template-columns: minmax(130px, 180px) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
}

.section-heading {
  display: grid;
  gap: 4px;
  margin-bottom: 0;
}

.section-heading span {
  color: var(--muted);
  font-size: 11px;
}

.reserve-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
}

.reserve-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 14px;
  border-left: 1px solid var(--line);
}

.reserve-item:first-child {
  border-left: 0;
}

.reserve-name,
.reserve-value {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.reserve-name strong,
.reserve-value strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reserve-name span,
.reserve-value span {
  color: var(--muted);
  font-size: 11px;
}

.reserve-value span.gain {
  color: var(--red);
}

.reserve-value span.loss {
  color: var(--green);
}

.reserve-value {
  text-align: right;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.visual-panel,
.side-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: var(--shadow);
}

.visual-panel {
  position: sticky;
  top: 14px;
  align-self: start;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--toolbar-bg);
}

.query-indicator {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: var(--query-bg);
  font-size: 13px;
}

.query-indicator.is-active {
  color: var(--text);
  background: var(--query-active-bg);
}

.query-indicator strong {
  color: var(--query-accent);
  font-size: 16px;
}

.query-indicator span:last-child {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.query-indicator-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: var(--query-dot-shadow);
  animation: query-dot-pulse 1.2s ease-in-out infinite;
}

.search-box,
.select-box {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search-box {
  width: min(260px, 34vw);
}

.select-box {
  width: 160px;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--text);
  background: var(--panel-strong);
}

.segmented,
.view-mode-toggle {
  display: inline-grid;
  min-height: 38px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.segmented {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-width: 210px;
  margin-left: auto;
}

.view-mode-toggle {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 150px;
}

.view-mode-button,
.segment {
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}

.view-mode-button.is-active,
.segment.is-active {
  color: var(--text);
  background: var(--panel-strong);
  box-shadow: var(--control-active-shadow);
}

.treemap-wrap {
  display: grid;
  min-height: 0;
  padding: 12px;
  place-items: stretch;
}

.treemap {
  position: relative;
  width: 100%;
  min-width: 0;
  height: clamp(560px, calc(100vh - 310px), 820px);
  min-height: 560px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--treemap-bg);
}

.treemap-group {
  position: absolute;
  z-index: 0;
  overflow: hidden;
  border: 1px solid var(--treemap-group-border);
  border-radius: 7px;
  background: var(--treemap-group-bg);
  pointer-events: none;
}

.treemap-group-label {
  position: absolute;
  top: 0;
  right: 6px;
  left: 6px;
  display: flex;
  height: var(--group-header-height);
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  overflow: hidden;
  color: var(--treemap-group-label);
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}

.treemap-group-label strong {
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 850;
  text-overflow: ellipsis;
}

.treemap-group-label > span {
  overflow: hidden;
  flex: 0 1 auto;
  text-overflow: ellipsis;
}

.treemap-group.is-compact .treemap-group-label > span,
.treemap-group.is-label-hidden .treemap-group-label {
  display: none;
}

.tile {
  position: absolute;
  z-index: 1;
  display: flex;
  min-width: 0;
  min-height: 0;
  align-items: center;
  justify-content: center;
  padding: var(--tile-padding, 9px);
  overflow: hidden;
  border: 2px solid var(--tile-border);
  border-radius: 8px;
  color: var(--text);
  text-align: center;
  background: var(--tile-color, var(--tile-neutral));
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    opacity 160ms ease;
}

.tile:hover,
.tile.is-selected,
.tile.is-querying {
  z-index: 5;
  transform: translateY(-1px);
  box-shadow: var(--tile-shadow);
}

@keyframes query-surface-breathe {
  0%, 100% { opacity: 0.08; }
  50% { opacity: 0.48; }
}

@keyframes query-row-breathe {
  0%, 100% { background-color: var(--query-bg); }
  50% { background-color: var(--query-active-bg); }
}

.tile.is-querying {
  z-index: 6;
}

.tile.is-querying::before {
  position: absolute;
  z-index: 1;
  inset: 0;
  content: "";
  pointer-events: none;
  background: var(--amber);
  animation: query-surface-breathe 1.3s ease-in-out infinite;
}

.tile-content {
  position: relative;
  z-index: 2;
  display: grid;
  align-content: center;
  justify-items: center;
  width: 100%;
  min-width: 0;
  gap: var(--tile-gap, 5px);
}

.tile-content > span {
  width: 100%;
  min-width: 0;
  overflow: hidden;
  font-size: 0;
  line-height: 1;
}

.tile-code {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--tile-code-size, 18px);
  font-weight: 850;
  line-height: 1;
}

.tile-name,
.tile-amount,
.tile-profit {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-name {
  display: -webkit-box;
  color: var(--tile-detail);
  font-size: var(--tile-detail-size, 12px);
  line-height: 1.15;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.tile-amount {
  font-size: var(--tile-detail-size, 13px);
  font-weight: 800;
}

.tile-profit {
  font-size: var(--tile-profit-size, 12px);
  font-weight: 800;
}

.tile .gain,
.tile .loss {
  color: var(--tile-text-on-fill);
}

.tile .neutral {
  color: var(--tile-text-muted-on-fill);
}

.tile.is-compact {
  padding: var(--tile-padding, 5px);
  border-radius: 6px;
}

.tile.is-name-hidden .tile-name {
  display: none;
}

.tile.is-tiny {
  padding: var(--tile-padding, 1px);
  border-width: 1px;
  border-radius: 4px;
}

.tile.is-tiny .tile-name,
.tile.is-tiny .tile-profit {
  display: none;
}

.tile.is-micro {
  padding: 0;
}

.tile.is-micro .tile-content {
  display: none;
}

.side-panel {
  display: flex;
  height: auto;
  min-height: 0;
  flex-direction: column;
  padding: 14px;
}

.status-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.selected-fund {
  min-height: 188px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.empty-state {
  display: grid;
  min-height: 150px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.detail-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.detail-title strong {
  font-size: 24px;
}

.detail-title span {
  color: var(--muted);
  font-size: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.detail-cell {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--detail-cell-bg);
}

.detail-cell span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.detail-cell strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 16px;
}

.rank-panel {
  display: flex;
  flex: none;
  flex-direction: column;
  padding-top: 14px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel-heading span {
  color: var(--muted);
  font-size: 12px;
}

.rank-list {
  display: grid;
  gap: 8px;
}

.rank-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--rank-bg);
}

.rank-item.is-selected {
  border-color: var(--selected-border);
  background: var(--panel-strong);
}

.rank-item.is-querying,
.reserve-item.is-querying {
  animation: query-row-breathe 1.3s ease-in-out infinite;
}

.rank-select {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
  padding: 6px;
  border: 0;
  color: inherit;
  text-align: left;
  background: transparent;
}

.icon-action {
  display: grid;
  width: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: var(--panel-strong);
}

.icon-action:hover,
.icon-action:focus-visible {
  color: var(--text);
  border-color: var(--focus-border);
}

.holding-dialog {
  width: min(420px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.holding-dialog::backdrop {
  background: var(--dialog-backdrop);
}

.holding-form {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.dialog-heading {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.dialog-heading h2 {
  margin-bottom: 4px;
  font-size: 20px;
}

.dialog-heading span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.holding-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

.secondary-action {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel-strong);
}

.tile-tooltip {
  position: fixed;
  z-index: 1000;
  width: min(370px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--tooltip-border);
  border-radius: 8px;
  color: var(--tooltip-text);
  background: var(--tooltip-bg);
  box-shadow: var(--tooltip-shadow);
  pointer-events: auto;
}

.tile-tooltip[hidden] {
  display: none;
}

body.is-monitor-fullscreen {
  overflow: hidden;
  background: var(--bg);
}

body.is-monitor-fullscreen .app-shell {
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 12px;
}

body.is-monitor-fullscreen .topbar,
body.is-monitor-fullscreen .summary-grid,
body.is-monitor-fullscreen .reserve-section,
body.is-monitor-fullscreen .toolbar,
body.is-monitor-fullscreen .query-indicator,
body.is-monitor-fullscreen .side-panel {
  display: none;
}

body.is-monitor-fullscreen .workspace {
  height: 100%;
  grid-template-columns: minmax(0, 1fr) clamp(400px, 22vw, 520px);
  gap: 12px;
  align-items: stretch;
}

body.is-monitor-fullscreen .visual-panel {
  position: static;
  height: 100%;
  align-self: stretch;
  border: 0;
  background: transparent;
  box-shadow: none;
}

body.is-monitor-fullscreen .treemap-wrap,
body.is-monitor-fullscreen .treemap {
  height: 100%;
  min-height: 0;
}

body.is-monitor-fullscreen .treemap-wrap {
  padding: 0;
}

body.is-monitor-fullscreen .treemap-group-label {
  right: 8px;
  left: 8px;
  font-size: 13px;
}

body.is-monitor-fullscreen .treemap-group-label strong {
  font-size: 14px;
}

body.is-monitor-fullscreen .tile-tooltip {
  top: 12px !important;
  right: 12px;
  bottom: 12px;
  left: auto !important;
  width: clamp(400px, 22vw, 520px);
  max-height: none;
}

.tooltip-heading {
  display: grid;
  gap: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--tooltip-divider-strong);
}

.tooltip-heading strong {
  font-size: 17px;
}

.tooltip-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tooltip-heading > span {
  overflow-wrap: anywhere;
  color: var(--tooltip-muted-1);
  font-size: 13px;
  line-height: 1.45;
}

.tooltip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 11px 0;
}

.tooltip-grid > span {
  display: grid;
  gap: 3px;
  color: var(--tooltip-muted-2);
  font-size: 11px;
}

.tooltip-grid strong {
  color: var(--tooltip-text);
  font-size: 14px;
}

.tooltip-grid strong.gain {
  color: var(--chart-gain);
}

.tooltip-grid strong.loss {
  color: var(--chart-loss);
}

.tooltip-history {
  padding: 10px 0;
  border-top: 1px solid var(--tooltip-divider);
}

.tooltip-history-heading,
.tooltip-history-axis {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tooltip-history-heading {
  padding-bottom: 6px;
  color: var(--tooltip-muted-3);
  font-size: 12px;
}

.tooltip-history-heading strong {
  font-size: 13px;
}

.tooltip-history-position {
  margin-left: 8px;
  color: var(--tooltip-muted-4);
  font-size: 12px;
  white-space: nowrap;
}

.tooltip-history-heading strong.gain {
  color: var(--chart-gain);
}

.tooltip-history-heading strong.loss {
  color: var(--chart-loss);
}

.tooltip-history-chart {
  display: block;
  width: 100%;
  height: 92px;
  overflow: visible;
}

.tooltip-history-chart line {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.tooltip-history-chart .tooltip-history-y-axis {
  stroke: var(--chart-axis);
}

.tooltip-history-chart .tooltip-history-zero {
  stroke: var(--chart-zero);
}

.tooltip-history-y-label {
  fill: var(--chart-label);
  font-family: inherit;
  font-size: 11.5px;
  text-anchor: end;
  dominant-baseline: middle;
}

.tooltip-history-line {
  fill: none;
  stroke: var(--chart-line);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.tooltip-history-line.gain {
  stroke: var(--chart-gain);
}

.tooltip-history-line.loss {
  stroke: var(--chart-loss);
}

.tooltip-history-axis {
  padding-top: 4px;
  color: var(--tooltip-muted-5);
  font-size: 11px;
}

.tooltip-history-state {
  min-height: 118px;
  display: grid;
  place-items: center;
  border-top: 1px solid var(--tooltip-divider);
  color: var(--tooltip-muted-6);
  font-size: 11px;
}

.tooltip-history-state.is-loading {
  animation: tooltip-history-pulse 1.2s ease-in-out infinite;
}

@keyframes tooltip-history-pulse {
  0%, 100% { opacity: 0.42; }
  50% { opacity: 0.9; }
}

.tooltip-meta {
  color: var(--tooltip-muted-6);
  font-size: 11px;
}

body.is-monitor-fullscreen .tooltip-heading strong {
  font-size: 22px;
}

body.is-monitor-fullscreen .tooltip-heading > span {
  font-size: 16px;
}

body.is-monitor-fullscreen .tooltip-grid > span {
  font-size: 14px;
}

body.is-monitor-fullscreen .tooltip-grid strong {
  font-size: 18px;
}

body.is-monitor-fullscreen .tooltip-history-heading,
body.is-monitor-fullscreen .tooltip-history-position {
  font-size: 15px;
}

body.is-monitor-fullscreen .tooltip-history-heading strong {
  font-size: 16px;
}

body.is-monitor-fullscreen .tooltip-history-y-label,
body.is-monitor-fullscreen .tooltip-history-axis,
body.is-monitor-fullscreen .tooltip-history-state,
body.is-monitor-fullscreen .tooltip-meta {
  font-size: 14px;
}

body.is-monitor-fullscreen .tooltip-grid {
  padding: 9px 0;
}

body.is-monitor-fullscreen .tooltip-history {
  padding: 8px 0;
}

body.is-monitor-fullscreen .tooltip-history-heading {
  padding-bottom: 4px;
}

@media (prefers-reduced-motion: reduce) {
  .tooltip-history-state.is-loading {
    animation: none;
  }

  .rank-item.is-querying,
  .reserve-item.is-querying {
    animation: none;
    outline: 0;
    background: var(--reduced-query-bg);
  }

  .query-indicator-dot {
    animation: none;
  }

  .tile.is-querying {
    outline: 0;
  }

  .tile.is-querying::before {
    opacity: 0.22;
    animation: none;
  }
}

.rank-main {
  min-width: 0;
}

.rank-code {
  display: block;
  font-weight: 850;
}

.rank-name {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-value {
  text-align: right;
  font-size: 12px;
  font-weight: 800;
}

.gain {
  color: var(--red);
}

.loss {
  color: var(--green);
}

.neutral {
  color: var(--muted);
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .visual-panel {
    position: static;
  }

  .treemap {
    height: clamp(540px, 70vh, 760px);
    min-height: 540px;
  }

  .rank-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100vw - 20px, 1480px);
    padding-top: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar > div:first-child {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .reserve-section {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .reserve-list {
    grid-template-columns: 1fr;
  }

  .reserve-item {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 9px 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .reserve-item:first-child {
    border-top: 0;
  }

  .metric strong {
    font-size: 23px;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .query-indicator {
    flex-wrap: wrap;
  }

  .query-indicator span:last-child {
    width: 100%;
    padding-left: 18px;
  }

  .search-box,
  .select-box,
  .view-mode-toggle,
  .segmented {
    width: 100%;
    min-width: 0;
  }

  .treemap {
    height: clamp(520px, 72vh, 680px);
    min-height: 520px;
  }

  .rank-list {
    grid-template-columns: 1fr;
  }
}
