:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #e3e8ef;
  --line-strong: #c9d3df;
  --text: #1d2b3a;
  --muted: #526171;
  --faint: #7c8a99;
  --green: #12a777;
  --red: #df4c42;
  --blue: #2563d8;
  --purple: #7357d7;
  --orange: #e47b2f;
  --cream: #8ca1b6;
  --side-bg: #f8fafc;
  --button-bg: #ffffff;
  --control-bg: #ffffff;
  --chip-bg: #ffffff;
  --metric-bg: #f8fafc;
  --tooltip-bg: rgba(255, 255, 255, 0.98);
  --tooltip-shadow: rgba(15, 23, 42, 0.14);
  --table-border: rgba(28, 39, 54, 0.08);
  --baseline-bg: #eef2f7;
  --danger-soft: rgba(255, 106, 80, 0.14);
  --grid-line: #e6ebf1;
  --axis-text: #8290a0;
  --point-stroke: #ffffff;
}
body[data-theme="dark"] {
  --bg: #14171b;
  --panel: #1c2026;
  --panel-2: #22272e;
  --line: #2d333b;
  --line-strong: #3f4650;
  --text: #eef1f4;
  --muted: #b8c0c8;
  --faint: #8e98a3;
  --green: #2fc38d;
  --red: #f06b63;
  --blue: #6aa7e8;
  --purple: #a593e2;
  --orange: #f0a35d;
  --cream: #bcb7aa;
  --side-bg: #181c21;
  --button-bg: #232830;
  --control-bg: #232830;
  --chip-bg: #232830;
  --metric-bg: #22272e;
  --tooltip-bg: rgba(31, 35, 41, 0.98);
  --tooltip-shadow: rgba(0, 0, 0, 0.28);
  --table-border: rgba(210, 217, 225, 0.08);
  --baseline-bg: #282e36;
  --danger-soft: rgba(240, 107, 99, 0.14);
  --grid-line: #30363d;
  --axis-text: #9aa4af;
  --point-stroke: #14171b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}
.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 392px;
  height: 100vh;
  align-items: stretch;
  overflow: hidden;
}
main {
  padding: 18px 18px 22px;
  border-right: 1px solid var(--line);
  min-height: 0;
  overflow-y: auto;
}
aside {
  padding: 18px 16px;
  background: var(--side-bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.close {
  color: var(--faint);
  font-size: 18px;
}
h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 760;
}
.ghost-btn {
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--button-bg);
  color: var(--muted);
  padding: 0 12px;
  font-weight: 650;
  cursor: pointer;
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.filters {
  display: grid;
  grid-template-columns: .9fr .9fr 1fr 1fr;
  gap: 10px;
  margin: -6px 0 12px;
}
.filter-card {
  min-height: 86px;
  padding: 10px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.filter-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 760;
  margin-bottom: 8px;
}
.filter-body {
  display: grid;
  gap: 8px;
}
.control {
  min-width: 0;
  height: 32px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: var(--control-bg);
  color: var(--text);
  padding: 0 9px;
  font: inherit;
  font-size: 12px;
  font-weight: 680;
  outline: none;
}
select.control {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 13px, calc(100% - 8px) 13px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 24px;
}
.kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.kpi, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.kpi {
  min-height: 62px;
  padding: 12px 12px 10px;
}
.kpi .label {
  color: var(--faint);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 7px;
}
.formula-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: help;
  outline: none;
}
.formula-label::after {
  content: attr(data-formula);
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 30;
  display: none;
  width: max-content;
  max-width: 360px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--tooltip-bg);
  box-shadow: 0 14px 28px var(--tooltip-shadow);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
  white-space: normal;
}
.formula-label:hover::after,
.formula-label:focus::after {
  display: block;
}
.kpi .value {
  font-size: 23px;
  font-weight: 780;
  line-height: 1;
}
.delta {
  color: var(--green);
  font-size: 12px;
  font-weight: 760;
  margin-left: 5px;
}
.delta.bad { color: var(--red); }
.legend-lines {
  display: grid;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.1;
}
.legend-lines span { display: flex; align-items: center; gap: 7px; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  transition: border-color .14s ease, background .14s ease, color .14s ease;
}
.legend-item:hover {
  border-color: var(--line-strong);
  background: var(--panel-2);
}
.legend-item.active {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--panel-2);
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 99px;
  display: inline-block;
}
.chart-panel {
  height: 640px;
  padding: 14px;
  position: relative;
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 10px;
}
h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
  font-weight: 760;
}
.sub {
  color: var(--faint);
  font-size: 12px;
  margin-top: 4px;
  font-weight: 600;
}
.chart-wrap {
  height: 505px;
  border-bottom: 1px solid var(--line);
  margin: 4px 0 0;
  position: relative;
}
svg { width: 100%; height: 100%; display: block; }
.chart-point {
  cursor: crosshair;
  transition: r .14s ease, filter .14s ease;
}
.chart-series {
  cursor: crosshair;
  pointer-events: stroke;
  transition: filter .14s ease, stroke-width .14s ease, opacity .14s ease;
}
.chart-series:hover {
  stroke-width: 7;
  filter: drop-shadow(0 0 10px rgba(37, 99, 216, 0.22));
  opacity: 1;
}
.chart-point:hover {
  r: 10;
  filter: drop-shadow(0 0 8px rgba(37, 99, 216, 0.22));
}
.chart-tooltip {
  position: fixed;
  z-index: 20;
  display: none;
  width: 238px;
  padding: 10px 11px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--tooltip-bg);
  box-shadow: 0 18px 40px var(--tooltip-shadow);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
}
.chart-tooltip strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  margin-bottom: 5px;
}
.chart-tooltip b {
  color: var(--green);
  font-weight: 780;
}
.flow-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.rank-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.rank-tab {
  flex: 1;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--button-bg);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 760;
  cursor: pointer;
  transition: background .14s ease, border-color .14s ease, color .14s ease;
}
.rank-tab:hover {
  border-color: var(--green);
  color: var(--green);
}
.rank-tab.active {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
}
.ranking-list.ranking-panel {
  display: none;
}
.ranking-list.ranking-panel.active {
  display: grid;
}

.ranking-list {
  display: grid;
  gap: 10px;
}
.ranking-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}
.ranking-scroll::-webkit-scrollbar {
  width: 6px;
}
.ranking-scroll::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 999px;
}
.rank-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 11px;
  transition: background .2s ease, border-color .2s ease;
}
.rank-card.best {
  border-color: rgba(53, 201, 143, 0.48);
  background: rgba(53, 201, 143, 0.08);
}
.rank-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}
.developer {
  display: block;
  margin-top: 3px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 700;
}
.model-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 780;
}
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 23px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
}
.rank-card.best .rank-badge {
  color: #ffffff;
  background: var(--green);
  border-color: var(--green);
}
.rank-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.rank-metric {
  min-height: 48px;
  padding: 8px;
  border-radius: 7px;
  background: var(--metric-bg);
  border: 1px solid var(--table-border);
}
.rank-metric span {
  display: block;
  color: var(--faint);
  font-size: 11px;
  font-weight: 760;
  margin-bottom: 5px;
}
.rank-metric strong {
  display: block;
  color: var(--text);
  font-size: 16px;
  font-weight: 820;
  line-height: 1;
}
.decision {
  margin-top: 14px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.decision h3 {
  margin: 0 0 8px;
  font-size: 14px;
}
.list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}
.list strong { color: var(--green); }
.upload-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: -6px 0 12px;
}
.upload-panel .panel-head {
  margin-bottom: 12px;
}
.upload-fields {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: 12px;
  align-items: end;
}
.upload-fields label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.upload-fields input[type="file"] {
  padding: 6px 0;
  color: var(--text);
  font: inherit;
  font-size: 12px;
}
.upload-fields input[type="text"].control {
  width: 100%;
}
.upload-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
#uploadStatus {
  font-size: 12px;
  font-weight: 700;
}
.upload-success { color: var(--green); }
.upload-error { color: var(--red); }
.upload-hint {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 12px;
  line-height: 1.6;
}
.upload-hint p { margin: 0; }
.upload-hint p + p { margin-top: 4px; }

@media (max-width: 1180px) {
  .upload-fields { grid-template-columns: 1fr; }
}

.loading {
  color: var(--faint);
  font-size: 12px;
  padding: 20px;
  text-align: center;
}
@media (max-width: 1180px) {
  .shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    overflow: visible;
  }
  main {
    overflow-y: visible;
  }
  aside {
    height: auto;
    max-height: 720px;
    border-top: 1px solid var(--line);
  }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .filters { grid-template-columns: 1fr; }
  .topbar, .brand { align-items: flex-start; flex-wrap: wrap; }
  .chart-panel { height: auto; }
  .chart-wrap { height: 360px; }
  .kpis { grid-template-columns: 1fr; }
}
