:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d7dde5;
  --accent: #126b73;
  --accent-dark: #0e5258;
  --risk: #b42318;
  --good: #047857;
  --ink-soft: #344054;
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

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

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 28px 18px;
  background: #18212b;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 700;
}

h2 {
  font-size: 16px;
  font-weight: 700;
}

.app-header p {
  margin-top: 8px;
  color: #b7c2ce;
  font-size: 13px;
}

.period-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.period-tabs button,
.button-row button {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}

.period-tabs button {
  color: #dce7ee;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
}

.period-tabs button.active {
  color: #0f1720;
  background: #ffffff;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.4fr);
  gap: 16px;
  padding: 16px;
}

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

.control-panel,
.metric-panel,
.chart-wide,
.chart-panel,
.table-panel {
  padding: 16px;
}

.chart-wide {
  grid-column: 1 / -1;
}

.chart-panel,
.table-panel {
  min-height: 320px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title span,
.hint,
.fit-status {
  color: var(--muted);
  font-size: 12px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 650;
}

input[type="number"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  font-size: 14px;
}

.button-row {
  display: flex;
  gap: 10px;
  margin: 14px 0;
}

.button-row button {
  background: var(--accent);
  color: #fff;
}

.button-row button:hover {
  background: var(--accent-dark);
}

.button-row button.secondary {
  background: #eef2f6;
  color: var(--text);
  border-color: var(--line);
}

.weights {
  display: grid;
  gap: 10px;
}

.weight-row {
  display: grid;
  grid-template-columns: 86px 1fr 54px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.weight-row input {
  width: 100%;
  accent-color: var(--accent);
}

.weight-value {
  text-align: right;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.hint {
  margin-top: 12px;
  line-height: 1.6;
}

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

.metric-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 82px;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  margin-top: 8px;
  font-size: 22px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.metric-value.negative,
.risk-value {
  color: var(--risk);
}

.metric-value.positive {
  color: var(--good);
}

.fit-status {
  margin-top: 12px;
  line-height: 1.6;
}

.chart {
  width: 100%;
  height: 260px;
}

.chart svg {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-hit-area {
  cursor: crosshair;
  pointer-events: all;
}

.chart-hover-layer {
  pointer-events: none;
}

.axis-label {
  fill: var(--muted);
  font-size: 11px;
}

.empty-chart {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
  max-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
  font-size: 13px;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: var(--ink-soft);
  font-weight: 700;
  z-index: 1;
}

td.numeric,
th.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 980px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 620px) {
  .app-header {
    padding: 18px 14px;
  }

  .app-shell {
    padding: 10px;
  }

  .controls-grid,
  .metrics {
    grid-template-columns: 1fr;
  }

  .weight-row {
    grid-template-columns: 74px 1fr 48px;
  }

  .chart {
    height: 220px;
  }
}
