/* BI dashboard tokens: cool slate workspace + vibrant chart accents */
:root {
  --bg: #eef1f5;
  --bg-subtle: #e4e9ef;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --border: #d0d7e2;
  --border-strong: #b8c2d0;
  --text: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --accent: #14b8a6;
  --accent-hover: #0d9488;
  --accent-subtle: #ecfdf9;
  --accent-border: #99f6e4;
  --warn: #f97316;
  --danger: #ef4444;
  --good: #38bdf8;
  --excellent: #059669;
  --chart-1: #14b8a6;
  --chart-2: #38bdf8;
  --chart-3: #fb7185;
  --chart-4: #fbbf24;
  --chart-5: #22d3ee;
  --chart-6: #a78bfa;
  --nav-width: 232px;
  --header-h: 52px;
  --radius: 6px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --font: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "IBM Plex Sans", "SF Mono", ui-monospace, monospace;
  --transition-fast: 0.05s ease;
  --transition-page: 0s;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}

.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--nav-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-header {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.sidebar-header h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 8px 0;
  flex: 1;
  overflow-y: auto;
}

.nav-list > li {
  margin: 0 8px 2px;
}

.nav-group {
  margin-bottom: 6px;
}

.nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: left;
  cursor: pointer;
}

.nav-group-toggle:hover {
  background: var(--bg);
}

.nav-group.is-active-group > .nav-group-toggle {
  color: var(--accent-hover);
}

.nav-group-chevron {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--text-muted);
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

.nav-group.is-open > .nav-group-toggle .nav-group-chevron {
  transform: rotate(180deg);
}

.nav-sublist {
  list-style: none;
  margin: 0;
  padding: 0 0 4px;
  display: none;
}

.nav-group.is-open > .nav-sublist {
  display: block;
}

.nav-subitem {
  margin: 0 0 1px;
}

.nav-list a {
  display: block;
  padding: 8px 10px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.nav-sublist a {
  padding: 7px 10px 7px 14px;
  font-size: 13px;
}

.nav-list a small {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
}

.nav-list a:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-list a.active {
  background: var(--accent-subtle);
  border-left-color: var(--accent);
  color: var(--accent-hover);
  font-weight: 600;
}

.nav-list a.active small {
  color: var(--text-muted);
  font-weight: 400;
}

/* Main */
.main {
  margin-left: var(--nav-width);
  flex: 1;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.load-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 1 240px;
  min-width: 148px;
  max-width: 280px;
}

.load-progress[hidden] {
  display: none;
}

.load-progress-text {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex: 0 0 auto;
}

.load-progress-track {
  flex: 1;
  height: 4px;
  min-width: 56px;
  background: var(--bg-subtle);
  border-radius: 99px;
  overflow: hidden;
}

.load-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: inherit;
  transition: width 0.2s ease;
}

.topbar h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Page / chart metric help (? icon + tooltip) */
.heading-with-tip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.help-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  flex-shrink: 0;
}

.help-tip-btn {
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  cursor: help;
  font-family: var(--font-mono);
  transition: border-color var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
}

.help-tip-btn:hover,
.help-tip-btn:focus-visible {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: var(--accent-subtle);
  outline: none;
}

.help-tip-popover {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1100;
  width: max-content;
  max-width: min(320px, calc(100vw - 32px));
  padding: 10px 12px;
  background: var(--text);
  color: #f8fafc;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.22);
  white-space: normal;
  text-align: left;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast), visibility var(--transition-fast);
}

.help-tip-popover.is-visible {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.help-tip-list {
  margin: 0;
  padding-left: 1.15em;
  list-style: disc;
}

.help-tip-list li {
  margin: 0;
  padding: 0;
}

.help-tip-list li + li {
  margin-top: 6px;
}

@media (max-width: 768px) {
  .help-tip-popover {
    max-width: min(280px, calc(100vw - 24px));
  }
}

.content {
  padding: 16px 20px 32px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.page-note {
  margin: 0 0 14px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted, #64748b);
  background: rgba(15, 118, 110, 0.06);
  border-left: 3px solid var(--accent, #0f766e);
  border-radius: 0 6px 6px 0;
}

@media (prefers-reduced-motion: reduce) {
  .nav-list a,
  .toggle-btn,
  .menu-toggle,
  .heatmap-link,
  .help-tip-btn,
  .help-tip-popover {
    transition: none;
  }
}

.subsection {
  margin-bottom: 22px;
}

.subsection-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.subsection h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 12px;
  /* 默认同行等高对齐；单独调高的图卡用 align-self:start 脱离拉伸 */
  align-items: stretch;
}

/* 固定每行两张 */
.chart-grid-2,
#page-baidu_source .chart-grid,
#page-baidu_pages .chart-grid,
#page-wechat_visit .chart-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

#page-survey_ib_compare .chart-grid-ib-compare-full {
  grid-template-columns: minmax(0, 1fr);
}

#page-survey_ib_compare .chart-grid-ib-compare-full.chart-grid--free-width > .chart-panel {
  flex: 0 0 100%;
  width: 100%;
  max-width: 100%;
}

/* 自定义宽度：按行 flex，断行锁定每行张数；图卡宽度之和不超过行宽，避免重叠 */
.chart-grid.chart-grid--free-width,
.chart-grid-2.chart-grid--free-width,
#page-baidu_source .chart-grid.chart-grid--free-width,
#page-baidu_pages .chart-grid.chart-grid--free-width,
#page-wechat_visit .chart-grid-2.chart-grid--free-width {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  grid-template-columns: unset;
}

.chart-grid--free-width > .chart-row-break {
  flex: 0 0 100%;
  width: 100%;
  height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  pointer-events: none;
}

.chart-grid--free-width > .chart-panel {
  flex: 1 1 0;
  min-width: min(100%, 320px);
  box-sizing: border-box;
}

.chart-grid--free-width > .chart-panel.is-custom-width {
  flex: 0 0 auto;
  max-width: none;
  min-width: 0;
}

/* 有自定义高度时取消行内 stretch，避免拖高一张带动同行其它图 */
.chart-grid.chart-grid--free-height,
.chart-grid-2.chart-grid--free-height,
.chart-grid--free-width.chart-grid--free-height,
#page-baidu_source .chart-grid.chart-grid--free-height,
#page-baidu_pages .chart-grid.chart-grid--free-height,
#page-wechat_visit .chart-grid-2.chart-grid--free-height {
  align-items: start;
}

.chart-panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px 10px;
}

.chart-panel-head {
  margin-bottom: 8px;
}

.chart-panel-head h4 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.chart-panel-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 12px;
}

.chart-panel-head-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  overflow: visible;
}

/* Chart series picker (#baidu_pages) */
.chart-series-bar {
  margin-bottom: 0;
  flex-wrap: nowrap;
  max-width: 100%;
}

.chart-series-bar .series-picker {
  position: relative;
  flex-shrink: 0;
}

.chart-series-bar .series-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chart-series-bar .series-picker-btn[aria-expanded="true"] {
  background: var(--surface);
  color: var(--accent-hover);
  font-weight: 600;
  border: 1px solid var(--accent-border);
  box-shadow: 0 1px 3px rgba(13, 148, 136, 0.14);
}

.series-picker-count {
  font-variant-numeric: tabular-nums;
  color: inherit;
  opacity: 0.85;
  font-weight: 600;
}

.series-picker-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 200;
  width: min(280px, calc(100vw - 32px));
  max-height: min(320px, 55vh);
  display: none;
  flex-direction: column;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.series-picker-popover.is-open {
  display: flex;
}

.series-picker-popover[hidden] {
  display: none !important;
}

.series-picker-search {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-subtle);
}

.series-picker-search::placeholder {
  color: var(--text-muted);
}

.series-picker-search:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

.series-picker-shortcuts {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.series-picker-shortcut {
  padding: 2px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 11px;
  font-family: var(--font);
  color: var(--accent-hover);
  cursor: pointer;
}

.series-picker-shortcut:hover {
  background: var(--accent-subtle);
  color: var(--accent-hover);
}

.series-picker-list {
  overflow: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.series-picker-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 6px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}

.series-picker-item:hover {
  background: var(--bg-subtle);
}

.series-picker-item.is-hidden {
  display: none;
}

.series-picker-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  margin: 2px 0 0;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--surface);
  cursor: pointer;
}

.series-picker-item input[type="checkbox"]:checked {
  border-color: var(--accent);
  background: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%23fff' stroke-width='2' d='M2 6l3 3 5-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 10px;
}

.series-picker-label {
  flex: 1;
  line-height: 1.35;
  word-break: break-word;
}

.series-picker-total {
  flex-shrink: 0;
  font-size: 10px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.series-picker-empty {
  margin: 0;
  padding: 14px 8px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

.series-picker-empty[hidden] {
  display: none;
}

@media (max-width: 768px) {
  .chart-series-bar {
    flex-wrap: wrap;
  }

  .series-picker-popover {
    right: auto;
    left: 0;
    width: min(300px, calc(100vw - 24px));
  }
}

.toggle-bar--inline {
  margin-bottom: 0;
}

.data-end-label {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  white-space: nowrap;
}

.data-end-label .help-tip-btn {
  width: 14px;
  height: 14px;
  font-size: 10px;
  margin-left: 2px;
}

.archive-coverage {
  margin: 0 0 12px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2, #f8fafc);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
}

.ov-row-end {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
}

.track-kpi-end {
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-muted);
}

.chart-series-focus-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-top: 6px;
  padding: 0 2px 2px;
}

.chart-series-bulk-btn {
  appearance: none;
  border: 1px solid var(--border-strong, #cbd5e1);
  background: var(--surface, #fff);
  color: var(--text-secondary, #334155);
  font: 500 12px/1.2 var(--font, sans-serif);
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.chart-series-bulk-btn:hover {
  border-color: var(--accent, #0d9488);
  color: var(--accent, #0d9488);
}

.chart-series-focus-hint {
  font-size: 11px;
  color: var(--text-muted, #64748b);
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.chart-wrap.is-empty > canvas {
  opacity: 1;
  filter: none;
}

.chart-empty-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 24px;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.5;
  color: #334155;
  /* 半透明罩层：底下空图坐标轴/网格仍可见 */
  background: rgba(248, 250, 252, 0.7);
  pointer-events: none;
  border-radius: 4px;
}

.chart-wrap.tall {
  height: 320px;
}

.chart-wrap.tall-2x {
  height: 520px;
}

.chart-grid-facet {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-items: stretch;
}

.chart-wrap.facet {
  height: 220px;
}

.chart-panel-note {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.chart-wrap.pie {
  height: 300px;
  max-width: 440px;
}

/* 页面全局切换：吸顶在 topbar 下方 */
.page-sticky-controls {
  position: sticky;
  top: var(--header-h);
  z-index: 45;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  margin: -16px -20px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.page-sticky-controls-main {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.page-sticky-controls-end {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

.chart-resize-sticky-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.chart-resize-reset-btn {
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: calc(var(--radius-sm) + 1px);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1.25;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.chart-resize-reset-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
  background: var(--bg-subtle);
}

.page-sticky-controls .toggle-bar {
  margin-bottom: 0;
}

.chart-resize-handle {
  display: none;
  position: absolute;
  z-index: 6;
  background: transparent;
  touch-action: none;
}

.page.is-chart-resize-on .chart-resize-handle,
body.is-chart-resize-on .page.active .chart-resize-handle {
  display: block;
}

.chart-resize-handle--s {
  left: 14px;
  right: 14px;
  bottom: 0;
  height: 8px;
  cursor: ns-resize;
}

.chart-resize-handle--e {
  top: 14px;
  right: 0;
  bottom: 14px;
  width: 8px;
  cursor: ew-resize;
}

.chart-resize-handle--w {
  top: 14px;
  left: 0;
  bottom: 14px;
  width: 8px;
  cursor: ew-resize;
}

.chart-resize-handle--se {
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
}

.chart-resize-handle--sw {
  left: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  cursor: nesw-resize;
}

.chart-resize-handle--nw {
  left: 0;
  top: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
}

.chart-resize-handle--s::after,
.chart-resize-handle--e::after,
.chart-resize-handle--w::after,
.chart-resize-handle--se::after,
.chart-resize-handle--sw::after,
.chart-resize-handle--nw::after {
  content: "";
  position: absolute;
  background: var(--accent, #14b8a6);
  opacity: 0.35;
  border-radius: 2px;
}

.chart-resize-handle--s::after {
  left: 30%;
  right: 30%;
  top: 2px;
  height: 3px;
}

.chart-resize-handle--e::after {
  top: 30%;
  bottom: 30%;
  left: 2px;
  width: 3px;
}

.chart-resize-handle--w::after {
  top: 30%;
  bottom: 30%;
  right: 2px;
  width: 3px;
}

.chart-resize-handle--se::after {
  right: 3px;
  bottom: 3px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--accent, #14b8a6);
  border-bottom: 2px solid var(--accent, #14b8a6);
  background: transparent;
  opacity: 0.7;
  border-radius: 0;
}

.chart-resize-handle--sw::after {
  left: 3px;
  bottom: 3px;
  width: 8px;
  height: 8px;
  border-left: 2px solid var(--accent, #14b8a6);
  border-bottom: 2px solid var(--accent, #14b8a6);
  background: transparent;
  opacity: 0.7;
  border-radius: 0;
}

.chart-resize-handle--nw::after {
  left: 3px;
  top: 3px;
  width: 8px;
  height: 8px;
  border-left: 2px solid var(--accent, #14b8a6);
  border-top: 2px solid var(--accent, #14b8a6);
  background: transparent;
  opacity: 0.7;
  border-radius: 0;
}

body.is-chart-resizing {
  user-select: none;
  cursor: grabbing;
}

body.is-chart-resizing iframe {
  pointer-events: none;
}

/* Segmented controls */
.toggle-bar {
  display: inline-flex;
  gap: 2px;
  margin-bottom: 12px;
  padding: 3px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  flex-wrap: wrap;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.toggle-btn {
  padding: 6px 14px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: calc(var(--radius-sm) + 1px);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  color: var(--text-secondary);
  line-height: 1.25;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.toggle-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.75);
  border-color: var(--border);
}

.toggle-btn.active {
  background: var(--surface);
  color: var(--accent-hover);
  font-weight: 600;
  border-color: var(--accent-border);
  box-shadow: 0 1px 3px rgba(13, 148, 136, 0.14);
}

.heatmap-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.heatmap-embed-panel {
  padding: 0;
  overflow: visible;
}

.heatmap-chart {
  width: 100%;
  height: 520px;
  overflow: visible;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-subtle) 100%);
}

.heatmap-iframe {
  display: block;
  width: 100%;
  height: 520px;
  border: 0;
  background: #fff;
}

.heatmap-embed-footer {
  display: flex;
  justify-content: flex-end;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
}

.heatmap-open-link {
  font-size: 11px;
  color: var(--text-muted);
  text-decoration: none;
}

.heatmap-open-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.top20-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
}

.top20-panel .data-table-wrap {
  max-height: 420px;
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}

.data-table th:first-child,
.data-table td:first-child,
.data-table td:nth-child(2) {
  text-align: left;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 600;
  z-index: 1;
}

.data-table tbody tr:hover {
  background: var(--accent-subtle);
}

.heatmap-link {
  display: block;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--accent);
  font-weight: 500;
  font-size: 13px;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.heatmap-link:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.heatmap-link:active {
  transform: translateY(1px);
}

.heatmap-link span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 3px;
}

.loading {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
  pointer-events: none;
}

.page-loading {
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.heatmap-intro {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.chart-hint {
  margin: 0 0 12px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
}

.error-box {
  padding: 14px 16px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  color: #991b1b;
  font-size: 13px;
}

.error-box code {
  font-size: 12px;
  background: rgba(0, 0, 0, 0.04);
  padding: 1px 4px;
  border-radius: 3px;
}

/* Overview / home — change board */
.ov-board {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ov-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 13px;
  color: var(--text-secondary);
}

.ov-summary-sep {
  color: var(--text-muted);
}

.ov-summary-label {
  font-weight: 600;
  color: var(--text-secondary);
}

.ov-tabs {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.ov-board > .ov-tabs .toggle-bar {
  margin-bottom: 0;
}

.ov-scope-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.ov-pane {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ov-pane-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.ov-pane-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.ov-pane-empty {
  margin: 0;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.ov-board--enter.ov-board--play .ov-pane:nth-of-type(1) {
  animation: ov-group-in 380ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.ov-board--enter.ov-board--play .ov-pane:nth-of-type(2) {
  animation: ov-group-in 380ms cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: 80ms;
}

.ov-summary-item--excellent strong {
  color: var(--excellent);
}

.ov-summary-item--good strong {
  color: var(--good);
}

.ov-summary-item--watch strong {
  color: var(--warn);
}

.ov-summary-item--alert strong {
  color: var(--danger);
}

.ov-summary-item--flat strong {
  color: var(--text-muted);
}

.ov-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.ov-board--enter .ov-group {
  opacity: 0;
  transform: translateY(10px);
}

.ov-board--enter.ov-board--play .ov-group {
  animation: ov-group-in 380ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.ov-board--enter.ov-board--play .ov-group:nth-of-type(1) {
  animation-delay: 0ms;
}

.ov-board--enter.ov-board--play .ov-group:nth-of-type(2) {
  animation-delay: 60ms;
}

.ov-board--enter.ov-board--play .ov-group:nth-of-type(3) {
  animation-delay: 120ms;
}

.ov-board--enter.ov-board--play .ov-group:nth-of-type(4) {
  animation-delay: 180ms;
}

.ov-board--enter.ov-board--play .ov-group:nth-of-type(5) {
  animation-delay: 240ms;
}

@keyframes ov-group-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ov-group-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle, rgba(0, 0, 0, 0.02));
}

.ov-group-head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.ov-group-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.ov-group-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.ov-table-head,
.ov-row {
  display: grid;
  grid-template-columns: 72px 1fr 96px minmax(120px, 1.2fr) minmax(120px, 1.2fr) 88px;
  gap: 8px 12px;
  align-items: center;
  padding: 8px 14px;
}

.ov-table-head {
  font-size: 11px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.ov-row {
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-fast);
}

.ov-row:last-child {
  border-bottom: none;
}

.ov-row:hover {
  background: var(--accent-subtle);
}

.ov-row-domain {
  font-size: 11px;
  color: var(--text-muted);
}

.ov-row-label {
  font-size: 13px;
  font-weight: 500;
}

.ov-row-current {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

.ov-change {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

.ov-change-arrow {
  font-weight: 700;
}

.ov-change-pct {
  color: var(--text-muted);
  font-size: 11px;
}

.ov-change-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.05);
}

.ov-change--excellent {
  color: var(--excellent);
}

.ov-change--excellent .ov-change-tag {
  background: rgba(5, 150, 105, 0.14);
  color: var(--excellent);
}

.ov-change--good {
  color: var(--good);
}

.ov-change--good .ov-change-tag {
  background: rgba(56, 189, 248, 0.16);
  color: var(--good);
}

.ov-change--watch {
  color: var(--warn);
}

.ov-change--watch .ov-change-tag {
  background: rgba(249, 115, 22, 0.12);
  color: var(--warn);
}

.ov-change--alert {
  color: var(--danger);
}

.ov-change--alert .ov-change-tag {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger);
}

.ov-change--flat,
.ov-change--na {
  color: var(--text-muted);
}

.ov-change--flat .ov-change-tag,
.ov-change--na {
  background: transparent;
}

.ov-spark {
  height: 36px;
}

.ov-spark--empty {
  opacity: 0.25;
}

.ov-board--enter:not(.ov-board--play) .ov-spark canvas {
  opacity: 0;
}

.ov-board--enter.ov-board--play .ov-spark canvas {
  animation: ov-spark-in 280ms ease 120ms both;
}

@keyframes ov-spark-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.menu-toggle {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  color: var(--text-secondary);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.menu-toggle:hover {
  border-color: var(--border-strong);
  background: var(--bg);
}

.menu-toggle:active {
  transform: translateY(1px);
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 16px rgba(15, 23, 42, 0.08);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
  }

  .menu-toggle {
    display: inline-block;
  }

  .chart-grid,
  .chart-grid-2,
  #page-baidu_source .chart-grid,
  #page-baidu_pages .chart-grid,
  #page-wechat_visit .chart-grid-2 {
    grid-template-columns: 1fr;
  }

  .ov-table-head,
  .ov-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .ov-table-head {
    display: none;
  }

  .ov-row {
    padding: 12px 14px;
  }

  .ov-spark {
    grid-column: 1 / -1;
    height: 40px;
  }

  .content {
    padding: 12px;
  }

  .topbar {
    padding: 0 12px;
    flex-wrap: wrap;
    min-height: var(--header-h);
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .load-progress {
    flex: 1 1 100%;
    max-width: none;
    margin-bottom: 4px;
  }

}

.track-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 10px;
}

.track-kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.track-kpi-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.track-kpi-value {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
}

.track-kpi-delta {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.track-kpi-delta--up {
  color: var(--accent);
}

.track-kpi-delta--down {
  color: var(--chart-3);
}

.track-kpi-delta--flat {
  color: var(--text-muted);
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }

  .ov-board--enter .ov-group,
  .ov-board--enter .ov-spark canvas {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }

  .ov-row {
    transition: background var(--transition-fast);
  }

  .ov-row:hover {
    transform: none;
  }
}
