.cockpit {
  --ink: var(--text);
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
}

.cockpit *,
.cockpit *::before,
.cockpit *::after {
  box-sizing: border-box;
}

.cockpit [hidden] {
  display: none !important;
}

.cockpit button,
.cockpit select,
.cockpit input {
  max-width: 100%;
  min-height: 36px;
  font: inherit;
}

.cockpit button:not(.primary):not(.quiet-button),
.cockpit select,
.cockpit input {
  padding: 6px 10px;
  border: 1px solid rgba(148, 163, 184, 0.34);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.9);
}

.cockpit button:not(.primary):not(.quiet-button) {
  color: var(--blue-deep);
  font-weight: 700;
}

.cockpit a {
  color: var(--blue-deep);
  text-underline-offset: 3px;
}

.cockpit h1,
.cockpit h2,
.cockpit h3,
.cockpit p {
  margin: 0;
}

.cockpit h2 {
  font-size: 20px;
}

.cockpit h3 {
  font-size: 14px;
  font-weight: 750;
}

.cockpit .topbar {
  margin-bottom: 16px;
}

.cockpit .quiet-button {
  color: var(--blue-deep);
  background: var(--blue-soft);
}

.cockpit-workspace {
  min-width: 0;
}

.cockpit .filter-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 1fr)) repeat(4, minmax(100px, 1fr)) auto auto;
  align-items: end;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--glass-line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
}

.cockpit .filter-bar label,
.cockpit .snapshot-filter label {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.cockpit .filter-bar select,
.cockpit .filter-bar input {
  width: 100%;
  min-width: 0;
}

.cockpit .primary {
  color: #fff;
  background: linear-gradient(135deg, var(--blue-deep), var(--blue));
  box-shadow: 0 9px 22px rgba(37, 99, 235, 0.2);
}

.cockpit .status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin-top: 12px;
  padding: 11px 14px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  font-size: 12px;
}

.cockpit .status-bar strong {
  margin-left: 5px;
  color: var(--text);
}

.cockpit .tab-bar {
  display: flex;
  gap: 7px;
  margin: 12px 0 16px;
  padding: 5px;
  overflow-x: auto;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.58);
  width: fit-content;
  max-width: 100%;
}

.cockpit .tab-bar button {
  flex: 0 0 auto;
  padding: 8px 22px;
  border-color: transparent;
  background: transparent;
}

.cockpit .tab-bar [aria-selected="true"] {
  border-color: rgba(255, 255, 255, 0.82);
  color: var(--blue-deep);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 7px 18px rgba(37, 99, 235, 0.12), inset 0 1px 0 #fff;
}

.cockpit .section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}

.cockpit .section-heading p,
.cockpit .period-label {
  color: var(--muted);
  font-size: 12px;
}

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

.cockpit .kpi {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--glass-line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px) saturate(130%);
  -webkit-backdrop-filter: blur(16px) saturate(130%);
}

.cockpit .kpi::before {
  content: "";
  display: block;
  width: 34px;
  height: 3px;
  margin-bottom: 10px;
  border-radius: 2px;
  background: var(--blue);
}

.cockpit .kpi:nth-child(4n+2)::before { background: var(--cyan); }
.cockpit .kpi:nth-child(4n+3)::before { background: var(--green); }
.cockpit .kpi:nth-child(4n+4)::before { background: #0ea5a4; }
.cockpit .kpi-label { color: var(--muted); font-size: 12px; }
.cockpit .kpi-value { margin: 4px 0; overflow-wrap: anywhere; font-size: 26px; font-weight: 780; font-variant-numeric: tabular-nums; line-height: 1.5; }
.cockpit .kpi-value.is-missing { color: var(--muted); font-size: 18px; }
.cockpit .kpi-unit { margin-left: 4px; font-size: 12px; font-weight: 400; }
.cockpit .kpi-comparison { display: flex; flex-wrap: wrap; gap: 2px 12px; color: var(--muted); font-size: 11px; }
.cockpit .positive { color: #b42318; }
.cockpit .negative { color: #15803d; }

.cockpit .analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.cockpit .analysis-block {
  min-width: 0;
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.06);
}

.cockpit .block-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.cockpit .chart-controls { display: flex; flex-wrap: wrap; gap: 6px; }
.cockpit .chart-controls select { min-height: 30px; padding: 3px 8px; font-size: 12px; }
.cockpit .chart { width: 100%; min-width: 0; height: 300px; }
.cockpit .member-ranking-chart { height: 320px; }
.cockpit .chart-summary { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.cockpit .chart-summary span::before { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #cbd5e1; content: ""; }
.cockpit .chart-summary .is-positive::before { background: #2563eb; }
.cockpit .chart-summary .is-zero::before { background: #94a3b8; }
.cockpit .metadata,
.cockpit .notice { margin: 0 0 12px; padding: 9px 12px; border: 1px solid #eadcae; border-radius: 8px; color: #765c12; background: #fff8e6; font-size: 12px; overflow-wrap: anywhere; }
.cockpit .metadata { line-height: 1.8; }
.cockpit .module-meta { margin: 4px 0 8px; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.cockpit #quality summary { cursor: pointer; font-weight: 700; }
.cockpit .empty-state,
.cockpit .loading-state,
.cockpit .error-state { display: flex; min-height: 100px; align-items: center; justify-content: center; flex-wrap: wrap; gap: 12px; padding: 24px 12px; color: var(--muted); text-align: center; }
.cockpit .error-state,
.cockpit .filter-error { color: #b42318; }
.cockpit .filter-error { padding: 8px 0; }
.cockpit [role="tabpanel"][data-query-stale="true"]::before { content: "上次查询结果 · 当前筛选无效，未加载新结果"; display: block; margin-bottom: 12px; padding: 8px 12px; border: 1px solid #f4c7c3; border-radius: 8px; color: #b42318; background: #fef3f2; }
.cockpit .loading-state::before { content: ""; width: 14px; height: 14px; border: 2px solid #d5dbdb; border-top-color: var(--blue); border-radius: 50%; animation: cockpit-spin 1s linear infinite; }
.cockpit .table-wrap { max-width: 100%; overflow-x: auto; border-radius: 8px; }
.cockpit table { width: 100%; border-collapse: collapse; background: #fff; font-size: 12px; font-variant-numeric: tabular-nums; }
.cockpit th,
.cockpit td { padding: 8px 10px; border-bottom: 1px solid #eaeef1; text-align: right; white-space: nowrap; }
.cockpit th { color: #5d6d7e; background: #f8fafc; font-weight: 700; }
.cockpit th:first-child,
.cockpit td:first-child { min-width: 120px; text-align: left; white-space: normal; }
.cockpit .table-wrap button { min-height: 24px; padding: 0; border: 0; color: var(--blue-deep); background: none; text-align: left; }
.cockpit .table-wrap summary { padding: 6px 0; color: var(--muted); cursor: pointer; }
.cockpit .warning-list { margin: 8px 0 0; padding-left: 20px; font-size: 12px; }
.cockpit .snapshot-filter { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; margin: 0 0 12px; }
.cockpit .snapshot-filter select { min-width: 220px; }
.cockpit .snapshot-filter p { color: var(--muted); font-size: 12px; }
.cockpit-footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }

@keyframes cockpit-spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .cockpit .filter-bar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .cockpit .topbar { position: static; }
  .cockpit .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; }
  .cockpit .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .cockpit .kpi { padding: 10px 12px; }
  .cockpit .kpi-value { font-size: 22px; }
  .cockpit .analysis-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .cockpit .section-heading { align-items: flex-start; flex-direction: column; gap: 4px; }
  .cockpit .analysis-block { padding: 12px; }
}

@media (max-width: 420px) {
  .cockpit .tab-bar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; overflow: visible; }
  .cockpit .tab-bar button { width: 100%; padding-inline: 10px; }
}

@media (max-width: 380px) {
  .cockpit .kpi-grid { grid-template-columns: minmax(0, 1fr); }
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .cockpit .filter-bar,
  .cockpit .status-bar,
  .cockpit .tab-bar,
  .cockpit .kpi { background: #fff; }
}

@media (prefers-reduced-transparency: reduce) {
  .cockpit .filter-bar,
  .cockpit .status-bar,
  .cockpit .tab-bar,
  .cockpit .kpi { background: #fff; backdrop-filter: none; -webkit-backdrop-filter: none; }
}

@media (prefers-reduced-motion: reduce) {
  .cockpit .loading-state::before { animation: none; }
}
