:root {
  --bg: #f2f5f7;
  --card: #ffffff;
  --ink: #1f2a33;
  --muted: #6c7a86;
  --line: #d5dde4;
  --accent: #007a78;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 10%, #dceff0, transparent 40%), var(--bg);
}

.dashboard {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.8rem;
}

.dashboard-header h1 {
  margin: 0;
  font-size: 1.75rem;
}

.dashboard-header p {
  margin: 0;
  color: var(--muted);
}

.cards {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  margin-top: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.8rem 1rem;
  box-shadow: 0 4px 10px rgb(0 0 0 / 4%);
}

.card h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--muted);
}

.card p {
  margin: 0.3rem 0 0;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
}

.card-limit {
  display: block;
  min-height: 1.1rem;
  margin-top: 0.2rem;
  text-align: right;
  font-size: 0.85rem;
  color: var(--muted);
}

.card p.level-yellow,
td.level-yellow {
  color: #b7791f;
}

.card p.level-red,
td.level-red {
  color: #c62828;
}

.card p.level-blue,
td.level-blue {
  color: #1565c0;
}

td.level-yellow,
td.level-red,
td.level-blue {
  font-weight: 700;
}

#pollutant-thresholds-body input,
#range-thresholds-body input {
  width: 8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
}

.table-section {
  margin-top: 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.8rem;
}

.table-section h2 {
  margin: 0 0 0.7rem;
}

.table-wrapper {
  overflow-x: auto;
}

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

th,
td {
  text-align: center;
  border-bottom: 1px solid var(--line);
  padding: 0.55rem;
  white-space: nowrap;
}

th {
  background: #eef4f6;
}

.nodes-controls {
  display: flex;
  gap: 0.6rem;
  align-items: end;
  flex-wrap: wrap;
}

.nodes-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.85rem;
}

.nodes-controls input,
.nodes-controls select,
.nodes-form-grid input,
.nodes-form-grid select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  min-width: 140px;
}

.nodes-controls button,
.nodes-actions button,
#nodes-body button,
#sources-body button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6fafb;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
}

#sources-body button + button {
  margin-left: 0.35rem;
}

.sensor-picker {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.sensor-picker select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
}

.sensor-picker.hidden {
  display: none;
}

.nodes-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.55rem;
}

.nodes-actions {
  margin-top: 0.7rem;
  display: flex;
  gap: 0.5rem;
}

.nodes-message {
  min-height: 1.2rem;
  margin: 0.2rem 0 0.6rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.nodes-hint {
  margin: 0 0 0.6rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.nodes-tabs {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.nodes-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f6fafb;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}

.nodes-tab.is-active {
  background: #d9eef0;
  border-color: #9cc8ce;
}

.node-panel.hidden {
  display: none;
}

.nodes-form-grid label,
.nodes-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nodes-form-grid label[hidden] {
  display: none;
}

.taxonomy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.node-chart-panel {
  margin-top: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: #fff;
}

.node-chart-panel.hidden {
  display: none;
}

.node-chart-header {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.node-chart-header h3 {
  margin: 0;
  margin-right: auto;
}

.chart-metric-picks {
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.35rem;
}

.node-chart-svg {
  width: 100%;
  height: 320px;
  margin-top: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.node-chart-legend {
  margin-top: 0.55rem;
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.86rem;
  color: var(--muted);
}

.legend-item i {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 2px;
}

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

  .card p {
    font-size: 1.5rem;
  }
}
