:root {
  --bg: #ffffff;
  --surface: #fafafa;
  --surface-2: #f4f4f4;
  --border: #e8e8e8;
  --border-strong: #d0d0d0;
  --text: #0d0d0d;
  --text-sub: #555555;
  --text-muted: #999999;
  --text-faint: #cccccc;
  --ink: #171717;
  --success: #1a6b3c;
  --success-bg: #f2faf6;
  --success-border: #b6ddc8;
  --failure: #991b1b;
  --failure-bg: #fef5f5;
  --failure-border: #f0b9b9;
  --warn: #7a5c00;
  --warn-bg: #fffbee;
  --warn-border: #e8d870;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

code,
.mono {
  font-family: "JetBrains Mono", "SF Mono", "Fira Mono", "IBM Plex Mono", monospace;
  font-size: 0.88em;
}

/* ─── Layout ─────────────────────────────── */

.page-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.topbar {
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-logo {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.topbar-sep {
  width: 1px;
  height: 16px;
  background: var(--border-strong);
}

.topbar-title {
  font-size: 13px;
  color: var(--text-sub);
}

.topbar-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.main-content {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 32px 64px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ─── Stats row ──────────────────────────── */

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--border);
}

.stat-cell {
  background: var(--bg);
  padding: 20px 24px;
}

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

.stat-value {
  margin-top: 6px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1;
}

.stat-value.mono {
  font-size: 18px;
}

/* ─── Panel ──────────────────────────────── */

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

.panel-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.panel-caption {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.panel-body {
  padding: 24px;
}

.panel-link {
  font-size: 12px;
  color: var(--text-sub);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  transition: background 120ms, border-color 120ms;
  white-space: nowrap;
}

.panel-link:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.panel-link.hidden {
  display: none;
}

/* ─── Tab bar ────────────────────────────── */

.tab-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.tab {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-sub);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background 100ms, color 100ms, border-color 100ms;
  white-space: nowrap;
}

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

.tab.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

/* ─── Chart ──────────────────────────────── */

.chart-wrap {
  padding: 0 24px 8px;
}

.chart-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 24px 0;
}

.chart-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.chart-runs {
  font-size: 12px;
  color: var(--text-muted);
}

#main-chart,
#pr-chart {
  width: 100%;
  height: 260px;
  display: block;
  overflow: visible;
}

.chart-grid-line {
  stroke: var(--border);
  stroke-width: 1;
}

.chart-axis-line {
  stroke: var(--border-strong);
  stroke-width: 1;
}

.chart-area {
  fill: url(#chart-gradient);
}

.chart-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dot {
  fill: var(--bg);
  stroke: var(--ink);
  stroke-width: 2.5;
  cursor: pointer;
  transition: r 100ms;
}

.chart-dot:hover {
  r: 6;
}

.chart-tick {
  font-size: 11px;
  fill: var(--text-muted);
  font-family: "JetBrains Mono", "SF Mono", monospace;
}

.chart-axis-label {
  font-size: 11px;
  fill: var(--text-muted);
  font-family: "JetBrains Mono", "SF Mono", monospace;
}

.chart-value-label {
  font-size: 11px;
  fill: var(--text-sub);
  font-family: "JetBrains Mono", "SF Mono", monospace;
}

/* ─── Data table ─────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 500;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.data-table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
}

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

.data-table td.mono {
  color: var(--text-sub);
}

.data-table td.positive {
  color: var(--failure);
}

.data-table td.negative {
  color: var(--success);
}

/* ─── PR layout ──────────────────────────── */

.pr-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 500px;
}

.pr-sidebar {
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.pr-sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 500;
  background: var(--surface);
  position: sticky;
  top: 0;
}

.pr-list {
  display: flex;
  flex-direction: column;
}

.pr-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  text-align: left;
  border-left: 3px solid transparent;
  transition: background 100ms;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.pr-item:hover {
  background: var(--surface);
}

.pr-item.active {
  background: var(--surface);
  border-left-color: var(--ink);
}

.pr-item-number {
  font-size: 11px;
  color: var(--text-muted);
  font-family: "JetBrains Mono", "SF Mono", monospace;
}

.pr-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
}

.pr-item-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

/* ─── PR detail ──────────────────────────── */

.pr-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pr-detail {
  display: flex;
  flex-direction: column;
}

.pr-detail-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
}

.pr-detail-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.pr-detail-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.pr-detail-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.pr-links {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.pr-status-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ─── Status badge ───────────────────────── */

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid transparent;
  line-height: 1.4;
}

.status-badge .badge-label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: inherit;
  opacity: 0.7;
  font-size: 10px;
}

.status-badge .badge-value {
  font-weight: 600;
}

.status-badge.success {
  color: var(--success);
  background: var(--success-bg);
  border-color: var(--success-border);
}

.status-badge.failure {
  color: var(--failure);
  background: var(--failure-bg);
  border-color: var(--failure-border);
}

.status-badge.muted {
  color: var(--text-sub);
  background: var(--surface-2);
  border-color: var(--border);
}

/* small inline badge (PR list) */
.inline-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.inline-badge.success {
  color: var(--success);
  background: var(--success-bg);
  border-color: var(--success-border);
}

.inline-badge.failure {
  color: var(--failure);
  background: var(--failure-bg);
  border-color: var(--failure-border);
}

.inline-badge.muted {
  color: var(--text-sub);
  background: var(--surface-2);
  border-color: var(--border);
}

/* ─── Sub-panels (delta / run history) ──── */

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(260px, 0.7fr);
  border-top: 1px solid var(--border);
}

.subpanel {
  overflow: hidden;
}

.subpanel + .subpanel {
  border-left: 1px solid var(--border);
}

.subpanel-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 500;
  background: var(--surface);
}

/* ─── Run history ────────────────────────── */

.run-history {
  display: flex;
  flex-direction: column;
}

.run-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 20px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  transition: background 100ms;
  gap: 12px;
}

.run-history-item:hover {
  background: var(--surface);
}

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

.run-history-commit {
  font-family: "JetBrains Mono", "SF Mono", monospace;
  font-size: 12px;
  color: var(--text-sub);
  flex-shrink: 0;
}

.run-history-info {
  flex: 1;
  min-width: 0;
}

.run-history-time {
  font-size: 11px;
  color: var(--text-muted);
}

.run-history-stats {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── Empty state ────────────────────────── */

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  color: var(--text-muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

/* ─── Responsive ─────────────────────────── */

@media (max-width: 1024px) {
  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .main-content {
    padding: 20px 16px 48px;
  }

  .topbar {
    padding: 0 16px;
  }

  .pr-layout {
    grid-template-columns: 1fr;
  }

  .pr-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 280px;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .subpanel + .subpanel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 480px) {
  .stats-row {
    grid-template-columns: 1fr;
  }

  .pr-detail-top {
    flex-direction: column;
  }
}
