:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #5c6670;
  --line: #d9e0e6;
  --panel: #ffffff;
  --page: #f5f7f9;
  --teal: #147c7c;
  --blue: #2f6fbb;
  --green: #3f7d3d;
  --gold: #b7791f;
  --red: #b3404a;
  --shadow: 0 8px 22px rgba(23, 32, 38, 0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
}

.shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 8px 0 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }
h1 { font-size: 2rem; font-weight: 750; }
h2 { font-size: 1rem; font-weight: 720; }
.panel p { color: var(--muted); font-size: 0.82rem; margin-top: 3px; }

.status {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.status span,
.toolbar,
.panel,
.metric {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.status span {
  padding: 8px 10px;
  border-radius: 6px;
  box-shadow: none;
}

.toolbar {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  min-height: 64px;
  padding: 14px;
  border-radius: 8px;
}

.control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control.grow {
  flex: 1;
  align-items: flex-start;
  flex-direction: column;
  gap: 8px;
}

label,
.control span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

select {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 28px 0 10px;
  font: inherit;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle-row button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  font-weight: 650;
  cursor: pointer;
}

.quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.quick-actions button {
  min-height: 30px;
  border: 1px solid #b9c8d3;
  border-radius: 6px;
  background: #edf5f5;
  color: var(--teal);
  padding: 0 10px;
  font-weight: 750;
  cursor: pointer;
}

.toggle-row button[aria-pressed="false"] {
  color: var(--muted);
  background: #f8fafb;
}

.toggle-row button[aria-pressed="true"] {
  border-color: rgba(20, 124, 124, 0.55);
  background: #edf7f6;
  color: #0e595b;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.metric {
  min-height: 94px;
  border-radius: 8px;
  padding: 14px;
}

.metric span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 1.55rem;
}

.metric small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.live-status {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.live-status > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.live-status span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  text-transform: uppercase;
}

.live-status strong {
  display: block;
  margin-top: 6px;
  font-size: 0.95rem;
}

.compare-panel {
  margin: 14px 0;
}

.compare-controls {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto minmax(180px, 1fr);
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.compare-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 12px;
}

.compare-card span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  text-transform: uppercase;
}

.compare-card strong {
  display: block;
  margin-top: 7px;
  font-size: 1.1rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.dashboard-grid .wide { grid-column: span 2; }
.dashboard-grid.bottom { margin-top: 14px; grid-template-columns: 0.9fr 1.1fr; }
.dashboard-grid.bottom .wide { grid-column: auto; }

.panel {
  border-radius: 8px;
  padding: 16px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  margin-bottom: 8px;
}

.panel-head span {
  color: var(--muted);
  white-space: nowrap;
  font-size: 0.82rem;
}

.chart {
  width: 100%;
  height: 390px;
  border: 1px solid #e6ecef;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfd 100%);
  overflow: hidden;
}

.chart.compact { height: 340px; }
.chart.mini { height: 250px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  max-height: 86px;
  overflow: auto;
  padding: 10px 2px 0;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}

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

.axis { stroke: #aebcc5; stroke-width: 1.2; }
.grid { stroke: #e8edf1; stroke-width: 1; }
.tick { fill: var(--muted); font-size: 11px; }
.label { fill: var(--ink); font-size: 12px; font-weight: 700; }
.subtle-label { fill: var(--muted); font-size: 10px; font-weight: 650; }
.tooltip-box { fill: #172026; opacity: 0.92; rx: 6; }
.tooltip-text { fill: #fff; font-size: 11px; font-weight: 650; }
.guide { stroke: #56636f; stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.8; }

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
  font-size: 0.9rem;
}

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

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafb;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
}

.positive { color: var(--green); font-weight: 750; }
.negative { color: var(--red); font-weight: 750; }
.positive-bg { background: #edf7ef; color: var(--green); }
.negative-bg { background: #fbefef; color: var(--red); }

.correlation {
  display: grid;
  gap: 4px;
  overflow: auto;
  padding-bottom: 2px;
}

.corr-row {
  display: grid;
  grid-template-columns: 86px repeat(var(--corr-count), 31px);
  gap: 3px;
  align-items: center;
}

.corr-cell {
  width: 31px;
  height: 27px;
  border-radius: 4px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 750;
}

.corr-label {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 960px) {
  .topbar,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }
  .status { justify-content: flex-start; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .live-status { grid-template-columns: 1fr; }
  .compare-controls { grid-template-columns: 1fr; }
  .compare-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid,
  .dashboard-grid.bottom { grid-template-columns: 1fr; }
  .dashboard-grid .wide,
  .dashboard-grid.bottom .wide { grid-column: auto; }
}

@media (max-width: 560px) {
  .shell { width: min(100% - 20px, 1480px); padding-top: 14px; }
  h1 { font-size: 1.55rem; }
  .metric-grid { grid-template-columns: 1fr; }
  .compare-grid { grid-template-columns: 1fr; }
  .chart { height: 330px; }
  .chart.compact { height: 300px; }
  .legend { max-height: 116px; }
}
