:root {
  color-scheme: dark;
  --bg: #07100e;
  --surface: rgba(20, 31, 28, 0.88);
  --surface-strong: #17231f;
  --stroke: rgba(255, 255, 255, 0.08);
  --text: #f4f7f5;
  --muted: #91a19b;
  --green: #55d786;
  --green-deep: #153d27;
  --orange: #ff9c3f;
  --red: #ff5f64;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 80% -10%, rgba(79, 209, 132, 0.16), transparent 36%),
    radial-gradient(circle at -20% 40%, rgba(60, 115, 91, 0.12), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }

.shell {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 16px max(34px, env(safe-area-inset-bottom));
}

.topbar, .section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1, h2, p { margin: 0; }
h1 { margin-top: 4px; font-size: 22px; letter-spacing: -0.03em; }
h2 { margin-top: 3px; font-size: 18px; letter-spacing: -0.02em; }

.eyebrow {
  color: var(--green);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--stroke);
  border-radius: 15px;
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
}

.icon-button:active { transform: scale(0.95); }
.icon-button.loading { animation: spin 0.8s linear infinite; }

.hero {
  position: relative;
  overflow: hidden;
  margin-top: 22px;
  min-height: 196px;
  padding: 24px;
  border: 1px solid var(--stroke);
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(38, 61, 52, 0.88), rgba(16, 27, 24, 0.96));
  box-shadow: 0 24px 70px rgba(0,0,0,0.28);
}

.hero::after {
  content: "";
  position: absolute;
  right: -54px;
  bottom: -72px;
  width: 210px;
  height: 210px;
  border-radius: 50%;
  background: var(--status-color, var(--green));
  opacity: 0.14;
  filter: blur(2px);
}

.status-dot {
  position: absolute;
  right: 24px;
  top: 24px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--status-color, var(--green));
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--status-color, var(--green)) 14%, transparent);
}

.status-normal { --status-color: var(--green); }
.status-high { --status-color: var(--orange); }
.status-low { --status-color: var(--red); }
.status-stale, .status-no_data { --status-color: #9aa39f; }

.status-label { color: var(--status-color); font-size: 14px; font-weight: 750; }
.reading-line { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.reading-line strong { font-size: clamp(58px, 18vw, 82px); line-height: 0.95; letter-spacing: -0.075em; }
.reading-line span { color: var(--status-color); font-size: 34px; font-weight: 800; }
.unit { margin-top: 8px; color: var(--muted); font-size: 14px; }
.freshness { position: absolute; left: 24px; bottom: 20px; color: var(--muted); font-size: 12px; }

.chart-card, .metrics-section {
  margin-top: 16px;
  padding: 20px;
  border: 1px solid var(--stroke);
  border-radius: 24px;
  background: var(--surface);
  backdrop-filter: blur(20px);
}

.legend { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.legend span { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.legend b { font-weight: 650; }

.chart-wrap { position: relative; height: 238px; margin-top: 18px; }
canvas { display: block; width: 100%; height: 100%; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.time-axis { display: flex; justify-content: space-between; margin: 5px 0 0 34px; color: #687771; font-size: 10px; }

.coverage { color: var(--muted); font-size: 11px; }
.metrics-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 17px; }
.metric {
  min-height: 104px;
  padding: 15px;
  border: 1px solid var(--stroke);
  border-radius: 18px;
  background: rgba(255,255,255,0.035);
}
.metric span, .metric small { display: block; color: var(--muted); font-size: 11px; }
.metric strong { display: block; margin: 8px 0 3px; font-size: 28px; letter-spacing: -0.05em; }
.metric-primary { background: linear-gradient(145deg, rgba(85,215,134,0.17), rgba(85,215,134,0.06)); }
.metric-primary strong { color: var(--green); }
.metric-low strong { color: var(--red); }
.metric-high strong { color: var(--orange); }

.disclaimer { margin: 18px 8px 0; color: #67756f; font-size: 10px; line-height: 1.5; text-align: center; }
.error-box { margin-top: 16px; padding: 14px; border: 1px solid rgba(255,95,100,0.35); border-radius: 16px; background: rgba(255,95,100,0.1); color: #ffb9bc; font-size: 13px; }

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

@media (min-width: 540px) {
  .metrics-grid { grid-template-columns: repeat(4, 1fr); }
  .metric-primary { grid-column: span 2; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
}
