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

/* Light theme */
:root, [data-theme="light"] {
  --bg: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #eaeef2;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #656d76;
  --green: #1a7f37;
  --yellow: #9a6700;
  --red: #cf222e;
  --blue: #0969da;
  --gray: #8c959f;
}

/* Dark theme */
[data-theme="dark"] {
  --bg: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --blue: #58a6ff;
  --gray: #484f58;
}

/* System preference when no explicit theme is set */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --green: #3fb950;
    --yellow: #d29922;
    --red: #f85149;
    --blue: #58a6ff;
    --gray: #484f58;
  }
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* Header / Status Banner */
header {
  margin-bottom: 2rem;
}

.status-banner {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem 2rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gray);
  flex-shrink: 0;
}

.status-dot.operational, .status-dot.healthy { background: var(--green); }
.status-dot.degraded, .status-dot.partial { background: var(--yellow); }
.status-dot.major_outage, .status-dot.down, .status-dot.unhealthy { background: var(--red); }
.status-dot.maintenance { background: var(--yellow); }


/* Sections */
.section {
  margin-bottom: 2rem;
}

.section h2 {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* Location Groups */
.location-group {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.location-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.875rem 1.25rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.location-header:hover {
  background: var(--bg-tertiary);
}

.location-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.location-chevron {
  font-size: 0.625rem;
  color: var(--text-muted);
  width: 1rem;
  text-align: center;
}

.location-label {
  font-size: 0.9375rem;
}

.location-count {
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 400;
}

.location-body {
  display: none;
  padding: 0 0.75rem 0.75rem;
}

.location-body.open {
  display: block;
}

/* Node Cards */
.node-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin-bottom: 0.5rem;
}

.node-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.node-name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.node-name .status-dot {
  width: 10px;
  height: 10px;
}

.node-state {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.node-state.healthy {
  color: var(--green);
}

.node-state.unhealthy {
  color: var(--red);
}

.node-state.maintenance,
.node-state.draining {
  color: var(--yellow);
}


/* Uptime Bar */
.uptime-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.uptime-bars {
  display: flex;
  gap: 1px;
  flex: 1;
  height: 28px;
}

.uptime-bar {
  flex: 1;
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  min-width: 2px;
}

.uptime-bar.perfect { background: var(--green); }
.uptime-bar.degraded { background: var(--yellow); }
.uptime-bar.down { background: var(--red); }
.uptime-bar.no-data { background: var(--gray); opacity: 0.3; }

.uptime-bar:hover {
  opacity: 0.8;
}

.uptime-bar .tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 10;
  color: var(--text);
}

.uptime-bar:hover .tooltip {
  display: block;
}

.uptime-percent {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 60px;
  text-align: right;
}

/* Incidents */
.incident-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.75rem;
}

.incident-header {
  padding: 1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.incident-title {
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.incident-date {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.impact-badge {
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-weight: 500;
}

.impact-badge.minor { background: rgba(210, 153, 34, 0.15); color: var(--yellow); }
.impact-badge.major { background: rgba(248, 81, 73, 0.15); color: var(--red); }
.impact-badge.critical { background: rgba(248, 81, 73, 0.3); color: var(--red); }

.incident-timeline {
  padding: 0 1.25rem 1rem;
  display: none;
}

.incident-timeline.open {
  display: block;
}

.timeline-entry {
  display: flex;
  gap: 0.75rem;
  padding: 0.5rem 0;
  font-size: 0.875rem;
  border-top: 1px solid var(--border);
}

.timeline-time {
  color: var(--text-muted);
  min-width: 50px;
  flex-shrink: 0;
}

.timeline-status {
  font-weight: 500;
  min-width: 100px;
  flex-shrink: 0;
}

.timeline-status.investigating { color: var(--yellow); }
.timeline-status.identified { color: var(--yellow); }
.timeline-status.monitoring { color: var(--blue); }
.timeline-status.resolved { color: var(--green); }

.timeline-message {
  color: var(--text-muted);
}

/* No incidents */
.no-incidents {
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 1rem 0;
}

/* Loading */
.loading {
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 1rem 0;
}

/* Footer */
footer {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.last-updated {
  margin-top: 0.25rem;
}

/* Theme Toggle */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  z-index: 100;
}

.theme-toggle button {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.375rem 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.theme-toggle button:hover {
  background: var(--bg-tertiary);
  color: var(--text);
}

.theme-toggle button.active {
  background: var(--bg-tertiary);
  color: var(--text);
}

/* Responsive */
@media (max-width: 600px) {
  .container {
    padding: 1rem 0.75rem;
  }

  .status-banner {
    padding: 1rem 1.25rem;
    font-size: 1.1rem;
  }

  .uptime-bars {
    height: 22px;
  }
}
