:root {
  --bg: #f3f5fa;
  --bg-accent: #e7edfb;
  --card: #ffffff;
  --hover: #f8fafc;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #94a3b8;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --accent-soft: #eff6ff;
  --today-bg: #eff6ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 14px 34px -16px rgba(15, 23, 42, 0.16);
  --shadow-soft: 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 16px;
  --radius-sm: 10px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system,
    sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --bg-accent: #101b33;
    --card: #111a2c;
    --hover: rgba(148, 163, 184, 0.07);
    --text: #e2e8f0;
    --text-2: #a9b6c9;
    --muted: #64748b;
    --line: #1e293b;
    --line-strong: #334155;
    --accent: #60a5fa;
    --accent-2: #3b82f6;
    --accent-soft: rgba(59, 130, 246, 0.14);
    --today-bg: rgba(59, 130, 246, 0.13);
    --green: #34d399;
    --green-soft: rgba(16, 185, 129, 0.14);
    --red: #f87171;
    --red-soft: rgba(239, 68, 68, 0.13);
    --amber: #fbbf24;
    --amber-soft: rgba(245, 158, 11, 0.13);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 18px 40px -20px rgba(0, 0, 0, 0.7);
    --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 8% -8%, var(--bg-accent), transparent 62%),
    radial-gradient(900px 480px at 100% 0%, var(--accent-soft), transparent 58%),
    var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.modal-open {
  overflow: hidden;
}

button,
input {
  font-family: inherit;
}

/* ---------- 顶部 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 90%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 13px;
  color: #fff;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 22px -10px rgba(37, 99, 235, 0.85);
}

.brand-text h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
}

.controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.field-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-transform: uppercase;
}

input[type="date"],
input[type="search"] {
  appearance: none;
  -webkit-appearance: none;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

input[type="date"] {
  min-width: 142px;
}

input[type="search"] {
  width: 210px;
}

input[type="date"]:focus,
input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition:
    transform 0.12s ease,
    background 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 22px -12px rgba(37, 99, 235, 0.9);
}

.btn.primary:hover {
  filter: brightness(1.05);
}

.btn.ghost {
  color: var(--text-2);
  background: var(--card);
  border-color: var(--line);
}

.btn.ghost:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.btn:disabled {
  cursor: progress;
  opacity: 0.65;
}

.btn.is-spinning svg {
  animation: spin 0.9s linear infinite;
}

.health {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text-2);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--shadow-soft);
}

.health-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px var(--bg-accent);
}

.health.ok .health-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-soft);
}

.health.bad {
  color: var(--red);
  border-color: var(--red-soft);
  background: var(--red-soft);
}

.health.bad .health-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.16);
  animation: pulse 1.6s ease-in-out infinite;
}

.health.pending .health-dot {
  animation: pulse 1.6s ease-in-out infinite;
}

/* ---------- 页面与标签 ---------- */

.page {
  width: 100%;
  max-width: 1580px;
  margin: 0 auto;
  padding: 22px 28px 64px;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 5px;
  margin-bottom: 18px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--line);
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 20px;
  border-radius: 999px;
  cursor: pointer;
  transition:
    background 0.15s ease,
    color 0.15s ease;
}

.tab:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.tab.is-active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 18px -10px rgba(37, 99, 235, 0.9);
}

.panel {
  display: none;
  animation: fade-in 0.2s ease;
}

.panel.is-active {
  display: block;
}

.panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0.01em;
}

.hint {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.stats-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text-2);
  font-size: 12px;
  box-shadow: var(--shadow-soft);
}

.chip b {
  color: var(--text);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 11.5px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend b {
  color: var(--text-2);
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background: var(--today-bg);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}

/* ---------- 表格 ---------- */

.table-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-scroll {
  overflow: auto;
  max-height: calc(100vh - 268px);
  min-height: 180px;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--card);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--line-strong);
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover td {
  background: var(--hover);
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table .col-rank {
  width: 64px;
  text-align: center;
}

.summary-table {
  min-width: 980px;
}

.summary-table td.num {
  font-size: 13.5px;
  font-weight: 600;
}

th.sortable {
  position: relative;
  padding-right: 26px;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease;
}

th.sortable::after {
  content: "↕";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  opacity: 0.25;
}

th.sortable:hover {
  color: var(--accent);
}

th.sortable.sorted {
  color: var(--accent);
}

th.sortable.sorted[data-order="asc"]::after {
  content: "▲";
  opacity: 1;
  font-size: 9px;
}

th.sortable.sorted[data-order="desc"]::after {
  content: "▼";
  opacity: 1;
  font-size: 9px;
}

.rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.rank-1 {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #fff;
  box-shadow: 0 6px 14px -8px rgba(245, 158, 11, 0.9);
}

.rank-2 {
  background: linear-gradient(135deg, #cbd5e1, #94a3b8);
  color: #fff;
}

.rank-3 {
  background: linear-gradient(135deg, #d6a17a, #b97850);
  color: #fff;
}

.plate-link {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 2px 5px;
  margin: -2px -5px;
  border-radius: 7px;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.12s ease;
}

.plate-link:hover {
  background: var(--accent-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.zero,
.muted {
  color: var(--muted);
  font-weight: 400;
}

.avg {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.avg.is-missing {
  color: var(--muted);
  font-weight: 400;
}

.time-cell {
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.count {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---------- 每日矩阵 ---------- */

.daily-table {
  min-width: max-content;
  font-size: 12.5px;
}

.daily-table th,
.daily-table td {
  padding: 9px 10px;
  text-align: center;
}

.daily-table th:first-child,
.daily-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 104px;
  text-align: left;
  background: var(--card);
  box-shadow: 1px 0 0 var(--line);
}

.daily-table thead th:first-child {
  z-index: 4;
}

.daily-table tbody tr:hover td:first-child {
  background: var(--hover);
}

.daily-table th.date-col {
  min-width: 54px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.daily-table th.date-col em {
  display: block;
  margin-top: 1px;
  font-style: normal;
  font-size: 9.5px;
  font-weight: 500;
  color: var(--muted);
}

.daily-table td.date-cell {
  width: 54px;
  font-variant-numeric: tabular-nums;
}

.daily-table .is-today {
  background: var(--today-bg) !important;
}

.daily-table th.is-today {
  color: var(--accent);
}

.daily-table td.is-today .count {
  color: var(--accent);
}

.daily-table tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: var(--card);
  border-top: 2px solid var(--line-strong);
  border-bottom: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.daily-table tfoot td:first-child {
  z-index: 3;
}

.daily-table tfoot td.is-today {
  background: var(--today-bg) !important;
}

/* ---------- 排号明细 ---------- */

.cycles-table {
  min-width: 1040px;
}

.cycles-table tr.is-invalid td {
  background: var(--red-soft);
}

.cycles-table tr.is-invalid:hover td {
  background: color-mix(in srgb, var(--red-soft) 70%, var(--hover));
}

.status {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.status.ok {
  color: var(--green);
  background: var(--green-soft);
}

.status.bad {
  color: var(--red);
  background: var(--red-soft);
}

.bad-text {
  color: var(--red);
  font-weight: 700;
}

.note-cell {
  max-width: 260px;
  color: var(--text-2);
  white-space: normal;
}

.reason {
  color: var(--red);
}

/* ---------- 空状态 ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 58px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
}

.empty strong {
  color: var(--text-2);
  font-size: 14px;
}

/* ---------- 弹窗 ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: fade-in 0.16s ease;
}

.modal-card {
  display: flex;
  flex-direction: column;
  width: min(1080px, 100%);
  max-height: 88vh;
  border-radius: 20px;
  background: var(--card);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.65);
  overflow: hidden;
  animation: pop-in 0.18s ease;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.03em;
}

.modal-close {
  width: 34px;
  height: 34px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text-2);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--red);
  border-color: var(--red);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 20px 24px 28px;
  overflow: auto;
}

.modal-section h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 13.5px;
  color: var(--text-2);
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

.mini-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.mini-table {
  width: 100%;
  min-width: 640px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
}

.mini-table th,
.mini-table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.mini-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--card);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 700;
}

.mini-table tr:last-child td {
  border-bottom: 0;
}

.mini-table tbody tr:hover td {
  background: var(--hover);
}

.mini-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.modal-loading {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- 进度条 / Toast ---------- */

.progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 3px;
  overflow: hidden;
  background: transparent;
}

.progress::before {
  content: "";
  display: block;
  width: 42%;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: progress-slide 1s ease-in-out infinite;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 90;
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 18px;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.6);
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  background: var(--red);
}

.toast.warn {
  background: var(--amber);
}

/* ---------- 动画 ---------- */

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

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes progress-slide {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(340%);
  }
}

/* ---------- 响应式 ---------- */

@media (max-width: 1080px) {
  .topbar {
    flex-wrap: wrap;
  }

  .topbar-right {
    width: 100%;
    align-items: stretch;
  }

  .controls {
    justify-content: flex-start;
  }

  .health {
    align-self: flex-start;
  }

  .table-scroll {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .topbar {
    gap: 12px;
    padding: 12px 16px;
  }

  .brand-text p {
    display: none;
  }

  .page {
    padding: 16px 14px 48px;
  }

  .controls {
    gap: 8px;
  }

  .field-search {
    flex: 1 1 160px;
  }

  input[type="search"] {
    width: 100%;
  }

  .field {
    flex: 1 1 0;
  }

  .field-search {
    flex: 2 1 180px;
  }

  .btn {
    flex: 1 1 auto;
  }

  .tabs {
    display: flex;
    width: 100%;
  }

  .tab {
    flex: 1;
    padding: 8px 10px;
  }

  .panel-head {
    align-items: flex-start;
  }

  .stats-chips {
    width: 100%;
  }

  .health {
    white-space: normal;
    line-height: 1.35;
  }

  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal-card {
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
  }

  .modal-head,
  .modal-body {
    padding-left: 16px;
    padding-right: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
