:root {
  --bg: #ffffff;
  --sidebar: #eef0f2;
  --sidebar-active: #dedfe1;
  --ink: #282b2f;
  --muted: #7c858b;
  --line: #e3e6e8;
  --chip: #d7e0e3;
  --green: #18c987;
  --red: #ff6b6b;
  --purple: #6c3cff;
  --soft-green: #eefaf6;
  --shadow: 0 2px 7px rgba(0, 0, 0, .14);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
  font: inherit;
}
button {
  cursor: pointer;
}

.side-nav {
  position: fixed;
  inset: 0 auto 0 0;
  width: 226px;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid #d9dde0;
}
.logo {
  height: 78px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  color: var(--purple);
  text-decoration: none;
  font-size: 20px;
  white-space: nowrap;
}
.logo-mark {
  width: 28px;
  height: 24px;
  display: inline-block;
  border-radius: 24px 24px 6px 24px;
  background: linear-gradient(135deg, #7d48ff, #4f24e8);
  transform: rotate(-22deg);
}
.side-nav nav {
  display: grid;
  border-top: 1px solid #d9dde0;
}
.side-nav nav a {
  min-height: 38px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
  padding: 0 14px;
  color: #7890a1;
  text-decoration: none;
  font-size: 13px;
  line-height: 1.1;
}
.side-nav nav a.active {
  color: var(--purple);
  background: var(--sidebar-active);
  font-weight: 800;
}
.side-nav nav a span {
  color: currentColor;
  text-align: center;
}
.side-nav nav a b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.side-nav nav a small {
  color: currentColor;
  font-size: 12px;
  opacity: .78;
  white-space: nowrap;
}
.help-link {
  margin: auto 14px 22px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #7890a1;
  text-align: left;
}

.app-main {
  width: min(1180px, calc(100vw - 220px));
  margin-left: calc(226px + max(26px, (100vw - 226px - 1180px) / 2));
  padding: 52px 0 64px;
}
.page-actions {
  position: fixed;
  top: 10px;
  right: 22px;
  display: flex;
  gap: 10px;
  z-index: 3;
}
.page-actions button {
  width: 34px;
  height: 34px;
  border: 1px solid #bfc6ca;
  border-radius: 999px;
  background: white;
  color: #687176;
}

.summary-row {
  display: grid;
  grid-template-columns: 1.1fr .9fr .9fr;
  gap: 38px;
  align-items: start;
  margin: 42px 0 30px;
}
.portfolio-total p,
.what-if-card p,
.section-title h2,
.panel-title {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
}
.portfolio-total h1 {
  margin: 8px 0 10px;
  font-size: 48px;
  line-height: 1;
  letter-spacing: 0;
}
.gain-lines {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 8px 0;
  color: var(--green);
}
.gain-lines strong {
  font-size: 17px;
}
.gain-lines span,
.portfolio-total small,
.what-if-card small {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}
.what-if-card {
  min-width: 0;
}
.pill,
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 4px 13px;
  border: 0;
  border-radius: 999px;
  background: var(--chip);
  color: #1e2528;
  font-weight: 800;
  font-size: 12px;
  line-height: 1;
}
.pill.active,
.chip.active {
  background: var(--chip);
}
.what-if-card p {
  margin-top: 15px;
  color: #4d5357;
}
.what-if-card h2 {
  margin: 14px 0 8px;
  font-size: 34px;
  line-height: 1;
  font-weight: 500;
}
.what-if-card strong {
  display: block;
  color: var(--green);
  font-size: 13px;
}

.chart-controls {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}
.control-row,
.tabs,
.holding-controls,
.table-toolbar,
.section-title {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.control-row span {
  color: var(--muted);
  font-size: 12px;
}
.text-tab {
  border: 0;
  background: transparent;
  color: #575f64;
  font-size: 13px;
  font-weight: 500;
}
.text-tab.active {
  min-height: 25px;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--chip);
  color: #1e2528;
  font-weight: 800;
}

.performance-panel {
  margin-top: 12px;
}
.performance-panel svg {
  display: block;
  width: 100%;
  height: 430px;
}
.chart-grid line,
.bar-grid line {
  stroke: #e7eaec;
  stroke-width: 1;
}
.chart-axis {
  stroke: #333;
  stroke-width: 1.2;
}
.chart-labels text,
.bar-labels text,
.donut-label,
.chart-grid text,
.bar-grid text {
  fill: #858a8e;
  font-size: 13px;
}
.portfolio-line {
  fill: none;
  stroke: #111;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.benchmark-line {
  fill: none;
  stroke: #b8bdc0;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.cash-area {
  fill: #e1e1e1;
  opacity: .85;
}
.cash-line {
  stroke: #c9c9c9;
  stroke-width: 2;
}
.chart-hit {
  cursor: pointer;
}
.chart-hover-line {
  stroke: transparent;
  stroke-width: 1;
}
.chart-hover-line.active {
  stroke: #d6dadd;
  stroke-dasharray: 4 5;
}
.chart-point {
  fill: #fff;
  stroke: #111;
  stroke-width: 3;
  transition: r .15s ease, stroke .15s ease, fill .15s ease;
}
.chart-hit:hover .chart-point,
.chart-point.active {
  r: 8;
  fill: #111;
}
.snapshot-panel {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 18px;
  padding: 18px 0 4px;
  border-top: 1px solid var(--line);
}
.snapshot-panel > div:first-child {
  display: grid;
  gap: 4px;
  align-content: start;
}
.snapshot-kicker,
.snapshot-panel small,
.snapshot-metrics span,
.snapshot-accounts span {
  color: var(--muted);
  font-size: 12px;
}
.snapshot-panel strong {
  font-size: 20px;
}
.snapshot-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.snapshot-metrics article {
  min-width: 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: #f6f8f8;
}
.snapshot-metrics b {
  display: block;
  margin-top: 5px;
  font-size: 16px;
  white-space: nowrap;
}
.snapshot-accounts {
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.snapshot-accounts li {
  min-width: 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.snapshot-accounts b {
  display: block;
  margin-top: 3px;
  font-size: 13px;
}
.benchmarks {
  margin-top: 34px;
}
.section-title {
  justify-content: space-between;
  margin-bottom: 20px;
}
.section-title p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.benchmark-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.benchmark-card {
  min-height: 122px;
  padding: 16px 18px;
  border-radius: 12px;
  background: var(--soft-green);
}
.benchmark-card b {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}
.benchmark-card strong {
  display: block;
  margin-top: 12px;
  font-size: 26px;
  font-weight: 500;
}
.benchmark-card span {
  display: block;
  margin-top: 7px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}
.benchmark-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.allocation-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 42px;
  margin-top: 56px;
}
.allocation-panel {
  min-width: 0;
}
.tabs {
  min-height: 32px;
  margin-bottom: 14px;
  justify-content: center;
}
.donut-stage {
  min-height: 420px;
}
.donut-stage svg {
  display: block;
  width: 100%;
  height: 420px;
}
.donut-ring {
  fill: none;
  stroke-width: 50;
}
.donut-leader {
  fill: none;
  stroke-width: 1.4;
}
.donut-text {
  fill: #171717;
  font-size: 15px;
  font-weight: 800;
}
.mini-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 22px 34px;
  text-align: left;
}
.mini-metrics article {
  min-width: 0;
}
.mini-metrics span {
  display: block;
  color: #585f64;
  font-size: 14px;
  line-height: 1.35;
}
.mini-metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 25px;
  font-weight: 500;
  line-height: 1.05;
  white-space: nowrap;
}

.accounts-section,
.holdings-section,
.options-section {
  margin-top: 52px;
}
.account-tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.account-tab {
  min-height: 54px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--soft-green);
  color: var(--ink);
  text-align: left;
}
.account-tab.active {
  border-color: #abb7bc;
  box-shadow: inset 0 0 0 1px #abb7bc;
}
.account-tab b,
.account-tab span {
  display: block;
}
.account-tab b {
  font-size: 13px;
}
.account-tab span {
  margin-top: 6px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}
.search-box {
  width: min(320px, 100%);
  height: 38px;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}
.search-box input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}
.holding-controls {
  display: grid;
  gap: 12px;
  margin: 18px 0 12px;
}
.holding-controls > div,
.table-toolbar > div {
  display: flex;
  align-items: center;
  gap: 12px 18px;
  flex-wrap: wrap;
}
.holding-chart-wrap {
  position: relative;
  min-height: 300px;
  margin: 8px 0 22px;
}
.holding-chart-wrap svg {
  display: block;
  width: 100%;
  height: 300px;
}
.gain-bar {
  fill: #38c991;
}
.loss-bar {
  fill: var(--red);
}
.table-toolbar {
  justify-content: space-between;
  margin: 12px 0;
}
.table-toolbar button:not(.chip):not(.text-tab) {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: white;
}
.table-toolbar .rebalance {
  padding: 0 14px;
  font-weight: 700;
}
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
}
.options-table-wrap {
  box-shadow: none;
}
table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
  background: white;
}
th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}
th {
  color: #303437;
  font-size: 13px;
  font-weight: 500;
}
td {
  font-size: 14px;
}
td:first-child strong {
  display: block;
  font-size: 16px;
}
td:first-child small {
  display: block;
  max-width: 160px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
}
.positive {
  color: var(--green);
  font-weight: 700;
}
.negative {
  color: var(--red);
  font-weight: 700;
}

body.is-private .private-value {
  color: transparent !important;
  border-radius: 4px;
  background: #dce3e6;
  user-select: none;
}

body.data-missing .portfolio-total {
  outline: 2px solid var(--red);
  outline-offset: 6px;
}

@media (max-width: 1080px) {
  .side-nav {
    position: static;
    width: 100%;
    min-height: auto;
  }
  .side-nav nav {
    display: flex;
    overflow-x: auto;
  }
  .help-link {
    display: none;
  }
  .app-main {
    width: min(100% - 26px, 1180px);
    margin: 0 auto;
    padding-top: 18px;
  }
  .summary-row,
  .allocation-section,
  .benchmark-grid {
    grid-template-columns: 1fr;
  }
  .snapshot-panel,
  .snapshot-metrics,
  .snapshot-accounts {
    grid-template-columns: 1fr;
  }
  .snapshot-accounts {
    grid-column: auto;
  }
}

@media (max-width: 720px) {
  .logo {
    height: 56px;
  }
  .summary-row {
    gap: 22px;
  }
  .portfolio-total h1 {
    font-size: 38px;
  }
  .mini-metrics {
    grid-template-columns: 1fr 1fr;
  }
  .page-actions {
    display: none;
  }
  .search-box {
    width: 100%;
    margin-left: 0;
  }
}
