:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #18202f;
  --muted: #657287;
  --line: #dde4ef;
  --line-strong: #c7d2e1;
  --accent: #2563eb;
  --good: #15803d;
  --bad: #b42318;
  --warn: #b7791f;
  --shadow: 0 18px 50px rgba(38, 50, 77, 0.08);
  --radius: 8px;
  --spx: #2563eb;
  --nasdaq: #7c3aed;
  --ust10y: #0891b2;
  --gold: #d49a0b;
  --oil: #dc2626;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) auto auto;
  gap: 18px;
  align-items: center;
  min-height: 76px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #101828;
}

.brand-mark span {
  width: 24px;
  height: 24px;
  border: 2px solid #e5edff;
  border-top-color: #38bdf8;
  border-right-color: #f6b23f;
  transform: rotate(45deg);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand p,
.panel-title p,
.fineprint,
.alert-box p,
.playbook p {
  color: var(--muted);
}

.brand p {
  margin-top: 5px;
  font-size: 13px;
}

.nav-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3fa;
}

.nav-tab,
.filter {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  padding: 0 13px;
  color: #475569;
  background: transparent;
  cursor: pointer;
}

.nav-tab.active,
.filter.active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.control-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 12px 0 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.data-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 0 0 14px;
  padding: 13px 14px;
  border: 1px solid #f0d38a;
  border-radius: var(--radius);
  background: #fffaf0;
}

.data-status strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.data-status p {
  color: #6b5b35;
  font-size: 12px;
  line-height: 1.5;
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 6px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.ok {
  background: #e9f7ef;
  color: var(--good);
}

.status-pill.warn {
  background: #fff7ed;
  color: var(--warn);
}

.status-pill.bad {
  background: #fef2f2;
  color: var(--bad);
}

label,
.inline-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #475569;
  font-size: 13px;
  white-space: nowrap;
}

select {
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 0 30px 0 10px;
  color: var(--ink);
  background: #fff;
}

.asset-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.asset-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  background: #fff;
  color: #334155;
  cursor: pointer;
}

.asset-toggle.off {
  opacity: 0.45;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.upload-control {
  height: 34px;
  border: 1px dashed var(--line-strong);
  border-radius: 7px;
  padding: 0 10px;
  cursor: pointer;
}

.upload-control input {
  display: none;
}

.grid-main,
.grid-lower {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.grid-main {
  grid-template-columns: minmax(0, 1.85fr) minmax(330px, 0.7fr);
}

.grid-lower {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  margin-top: 14px;
}

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

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 18px 18px 12px;
}

.panel-title.compact {
  padding-bottom: 8px;
}

.panel-title h2 {
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.panel-title p {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.5;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
  max-width: 440px;
  font-size: 12px;
  color: #475569;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-wrap {
  position: relative;
  height: 472px;
  padding: 0 14px 6px;
}

.chart-tooltip {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 5;
  display: none;
  min-width: 220px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.14);
  pointer-events: none;
}

.tooltip-title {
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 800;
}

.tooltip-row {
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  gap: 8px;
  align-items: center;
  min-height: 22px;
  color: #334155;
  font-size: 12px;
}

.tooltip-row b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

#trendChart,
#miniChart,
.rolling-chart {
  width: 100%;
  height: 100%;
  display: block;
}

.mini-range {
  height: 68px;
  margin: 0 18px 8px;
  border-top: 1px solid var(--line);
}

.heatmap {
  display: grid;
  grid-template-columns: 74px repeat(24, minmax(16px, 1fr));
  gap: 3px;
  padding: 6px 18px 14px;
}

.heatmap-cell,
.heatmap-label,
.heatmap-month {
  min-height: 20px;
  border-radius: 4px;
  font-size: 10px;
}

.heatmap-label {
  display: flex;
  align-items: center;
  color: #475569;
  font-size: 12px;
}

.heatmap-month {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
}

.heatmap-cell {
  border: 1px solid rgba(15, 23, 42, 0.04);
}

.small-multiples {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 0 18px 16px;
}

.spark-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #fbfdff;
}

.spark-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 12px;
}

.spark-head strong {
  color: var(--ink);
}

.spark-head span:last-child {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.spark-card svg {
  width: 100%;
  height: 54px;
  display: block;
}

.fineprint {
  padding: 0 18px 16px;
  font-size: 12px;
  line-height: 1.55;
}

.action-list {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
}

.action-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-soft);
}

.action-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.action-head strong {
  font-size: 14px;
}

.stance {
  min-width: 78px;
  border-radius: 6px;
  padding: 5px 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.stance.buy,
.stance.hold {
  background: #e9f7ef;
  color: var(--good);
}

.stance.trim {
  background: #fff7ed;
  color: #b45309;
}

.stance.avoid {
  background: #fef2f2;
  color: var(--bad);
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.metric {
  border-left: 3px solid var(--line-strong);
  padding-left: 8px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.metric b {
  display: block;
  margin-top: 2px;
  font-size: 13px;
}

.reason {
  margin-top: 10px;
  color: #475569;
  font-size: 12px;
  line-height: 1.45;
}

.alert-box {
  margin: 0 14px 14px;
  border: 1px solid #cfe1ff;
  border-radius: 8px;
  padding: 13px;
  background: #f3f8ff;
}

.alert-box strong {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}

.alert-box p {
  font-size: 13px;
  line-height: 1.55;
}

.correlation-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.95fr) minmax(250px, 1fr);
  gap: 14px;
  padding: 0 18px 18px;
}

.matrix-wrap,
.table-wrap {
  max-width: 100%;
  overflow: auto;
}

.matrix,
.signal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

.matrix th {
  color: var(--muted);
  font-weight: 600;
}

.matrix td:not(:first-child) {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.rolling-chart {
  height: 260px;
  margin-top: 12px;
}

.filter-buttons {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: #eef3fa;
}

.signal-table {
  min-width: 720px;
}

.signal-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.tag {
  display: inline-flex;
  min-width: 52px;
  justify-content: center;
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 12px;
  font-weight: 700;
}

.tag.crisis {
  color: var(--bad);
  background: #fef2f2;
}

.tag.opportunity {
  color: var(--good);
  background: #e9f7ef;
}

.tag.watch {
  color: var(--warn);
  background: #fff7ed;
}

.playbook {
  margin-top: 14px;
}

.playbook-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  border-top: 1px solid var(--line);
}

.playbook-grid > div {
  min-height: 170px;
  padding: 18px;
  border-right: 1px solid var(--line);
}

.playbook-grid > div:last-child {
  border-right: 0;
}

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

.playbook strong {
  display: block;
  min-height: 44px;
  font-size: 18px;
  line-height: 1.25;
}

.playbook p {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.6;
}

.axis,
.gridline {
  stroke: #d8e1ee;
  stroke-width: 1;
}

.gridline {
  stroke-dasharray: 4 5;
}

.axis-label,
.point-label {
  fill: #64748b;
  font-size: 11px;
}

.line-path {
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.zero-line {
  stroke: #94a3b8;
  stroke-dasharray: 5 5;
}

.hover-line {
  stroke: #334155;
  stroke-width: 1;
  stroke-dasharray: 4 4;
  opacity: 0;
}

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

  .meta {
    justify-content: flex-start;
  }

  .grid-main,
  .grid-lower,
  .correlation-layout,
  .playbook-grid,
  .small-multiples {
    grid-template-columns: 1fr;
  }

  .asset-toggles {
    margin-left: 0;
  }

  .playbook-grid > div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 18px, 1480px);
    padding-top: 10px;
  }

  .brand {
    align-items: flex-start;
  }

  h1 {
    font-size: 19px;
  }

  .nav-tabs,
  .control-strip {
    max-width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .control-strip > *,
  .nav-tabs > * {
    flex: 0 0 auto;
  }

  .asset-toggles {
    flex-wrap: nowrap;
  }

  .panel-title {
    flex-direction: column;
  }

  .chart-wrap {
    height: 360px;
  }

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

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

  .status-pills {
    justify-content: flex-start;
  }

  .heatmap {
    grid-template-columns: 64px repeat(12, minmax(18px, 1fr));
    overflow-x: auto;
  }
}
