/* ========================================
   CrawlGenius Status Page
   Stripe-inspired clean design
   ======================================== */

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

:root {
  --color-operational: #22c55e;
  --color-operational-bg: #f0fdf4;
  --color-degraded: #eab308;
  --color-degraded-bg: #fefce8;
  --color-down: #ef4444;
  --color-down-bg: #fef2f2;
  --color-unknown: #9ca3af;
  --color-unknown-bg: #f3f4f6;
  --color-bg: #ffffff;
  --color-text: #1a1a2e;
  --color-text-secondary: #6b7280;
  --color-border: #e5e7eb;
  --color-surface: #f8f9fa;
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --max-width: 800px;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --transition: 150ms ease;
}

body {
  font-family: var(--font-family);
  color: var(--color-text);
  background: var(--color-surface);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px 60px;
}

/* ---- Header ---- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 32px 0 24px;
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--color-text);
}

.header-right {
  font-size: 13px;
  color: var(--color-text-secondary);
  font-weight: 400;
}

/* ---- Environment Tabs ---- */

.env-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow-sm);
}

.env-tab {
  flex: 1;
  padding: 8px 16px;
  border: none;
  background: transparent;
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: 6px;
  transition: all var(--transition);
}

.env-tab:hover {
  color: var(--color-text);
  background: var(--color-surface);
}

.env-tab.active {
  color: var(--color-text);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

/* ---- Overall Banner ---- */

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  font-size: 15px;
  font-weight: 500;
  transition: all 300ms ease;
}

.banner-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.banner--operational {
  background: var(--color-operational-bg);
  color: #166534;
  border: 1px solid #bbf7d0;
}

.banner--operational .banner-dot {
  background: var(--color-operational);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.banner--degraded {
  background: var(--color-degraded-bg);
  color: #854d0e;
  border: 1px solid #fde68a;
}

.banner--degraded .banner-dot {
  background: var(--color-degraded);
  box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.2);
}

.banner--down {
  background: var(--color-down-bg);
  color: #991b1b;
  border: 1px solid #fecaca;
}

.banner--down .banner-dot {
  background: var(--color-down);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

.banner--unknown,
.banner--loading {
  background: var(--color-unknown-bg);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.banner--unknown .banner-dot,
.banner--loading .banner-dot {
  background: var(--color-unknown);
}

.banner--loading .banner-dot {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ---- Services Grid ---- */

.services-grid {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 32px;
  box-shadow: var(--shadow-md);
}

.service-row {
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
}

.service-row:last-child {
  border-bottom: none;
}

.service-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.service-summary:hover {
  background: var(--color-surface);
}

.service-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
}

.service-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.service-latency {
  font-size: 13px;
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}

.service-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
}

.service-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.service-status--operational .service-status-dot { background: var(--color-operational); }
.service-status--operational { color: #166534; }

.service-status--degraded .service-status-dot { background: var(--color-degraded); }
.service-status--degraded { color: #854d0e; }

.service-status--down .service-status-dot { background: var(--color-down); }
.service-status--down { color: #991b1b; }

.service-status--unknown .service-status-dot { background: var(--color-unknown); }
.service-status--unknown { color: var(--color-text-secondary); }

.service-expand-icon {
  font-size: 12px;
  color: var(--color-text-secondary);
  transition: transform var(--transition);
  margin-left: 4px;
}

.service-row.expanded .service-expand-icon {
  transform: rotate(180deg);
}

/* ---- Service Detail (expanded checks) ---- */

.service-detail {
  max-height: 0;
  overflow: hidden;
  transition: max-height 300ms ease, opacity 200ms ease;
  opacity: 0;
}

.service-row.expanded .service-detail {
  max-height: 600px;
  opacity: 1;
}

.service-detail-inner {
  padding: 0 20px 16px;
}

.checks-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.checks-table th {
  text-align: left;
  padding: 8px 12px;
  font-weight: 500;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.checks-table td {
  padding: 6px 12px;
  color: var(--color-text);
  border-bottom: 1px solid #f3f4f6;
  font-variant-numeric: tabular-nums;
}

.checks-table tr:last-child td {
  border-bottom: none;
}

.check-status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.service-detail-loading {
  padding: 20px;
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 13px;
}

.check-error {
  font-size: 12px;
  color: var(--color-text-secondary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- 90-Day Uptime Bars ---- */

.history-section {
  margin-bottom: 32px;
}

.history-section h2,
.incidents-section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--color-text);
}

#uptime-bars {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.uptime-row {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--color-border);
  gap: 16px;
}

.uptime-row:last-child {
  border-bottom: none;
}

.uptime-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  width: 140px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.uptime-bar {
  flex: 1;
  display: flex;
  gap: 1px;
  align-items: center;
  min-width: 0;
}

.uptime-day {
  flex: 1;
  height: 24px;
  border-radius: 2px;
  position: relative;
  cursor: pointer;
  transition: opacity var(--transition);
  min-width: 2px;
}

.uptime-day:first-child {
  border-radius: 2px 0 0 2px;
}

.uptime-day:last-child {
  border-radius: 0 2px 2px 0;
}

.uptime-day:hover {
  opacity: 0.7;
}

.uptime-day--operational { background: var(--color-operational); }
.uptime-day--degraded { background: var(--color-degraded); }
.uptime-day--down { background: var(--color-down); }
.uptime-day--no-data { background: #e5e7eb; }

.uptime-pct {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  width: 60px;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* ---- Uptime Tooltip ---- */

.uptime-tooltip {
  position: fixed;
  background: var(--color-text);
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  pointer-events: none;
  z-index: 1000;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transition: opacity 100ms ease;
}

.uptime-tooltip.visible {
  opacity: 1;
}

/* ---- Incidents ---- */

.incidents-section {
  margin-bottom: 32px;
}

#incidents-list {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.no-incidents {
  padding: 24px 20px;
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 14px;
}

.incident-item {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
}

.incident-item:last-child {
  border-bottom: none;
}

.incident-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.incident-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.incident-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
}

.incident-time {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-left: auto;
  flex-shrink: 0;
}

.incident-body {
  font-size: 13px;
  color: var(--color-text-secondary);
  padding-left: 16px;
  line-height: 1.5;
}

/* ---- Footer ---- */

.footer {
  text-align: center;
  padding: 24px 0;
  color: var(--color-text-secondary);
  font-size: 13px;
}

/* ---- Loading / Error States ---- */

.services-grid--loading,
#uptime-bars.loading {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  font-size: 14px;
}

.error-message {
  padding: 24px 20px;
  text-align: center;
  color: var(--color-down);
  font-size: 14px;
  background: var(--color-down-bg);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  margin-bottom: 24px;
}

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- Responsive ---- */

@media (max-width: 640px) {
  #app {
    padding: 0 16px 40px;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 24px 0 16px;
  }

  .header h1 {
    font-size: 18px;
  }

  .service-summary {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .service-name {
    width: 100%;
  }

  .service-right {
    width: 100%;
    justify-content: flex-end;
  }

  .uptime-row {
    flex-wrap: wrap;
    padding: 12px 16px;
    gap: 8px;
  }

  .uptime-name {
    width: 100%;
  }

  .uptime-bar {
    width: 100%;
    order: 3;
  }

  .uptime-pct {
    text-align: left;
    width: auto;
  }

  .uptime-day {
    height: 20px;
  }

  .checks-table th:nth-child(3),
  .checks-table td:nth-child(3) {
    display: none;
  }
}
