:root {
  --color-success: #2da44e;
  --color-failure: #cf222e;
  --color-pending: #bf8700;
  --color-neutral: #656d76;
  --color-bg: #f6f8fa;
  --color-card: #ffffff;
  --color-border: #d0d7de;
  --color-text: #1f2328;
  --color-text-secondary: #656d76;
  --color-header-bg: #24292f;
  --color-header-text: #ffffff;
  --color-link: #0969da;
  --color-input-bg: #ffffff;
  --color-input-border: #d0d7de;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0d1117;
    --color-card: #161b22;
    --color-border: #30363d;
    --color-text: #e6edf3;
    --color-text-secondary: #8b949e;
    --color-header-bg: #010409;
    --color-link: #58a6ff;
    --color-input-bg: #0d1117;
    --color-input-border: #30363d;
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

a:hover {
  text-decoration: underline;
}

/* Header */
#header {
  background: var(--color-header-bg);
  color: var(--color-header-text);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

#header-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}

#refresh-btn {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--color-input-border);
  border-radius: 6px;
  background: var(--color-card);
  color: var(--color-text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}

#refresh-btn:hover {
  background: var(--color-bg);
}

/* Dashboard Container */
#dashboard {
  padding: 1.5rem;
  flex: 1;
}

/* Section Headings */
.section-heading {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin: 1.5rem 0 0.75rem;
}

.section-heading:first-child {
  margin-top: 0;
}

.repo-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--color-link);
}

.status-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* Status Timeline */
.status-timeline {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
}

.status-bar {
  width: 3px;
  height: 16px;
  border-radius: 1px;
  display: inline-block;
}

.status-bar-stacked {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.status-bar-latest {
  width: 8px;
  margin-left: 3px;
}

.bar-segment {
  width: 100%;
}

.bar-pass {
  background: var(--color-success);
}

.bar-fail {
  background: var(--color-failure);
}

.bar-other {
  background: var(--color-neutral);
}

.status-bar:hover {
  opacity: 0.7;
}

.docs-link,
.coverage-link {
  font-size: 0.8rem;
  font-weight: 500;
}

.release-badge {
  background: #dafbe1;
  color: #1a7f37;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.pending-badge {
  background: #fff8c5;
  color: #9a6700;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

@media (prefers-color-scheme: dark) {
  .release-badge {
    background: #0d3117;
    color: #3fb950;
  }

  .pending-badge {
    background: #3b2300;
    color: #d29922;
  }
}

.issues-cell {
  font-size: 0.8rem;
  white-space: nowrap;
  text-align: center;
}

.issues-open {
  color: var(--color-success);
  font-weight: 500;
}

.issues-closed {
  color: var(--color-neutral);
  font-weight: 500;
}

/* Table View */
#dashboard.view-table {
  display: block;
  overflow-x: auto;
}

.repo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
}

.repo-table thead {
  background: var(--color-bg);
}

.repo-table th {
  text-align: left;
  padding: 0.4rem 0.5rem;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}

.repo-table th:hover {
  color: var(--color-text);
}

.repo-table th.sorted {
  color: var(--color-text);
}

.repo-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

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

.repo-table tbody tr:hover {
  background: var(--color-bg);
}

.repo-table tbody tr[data-status="success"] td:first-child {
  box-shadow: inset 3px 0 0 var(--color-success);
}

.repo-table tbody tr[data-status="failure"] td:first-child {
  box-shadow: inset 3px 0 0 var(--color-failure);
}

.repo-table tbody tr[data-status="in_progress"] td:first-child,
.repo-table tbody tr[data-status="queued"] td:first-child {
  box-shadow: inset 3px 0 0 var(--color-pending);
}

.repo-table .repo-name {
  font-size: 0.8rem;
}

.num-cell {
  font-size: 0.8rem;
  white-space: nowrap;
  text-align: center;
}

.table-desc {
  display: block;
  font-size: 0.7rem;
  color: var(--color-text-secondary);
  max-width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-cell .status-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
}

.repo-links {
  display: inline;
  font-size: 0.8rem;
  margin-left: 0.5rem;
}

.text-muted {
  color: var(--color-text-secondary);
}

/* Loading / Error */
.loading,
.error {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-secondary);
}

.error {
  color: var(--color-failure);
}

.loading::after {
  content: '';
  display: block;
  width: 24px;
  height: 24px;
  margin: 1rem auto 0;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-link);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Responsive */
@media (max-width: 600px) {
  #dashboard {
    padding: 1rem;
  }

  .repo-table {
    font-size: 0.8rem;
  }

  .repo-table th,
  .repo-table td {
    padding: 0.3rem 0.35rem;
  }

  .table-desc {
    max-width: 150px;
  }
}
