:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d9be9;
  --accent-dim: #2a6fad;
  --ok: #3ecf8e;
  --warn: #e8b84a;
  --err: #e85d5d;
  --radius: 8px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

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

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  align-items: flex-end;
  padding: 1.25rem 2rem 0.5rem;
}

.topbar h1 { font-size: 1.35rem; font-weight: 650; }
.topbar p { color: var(--muted); font-size: 0.85rem; max-width: 52rem; margin-top: 0.35rem; }
.top-actions { display: flex; gap: 0.75rem; align-items: center; flex-shrink: 0; }

main { padding: 1rem 2rem 2.5rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card h3 {
  font-size: 0.95rem;
  margin-bottom: 0.85rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.toolbar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; margin-bottom: 0.85rem; }
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field label { font-size: 0.75rem; color: var(--muted); }

input, select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  font-size: 0.875rem;
  min-width: 140px;
}

.btn {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: none;
  font-size: 0.875rem;
  cursor: pointer;
  font-weight: 500;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dim); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.check-label { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.85rem; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 0.35rem 0 0.75rem; }
.empty { color: var(--muted); font-size: 0.85rem; padding: 0.5rem 0; }

.site-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr));
  gap: 0.65rem;
}

.site-card {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.7rem 0.8rem;
  cursor: pointer;
  font-family: inherit;
}
.site-card.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.site-card .name { font-weight: 650; font-size: 0.95rem; }
.site-card .meta { color: var(--muted); font-size: 0.75rem; margin-top: 0.2rem; }
.site-card .avg { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.site-card .avg.ok { color: var(--ok); }
.site-card .avg.warn { color: var(--warn); }
.site-card .avg.bad { color: var(--err); }
.site-card .avg.none { color: var(--muted); }
.site-card.error { border-color: var(--err); }

.diag-overview-counts { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.85rem; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  font-size: 0.85rem;
  color: var(--muted);
}
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.pill.bad { color: var(--err); }
.pill.none { color: var(--muted); }

.diag-heat-legend, .diag-timeline-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
  margin-bottom: 0.85rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.heat-scale {
  width: 7rem;
  height: 0.55rem;
  border-radius: 999px;
  background: linear-gradient(90deg, #e85d5d 0%, #e8b84a 55%, #3ecf8e 100%);
  border: 1px solid var(--border);
}
.heat-online-legend { display: inline-flex; align-items: center; gap: 0.3rem; }
.heat-dot {
  width: 0.55rem; height: 0.55rem; border-radius: 50%; display: inline-block; background: var(--muted);
}
.heat-dot.on { background: var(--ok); box-shadow: 0 0 0 2px rgba(62, 207, 142, 0.25); }
.heat-dot.off { background: #5a6578; }

.diag-heatmap { display: flex; flex-direction: column; gap: 1rem; }
.diag-heat-group-title, .diag-tl-group-title {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0.35rem 0 0.4rem;
}
.diag-heat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.8rem, 1fr));
  gap: 0.45rem;
}
.diag-heat-cell {
  position: relative;
  min-height: 4.7rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.4rem 0.35rem 0.35rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  color: #0f1419;
  font-family: inherit;
}
.diag-heat-cell:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); }
.diag-heat-cell.offline {
  color: #c5cedb;
  background: #232c3b !important;
  border: 1px dashed #6a7385;
}
.diag-heat-cell.offline .diag-heat-pct { font-size: 0.72rem; color: #9aa8bc; }
.diag-heat-cell.offline .diag-heat-meta { color: #e85d5d; font-weight: 700; font-size: 0.68rem; }
.diag-heat-cell.offline .diag-heat-id { color: #e8edf4; }
.diag-heat-cell.nodata { color: var(--muted); background: #1c2433 !important; border-color: var(--border); }
.diag-heat-badge {
  position: absolute; top: 0.28rem; left: 0.3rem;
  font-size: 0.58rem; font-weight: 700; padding: 0.05rem 0.28rem; border-radius: 3px;
}
.diag-heat-badge.on { background: rgba(15, 20, 25, 0.35); color: #0f1419; }
.diag-heat-badge.off { background: rgba(232, 93, 93, 0.2); color: #e85d5d; }
.diag-heat-id { font-size: 0.78rem; font-weight: 700; }
.diag-heat-pct { font-size: 0.95rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.diag-heat-meta { font-size: 0.62rem; }
.diag-heat-activity { position: absolute; top: 0.35rem; right: 0.35rem; }

.tl-swatch { display: inline-block; width: 0.85rem; height: 0.55rem; border-radius: 2px; border: 1px solid var(--border); }
.tl-swatch.idle { background: #2a3344; }
.tl-swatch.ok { background: #3ecf8e; }
.tl-swatch.warn { background: #e8b84a; }
.tl-swatch.bad { background: #e85d5d; }

.diag-timeline-wrap { overflow-x: auto; }
.diag-timeline { display: flex; flex-direction: column; gap: 0.28rem; min-width: 42rem; }
.diag-tl-axis, .diag-tl-row {
  display: grid;
  grid-template-columns: 4.2rem 1fr;
  gap: 0.4rem;
  align-items: center;
}
.diag-tl-axis-hours { display: grid; gap: 2px; font-size: 0.62rem; color: var(--muted); }
.diag-tl-axis-hours span { text-align: center; }
.diag-tl-label {
  background: transparent; border: none; color: #e8edf4; font-weight: 650;
  font-family: ui-monospace, monospace; font-size: 0.75rem; text-align: right; cursor: pointer;
}
.diag-tl-label:hover { color: var(--accent); }
.diag-tl-track { display: grid; gap: 2px; height: 1.15rem; }
.diag-tl-slot { border: none; padding: 0; border-radius: 2px; cursor: pointer; background: #2a3344; }
.diag-tl-slot.ok { background: #3ecf8e; }
.diag-tl-slot.warn { background: #e8b84a; }
.diag-tl-slot.bad { background: #e85d5d; }
.diag-tl-slot:hover { outline: 1px solid #fff; }

.diag-results { display: flex; flex-direction: column; gap: 1rem; }
.diag-metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; }
.diag-metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.diag-metric-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.diag-metric-value { font-size: 1.35rem; font-weight: 650; }
.diag-metric-hint { font-size: 0.75rem; color: var(--muted); }
.diag-metric.stale { border-color: #6a4a3a; }
.diag-metric.stale .diag-metric-value { color: var(--warn); }
.diag-metric.ok .diag-metric-value { color: var(--ok); }
.diag-metric.warn .diag-metric-value { color: var(--warn); }
.diag-metric.bad .diag-metric-value { color: var(--err); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.5rem 0.65rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; }
.cell-mono { font-family: ui-monospace, monospace; font-size: 0.82rem; }

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.7rem 1rem;
  border-radius: 8px;
  display: none;
  max-width: 24rem;
}
.toast.show { display: block; }
.toast.error { border-color: var(--err); }

@media (max-width: 800px) {
  .topbar, main { padding-left: 1rem; padding-right: 1rem; }
  .topbar { flex-direction: column; align-items: flex-start; }
}
