:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #102033;
  --muted: #667085;
  --line: #d9e2ec;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --gain: #047857;
  --loss: #b42318;
  --shadow: 0 18px 50px rgba(16, 32, 51, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

a { color: inherit; text-decoration: none; }
button, .button {
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  font-weight: 700;
  padding: 12px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button:hover, .button:hover { background: var(--brand-dark); }
button.small {
  padding: 8px 10px;
  font-size: 13px;
}
button.danger {
  background: #b42318;
}
button.danger:hover {
  background: #8f1d14;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 246px;
  background: #0f1f2e;
  color: white;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand span { display: block; color: #a9b8c7; font-size: 13px; margin-top: 3px; }
.mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: linear-gradient(135deg, #14b8a6, #f59e0b);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 900;
}
.mark.large { width: 54px; height: 54px; font-size: 24px; margin: 0 auto 12px; }
nav { display: grid; gap: 8px; }
nav a, .ghost {
  border-radius: 8px;
  padding: 12px 14px;
  color: #d9e5f2;
  background: transparent;
  text-align: left;
}
nav a.active, nav a:hover, .ghost:hover { background: rgba(255,255,255,0.1); }
.ghost { margin-top: auto; width: 100%; border: 1px solid rgba(255,255,255,0.16); }

.shell {
  margin-left: 246px;
  padding: 30px;
  max-width: 1320px;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}
.eyebrow {
  color: var(--brand);
  font-weight: 800;
  margin: 0 0 6px;
}
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 30px; }
h2 { font-size: 18px; }

.metrics, .grid {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}
.metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.metric {
  padding: 20px;
  min-height: 132px;
}
.metric span, .metric small, .mini { color: var(--muted); }
.nowrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.nowrap span {
  white-space: nowrap;
}
.metric strong {
  display: block;
  font-size: 28px;
  margin: 8px 0;
}
.metric.primary { border-color: rgba(15, 118, 110, 0.35); }
.panel { padding: 20px; margin-bottom: 16px; overflow-x: auto; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-head a { color: var(--brand); font-weight: 800; }

.rows { display: grid; gap: 10px; margin-top: 14px; }
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row em {
  grid-column: 1 / -1;
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.stack { display: grid; gap: 14px; margin-top: 14px; }
label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
input, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: white;
  font-size: 15px;
}
.wide { grid-column: span 2; }
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  min-width: 720px;
}
.inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 230px;
}
.inline-form input, .inline-form select {
  margin: 0;
  padding: 8px;
  min-width: 90px;
}
.inline-form.compact-action {
  min-width: 0;
}
th, td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th { color: var(--muted); font-size: 13px; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.muted { color: var(--muted); }
.subtle {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 3px;
}
.price-source {
  display: inline-block;
  margin-left: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  vertical-align: baseline;
}
td .price-source {
  color: #8a94a6;
  font-size: 11px;
  white-space: nowrap;
}
.level-low { color: var(--gain); }
.level-mid { color: #b7791f; }
.level-high { color: var(--loss); }
.signal-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.signal-grid div,
.month-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdff;
}
.signal-grid span,
.month-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.signal-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}
.month-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.month-card strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}
.month-card p {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
}
.month-card p span {
  white-space: nowrap;
}
.chart-panel {
  min-width: 0;
}
.line-chart {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 12px;
  background: linear-gradient(#fbfdff, #ffffff);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.line-chart polyline {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.asset-line { stroke: var(--brand); }
.expense-line { stroke: #b7791f; }
.zero-line {
  stroke: var(--line);
  stroke-width: 2;
  stroke-dasharray: 8 8;
}
.chart-labels {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-top: 10px;
}
.chart-labels span {
  min-width: 82px;
  color: var(--muted);
  font-size: 12px;
}
.chart-labels strong {
  display: block;
  margin-top: 3px;
  color: var(--ink);
  font-size: 13px;
}
.chart-labels strong.gain { color: var(--gain); }
.chart-labels strong.loss { color: var(--loss); }
.error {
  background: #fff1f0;
  color: var(--loss);
  border: 1px solid #ffccc7;
  border-radius: 8px;
  padding: 10px;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(circle at top, #dff7f2, var(--bg) 48%);
}
.login-card {
  width: min(420px, 100%);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
  text-align: center;
}
.login-card p { color: var(--muted); }

@media (max-width: 920px) {
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    width: 100%;
    padding: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
  }
  .brand span, .sidebar form { display: none; }
  nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
  }
  nav a { white-space: nowrap; padding: 10px 12px; }
  .shell { margin-left: 0; padding: 18px; }
  .page-head { align-items: flex-start; }
  h1 { font-size: 24px; }
  .metrics, .grid.two, .grid.four, .form-grid, .signal-grid, .month-cards { grid-template-columns: 1fr; }
  .wide { grid-column: span 1; }
  .metric { min-height: 112px; }
}
