:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-card-hover: #1c2129;
  --border: #30363d;
  --text: #c9d1d9;
  --text-dim: #8b949e;
  --text-bright: #f0f6fc;
  --accent: #58a6ff;
  --success: #3fb950;
  --running: #58a6ff;
  --failed: #f85149;
  --queued: #d29922;
  --pending: #6e7681;
  --skipped: #484f58;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  gap: 20px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-bright);
  letter-spacing: -0.2px;
}

.brand-author {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-dim);
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.brand-author:hover {
  background: var(--bg-card-hover);
  color: var(--accent);
  border-color: var(--accent);
}

.brand-author svg {
  flex-shrink: 0;
  opacity: 0.85;
}

.brand-tagline {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  max-width: 720px;
}

.brand-sub {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.brand-sub .arrow {
  color: var(--text-dim);
  opacity: 0.6;
}

.controls {
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 4px;
}

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

.last-updated {
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--mono);
}

.auto-refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.auto-refresh input {
  accent-color: var(--accent);
  cursor: pointer;
}

.btn {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:hover {
  background: var(--bg-card-hover);
}

.brand-sub a {
  color: var(--accent);
  text-decoration: none;
}
.brand-sub a:hover { text-decoration: underline; }

.brand-sub .track-label {
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-right: 2px;
  opacity: 0.85;
}

.legend-intro {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.55;
  margin: 8px 0 12px;
}

.legend-status-list {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
  margin: 8px 0 0;
  padding-left: 18px;
}
.legend-status-list li { margin-bottom: 6px; }
.legend-status-list strong { color: var(--text); }

.legend {
  max-width: 1400px;
  margin: 16px auto 0;
  padding: 0 24px;
}

.legend details {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
}

.legend summary {
  cursor: pointer;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text-bright);
  font-size: 13px;
  user-select: none;
  list-style: none;
}
.legend summary::-webkit-details-marker { display: none; }

.legend summary::before {
  content: "▸";
  color: var(--text-dim);
  display: inline-block;
  transition: transform 0.15s;
  margin-right: 8px;
}

.legend details[open] summary::before {
  transform: rotate(90deg);
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1px;
  background: var(--border);
  border-top: 1px solid var(--border);
}

.legend-item {
  background: var(--bg-card);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--bg);
  font-weight: bold;
  flex-shrink: 0;
}

.legend-icon.commit  { background: var(--success); }
.legend-icon.sync    { background: var(--running); }
.legend-icon.bottest { background: #a371f7; }
.legend-icon.audit   { background: var(--queued); }
.legend-icon.pr      { background: #db61a2; }
.legend-icon.verify  { background: #2fd4a7; }

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

.legend-eli5 {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  font-weight: 500;
}

.legend-desc {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
  padding-top: 6px;
  margin-top: 2px;
  border-top: 1px dashed var(--border);
}

.legend-tech-label {
  color: var(--pending);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 10px;
  font-weight: 600;
  margin-right: 4px;
}

.legend-desc a {
  color: var(--accent);
  text-decoration: none;
}
.legend-desc a:hover { text-decoration: underline; }

.legend-desc code {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-family: var(--mono);
}

.summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  padding: 20px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}

.summary-value {
  font-size: 28px;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--text-bright);
}

.summary-label {
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

.summary-card.success .summary-value { color: var(--success); }
.summary-card.running .summary-value { color: var(--running); }
.summary-card.failed .summary-value { color: var(--failed); }
.summary-card.skipped .summary-value { color: var(--skipped); }

.pipelines {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.loading {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 20px;
}

.pipeline {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.pipeline:hover {
  border-color: var(--accent);
}

.pipeline-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.pipeline-header:hover {
  background: var(--bg-card-hover);
}

.pipeline-title {
  flex: 1;
  min-width: 0;
}

.pipeline-message {
  font-weight: 500;
  color: var(--text-bright);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pipeline-meta {
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--mono);
  margin-top: 2px;
}

.pipeline-meta .sha {
  color: var(--accent);
}

.pipeline-meta a {
  color: inherit;
  text-decoration: none;
}
.pipeline-meta a:hover { text-decoration: underline; }

.pipeline-overall {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-family: var(--mono);
}

.overall-badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 11px;
}
.overall-badge.success { background: rgba(63, 185, 80, 0.15); color: var(--success); }
.overall-badge.running { background: rgba(88, 166, 255, 0.15); color: var(--running); }
.overall-badge.failed  { background: rgba(248, 81, 73, 0.15);  color: var(--failed); }
.overall-badge.skipped { background: rgba(110, 118, 129, 0.15); color: var(--skipped); }
.overall-badge.pending { background: rgba(110, 118, 129, 0.15); color: var(--pending); }
.overall-badge.queued  { background: rgba(210, 153, 34, 0.15);  color: var(--queued); }

.pipeline-stages {
  display: flex;
  align-items: stretch;
  padding: 20px 20px 24px;
  gap: 0;
  overflow-x: auto;
}

.stage {
  flex: 1 1 0;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  padding: 0 8px;
}

.stage-connector {
  position: absolute;
  top: 20px;
  right: -50%;
  left: 50%;
  height: 2px;
  background: var(--border);
  z-index: 0;
}

.stage:last-child .stage-connector { display: none; }

.stage.success + .stage .stage-connector,
.stage.success .stage-connector { background: var(--success); }

.stage-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
  background: var(--bg);
  border: 2px solid var(--pending);
  color: var(--pending);
  position: relative;
  z-index: 1;
  transition: all 0.2s;
}

.stage.success .stage-icon {
  background: var(--success);
  border-color: var(--success);
  color: var(--bg);
}

.stage.running .stage-icon {
  background: var(--running);
  border-color: var(--running);
  color: var(--bg);
  animation: pulse 1.5s ease-in-out infinite;
}

.stage.queued .stage-icon {
  background: var(--queued);
  border-color: var(--queued);
  color: var(--bg);
}

.stage.failed .stage-icon {
  background: var(--failed);
  border-color: var(--failed);
  color: var(--bg);
}

.stage.skipped .stage-icon {
  background: var(--bg);
  border-color: var(--skipped);
  color: var(--skipped);
  border-style: dashed;
}

.stage-label {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-bright);
}

.stage-sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
}

.stage-sub a {
  color: var(--accent);
  text-decoration: none;
}
.stage-sub a:hover { text-decoration: underline; }

.tokens-intro {
  padding: 14px 16px 4px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

.tokens-intro strong {
  color: var(--text-bright);
}

.tokens-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
  border-top: 1px solid var(--border);
}

.token-item {
  background: var(--bg-card);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.token-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.token-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border: 1px solid transparent;
  flex-shrink: 0;
}

.token-badge.read {
  color: var(--success);
  background: rgba(63, 185, 80, 0.12);
  border-color: rgba(63, 185, 80, 0.35);
}

.token-badge.write {
  color: var(--queued);
  background: rgba(210, 153, 34, 0.12);
  border-color: rgba(210, 153, 34, 0.35);
}

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

.token-name code {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--accent);
  margin-left: 6px;
}

.token-eli5 {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

.token-eli5 em {
  color: var(--text-bright);
  font-style: normal;
  font-weight: 600;
}

.token-scopes {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.6;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.token-scopes code {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text);
}

.token-on {
  margin-top: 4px;
  color: var(--pending);
}

.retry-chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-family: var(--mono);
  border: 1px solid transparent;
  vertical-align: baseline;
}
.retry-chip.active {
  color: var(--queued);
  background: rgba(210, 153, 34, 0.12);
  border-color: rgba(210, 153, 34, 0.35);
}
.retry-chip.exhausted {
  color: var(--failed);
  background: rgba(248, 81, 73, 0.12);
  border-color: rgba(248, 81, 73, 0.35);
}

.pipeline-details {
  display: none;
  border-top: 1px solid var(--border);
  padding: 16px 20px 20px;
  background: rgba(0, 0, 0, 0.2);
}

.pipeline.expanded .pipeline-details {
  display: block;
}

.pipeline.expanded .pipeline-chevron {
  transform: rotate(90deg);
}

.pipeline-chevron {
  color: var(--text-dim);
  transition: transform 0.15s;
  font-size: 16px;
  margin-left: 8px;
}

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

.detail-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
}

.detail-card-title {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.detail-card-value {
  font-family: var(--mono);
  font-size: 12px;
}

.detail-card-value a {
  color: var(--accent);
  text-decoration: none;
}
.detail-card-value a:hover { text-decoration: underline; }

.detail-full-message {
  grid-column: 1 / -1;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  color: var(--text);
  max-height: 300px;
  overflow-y: auto;
}

.footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 20px;
  border-top: 1px solid var(--border);
  margin-top: 20px;
}

.footer code {
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--mono);
}
.footer a:hover { text-decoration: underline; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--running); opacity: 1; }
  50% { box-shadow: 0 0 0 8px transparent; opacity: 0.85; }
}

.error-banner {
  background: rgba(248, 81, 73, 0.15);
  border: 1px solid var(--failed);
  color: var(--failed);
  padding: 12px 16px;
  border-radius: 6px;
  margin: 12px 24px;
  font-family: var(--mono);
  font-size: 13px;
}

@media (max-width: 1200px) {
  .legend-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
  .pipeline-stages { overflow-x: scroll; }
  .stage { min-width: 110px; }
  .legend-grid { grid-template-columns: repeat(2, 1fr); }
  .tokens-grid { grid-template-columns: 1fr; }
}
