/* === 基础 === */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: #1f2937;
  background: #f5f7fb;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; }

/* === 顶栏 === */
.topbar {
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar h1 { font-size: 18px; }
.subtitle { margin: 2px 0 0; color: #6b7280; font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* === 通用 === */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}
.muted { color: #6b7280; }
.small { font-size: 12px; }
.num { text-align: center; font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; }

/* === 按钮 === */
.btn {
  appearance: none;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #1f2937;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
}
.btn:hover { border-color: #2563eb; color: #2563eb; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
}
.btn-ghost:hover { background: #dbeafe; }
.btn-warn {
  background: #fff7ed;
  border-color: #fdba74;
  color: #c2410c;
}
.btn-warn:hover { background: #ffedd5; }

/* === KPI === */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 16px 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.kpi-label { color: #6b7280; font-size: 12px; margin-bottom: 8px; }
.kpi-value {
  font-size: 28px;
  font-weight: 600;
  color: #111827;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-sub {
  margin-top: 6px;
  font-size: 12px;
  color: #6b7280;
  font-variant-numeric: tabular-nums;
}
.kpi-value.text-green { color: #15803d; }
.kpi-value.text-red   { color: #b91c1c; }
.kpi-value.text-orange{ color: #c2410c; }
.kpi-value.text-blue  { color: #1d4ed8; }
.text-green { color: #15803d; font-weight: 600; }
.text-red   { color: #b91c1c; font-weight: 600; }
.text-orange{ color: #c2410c; font-weight: 600; }

/* === 卡片 === */
.card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-head.row { gap: 16px; }
.card-head h2 { font-size: 15px; }

/* === 当前时段卡 === */
.cur-period {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-color: #93c5fd;
}
.cur-period-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; }
.cur-period-name { font-size: 22px; font-weight: 600; color: #1e3a8a; }
.cur-period-meta { padding: 0 18px 14px; }

/* 当前时段站点明细 */
#cur-period-table-wrap { padding: 0 18px 14px; }
#cur-period-table-wrap .data-table th,
#cur-period-table-wrap .data-table td { padding: 6px 10px; }

/* === 时段矩阵(紧凑版,钉钉端友好) === */
.matrix-wrap {
  overflow-x: auto;
  max-width: 100%;
}
.matrix-table {
  width: auto;
  min-width: 100%;
  font-size: 12px;
}
.matrix-table th,
.matrix-table td {
  padding: 6px 6px;
  min-width: 56px;
}
.matrix-table .sticky-col,
.matrix-table .sticky-right {
  position: sticky;
  z-index: 2;
  background: #fff;
}
.matrix-table .sticky-col:first-child,
.matrix-table td.sticky-col:first-child,
.matrix-table th.sticky-col:first-child {
  left: 0;
  min-width: 130px;
  padding-left: 12px;
  border-right: 1px solid #e5e7eb;
}
.matrix-table th.sticky-col:nth-child(2),
.matrix-table td.sticky-col:nth-child(2) {
  left: 130px;
  padding-left: 10px;
  min-width: 56px;
  border-right: 1px solid #e5e7eb;
}
.matrix-table .sticky-right {
  right: 0;
  padding-right: 12px;
  border-left: 1px solid #e5e7eb;
  min-width: 72px;
}
.matrix-table thead th {
  top: 0;
  z-index: 3;
}
.matrix-table thead th.sticky-col,
.matrix-table thead th.sticky-right {
  z-index: 4;
}
.matrix-table .matrix-th {
  line-height: 1.25;
  text-align: center;
}
.matrix-table .th-period {
  font-size: 12px;
  color: #374151;
  font-weight: 500;
}
.matrix-table .th-weight {
  font-size: 10px;
  color: #9ca3af;
  font-weight: 400;
  margin-top: 1px;
}
.matrix-cell {
  font-size: 12px;
  text-align: center;
  cursor: default;
}
.matrix-cell .rate-pill { font-size: 12px; }

/* 紧凑 Pill 标记 —— 取代原来彩色的 rate-bar 进度条 */
.rate-pill {
  display: inline-block;
  min-width: 42px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
  border: 1px solid transparent;
}
.rate-pill.rate-good { background: #ecfdf5; color: #15803d; border-color: #bbf7d0; }
.rate-pill.rate-mid  { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.rate-pill.rate-bad  { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }

.matrix-legend {
  padding: 8px 18px 12px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 11px;
}
.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 4px;
}

/* === Badge === */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  vertical-align: middle;
}
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-gray   { background: #f3f4f6; color: #4b5563; }

/* 差值 Pill —— AC 列「单量-X，时长-Y」专用 */
.badge.gap-pill {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: .2px;
}

/* === 表格 === */
.table-wrap {
  overflow-x: auto;
  padding: 6px 6px 14px;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th, .data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #f3f4f6;
  text-align: center;
  white-space: nowrap;
}
.data-table th:first-child,
.data-table td:first-child { text-align: left; }
.data-table thead th {
  background: #f9fafb;
  color: #6b7280;
  font-weight: 500;
  font-size: 12px;
  position: sticky;
  top: 0;
}
.data-table tbody tr:hover { background: #f9fafb; }
.data-table tfoot td {
  background: #f9fafb;
  border-top: 2px solid #e5e7eb;
  border-bottom: none;
}
.data-table .row-solved   td { background: #f0fdf4; }
.data-table .row-pending  td { background: #fefce8; }
.data-table .row-failed   td { background: #fef2f2; }

/* === 未达标折叠区 === */
.unsolved-card { padding-bottom: 4px; }
.unsolved-block {
  border-top: 1px solid #f3f4f6;
  padding: 0;
}
.unsolved-block summary {
  cursor: pointer;
  list-style: none;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  user-select: none;
}
.unsolved-block summary::-webkit-details-marker { display: none; }
.unsolved-block summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  color: #6b7280;
  font-size: 11px;
  transition: transform .15s;
}
.unsolved-block[open] > summary::before { transform: rotate(90deg); }
.unsolved-block summary:hover { background: #f9fafb; }
.unsolved-block .table-wrap { padding-top: 0; }

/* === 数据来源 === */
.source-card { padding-bottom: 16px; }
.source-list {
  margin: 8px 18px 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}
.source-list > div {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 12px;
  font-size: 13px;
  padding: 4px 0;
}
.source-list dt { color: #374151; font-weight: 500; }
.source-list dd { margin: 0; color: #6b7280; }
.source-note {
  margin: 12px 18px 0;
  padding: 10px 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  font-size: 12px;
  color: #92400e;
}
.source-note.muted {
  background: #f9fafb;
  border-color: #e5e7eb;
  color: #4b5563;
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1f2937;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  transition: all .25s;
  pointer-events: none;
  z-index: 200;
  max-width: 90vw;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: #15803d; }
.toast.error   { background: #b91c1c; }

/* === 响应式 === */
@media (max-width: 880px) {
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar-inner { flex-wrap: wrap; }
  .container { padding: 16px 14px 32px; }
  .source-list > div { grid-template-columns: 1fr; gap: 2px; }
}
