:root {
  --ink: #19303a;
  --ink-soft: #42555d;
  --teal: #007d7b;
  --teal-dark: #005f60;
  --teal-soft: #e2f2f0;
  --orange: #bd5b18;
  --orange-soft: #fff0e4;
  --green: #15784f;
  --green-soft: #e8f5ed;
  --red: #b3403d;
  --red-soft: #fdeeed;
  --background: #f5f8f8;
  --surface: #ffffff;
  --line: #d7e2e3;
  --muted: #6a7d84;
  --shadow: 0 12px 32px rgb(25 48 58 / 8%);
  --radius: 8px;
  --focus: 0 0 0 3px rgb(0 125 123 / 28%);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--background);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: none; box-shadow: var(--focus); }

.skip-link { position: fixed; top: -4rem; left: 1rem; z-index: 100; padding: 0.65rem 1rem; background: var(--surface); color: var(--ink); border: 1px solid var(--teal); border-radius: 4px; }
.skip-link:focus { top: 1rem; }

.topbar { background: var(--ink); color: #fff; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; max-width: 1540px; min-height: 58px; margin: 0 auto; padding: 0 28px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; }
.brand-mark { font-weight: 800; letter-spacing: 0; }
.brand-divider { width: 1px; height: 18px; background: rgb(255 255 255 / 45%); }
.dashboard-nav { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.dashboard-nav a { color: #d4e1e3; font-size: 0.82rem; font-weight: 650; text-decoration: none; }
.dashboard-nav a:hover { color: #fff; text-decoration: underline; text-underline-offset: 3px; }
.header-meta { color: #c4d0d2; font-size: 0.875rem; }

.page-shell { max-width: 1540px; margin: 0 auto; padding: 32px 28px 56px; }
.page-intro { display: flex; align-items: end; justify-content: space-between; gap: 2rem; padding-bottom: 26px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 2rem; line-height: 1.25; font-weight: 720; }
.mobile-break { display: none; }
h2 { font-size: 1.05rem; line-height: 1.3; font-weight: 700; }
h3 { font-size: 1rem; line-height: 1.35; font-weight: 700; }
.page-intro p, .panel-title-row p, .filter-heading p, .source-status p { color: var(--muted); margin-top: 8px; }
.intro-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.button { min-height: 42px; padding: 0.6rem 0.95rem; border: 1px solid transparent; border-radius: 6px; font-size: 0.9rem; font-weight: 650; transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease, transform 180ms ease; }
.button:active { transform: translateY(1px); }
.button-primary { background: var(--teal); color: #fff; border-color: var(--teal); }
.button-primary:hover { background: var(--teal-dark); }
.button-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.button-secondary:hover { background: var(--teal-soft); border-color: #9ecfcb; }

.kpi-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 22px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.metric { min-height: 106px; padding: 18px 20px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 0.82rem; font-weight: 650; }
.metric strong { display: block; margin-top: 6px; font-size: 1.75rem; line-height: 1.1; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.metric.teal strong { color: var(--teal); }
.metric.orange strong { color: var(--orange); }
.metric.green strong { color: var(--green); }

.filter-region, .result-pane, .detail-panel, .source-status { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.filter-region { padding: 18px 20px 20px; margin-bottom: 22px; }
.filter-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.filter-heading p { font-size: 0.875rem; }
.filter-controls { display: grid; grid-template-columns: minmax(220px, 1.7fr) repeat(5, minmax(132px, 1fr)); gap: 14px; margin-top: 18px; }
label { display: grid; gap: 6px; color: var(--ink-soft); font-size: 0.8rem; font-weight: 650; }
input, select { width: 100%; min-height: 42px; padding: 0.55rem 0.7rem; color: var(--ink); background: #fff; border: 1px solid #c6d5d7; border-radius: 5px; font-size: 0.93rem; }
input::placeholder { color: #8a9b9f; }

.workspace { display: grid; grid-template-columns: minmax(640px, 1.7fr) minmax(340px, 0.78fr); align-items: start; gap: 22px; }
.result-pane { min-width: 0; overflow: hidden; }
.panel-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding: 20px 20px 15px; }
.panel-title-row p { font-size: 0.88rem; }
.legend { display: flex; flex-wrap: wrap; justify-content: end; gap: 12px; color: var(--muted); font-size: 0.76rem; }
.legend span { display: inline-flex; gap: 5px; align-items: center; }
.legend-line { display: inline-block; width: 14px; height: 3px; border-radius: 1px; }
.legend-top { background: var(--teal); }
.legend-gap { background: var(--orange); }
.round-head, .round-row { display: grid; grid-template-columns: minmax(180px, 2.2fr) minmax(112px, 1.2fr) minmax(82px, .9fr) minmax(82px, .9fr) minmax(82px, .9fr) minmax(82px, .9fr); column-gap: 12px; align-items: center; }
.round-head { padding: 10px 20px; color: var(--muted); background: #f1f6f6; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 0.73rem; font-weight: 700; }
.round-head span:not(:first-child), .round-row .metric-value { text-align: right; }
.round-list { display: grid; }
.round-row { width: 100%; padding: 14px 20px; color: var(--ink); text-align: left; background: var(--surface); border: 0; border-bottom: 1px solid var(--line); border-left: 3px solid transparent; transition: background-color 180ms ease, border-color 180ms ease; }
.round-row:hover { background: #f3fbfa; }
.round-row.is-selected { background: var(--teal-soft); border-left-color: var(--teal); }
.round-row:last-child { border-bottom: 0; }
.round-name { display: grid; gap: 2px; min-width: 0; }
.round-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; }
.round-name span { color: var(--muted); font-size: 0.76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.round-name .spu-tag { display: inline-flex; width: fit-content; align-items: center; padding: 2px 6px; color: #6c4e00; background: var(--orange-soft); border: 1px solid #f0d19d; border-radius: 3px; font-size: 0.68rem; font-weight: 750; }
.metric-value { color: var(--ink-soft); font-size: 0.87rem; font-variant-numeric: tabular-nums; }
.metric-value.primary { color: var(--teal-dark); font-weight: 750; }
.metric-value.advantage { color: var(--orange); font-weight: 700; }
.empty-state { padding: 50px 24px; text-align: center; }
.empty-state p { margin-bottom: 15px; color: var(--muted); }

.detail-panel { position: sticky; top: 16px; padding: 20px; box-shadow: var(--shadow); }
.detail-empty { color: var(--muted); padding: 38px 10px; text-align: center; }
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.detail-header p { color: var(--muted); font-size: 0.82rem; margin-top: 5px; }
.copy-link { flex: 0 0 auto; min-height: 40px; padding-inline: 0.7rem; font-size: 0.8rem; }
.detail-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.detail-stat span { display: block; color: var(--muted); font-size: 0.72rem; }
.detail-stat strong { display: block; margin-top: 4px; color: var(--ink); font-size: 1rem; font-variant-numeric: tabular-nums; }
.detail-stat strong.orange { color: var(--orange); }
.candidate-list { display: grid; gap: 0; margin-top: 16px; }
.candidate { display: grid; grid-template-columns: 116px minmax(0, 1fr); gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.candidate:first-child { border-top: 0; padding-top: 0; }
.candidate.is-winner { margin-inline: -8px; padding: 14px 8px; border-left: 3px solid var(--green); background: var(--green-soft); }
.candidate.is-winner:first-child { padding-top: 8px; }
.candidate-image { position: relative; width: 116px; height: 145px; padding: 0; overflow: hidden; background: #ecf1f1; border: 1px solid var(--line); border-radius: 5px; }
.candidate-image:hover img { transform: scale(1.025); }
.candidate-image img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform 180ms ease; }
.candidate-info { min-width: 0; }
.candidate-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.candidate-heading strong { font-size: 0.95rem; }
.winner-label { color: var(--green); font-size: 0.76rem; font-weight: 750; }
.candidate-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-top: 13px; }
.candidate-metrics div { min-width: 0; }
.candidate-metrics span { display: block; color: var(--muted); font-size: 0.72rem; }
.candidate-metrics strong { display: block; margin-top: 2px; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.candidate-metrics .candidate-ctr strong { color: var(--teal-dark); }

.spu-history { margin-top: 18px; }
.spu-history-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.spu-history-heading span { color: var(--muted); font-size: 0.76rem; font-variant-numeric: tabular-nums; }
.expanded-test-list { display: grid; gap: 20px; }
.expanded-test { border-top: 1px solid var(--line); padding-top: 16px; }
.expanded-test-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.expanded-test-header h3 { font-size: 0.95rem; }
.expanded-test-header p { margin-top: 3px; color: var(--muted); font-size: 0.72rem; }
.expanded-test-header > strong { color: var(--teal-dark); font-size: 1rem; font-variant-numeric: tabular-nums; }
.expanded-test-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.expanded-test-summary span { display: block; color: var(--muted); font-size: 0.7rem; }
.expanded-test-summary strong { display: block; margin-top: 3px; color: var(--ink); font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.expanded-test-summary strong.orange { color: var(--orange); }
.test-conclusion { margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--teal); background: #f0f7f7; }
.test-conclusion strong { color: var(--teal-dark); font-size: 0.78rem; }
.test-conclusion p { margin-top: 3px; color: var(--ink-soft); font-size: 0.82rem; line-height: 1.5; }
.test-conclusion.is-manual { border-left-color: var(--orange); background: var(--orange-soft); }
.test-conclusion.is-manual strong { color: var(--orange); }

.source-status { display: flex; align-items: start; justify-content: space-between; gap: 2rem; margin-top: 22px; padding: 20px; }
.source-status h2 { color: var(--red); }
.source-status p { font-size: 0.87rem; }
details { min-width: 260px; }
summary { color: var(--ink); cursor: pointer; font-weight: 700; }
summary:hover { color: var(--teal-dark); }
#missing-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0 0; margin: 0; list-style: none; }
#missing-list li { padding: 4px 8px; color: var(--red); background: var(--red-soft); border-radius: 4px; font-size: 0.8rem; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 30; max-width: min(360px, calc(100vw - 32px)); padding: 11px 14px; color: #fff; background: var(--ink); border-radius: 6px; box-shadow: var(--shadow); font-size: 0.875rem; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity 180ms ease, transform 180ms ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.lightbox[hidden] { display: none; }
.lightbox { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px; }
.lightbox-backdrop { position: absolute; inset: 0; background: rgb(14 28 33 / 74%); }
.lightbox-content { position: relative; z-index: 1; display: grid; justify-items: end; gap: 12px; max-width: min(730px, 100%); max-height: 100%; }
.lightbox-content img { display: block; max-width: 100%; max-height: min(72vh, 860px); object-fit: contain; background: #fff; border-radius: 4px; }
.lightbox-content p { width: 100%; color: #fff; text-align: center; font-size: 0.9rem; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 350px; }
  .filter-controls { grid-template-columns: minmax(210px, 1.5fr) repeat(2, minmax(150px, 1fr)); }
  .round-head, .round-row { grid-template-columns: minmax(165px, 2fr) 95px 76px 76px 76px 76px; gap: 9px; }
}

@media (max-width: 940px) {
  .workspace { grid-template-columns: 1fr; }
  .detail-panel { position: static; }
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }
  .metric:nth-child(3) { border-right: 0; }
  .metric:nth-child(n + 4) { border-top: 1px solid var(--line); }
}

@media (max-width: 680px) {
  .topbar-inner, .page-shell { padding-left: 16px; padding-right: 16px; }
  .topbar-inner { min-height: 54px; }
  .header-meta { display: none; }
  .dashboard-nav { gap: 11px; }
  .dashboard-nav a { font-size: 0.78rem; }
  .page-shell { padding-top: 24px; padding-bottom: 32px; }
  .page-intro { display: grid; gap: 20px; align-items: start; }
  h1 { font-size: 1.5rem; }
  .mobile-break { display: block; }
  .intro-actions { width: 100%; }
  .intro-actions .button { flex: 1 1 150px; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .metric { min-height: 88px; padding: 14px; border-top: 1px solid var(--line); border-right: 1px solid var(--line); }
  .metric:nth-child(-n + 2) { border-top: 0; }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:last-child { grid-column: span 2; }
  .metric strong { font-size: 1.45rem; }
  .filter-region, .result-pane, .detail-panel, .source-status { border-radius: 6px; }
  .filter-region { padding: 16px; }
  .filter-heading { display: grid; gap: 4px; }
  .filter-controls { grid-template-columns: 1fr; gap: 12px; }
  .round-head { display: none; }
  .round-row { grid-template-columns: 1fr 1fr; gap: 9px 14px; padding: 15px 16px; }
  .round-name { grid-column: 1 / -1; }
  .round-name strong { font-size: 0.95rem; }
  .metric-value { display: flex; justify-content: space-between; gap: 10px; text-align: left !important; font-size: 0.85rem; }
  .metric-value::before { color: var(--muted); font-size: 0.72rem; }
  .metric-value.launch::before { content: "上线"; }
  .metric-value.test-count::before { content: "测试轮次"; }
  .metric-value.exposure::before { content: "曝光 UV"; }
  .metric-value.weighted::before { content: "加权 CTR"; }
  .metric-value.top::before { content: "最高 CTR"; }
  .detail-panel { padding: 16px; }
  .expanded-test { padding-top: 14px; }
  .candidate.is-winner { margin-inline: -5px; padding: 12px 5px; }
  .test-conclusion { padding: 9px 10px; }
  .source-status { display: grid; gap: 16px; padding: 16px; }
  details { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
