/* apps/status-page/src/styles.css */

/* CSS Variables for theming.
 *
 * Every color derives from the --te-* tokens the published theme injects
 * (a <style> block of custom properties from current.json — see DOWN-176
 * AC-2 / DOWN-D54). The literals here are only the fallback look for the
 * moment before the theme loads, or when a page carries no theme. */
:root {
  /* Status colors */
  --status-operational: var(--te-status-up, #10b981);
  --status-degraded: var(--te-status-slow, #f59e0b);
  --status-partial-outage: var(--te-status-slow, #f97316);
  --status-major-outage: var(--te-status-down, #ef4444);

  /* Monitor status colors */
  --monitor-up: var(--te-status-up, #10b981);
  --monitor-down: var(--te-status-down, #ef4444);
  --monitor-degraded: var(--te-status-slow, #f59e0b);
  --monitor-maintenance: var(--te-status-paused, #6b7280);

  /* Uptime bar colors */
  --uptime-up: var(--te-status-up, #10b981);
  --uptime-down: var(--te-status-down, #ef4444);
  --uptime-partial: var(--te-status-slow, #f59e0b);
  --uptime-no-data: var(--te-surface-border, #e5e7eb);

  /* UI colors */
  --bg-primary: var(--te-surface, #ffffff);
  --bg-secondary: var(--te-background, #f9fafb);
  --text-primary: var(--te-text-primary, #111827);
  --text-secondary: var(--te-text-secondary, #6b7280);
  --border-color: var(--te-surface-border, #e5e7eb);
  --accent: var(--te-accent-primary, #3b82f6);

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;

  /* Border radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
}

/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Layout */
#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--spacing-xl);
}

/* Loading state */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: var(--spacing-md);
}

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

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

/* Error state */
.error {
  text-align: center;
  padding: var(--spacing-xl);
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.error h1 {
  color: var(--status-major-outage);
  margin-bottom: var(--spacing-md);
}

/* Header */
.status-header {
  text-align: center;
  padding: var(--spacing-xl);
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  margin-bottom: var(--spacing-xl);
  border: 3px solid;
}

.status-header.operational {
  border-color: var(--status-operational);
}

.status-header.degraded {
  border-color: var(--status-degraded);
}

.status-header.partial_outage {
  border-color: var(--status-partial-outage);
}

.status-header.major_outage {
  border-color: var(--status-major-outage);
}

.status-header .logo {
  max-height: 64px;
  margin-bottom: var(--spacing-md);
}

.status-header h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: var(--spacing-sm);
}

.status-header p {
  color: var(--text-secondary);
  margin-bottom: var(--spacing-lg);
}

.overall-status {
  font-size: 1.25rem;
  font-weight: 600;
  padding: var(--spacing-md);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  display: inline-block;
}

/* Main content */
main {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xl);
}

section {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: var(--spacing-xl);
  border: 1px solid var(--border-color);
}

section h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--spacing-lg);
  color: var(--text-primary);
}

/* Monitors section */
.monitors {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.monitors h2 {
  margin-bottom: 0;
}

.section-note {
  margin-bottom: var(--spacing-md);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* One row per monitor: its name, status and uptime, its bars beneath. */
.monitor {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  padding: var(--spacing-md);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  transition: background 0.2s;
}

.monitor:hover {
  background: var(--te-surface-hover, #f3f4f6);
}

.monitor-summary {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: var(--spacing-md);
}

.monitor-info {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.monitor.up .status-indicator {
  background: var(--monitor-up);
}

.monitor.down .status-indicator {
  background: var(--monitor-down);
}

.monitor.degraded .status-indicator {
  background: var(--monitor-degraded);
}

.monitor.maintenance .status-indicator {
  background: var(--monitor-maintenance);
}

.monitor .name {
  font-weight: 500;
}

.monitor-status {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.monitor .uptime {
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.bars {
  display: flex;
  gap: 2px;
  height: 32px;
}

.bar {
  flex: 1;
  min-width: 3px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.2s;
}

.bar:hover {
  opacity: 0.8;
}

.bar.up {
  background: var(--uptime-up);
}

.bar.down {
  background: var(--uptime-down);
}

.bar.partial {
  background: var(--uptime-partial);
}

.bar.no_data {
  background: var(--uptime-no-data);
}

/* Incidents section */
.incidents {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.incident {
  padding: var(--spacing-md);
  border-radius: var(--radius-md);
  border-left: 4px solid;
  background: var(--bg-secondary);
}

.incident.investigating,
.incident.identified,
.incident.monitoring {
  border-left-color: var(--status-partial-outage);
}

.incident.resolved {
  border-left-color: var(--status-operational);
}

.incident-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
}

.status-badge {
  display: inline-block;
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--text-secondary);
  color: var(--te-text-inverse, #ffffff);
}

.incident.resolved .status-badge {
  background: var(--status-operational);
}

.incident-header .title {
  font-weight: 600;
}

.incident-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-md);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.incident-meta span:not(:last-child)::after {
  content: '•';
  margin-left: var(--spacing-md);
}

/* Footer */
footer {
  text-align: center;
  padding: var(--spacing-xl);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

footer p {
  margin-bottom: var(--spacing-sm);
}

/* Vibe content styling */
.emoji {
  font-size: 1.25em;
}

.vibe-image {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: var(--spacing-sm) 0;
}

/* Responsive design */
@media (max-width: 768px) {
  #app {
    padding: var(--spacing-md);
  }

  .status-header h1 {
    font-size: 1.5rem;
  }

  .overall-status {
    font-size: 1rem;
  }

  section {
    padding: var(--spacing-md);
  }

  section h2 {
    font-size: 1.25rem;
  }

  .monitor-summary {
    grid-template-columns: 1fr;
    gap: var(--spacing-sm);
  }

  .monitor-status,
  .monitor .uptime {
    justify-self: start;
  }

  /* The bars sit inside the monitor's row, which does not scroll, so they
   * narrow to fit it: 90 bars and their gaps need 358px here, and 179px
   * below 480px. */
  .bars {
    height: 24px;
  }

  .bar {
    min-width: 2px;
  }

  .incident-meta {
    flex-direction: column;
    gap: var(--spacing-xs);
  }

  .incident-meta span:not(:last-child)::after {
    display: none;
  }
}

@media (max-width: 480px) {
  .status-header h1 {
    font-size: 1.25rem;
  }

  .overall-status {
    font-size: 0.875rem;
  }

  section h2 {
    font-size: 1rem;
  }

  .bars {
    gap: 1px;
  }

  .bar {
    min-width: 1px;
  }
}

/* Motion respects the visitor's preference (DOWN-R14 rule 6). Covers the
 * loading spinner and any animated weather layers the published theme adds. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* A known issue may be the cause: the sentence sits beside the
   monitor or incident it covers; a day that left such failures out is ringed. */
.known-issue {
  font-size: 0.85em;
  opacity: 0.85;
}

.bar.excluded {
  outline: 1px dashed currentColor;
  outline-offset: -1px;
}
