:root {
  --bg: #eef2f4;
  --panel: #ffffff;
  --ink: #182026;
  --muted: #60707a;
  --line: #d9e1e5;
  --teal: #168a80;
  --green: #3f8f52;
  --amber: #c78516;
  --red: #c3493d;
  --cyan: #2c7fa3;
  --leaf: #6b8f2f;
  --shadow: 0 16px 36px rgba(24, 32, 38, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

.dashboard {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px;
  overflow-x: hidden;
}

.topbar,
.section-head,
.status-strip,
.chart-legend,
.threshold-actions,
.threshold-control,
.threshold-item,
.category-head,
.category-tags {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 18px;
  padding: 16px 0 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(25px, 3vw, 38px);
  line-height: 1.15;
}

h2 {
  font-size: 18px;
}

.status-strip {
  flex: 0 0 auto;
  gap: 10px;
  min-width: 0;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  font-size: 14px;
  box-shadow: 0 10px 24px rgba(24, 32, 38, 0.06);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(63, 143, 82, 0.14);
}

.status-dot[data-status="connecting"] {
  background: var(--amber);
  box-shadow: 0 0 0 5px rgba(199, 133, 22, 0.16);
}

.status-dot[data-status="offline"] {
  background: var(--red);
  box-shadow: 0 0 0 5px rgba(195, 73, 61, 0.14);
}

.status-dot[data-status="demo"] {
  background: var(--cyan);
  box-shadow: 0 0 0 5px rgba(44, 127, 163, 0.14);
}

.divider {
  width: 1px;
  height: 16px;
  background: var(--line);
}

.page-section,
.trend-panel,
.warning-band,
.threshold-band,
.raw-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.page-section {
  margin-top: 18px;
  padding: 18px;
  min-width: 0;
}

.topbar + .overview {
  margin-top: 0;
}

.overview {
  display: grid;
  grid-template-columns: minmax(240px, 0.22fr) minmax(0, 0.78fr);
  gap: 18px;
  align-items: stretch;
  min-width: 0;
}

.risk-panel {
  display: grid;
  align-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 182px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafb;
}

.risk-label,
.sample-tag,
.metric-name,
.metric-state,
.threshold-item span,
.warning-time,
.category-title,
.category-state,
.category-card p,
.category-tags span {
  color: var(--muted);
  font-size: 13px;
}

.risk-panel strong {
  font-size: 30px;
  line-height: 1;
}

.risk-panel.is-warning strong {
  color: var(--amber);
}

.risk-panel.is-danger strong {
  color: var(--red);
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.category-card {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
  min-width: 0;
  min-height: 182px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.category-head {
  justify-content: space-between;
  gap: 10px;
}

.category-title {
  min-width: 0;
  font-weight: 700;
}

.category-state {
  flex: 0 0 auto;
  max-width: 100%;
  min-height: 25px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(63, 143, 82, 0.12);
  color: var(--green);
  font-weight: 700;
  white-space: nowrap;
}

.category-card strong {
  font-size: 25px;
  line-height: 1.1;
}

.category-card p {
  margin: 0;
  line-height: 1.5;
}

.category-tags {
  gap: 6px;
  flex-wrap: wrap;
}

.category-tags span {
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #edf3f4;
}

.category-card.is-warning {
  border-color: rgba(199, 133, 22, 0.42);
}

.category-card.is-warning .category-state {
  background: rgba(199, 133, 22, 0.12);
  color: var(--amber);
}

.category-card.is-danger {
  border-color: rgba(195, 73, 61, 0.45);
}

.category-card.is-danger .category-state {
  background: rgba(195, 73, 61, 0.12);
  color: var(--red);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.metric-card {
  display: grid;
  align-content: space-between;
  min-width: 0;
  min-height: 150px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 24px rgba(24, 32, 38, 0.05);
}

.metric-card strong {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  font-size: clamp(25px, 2.8vw, 36px);
  line-height: 1.05;
}

.metric-card small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.metric-state {
  width: fit-content;
  min-height: 25px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(63, 143, 82, 0.12);
  color: var(--green);
  font-weight: 700;
}

.metric-card.is-warning {
  border-color: rgba(199, 133, 22, 0.42);
}

.metric-card.is-warning .metric-state {
  background: rgba(199, 133, 22, 0.12);
  color: var(--amber);
}

.metric-card.is-danger {
  border-color: rgba(195, 73, 61, 0.45);
}

.metric-card.is-danger .metric-state {
  background: rgba(195, 73, 61, 0.12);
  color: var(--red);
}

.section-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.sample-tag {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7fafb;
  white-space: nowrap;
}

.chart {
  position: relative;
  height: 286px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(to right, rgba(217, 225, 229, 0.72) 1px, transparent 1px) 0 0 / 12.5% 100%,
    linear-gradient(to bottom, rgba(217, 225, 229, 0.72) 1px, transparent 1px) 0 0 / 100% 25%,
    #fbfcfd;
}

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

.chart-legend {
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.chart-legend i {
  display: inline-block;
  width: 24px;
  height: 3px;
  margin-right: 7px;
  border-radius: 999px;
  vertical-align: middle;
}

.line-temp {
  background: var(--red);
}

.line-humi {
  background: var(--teal);
}

.line-wind {
  background: var(--cyan);
}

.line-dust {
  background: var(--amber);
}

.warning-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.warning-item {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 13px;
  border-left: 4px solid var(--green);
  border-radius: 8px;
  background: #f7fafb;
}

.warning-item strong {
  font-size: 15px;
}

.warning-item.is-warning {
  border-left-color: var(--amber);
  background: rgba(199, 133, 22, 0.08);
}

.warning-item.is-danger {
  border-left-color: var(--red);
  background: rgba(195, 73, 61, 0.08);
}

.threshold-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

.threshold-actions {
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.threshold-actions button {
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

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

#thresholdPublishState {
  color: var(--muted);
  font-size: 13px;
}

#thresholdPublishState[data-status="pending"] {
  color: var(--amber);
}

#thresholdPublishState[data-status="success"] {
  color: var(--green);
}

#thresholdPublishState[data-status="error"] {
  color: var(--red);
}

.threshold-item {
  align-items: flex-start;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  min-height: 62px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafb;
}

.threshold-item label {
  color: var(--muted);
  font-size: 13px;
}

.threshold-control {
  width: 100%;
  gap: 8px;
}

.threshold-control input {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
}

.threshold-control span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1240px) {
  .overview {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 980px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 760px) {
  .dashboard {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-strip {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .divider {
    display: none;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .threshold-actions {
    width: 100%;
    justify-content: space-between;
  }

  .warning-list,
  .threshold-grid {
    grid-template-columns: 1fr;
  }

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

  .category-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .category-state {
    align-self: flex-start;
  }

  .category-card {
    min-height: 158px;
    padding: 13px;
  }

  .category-card strong {
    font-size: 22px;
  }

  .category-card p,
  .category-tags span {
    font-size: 12px;
  }

  .metric-card {
    min-height: 124px;
    padding: 13px;
  }

  .metric-card strong {
    font-size: 30px;
  }

  .chart {
    height: 230px;
  }
}

@media (max-width: 440px) {
  .dashboard {
    padding: 12px 10px;
  }

  .page-section {
    padding: 14px;
  }

  .status-strip {
    padding: 8px 10px;
    font-size: 13px;
  }

  h1 {
    font-size: 24px;
  }

  .risk-panel,
  .metric-card {
    padding: 14px;
  }

  .category-grid,
  .summary-grid {
    gap: 10px;
  }

  .category-card {
    padding: 12px;
  }

  .category-card strong {
    font-size: 20px;
  }

  .category-state,
  .category-tags span,
  .metric-state {
    padding: 4px 7px;
    font-size: 12px;
  }

  .metric-card strong {
    font-size: 27px;
  }

  .metric-card small {
    font-size: 11px;
  }
}
