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

:root {
  --bg:      #0d1117;
  --surface: #161b22;
  --border:  #21262d;
  --muted:   #8b949e;
  --text:    #e6edf3;
  --blue:    #58a6ff;
  --green:   #3fb950;
  --yellow:  #d29922;
  --red:     #f85149;
}

body {
  font-family: 'Lato', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left  { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 8px; }

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.75rem;
  transition: color .2s;
}
.back-link:hover { color: var(--blue); }

.header-sep   { color: var(--border); font-size: 0.75rem; }
.header-title { font-size: 0.9rem; font-weight: 700; letter-spacing: .04em; }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.loading { background: var(--yellow); animation: pulse 1s infinite; }
.status-dot.ok      { background: var(--green); }
.status-dot.err     { background: var(--red); }

.status-text { font-size: 0.72rem; color: var(--muted); }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── Main ─────────────────────────────────── */
main {
  flex: 1;
  padding: 20px 24px 40px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ── Intro ─────────────────────────────────── */
.intro-section {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.intro-text {
  flex: 1;
  min-width: 260px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.6;
}

.intro-text em { color: var(--yellow); font-style: normal; font-weight: 700; }

.window-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  flex-shrink: 0;
}

.window-control select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.78rem;
  cursor: pointer;
}

/* ── Stats row ─────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}

.stat-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.stat-value.red    { color: var(--red); }
.stat-value.green  { color: var(--green); }
.stat-value.yellow { color: var(--yellow); }
.stat-sub { font-size: 0.7rem; color: var(--muted); }

/* ── Chart sections ────────────────────────── */
.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
}

.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chart-title { font-size: 0.85rem; font-weight: 700; color: var(--text); }

.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--muted);
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.red   { background: var(--red); }
.dot.green { background: var(--green); }

.chart-subtitle {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.chart-half { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.filter-row {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.filter-row input { cursor: pointer; }

.chart-wrap { position: relative; height: 340px; }
.deviation-wrap { height: 220px; }
.rolling-wrap   { height: 220px; }
.hist-wrap      { height: 240px; }
.cal-wrap       { height: 240px; }

/* ── Table ─────────────────────────────────── */
.table-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
}

.table-section details > summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  list-style: none;
  user-select: none;
}
.table-section details > summary::before { content: '▶ '; font-size: 0.65rem; }
.table-section details[open] > summary::before { content: '▼ '; }

#table-count { font-weight: 400; font-size: 0.75rem; }

.table-wrap {
  margin-top: 12px;
  overflow-x: auto;
  max-height: 320px;
  overflow-y: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
thead { position: sticky; top: 0; }
th {
  background: var(--bg);
  color: var(--muted);
  text-align: left;
  padding: 6px 10px;
  font-weight: 700;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
tr:last-child td { border-bottom: none; }
tr.high td:last-child { color: var(--red); }
tr.low  td:last-child { color: var(--green); }

.badge-high { color: var(--red); }
.badge-low  { color: var(--green); }

/* ── Error banner ──────────────────────────── */
.error-banner {
  background: rgba(248, 81, 73, 0.15);
  border: 1px solid var(--red);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.error-banner button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 4px;
}

.hidden { display: none !important; }

/* ── Responsive ────────────────────────────── */
@media (max-width: 700px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .chart-wrap { height: 260px; }
  .deviation-wrap, .rolling-wrap { height: 160px; }
  .hist-wrap, .cal-wrap { height: 200px; }
  .two-col { grid-template-columns: 1fr; }
  main { padding: 14px 12px 32px; }
}
