:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-raised: #1c232d;
  --border: #2a3340;
  --text: #e6edf3;
  --text-muted: #8b98a9;
  --success: #3fb950;
  --failure: #f85149;
  --running: #d29922;
  --queued: #58a6ff;
  --neutral: #6e7681;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 2;
}

/* Barra de progreso del ciclo de refresco: pegada al borde inferior del
   header, se llena durante el minuto y al completarse llega el refresco. */
.refresh-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  overflow: hidden;
  pointer-events: none;
}

.refresh-progress-fill {
  height: 100%;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left;
  background: linear-gradient(90deg, #2563eb, #7c3aed);
  opacity: 0.85;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand h1 { margin: 0; font-size: 1.05rem; }
.subtitle { margin: 0; color: var(--text-muted); font-size: 0.8rem; }

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

.pill {
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border);
}
.pill-running { color: var(--running); }
.pill-failure { color: var(--failure); }
.pill-success { color: var(--success); }
.pill-running::before { content: "▶ "; }
.pill-failure::before { content: "✕ "; }
.pill-success::before { content: "✓ "; }

.controls { margin-left: auto; display: flex; gap: 0.5rem; }

#filter {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.45rem 0.75rem;
  width: 220px;
}
#filter:focus { outline: 1px solid var(--queued); }

.icon-btn {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 1rem;
}
.icon-btn:hover { border-color: var(--queued); }
#refresh.spinning { animation: spin 0.8s linear infinite; }
#notify.off { opacity: 0.55; }

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

main { padding: 1.25rem 1.5rem 3rem; max-width: 1500px; margin: 0 auto; }

.meta { color: var(--text-muted); font-size: 0.85rem; margin: 0 0 1rem; }
.meta.error { color: var(--failure); }

.grid {
  display: grid;
  /* min(290px, 100%) evita que la columna mínima supere el ancho del viewport
     en pantallas angostas y provoque scroll horizontal. */
  grid-template-columns: repeat(auto-fill, minmax(min(290px, 100%), 1fr));
  gap: 0.7rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-left: 4px solid var(--neutral);
  /* Sin esto, el contenido con nowrap (nombre del repo, línea del run) fija el
     ancho mínimo de la card y desborda la grilla en móvil. */
  min-width: 0;
  overflow: hidden;
}
.card.status-success { border-left-color: var(--success); }
.card.status-failure { border-left-color: var(--failure); }
.card.status-running { border-left-color: var(--running); }
.card.status-queued { border-left-color: var(--queued); }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; min-width: 0; }

.repo-name {
  flex: 1;
  min-width: 0;
  font-weight: 650;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.repo-name:hover { text-decoration: underline; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge-success { color: var(--success); background: rgba(63, 185, 80, 0.12); }
.badge-failure { color: var(--failure); background: rgba(248, 81, 73, 0.12); }
.badge-running { color: var(--running); background: rgba(210, 153, 34, 0.12); }
.badge-running .dot { animation: pulse 1.2s ease-in-out infinite; }
.badge-queued { color: var(--queued); background: rgba(88, 166, 255, 0.12); }
.badge-neutral { color: var(--text-muted); background: rgba(110, 118, 129, 0.15); }

@keyframes pulse { 50% { opacity: 0.25; } }

.run-line {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.run-line a { color: var(--text-muted); }
.run-line a:hover { color: var(--text); }

.commit {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--text);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.branches { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: auto; padding-top: 0.1rem; }

.branch-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.74rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-muted);
  text-decoration: none;
}
.branch-chip:hover { border-color: var(--queued); color: var(--text); }
.branch-chip .dot { width: 7px; height: 7px; border-radius: 50%; }
.dot-success { background: var(--success); }
.dot-failure { background: var(--failure); }
.dot-running { background: var(--running); animation: pulse 1.2s ease-in-out infinite; }
.dot-queued { background: var(--queued); }
.dot-neutral { background: var(--neutral); }

.card-error { color: var(--failure); font-size: 0.85rem; }

.no-actions { margin-top: 2rem; color: var(--text-muted); }
.no-actions h2 { font-size: 0.9rem; margin: 0 0 0.35rem; }
.no-actions p { margin: 0; font-size: 0.85rem; }

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--bg);
}
/* display:grid le gana al display:none del atributo hidden; sin esta regla el
   overlay taparía el tablero incluso "oculto". */
.login-overlay[hidden] { display: none; }

.login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 340px;
  padding: 2rem 1.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.login-card h2 { margin: 0; font-size: 1.15rem; }
.login-hint { margin: 0 0 0.5rem; color: var(--text-muted); font-size: 0.85rem; text-align: center; }

.login-card input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
}
.login-card input:focus { outline: 1px solid var(--queued); }

.login-error { margin: 0; color: var(--failure); font-size: 0.82rem; }

.login-card button {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.6rem;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
.login-card button:disabled { opacity: 0.6; cursor: wait; }

@media (max-width: 640px) {
  .controls { margin-left: 0; width: 100%; }
  #filter { flex: 1; width: auto; }
}
