:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --ink: #182024;
  --muted: #647176;
  --line: #dce3e6;
  --green: #138a60;
  --red: #bf3d31;
  --teal: #0d7f8c;
  --gold: #b47b18;
  --blue: #3267b1;
  --shadow: 0 14px 32px rgba(23, 34, 40, 0.07);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  height: 100vh;
  padding: 1.4rem;
  border-right: 1px solid var(--line);
  background: #fff;
}

.brand,
.topbar,
.section-heading,
.donut-row,
.topbar-actions,
.form-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 1rem;
}

.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 3.65rem;
  height: 3.65rem;
  border-radius: var(--radius);
  background: var(--ink);
  box-shadow:
    0 14px 28px rgba(31, 37, 40, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.brand-mark svg {
  width: 2.65rem;
  height: 2.65rem;
  overflow: visible;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.24));
}

.brand-mark path,
.brand-mark circle {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark-ribbon {
  stroke: #fff;
  stroke-width: 8;
}

.brand-mark-line {
  stroke: var(--gold);
  stroke-width: 6;
}

.brand-mark circle {
  fill: var(--gold);
  stroke: #fff;
  stroke-width: 3;
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.14rem;
  font-weight: 850;
}

h2 {
  margin-bottom: 0;
  font-size: 1.7rem;
}

h3 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

.nav-stack {
  display: grid;
  gap: 0.45rem;
}

.nav-item,
.primary-button,
.ghost-button,
.icon-button {
  min-height: 2.5rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
}

.nav-item {
  display: grid;
  grid-template-columns: 1.25rem 1fr;
  gap: 0.7rem;
  align-items: center;
  padding: 0 0.75rem;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: #eaf4f3;
  color: var(--ink);
}

.sidebar-panel,
.metric,
.allocation-panel,
.history-panel,
.table-panel,
.editor-panel,
.dialog-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar-panel {
  margin-top: auto;
  padding: 1rem;
}

.sidebar-panel label,
.asset-form label,
.dialog-card label {
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.sidebar-panel p {
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.55;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 2.55rem;
  padding: 0 0.75rem;
}

textarea {
  resize: vertical;
  padding: 0.75rem;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13, 127, 140, 0.14);
}

.workspace {
  display: grid;
  gap: 1.1rem;
  align-content: start;
  min-width: 0;
  padding: 1.4rem;
}

.topbar {
  justify-content: space-between;
  gap: 1rem;
}

.topbar-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.7rem;
}

.topbar-actions {
  gap: 0.6rem;
}

.storage-status {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.storage-status.online {
  color: var(--teal);
}

.primary-button {
  padding: 0 1rem;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.ghost-button {
  padding: 0 0.85rem;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 2.55rem;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 1.05rem;
  text-decoration: none;
}

.file-button input {
  display: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.metric {
  display: grid;
  gap: 0.55rem;
  padding: 1rem;
}

.metric.primary {
  background: #20302d;
  color: #fff;
}

.metric span {
  color: inherit;
  opacity: 0.74;
  font-size: 0.82rem;
  font-weight: 700;
}

.metric strong {
  font-size: 1.5rem;
  line-height: 1.05;
  word-break: break-word;
}

.metric small {
  color: inherit;
  opacity: 0.68;
}

.visual-band {
  display: grid;
  grid-template-columns: minmax(18rem, 0.82fr) minmax(0, 1.18fr);
  gap: 1rem;
  min-width: 0;
}

.allocation-panel,
.history-panel,
.table-panel,
.editor-panel {
  min-width: 0;
  padding: 1rem;
}

.section-heading {
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-heading > span {
  color: var(--muted);
  font-size: 0.82rem;
}

.donut-row {
  gap: 1.2rem;
}

.allocation-content {
  display: block;
}

.donut {
  flex: 0 0 auto;
  width: 12rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--teal) 0 40%, var(--gold) 40% 70%, var(--blue) 70% 100%);
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 2.35rem;
  border-radius: 50%;
  background: var(--panel);
}

.legend,
.rate-list {
  display: grid;
  gap: 0.65rem;
}

.history-panel {
  display: grid;
  grid-template-rows: auto minmax(12rem, 1fr);
  gap: 0.8rem;
  min-height: 15.4rem;
}

.history-head,
.history-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.history-head span,
.history-axis {
  fill: var(--muted);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.history-chart {
  position: relative;
  display: grid;
  min-width: 0;
}

.history-chart svg {
  width: 100%;
  height: 100%;
  min-height: 12rem;
  overflow: visible;
  color: var(--teal);
}

.history-hover-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  cursor: crosshair;
}

.history-summary {
  position: absolute;
  top: 0.15rem;
  right: 0.1rem;
  z-index: 2;
  padding: 0.35rem 0.45rem;
  border-radius: var(--radius);
  background: rgba(248, 250, 251, 0.9);
}

.history-summary strong {
  font-size: 1.05rem;
}

.history-summary span {
  font-size: 0.78rem;
  font-weight: 800;
}

.history-tooltip {
  position: absolute;
  z-index: 3;
  display: grid;
  gap: 0.15rem;
  min-width: 8.6rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(31, 37, 40, 0.94);
  color: #fff;
  box-shadow: 0 12px 24px rgba(31, 37, 40, 0.18);
  pointer-events: none;
  transform: translate(0.7rem, -110%);
}

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

.history-tooltip.is-left {
  transform: translate(calc(-100% - 0.7rem), -110%);
}

.history-tooltip strong {
  font-size: 0.76rem;
}

.history-tooltip span {
  color: rgba(255, 255, 255, 0.76);
  font-size: 0.72rem;
  font-weight: 700;
}

.history-grid {
  stroke: rgba(101, 112, 116, 0.18);
  stroke-width: 1;
}

.history-date-tick {
  stroke: rgba(101, 112, 116, 0.24);
  stroke-width: 1.5;
}

.history-date-label {
  font-size: 0.78rem;
}

.history-line {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.history-area {
  fill: url("#historyFill");
}

.history-point {
  cursor: crosshair;
  outline: none;
}

.history-hit {
  fill: transparent;
  stroke: transparent;
}

.history-dot {
  fill: var(--panel);
  stroke: currentColor;
  stroke-width: 3;
  transition:
    r 0.16s ease,
    stroke-width 0.16s ease;
}

.history-point:hover .history-dot,
.history-point.active .history-dot,
.history-point:focus .history-dot {
  r: 5;
  stroke-width: 4;
}

.history-up {
  color: var(--green);
}

.history-down {
  color: var(--red);
}

.legend-item,
.rate-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.legend-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 999px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22rem;
  gap: 1rem;
  align-items: start;
  min-width: 0;
}

.search-wrap {
  display: grid;
  grid-template-columns: auto minmax(10rem, 17rem);
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding-left: 0.75rem;
}

.search-wrap input {
  border: 0;
  box-shadow: none;
}

.asset-table {
  overflow-x: auto;
  scrollbar-width: thin;
}

.asset-row {
  display: grid;
  grid-template-columns:
    minmax(8.5rem, 1.35fr)
    minmax(4.2rem, 0.58fr)
    minmax(4.2rem, 0.54fr)
    minmax(5.2rem, 0.68fr)
    minmax(5.6rem, 0.72fr)
    minmax(5.6rem, 0.72fr)
    minmax(3.8rem, 0.42fr);
  gap: 0.65rem;
  align-items: center;
  min-width: 0;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
}

.table-head {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.asset-main {
  display: grid;
  gap: 0.2rem;
}

.asset-main strong {
  font-size: 0.96rem;
}

.asset-main small,
.muted {
  color: var(--muted);
}

.price-cell {
  display: inline-grid;
  gap: 0.12rem;
  justify-items: start;
}

.price-cell small {
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 800;
}

.type-pill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  min-height: 1.7rem;
  padding: 0 0.55rem;
  border-radius: 999px;
  background: #eef5f3;
  color: var(--teal);
  font-size: 0.8rem;
  font-weight: 800;
}

.pnl-up {
  color: var(--green);
}

.pnl-down {
  color: var(--red);
}

.row-actions {
  display: flex;
  gap: 0.35rem;
}

.row-actions .icon-button {
  width: 2rem;
  min-height: 2rem;
}

.asset-form {
  display: grid;
  gap: 0.85rem;
}

.form-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.form-actions {
  justify-content: flex-end;
  gap: 0.6rem;
}

dialog {
  width: min(31rem, calc(100vw - 2rem));
  padding: 0;
  border: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(31, 37, 40, 0.36);
  backdrop-filter: blur(4px);
}

.dialog-card {
  display: grid;
  gap: 0.9rem;
  padding: 1rem;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 13rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty-state.compact {
  min-height: 10rem;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding-bottom: 0.9rem;
  }

  .nav-stack {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .nav-item {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .sidebar-panel {
    display: none;
  }

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

  .visual-band,
  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  body {
    background: var(--bg);
  }

  .app-shell {
    min-height: auto;
  }

  .workspace,
  .sidebar {
    padding: 0.9rem;
  }

  .sidebar {
    gap: 0.9rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: #fff;
  }

  .brand {
    gap: 0.85rem;
  }

  .brand-mark {
    width: 3.2rem;
    height: 3.2rem;
  }

  .brand-mark svg {
    width: 2.3rem;
    height: 2.3rem;
  }

  h1 {
    font-size: 1.1rem;
  }

  .topbar,
  .section-heading,
  .donut-row {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace {
    gap: 0.85rem;
  }

  .topbar {
    gap: 0.85rem;
  }

  h2 {
    font-size: 1.65rem;
    line-height: 1.12;
  }

  .topbar-title {
    align-items: flex-start;
  }

  .storage-status {
    max-width: 100%;
    font-size: 0.72rem;
    white-space: normal;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions .primary-button {
    width: 100%;
    min-height: 2.85rem;
    font-size: 1rem;
    font-weight: 800;
  }

  .form-pair {
    grid-template-columns: 1fr;
  }

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

  .nav-stack {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .nav-item {
    min-height: 3.05rem;
    gap: 0.25rem;
    padding: 0.35rem 0.2rem;
    font-size: 0.84rem;
    font-weight: 800;
  }

  .nav-item span:first-child {
    font-size: 1rem;
    line-height: 1;
  }

  .metric,
  .allocation-panel,
  .table-panel,
  .editor-panel {
    padding: 0.9rem;
  }

  .summary-grid {
    gap: 0.75rem;
  }

  .metric {
    gap: 0.45rem;
    min-height: 6.9rem;
  }

  .metric strong {
    font-size: clamp(1.2rem, 6vw, 1.65rem);
  }

  .donut {
    width: min(10.5rem, 100%);
    align-self: center;
  }

  .donut::after {
    inset: 2.05rem;
  }

  .donut-row {
    gap: 0.85rem;
  }

  .history-panel {
    min-height: 14rem;
    padding: 0.75rem;
  }

  .history-head,
  .history-summary {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.25rem;
  }

  .history-summary {
    position: static;
    order: -1;
    padding: 0;
    background: transparent;
  }

  .history-chart svg {
    min-height: 10.5rem;
  }

  .history-date-label {
    font-size: 0.58rem;
    font-weight: 800;
  }

  .history-date-tick {
    opacity: 0.62;
  }

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

  .legend-item {
    min-height: 2.65rem;
    padding: 0.55rem 0.65rem;
  }

  .search-wrap {
    grid-template-columns: auto 1fr;
    width: 100%;
  }

  .content-grid {
    gap: 0.85rem;
  }

  .asset-table {
    overflow: visible;
  }

  #assetList {
    display: grid;
    gap: 0.75rem;
  }

  .asset-row {
    position: static;
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
    align-items: start;
    padding: 0.85rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
  }

  .table-head {
    display: none;
  }

  .asset-row > span {
    display: grid;
    gap: 0.18rem;
    min-width: 0;
  }

  .asset-row > span::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
  }

  .asset-row > span:first-child {
    display: block;
    grid-column: 1;
    padding-right: 0;
  }

  .asset-row > span:first-child::before {
    display: none;
  }

  .asset-row > span:nth-child(2) {
    grid-column: 1;
  }

  .asset-row > span:nth-child(3) {
    grid-column: 2;
  }

  .asset-row > span:nth-child(4) {
    grid-column: 1;
  }

  .asset-row > span:nth-child(5) {
    grid-column: 2;
  }

  .asset-row > span:nth-child(2),
  .asset-row > span:nth-child(3),
  .asset-row > span:nth-child(4),
  .asset-row > span:nth-child(5),
  .asset-row > span:nth-child(6) {
    min-height: 4rem;
    justify-content: center;
    padding: 0.58rem 0.62rem;
    border-radius: var(--radius);
    background: var(--panel-soft);
  }

  .asset-row > span:nth-child(3),
  .asset-row > span:nth-child(5) {
    justify-items: end;
    text-align: right;
  }

  .asset-row > span:nth-child(4) {
    justify-items: start;
    text-align: left;
  }

  .asset-row > span:nth-child(6) {
    grid-column: 1 / 3;
    min-height: 3.5rem;
    justify-items: start;
    text-align: left;
  }

  .asset-row > span:nth-child(6) small {
    display: block;
    margin-top: 0.1rem;
  }

  .asset-row > span:nth-child(7) {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  .row-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.38rem;
  }

  .row-actions::before {
    display: none;
  }

  .row-actions .icon-button {
    width: 2.25rem;
    min-height: 2.25rem;
  }

  .asset-main strong {
    font-size: 1.02rem;
    line-height: 1.2;
  }

  .asset-main small {
    line-height: 1.35;
    overflow-wrap: anywhere;
  }

  .price-cell {
    justify-items: start;
  }

  .editor-panel {
    order: 2;
  }

  .table-panel {
    order: 1;
  }

  input,
  select {
    height: 2.75rem;
  }
}
