:root {
  --font-sans: 'Source Han Sans SC', 'Noto Sans SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --bg: #eef3fb;
  --panel: rgba(255, 255, 255, 0.94);
  --line: #d3ddee;
  --text: #12213b;
  --text-soft: #607190;
  --primary: #1143b8;
  --primary-strong: #0a2d77;
  --danger: #bf2132;
  --warning: #b06814;
  --shadow: 0 18px 38px rgba(17, 43, 96, 0.1);
  --radius: 20px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(17, 67, 184, 0.14), transparent 26%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 48%, #dde6f6 100%);
  -webkit-tap-highlight-color: rgba(17, 67, 184, 0.12);
}

.history-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.24) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.24) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.9), transparent 80%);
}

.skip-link {
  position: absolute;
  top: -999px;
  left: 1rem;
  padding: 0.6rem 0.9rem;
  border-radius: 999px;
  background: #fff;
  color: var(--primary-strong);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.skip-link:focus-visible {
  top: 1rem;
}

.history-header,
.history-dashboard {
  width: min(1440px, calc(100% - 2rem));
  margin: 0 auto;
}

.history-header {
  margin-top: 1.25rem;
  padding: 1.1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(245, 249, 255, 0.86));
  border: 1px solid rgba(188, 201, 223, 0.72);
  box-shadow: var(--shadow);
}

.history-kicker {
  margin: 0 0 0.2rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--primary);
}

.history-header h1,
.panel h2 {
  margin: 0;
  text-wrap: balance;
}

.history-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.nav-link,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0.65rem 1rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease;
}

.nav-link:hover,
.btn:hover {
  transform: translateY(-1px);
}

.nav-link-secondary,
.btn-secondary {
  background: rgba(255, 255, 255, 0.84);
  color: var(--primary-strong);
  border-color: rgba(17, 67, 184, 0.18);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #2e67ea);
  color: #fff;
}

.nav-link:focus-visible,
.btn:focus-visible,
.field input:focus-visible,
.field select:focus-visible {
  outline: 3px solid rgba(17, 67, 184, 0.2);
  outline-offset: 2px;
}

.history-dashboard {
  margin-bottom: 1.5rem;
  padding-block: 1rem 1.5rem;
  display: grid;
  gap: 1rem;
}

#history-main,
#event-table-title {
  scroll-margin-top: 1rem;
}

.panel {
  min-width: 0;
  border-radius: var(--radius);
  border: 1px solid rgba(188, 201, 223, 0.76);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  padding: 1rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 0.9rem;
}

.panel-head-tight {
  margin-bottom: 0.75rem;
}

.panel-meta,
.query-status {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.9rem;
}

.filter-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.85rem;
  align-items: end;
}

.field {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
}

.field span {
  font-size: 0.78rem;
  color: var(--text-soft);
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  font: inherit;
  padding: 0.72rem 0.8rem;
}

.filter-actions {
  display: flex;
  gap: 0.65rem;
  justify-content: end;
  align-items: center;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.metric-card {
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.96), rgba(239, 245, 255, 0.9));
}

.metric-label {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.metric-value {
  margin: 0.55rem 0 0.2rem;
  font-size: clamp(1.55rem, 2vw, 2.15rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.metric-subline {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.88rem;
}

.table-panel {
  overflow: hidden;
}

.table-wrap {
  overflow: auto;
  border-radius: 18px;
  border: 1px solid rgba(188, 201, 223, 0.72);
  background: rgba(255, 255, 255, 0.92);
  content-visibility: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  padding: 0.8rem 0.75rem;
  background: #f2f6fd;
  color: var(--text-soft);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

tbody td {
  padding: 0.8rem 0.75rem;
  border-top: 1px solid rgba(208, 218, 234, 0.72);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

.route-progress-cell {
  min-width: 160px;
}

.route-progress {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 142px;
}

.route-progress-track {
  position: relative;
  width: 92px;
  height: 9px;
  border-radius: 999px;
  background: #deebff;
  overflow: hidden;
}

.route-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(90deg, #2f66de 0%, #1f4fbf 100%);
  border-radius: 999px;
}

.route-progress-text {
  min-width: 3.4rem;
  font-size: 0.76rem;
  color: #1a3f98;
  font-variant-numeric: tabular-nums;
}

.route-progress-na {
  font-size: 0.82rem;
  color: #64748b;
}

tbody tr:hover {
  background: rgba(17, 67, 184, 0.04);
}

.row-meta {
  color: var(--text);
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 4.8rem;
  padding: 0.28rem 0.62rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.badge-hard {
  color: #fff;
  background: linear-gradient(135deg, #d63247, var(--danger));
}

.badge-high {
  color: #7b4b0e;
  background: rgba(176, 104, 20, 0.12);
  border: 1px solid rgba(176, 104, 20, 0.22);
}

.badge-na {
  color: var(--text-soft);
  background: rgba(96, 113, 144, 0.1);
}

@media (max-width: 1180px) {
  .filter-form {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .history-header {
    align-items: start;
    flex-direction: column;
  }

  .filter-form,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .filter-actions {
    justify-content: stretch;
    flex-direction: column;
  }

  .filter-actions .btn {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
