:root {
  color-scheme: light;
  --ink: #161a1d;
  --muted: #687077;
  --line: #dfe3e5;
  --paper: #f5f6f3;
  --surface: #ffffff;
  --lime: #b8ed47;
  --lime-deep: #769f1e;
  --teal: #147d74;
  --coral: #e86f51;
  --blue: #3478c5;
  --shadow: 0 8px 24px rgba(23, 29, 32, 0.07);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(20, 125, 116, 0.2);
  outline-offset: 2px;
}

.section-inner {
  width: min(1440px, calc(100% - 64px));
  margin-inline: auto;
}

.app-header {
  height: 68px;
  padding: 0 max(32px, calc((100% - 1440px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #f9fbf6;
  background: #171b1d;
  border-bottom: 1px solid #303639;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #111512;
  background: var(--lime);
  border-radius: 6px;
}

.brand-mark svg {
  width: 21px;
  height: 21px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
  line-height: 1.25;
}

.brand small {
  margin-top: 3px;
  color: #939b9e;
  font-size: 9px;
  font-weight: 700;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #c7cdca;
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--lime);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(184, 237, 71, 0.12);
}

.query-band {
  padding: 38px 0 34px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.query-layout {
  display: grid;
  grid-template-columns: minmax(250px, 0.8fr) minmax(640px, 1.7fr);
  align-items: end;
  gap: 52px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 800;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 5px;
  font-size: 30px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.3;
}

.page-heading > p:last-child {
  margin-bottom: 0;
  color: var(--muted);
}

.channel-description {
  margin: 4px 0 0;
  color: #8a9295;
  font-size: 11px;
}

.query-form {
  min-width: 0;
  display: grid;
  gap: 16px;
}

.date-fields {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 24px minmax(220px, 1fr);
  align-items: end;
  gap: 12px;
}

.date-fields label {
  min-width: 0;
  display: grid;
  gap: 6px;
  color: #454b4e;
  font-size: 12px;
  font-weight: 700;
}

.date-fields input {
  min-width: 0;
  width: 100%;
  min-height: 42px;
  padding: 8px 11px;
  color: var(--ink);
  background: #fafbf9;
  border: 1px solid #cfd5d7;
  border-radius: 5px;
}

.date-arrow {
  width: 24px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #8b9296;
}

.date-arrow svg {
  width: 17px;
}

.form-actions,
.presets,
.record-actions,
.legend {
  display: flex;
  align-items: center;
}

.form-actions {
  justify-content: space-between;
  gap: 18px;
}

.presets {
  min-width: 0;
  overflow: hidden;
  border: 1px solid #d4d9db;
  border-radius: 5px;
}

.preset {
  min-height: 34px;
  padding: 0 15px;
  color: #60676b;
  background: #fff;
  border: 0;
  border-right: 1px solid #d4d9db;
  font-size: 12px;
}

.preset:last-child {
  border-right: 0;
}

.preset:hover,
.preset.active {
  color: #fff;
  background: #283034;
}

.primary-button,
.secondary-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 18px;
  border-radius: 5px;
  font-weight: 800;
}

.primary-button {
  color: #151915;
  background: var(--lime);
  border: 1px solid #a7d93c;
}

.primary-button:hover {
  background: #c5f363;
}

.primary-button svg,
.secondary-button svg {
  width: 16px;
  height: 16px;
}

.notice {
  margin-top: 20px;
  padding: 12px 15px;
  color: #8d3426;
  background: #fff1ed;
  border: 1px solid #f1b6a8;
  border-radius: 5px;
}

.summary-section {
  padding-block: 26px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.metric {
  min-height: 145px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--ink);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.metric-total { border-top-color: var(--teal); }
.metric-peak { border-top-color: var(--coral); }
.metric-average { border-top-color: var(--blue); }
.metric-count { border-top-color: var(--lime-deep); }

.metric-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #5d6569;
  font-size: 12px;
  font-weight: 700;
}

.metric-topline svg {
  width: 18px;
  height: 18px;
}

.metric-total .metric-topline svg { color: var(--teal); }
.metric-peak .metric-topline svg { color: var(--coral); }
.metric-average .metric-topline svg { color: var(--blue); }
.metric-count .metric-topline svg { color: var(--lime-deep); }

.metric-value {
  min-height: 54px;
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-top: 10px;
}

.metric-value strong {
  overflow: hidden;
  font-size: 29px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-value span {
  color: #737b7f;
  font-size: 11px;
  font-weight: 700;
}

.metric p {
  margin: 4px 0 0;
  overflow: hidden;
  color: #81898c;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-section {
  padding: 28px 0 32px;
  background: var(--surface);
  border-block: 1px solid var(--line);
}

.section-heading {
  min-height: 50px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.legend {
  gap: 20px;
  color: #687075;
  font-size: 11px;
}

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

.legend-bar {
  width: 9px;
  height: 9px;
  background: var(--teal);
}

.legend-line {
  width: 16px;
  height: 2px;
  background: var(--coral);
}

.chart {
  position: relative;
  height: 300px;
  margin-top: 14px;
}

.chart svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.chart-empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: #8a9295;
  background: repeating-linear-gradient(0deg, transparent, transparent 58px, #edf0ef 59px);
  border-bottom: 1px solid #dfe4e3;
}

.grid-line {
  stroke: #e7eae9;
  stroke-width: 1;
}

.axis-label {
  fill: #828a8e;
  font-size: 10px;
}

.traffic-bar {
  fill: var(--teal);
  opacity: 0.88;
}

.traffic-bar:hover {
  fill: #0d675f;
  opacity: 1;
}

.peak-line {
  fill: none;
  stroke: var(--coral);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.peak-point {
  fill: #fff;
  stroke: var(--coral);
  stroke-width: 2;
}

.chart-tooltip {
  position: absolute;
  z-index: 3;
  min-width: 144px;
  padding: 9px 11px;
  color: #fff;
  background: #1d2225;
  border-radius: 4px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
}

.chart-tooltip strong,
.chart-tooltip span {
  display: block;
}

.chart-tooltip strong {
  margin-bottom: 4px;
  font-size: 11px;
}

.chart-tooltip span {
  color: #d7ddda;
  font-size: 10px;
}

.records-section {
  padding-block: 34px 44px;
}

.records-heading {
  align-items: center;
}

.record-actions {
  gap: 16px;
}

#updated-at {
  color: #81898d;
  font-size: 11px;
}

.secondary-button {
  min-height: 36px;
  color: #333a3d;
  background: #fff;
  border: 1px solid #cbd1d3;
  font-size: 12px;
}

.secondary-button:hover:not(:disabled) {
  border-color: #8f999d;
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.table-wrap {
  margin-top: 17px;
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

th,
td {
  height: 48px;
  padding: 0 17px;
  border-bottom: 1px solid #e9eceb;
  text-align: left;
  white-space: nowrap;
}

th {
  height: 43px;
  color: #697175;
  background: #f8f9f7;
  font-size: 11px;
  font-weight: 800;
}

th span {
  color: #a0a7aa;
  font-weight: 500;
}

td {
  color: #343a3d;
  font-size: 12px;
}

tbody tr:hover td {
  background: #f8faf6;
}

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

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

.date-cell {
  font-weight: 800;
}

.domain-cell {
  color: #596268;
  font-size: 11px;
}

.empty-row td {
  height: 160px;
  color: #899194;
  text-align: center;
}

footer {
  padding: 18px 0;
  color: #91999c;
  background: #171b1d;
  font-size: 10px;
}

footer .section-inner {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(244, 246, 243, 0.72);
  backdrop-filter: blur(3px);
}

.loading-overlay[hidden] {
  display: none;
}

.loading-content {
  min-width: 210px;
  padding: 26px;
  display: grid;
  justify-items: center;
  color: #fff;
  background: #1c2123;
  border-radius: 6px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
}

.loading-content strong {
  margin-top: 14px;
  font-size: 13px;
}

.loading-content small {
  margin-top: 4px;
  color: #969fa2;
}

.loader {
  width: 30px;
  height: 30px;
  border: 3px solid #4d5659;
  border-top-color: var(--lime);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

@media (max-width: 980px) {
  .query-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
  }

  .summary-section {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .section-inner {
    width: min(100% - 28px, 1440px);
  }

  .app-header {
    height: 62px;
    padding-inline: 14px;
  }

  .brand strong {
    font-size: 14px;
  }

  .connection-status {
    font-size: 0;
  }

  .query-band {
    padding: 26px 0;
  }

  h1 {
    font-size: 26px;
  }

  .date-fields {
    grid-template-columns: minmax(0, 1fr);
  }

  .date-arrow {
    display: none;
  }

  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .presets {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .preset {
    min-width: 0;
    padding: 0 8px;
  }

  .primary-button {
    width: 100%;
  }

  .summary-section {
    grid-template-columns: 1fr;
    gap: 10px;
    padding-block: 16px;
  }

  .metric {
    min-height: 122px;
    padding: 16px;
  }

  .metric-value {
    min-height: 43px;
  }

  .metric-value strong {
    font-size: 25px;
  }

  .chart-section {
    padding-top: 24px;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .chart {
    height: 260px;
    margin-top: 8px;
    overflow-x: auto;
  }

  .chart svg {
    min-width: 640px;
  }

  .records-heading {
    align-items: stretch;
  }

  .record-actions {
    justify-content: space-between;
  }

  footer .section-inner {
    flex-direction: column;
    gap: 3px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loader {
    animation-duration: 1.5s;
  }
}
