/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #ffffff;
  --bg-soft:   #f6f8fa;
  --border:    #dde3e9;
  --text:      #1a2530;
  --text-dim:  #6b8090;
  --accent:    #0080a0;
  --accent-bg: #e8f5f8;
  --warn:      #b84010;
  --warn-bg:   #fff4ef;
  --warn-border:#f0c0a8;
  --font:      'Inter', system-ui, -apple-system, sans-serif;
  --mono:      'SF Mono', 'Fira Code', 'Consolas', monospace;
  --max-w:     1200px;
}

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ---- Header ---- */
header {
  padding: 1.1rem 2rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
}

.header-top {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
}

header h1 {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.subtitle {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem;
  margin-top: 0.35rem;
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--text-dim);
}

.meta-bar strong { font-weight: 500; color: var(--text); }

.last-data-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.last-data-chip.stale strong { color: var(--warn); }

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #22a060;
  display: inline-block;
  flex-shrink: 0;
}

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

/* ---- Page-level nav tabs ---- */
.page-nav {
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 70px;
  z-index: 19;
}

.page-nav-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  gap: 0;
}

.page-tab {
  padding: 0.75rem 1.5rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.88rem;
  font-family: var(--font);
  font-weight: 500;
  margin-bottom: -2px;
  transition: color 0.12s, border-color 0.12s;
  letter-spacing: 0.01em;
}

.page-tab:hover { color: var(--text); }

.page-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---- Main layout ---- */
main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 2rem 5rem;
}

/* ---- Page containers ---- */
.page { /* no special styles needed — just show/hide */ }

/* ---- Section blocks ---- */
.section-block {
  padding: 2.4rem 0 2rem;
  border-bottom: 1px solid var(--border);
}

.section-block:last-of-type { border-bottom: none; }

.section-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1.2rem;
}

.section-name {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
}

.section-unit {
  font-size: 0.72rem;
  font-family: var(--mono);
  color: var(--text-dim);
}

/* ---- Sub-tabs ---- */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.2rem;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  padding: 0.4rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font);
  margin-bottom: -1px;
  transition: color 0.12s, border-color 0.12s;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 500;
}

/* ---- Chart containers ---- */
.chart-wrap {
  width: 100%;
  min-height: 360px;
  position: relative;
}

.chart-wrap.tall { min-height: 480px; }

/* ---- Loading / error state ---- */
.state-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 240px;
  color: var(--text-dim);
  font-size: 0.75rem;
  font-family: var(--mono);
}

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ---- Sensor offline state (replaces chart when >80% data is interpolated) ---- */
.offline-msg {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  min-height: 240px;
  padding: 2rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.offline-icon {
  font-size: 2rem;
  flex-shrink: 0;
  opacity: 0.55;
}

.offline-text {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.offline-text strong {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.offline-text span {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.5;
  max-width: 52ch;
}

/* ---- Outage / data-gap banner ---- */
.outage-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.65rem 0.9rem;
  margin-bottom: 0.9rem;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 6px;
  font-size: 0.78rem;
  color: var(--warn);
  line-height: 1.45;
}

.outage-banner::before {
  content: "⚠";
  flex-shrink: 0;
  margin-top: 0.05em;
}

/* ---- Chart explanation text ---- */
.chart-note {
  margin-top: 0.8rem;
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.65;
  max-width: 76ch;
}

/* ---- Model intro ---- */
.model-intro {
  padding: 1.6rem 0 0.6rem;
}

.model-intro p {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.6;
  max-width: 76ch;
}

/* ---- Site pills ---- */
.site-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 2rem;
}

.site-pill {
  padding: 0.3rem 0.9rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.78rem;
  font-family: var(--font);
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}

.site-pill:hover {
  color: var(--text);
  border-color: #b0c4d0;
}

.site-pill.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-bg);
  font-weight: 500;
}

/* ---- Emulator metrics bar ---- */
.emulator-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem;
  padding: 0.75rem 1rem;
  background: var(--accent-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.72rem;
  font-family: var(--mono);
  color: var(--text-dim);
}
.emulator-metrics strong { color: var(--text); font-weight: 500; }

/* ---- Page intro (plain-language one-liner) ---- */
.page-intro {
  padding: 1.4rem 0 0.6rem;
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.5;
  max-width: 72ch;
}

/* ---- Collapsible model details ---- */
.model-details {
  margin: 1rem 0 1.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-soft);
}

.model-details summary {
  padding: 0.55rem 0.9rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.model-details summary::-webkit-details-marker { display: none; }

.model-details summary::before {
  content: "▶";
  font-size: 0.6rem;
  transition: transform 0.15s;
  flex-shrink: 0;
}

.model-details[open] summary::before { transform: rotate(90deg); }

.model-details summary:hover { color: var(--text); }

.model-details-body {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.model-details-body p {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.7;
  max-width: 76ch;
}

.model-details-body a { color: var(--accent); text-decoration: none; }
.model-details-body a:hover { text-decoration: underline; }

/* ---- About ---- */
.about-block {
  padding: 2rem 0 1rem;
}

.about-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}

.about-block p {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.7;
  max-width: 76ch;
}

.about-block a { color: var(--accent); text-decoration: none; }
.about-block a:hover { text-decoration: underline; }

/* ---- Footer ---- */
footer {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 1.2rem 2rem;
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}

footer a { color: var(--text-dim); text-decoration: none; }
footer a:hover { color: var(--text); }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  header, .page-nav-inner, main, footer { padding-left: 1rem; padding-right: 1rem; }
  .chart-wrap { min-height: 280px; }
  .chart-wrap.tall { min-height: 360px; }
  .tabs { overflow-x: auto; }
  .page-nav { top: 62px; }
}
