:root {
  --bg: #f4f7f6;
  --panel: #ffffff;
  --text: #1d2526;
  --muted: #647173;
  --line: #d7e0de;
  --accent: #007f8f;
  --accent-dark: #005f6b;
  --green: #168a4a;
  --amber: #b7791f;
  --red: #b83232;
  --shadow: 0 8px 24px rgba(24, 38, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  background: #143436;
  color: #ffffff;
  border-bottom: 4px solid #2db8a0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.45rem;
  font-weight: 700;
}

h2 {
  font-size: 1rem;
}

.topbar p,
.age-line,
.muted {
  color: #d3dddd;
  font-size: 0.9rem;
}

.status-wrap {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #ffffff;
}

.status-live {
  background: var(--green);
}

.status-stale {
  background: var(--amber);
}

.status-offline,
.status-error {
  background: var(--red);
}

.status-waiting {
  background: #617174;
}

.layout {
  display: grid;
  gap: 18px;
  width: min(1400px, 100%);
  margin: 0 auto;
  padding: 18px;
}

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

.metric-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 104px;
  padding: 14px;
  display: grid;
  align-content: space-between;
  gap: 10px;
}

.metric-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.metric-value {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
  font-weight: 700;
  color: var(--text);
}

.metric-number {
  font-size: 1.65rem;
  overflow-wrap: anywhere;
}

.metric-unit {
  color: var(--muted);
  font-size: 0.9rem;
}

.metric-sub {
  min-height: 18px;
  color: var(--muted);
  font-size: 0.82rem;
}

.panel {
  padding: 16px;
}

.panel-head {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.chart-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}

.chart-select-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

select {
  min-height: 34px;
  max-width: 260px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
}

.chart-panel {
  min-height: 440px;
}

#historyCanvas {
  display: block;
  width: 100%;
  height: 360px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

td {
  padding: 8px 6px;
  border-top: 1px solid var(--line);
  font-size: 0.92rem;
}

td:first-child {
  width: 230px;
  color: var(--muted);
  font-weight: 700;
}

td:last-child {
  overflow-wrap: anywhere;
}

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

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .status-wrap {
    justify-items: start;
  }

  .layout {
    padding: 12px;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

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

  .chart-controls,
  .chart-select-label {
    width: 100%;
  }

  .chart-controls {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .chart-select-label {
    justify-content: space-between;
  }

  select {
    width: 100%;
    max-width: none;
  }
}
