:root {
  color-scheme: light;
  --page: #f4f6f5;
  --surface: #ffffff;
  --ink: #151b1a;
  --muted: #68716f;
  --line: #dce2e0;
  --line-strong: #c5cfcc;
  --accent: #147d68;
  --accent-soft: #e5f3ef;
  --good: #167a54;
  --good-soft: #e7f4ed;
  --watch: #a26408;
  --watch-soft: #fff1d8;
  --high: #b53a32;
  --high-soft: #fbe9e7;
  --chart: #147d68;
  --chart-fill: rgba(20, 125, 104, 0.09);
  --reference: rgba(44, 145, 101, 0.09);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  color: var(--ink);
  background: var(--page);
  letter-spacing: 0;
}

button {
  font: inherit;
}

main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 36px 28px 64px;
}

.masthead,
.section-heading,
.history-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.masthead {
  align-items: center;
  min-height: 74px;
  margin-bottom: 42px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
}

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

h1 {
  margin-bottom: 0;
  font-size: 34px;
  line-height: 1;
  font-weight: 820;
}

h2 {
  margin-bottom: 5px;
  font-size: 20px;
  line-height: 1.25;
}

.section-heading p,
.history-toolbar p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.sync {
  display: flex;
  align-items: center;
  gap: 14px;
}

.freshness {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #9da6a4;
  box-shadow: 0 0 0 4px rgba(157, 166, 164, 0.14);
}

.status-dot.live {
  background: var(--good);
  box-shadow: 0 0 0 4px rgba(22, 122, 84, 0.13);
}

.status-dot.stale {
  background: var(--watch);
  box-shadow: 0 0 0 4px rgba(162, 100, 8, 0.13);
}

.refresh-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.refresh-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.refresh-button:active {
  transform: translateY(1px);
}

.refresh-button.loading span:first-child {
  animation: rotate 700ms linear infinite;
}

.current-section {
  margin-bottom: 54px;
}

.device-name {
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.metric {
  min-width: 0;
  min-height: 142px;
  padding: 17px 16px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  animation: metric-in 360ms both;
}

.metric:nth-child(2) {
  animation-delay: 35ms;
}

.metric:nth-child(3) {
  animation-delay: 70ms;
}

.metric:nth-child(4) {
  animation-delay: 105ms;
}

.metric:nth-child(5) {
  animation-delay: 140ms;
}

.metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.metric-state {
  padding: 3px 6px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 750;
  white-space: nowrap;
}

.metric-state.good {
  color: var(--good);
  background: var(--good-soft);
}

.metric-state.watch {
  color: var(--watch);
  background: var(--watch-soft);
}

.metric-state.high {
  color: var(--high);
  background: var(--high-soft);
}

.metric-value {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 5px;
  margin-top: 18px;
}

.metric-number {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 29px;
  line-height: 1;
  font-weight: 790;
  font-variant-numeric: tabular-nums;
}

.metric-unit {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.metric-reference {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.history-section {
  padding-top: 26px;
  border-top: 1px solid var(--line-strong);
}

.history-toolbar {
  align-items: flex-start;
  margin-bottom: 26px;
}

.range-control {
  display: grid;
  grid-template-columns: repeat(4, auto);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e9edec;
}

.range-button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.range-button.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(20, 27, 26, 0.1);
}

.chart-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 40px;
}

.chart-section {
  min-width: 0;
  padding: 24px 0 28px;
  border-bottom: 1px solid var(--line);
}

.chart-section:last-child {
  grid-column: 1 / -1;
}

.chart-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.chart-title {
  margin: 0;
  font-size: 14px;
  font-weight: 720;
}

.chart-latest {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chart-wrap {
  position: relative;
  height: 218px;
  overflow: hidden;
}

.chart-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: pan-y;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  top: 10px;
  left: 10px;
  display: none;
  min-width: 94px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 6px 18px rgba(20, 27, 26, 0.09);
  font-size: 11px;
  line-height: 1.45;
  pointer-events: none;
}

.chart-tooltip strong {
  display: block;
  font-size: 12px;
}

.empty-state {
  padding: 64px 0;
  color: var(--muted);
  text-align: center;
}

.empty-state strong,
.empty-state span {
  display: block;
}

.empty-state strong {
  margin-bottom: 7px;
  color: var(--ink);
  font-size: 15px;
}

.empty-state span {
  font-size: 12px;
}

.toast {
  position: fixed;
  z-index: 10;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  max-width: min(360px, calc(100vw - 36px));
  padding: 10px 13px;
  border-radius: 7px;
  color: #fff;
  background: #242b29;
  box-shadow: 0 8px 30px rgba(20, 27, 26, 0.18);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

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

@keyframes metric-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 820px) {
  main {
    padding: 28px 20px 52px;
  }

  .metric-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric:nth-child(4),
  .metric:nth-child(5) {
    min-height: 124px;
  }

  .chart-list {
    grid-template-columns: 1fr;
  }

  .chart-section:last-child {
    grid-column: auto;
  }
}

@media (max-width: 600px) {
  main {
    padding:
      calc(22px + env(safe-area-inset-top))
      15px
      calc(42px + env(safe-area-inset-bottom));
  }

  .masthead {
    min-height: 54px;
    margin-bottom: 32px;
  }

  h1 {
    font-size: 29px;
  }

  .sync {
    gap: 9px;
  }

  .freshness {
    max-width: 102px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .refresh-button {
    width: 38px;
    padding: 0;
  }

  .refresh-button span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .section-heading {
    align-items: flex-start;
  }

  .device-name {
    max-width: 42%;
    padding-top: 4px;
  }

  .metric-strip {
    display: flex;
    gap: 8px;
    margin-right: -15px;
    padding-right: 15px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .metric-strip::-webkit-scrollbar {
    display: none;
  }

  .metric {
    width: 145px;
    min-width: 145px;
    min-height: 132px;
    padding: 15px 14px;
    scroll-snap-align: start;
  }

  .metric-number {
    font-size: 26px;
  }

  .current-section {
    margin-bottom: 40px;
  }

  .history-toolbar {
    display: block;
    margin-bottom: 14px;
  }

  .range-control {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-top: 18px;
  }

  .range-button {
    padding: 0 7px;
    font-size: 11px;
  }

  .chart-section {
    padding: 20px 0 24px;
  }

  .chart-wrap {
    height: 205px;
  }
}

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