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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --text: #e1e4ed;
  --text-muted: #8b8fa3;
  --accent: #6c8cff;
  --success: #4ade80;
  --error: #f87171;
  --warning: #fbbf24;
  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

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

/* Auth overlay */
#auth-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}

#auth-overlay.hidden { display: none; }

.auth-box {
  text-align: center;
  max-width: 360px;
  width: 100%;
  padding: 0 20px;
}

.auth-box h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 6px;
}

.auth-box p {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.auth-box input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--mono);
  outline: none;
}

.auth-box input:focus { border-color: var(--accent); }

.auth-box button {
  margin-top: 12px;
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.auth-box button:hover { opacity: 0.9; }
.auth-error { color: var(--error); font-size: 12px; margin-top: 8px; min-height: 18px; }

/* Layout */
header {
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 52px;
  gap: 32px;
}

header h1 {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

nav { display: flex; gap: 4px; }

nav button {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
}

nav button:hover { color: var(--text); background: var(--surface); }
nav button.active { color: var(--text); background: var(--surface); }

.period-selector {
  margin-left: auto;
  display: flex;
  gap: 2px;
  background: var(--surface);
  border-radius: 6px;
  padding: 2px;
}

.period-selector button {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
}

.period-selector button.active {
  background: var(--border);
  color: var(--text);
}

main { padding: 24px; max-width: 1200px; }

.view { display: none; }
.view.active { display: block; }

/* Stats cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.stat-card .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 4px;
  letter-spacing: -0.02em;
}

.stat-card .value.success { color: var(--success); }
.stat-card .value.error { color: var(--error); }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:hover { background: rgba(108, 140, 255, 0.04); }

/* Status badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge.success { background: rgba(74, 222, 128, 0.12); color: var(--success); }
.badge.error { background: rgba(248, 113, 113, 0.12); color: var(--error); }
.badge.cache_hit { background: rgba(251, 191, 36, 0.12); color: var(--warning); }
.badge.pending { background: rgba(139, 143, 163, 0.12); color: var(--text-muted); }

/* Endpoint badges */
.endpoint {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
}

/* Duration */
.duration {
  font-family: var(--mono);
  font-size: 12px;
}

/* Episode ID */
.episode-id {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.episode-id:hover { text-decoration: underline; }

/* Error message */
.error-msg {
  color: var(--error);
  font-size: 12px;
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Expanded row detail */
.row-detail {
  display: none;
}

.row-detail.open {
  display: table-row;
}

.row-detail td {
  padding: 16px;
  background: rgba(26, 29, 39, 0.7);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.detail-item .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-item .value {
  font-family: var(--mono);
  font-size: 13px;
  margin-top: 2px;
}

/* Filters */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filters select,
.filters input {
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.filters select:focus,
.filters input:focus { border-color: var(--accent); }

/* Pagination */
.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.pagination button {
  padding: 6px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Section heading */
.section-heading {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* Timeline */
.timeline {
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  padding-bottom: 20px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -20px;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.timeline-item.error::before { background: var(--error); }
.timeline-item.success::before { background: var(--success); }
.timeline-item.cache_hit::before { background: var(--warning); }

.timeline-item .time {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.timeline-item .info {
  margin-top: 4px;
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* Error groups */
.error-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}

.error-group-header {
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.error-group-header:hover { background: rgba(108, 140, 255, 0.04); }

.error-group-header .msg {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--error);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 16px;
}

.error-group-header .count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.error-group-instances {
  display: none;
  border-top: 1px solid var(--border);
  padding: 12px 18px;
}

.error-group-instances.open { display: block; }

.error-instance {
  font-size: 12px;
  padding: 6px 0;
  display: flex;
  gap: 16px;
  color: var(--text-muted);
}

.error-instance .ep {
  color: var(--accent);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Back link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 16px;
}

.back-link:hover { color: var(--text); }

/* Responsive */
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  header { padding: 0 16px; gap: 16px; }
  main { padding: 16px; }
}
