:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #22252f;
  --border: #2a2d3a;
  --text: #e1e4ed;
  --text-dim: #8b8fa3;
  --accent: #6366f1;
  --accent-dim: #4f46e5;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

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

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-content h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.header-stats {
  display: flex;
  gap: 2rem;
  font-size: 0.85rem;
}

.stat { display: flex; flex-direction: column; align-items: center; }
.stat-value { font-size: 1.25rem; font-weight: 700; }
.stat-label { color: var(--text-dim); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; }

main { max-width: 1400px; margin: 0 auto; padding: 1.5rem 2rem; }

/* Charts */
.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  height: 260px;
  position: relative;
}

.chart-card h3 {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

/* Runs table */
.runs-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.section-header {
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.section-header h2 { font-size: 1rem; font-weight: 600; }

.filters { display: flex; gap: 0.5rem; }

.filters select, .filters input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  font-family: var(--font);
  color-scheme: dark;
}

.filters input[type="text"] { min-width: 280px; }
.filters input[type="text"]::placeholder { color: var(--text-dim); }
.filters { flex-wrap: wrap; align-items: center; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }

th {
  text-align: left;
  padding: 0.6rem 1rem;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}

tr:hover td { background: var(--surface-hover); }
tr { cursor: pointer; }

.loading { text-align: center; padding: 2rem; color: var(--text-dim); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
}

.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-error { background: rgba(239,68,68,0.15); color: var(--error); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }

.error-count { color: var(--error); font-weight: 600; }
.zero-count { color: var(--text-dim); }

.commit-link { color: #818cf8; text-decoration: underline; text-underline-offset: 2px; font-family: var(--mono); font-size: 0.8em; }
.commit-link:hover { color: #a5b4fc; }

tr.row-pass td { background: rgba(34,197,94,0.07); }
tr.row-pass:hover td { background: rgba(34,197,94,0.13); }
tr.row-fail td { background: rgba(239,68,68,0.07); }
tr.row-fail:hover td { background: rgba(239,68,68,0.13); }

/* Detail panel */
.detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.detail-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.detail-header h2 { font-size: 1rem; }

.detail-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0 1.25rem 1rem;
}

.back-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.8rem;
  font-family: var(--font);
  cursor: pointer;
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  margin-right: 1rem;
}

.back-btn:hover { color: var(--text); border-color: var(--text-dim); }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1rem 1.25rem;
}

.detail-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow: hidden;
  min-width: 0;
}

.detail-card h4 {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.detail-section {
  padding: 0 1.25rem 1rem;
}

.detail-section h3 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  padding-top: 0.5rem;
}

/* Error list */
.error-group {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
}

.error-group-header {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.error-group-header:hover { background: var(--surface-hover); }
.error-group-header .count { color: var(--text-dim); font-size: 0.75rem; }

.error-group-body {
  display: none;
  border-top: 1px solid var(--border);
  padding: 0.75rem;
}

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

.error-item {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.error-item:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.error-item .test-name { font-weight: 600; font-size: 0.8rem; margin-bottom: 0.25rem; }

.error-item .message {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 150px;
  overflow-y: auto;
  background: var(--surface);
  padding: 0.5rem;
  border-radius: 4px;
  margin-top: 0.25rem;
}

/* Downloads */
.download-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.artifacts-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.artifacts-card-header { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.artifacts-title { font-weight: 600; font-size: 0.85rem; }
.artifacts-subtitle { color: var(--text-dim); font-size: 0.7rem; }

.artifacts-grid {
  display: flex; flex-wrap: wrap; gap: 0;
}

.artifact-row {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.45rem 0.75rem; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); font-size: 0.8rem;
  flex: 1 1 auto; min-width: 0;
}
.artifact-row:last-child { border-right: none; }
.artifact-row:hover { background: var(--surface-hover); }
.artifact-name { font-family: var(--mono); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.artifact-dl {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  width: 24px; height: 24px; border-radius: 4px; font-size: 0.85rem; flex-shrink: 0;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none;
}
.artifact-dl:hover { color: var(--text); border-color: var(--text-dim); background: var(--surface-hover); }

/* Screenshots */
.screenshots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.75rem;
}

.screenshot-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.screenshot-card img {
  width: 100%;
  display: block;
  cursor: pointer;
}

.screenshot-card .caption {
  padding: 0.4rem 0.6rem;
  font-size: 0.7rem;
  color: var(--text-dim);
  word-break: break-all;
}

/* Worker bars */
.worker-bar-wrap { margin-bottom: 0.35rem; }

.worker-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  margin-bottom: 0.15rem;
}

.worker-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.worker-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.3s ease;
}

/* Slowest tests table */
.slowest-table { width: 100%; font-size: 0.8rem; table-layout: fixed; }
.slowest-table td { padding: 0.3rem 0.5rem; border: none; overflow: hidden; text-overflow: ellipsis; }
.slowest-table tr:hover td { background: var(--surface-hover); }
.slowest-table .time-col { text-align: right; font-family: var(--mono); color: var(--warning); width: 80px; white-space: nowrap; overflow: visible; }

footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-dim);
  font-size: 0.75rem;
}

/* Login screen */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3rem 2.5rem;
  text-align: center;
  max-width: 400px;
}

.login-card h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.login-card p { color: var(--text-dim); margin-bottom: 1.5rem; font-size: 0.9rem; }

.login-btn {
  display: inline-block;
  padding: 0.6rem 1.5rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.9rem;
  font-family: var(--font);
  cursor: pointer;
}

.login-btn:hover { background: var(--accent-dim); }

/* User info in header */
.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.user-name { color: var(--text-dim); font-size: 0.8rem; }

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  font-family: var(--font);
  cursor: pointer;
}

.logout-btn:hover { color: var(--text); border-color: var(--text-dim); }

@media (max-width: 900px) {
  .charts, .detail-grid { grid-template-columns: 1fr; }
  main { padding: 1rem; }
  header { flex-direction: column; gap: 0.5rem; }
}
