:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fbfbfd;
  --border: #e2e5ea;
  --text: #1a1d23;
  --muted: #6b7280;
  --accent: #2f6df6;
  --accent-soft: #e8f0ff;
  --ok: #16874b;
  --ok-soft: #e4f4ea;
  --fail: #c62828;
  --fail-soft: #fdeaea;
  --warn: #9a6200;
  --warn-soft: #fdf1dd;
  --run: #2f6df6;
  --run-soft: #e8f0ff;
  --idle: #6b7280;
  --idle-soft: #eef0f3;
  --radius: 10px;

  /* Messbalken für Laufzeiten. Eine einzige Farbe - die Länge trägt die
     Aussage, nicht der Farbton. Füllung gegen die Fläche geprüft: >= 3:1,
     Helligkeitsband und Buntheit bestanden. Die Spur ist eine hellere Stufe
     desselben Blaus und tritt bewusst zur Fläche hin zurück. */
  --bar-fill: #2a78d6;
  --bar-track: #cde2fb;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a;
    --panel: #1a1d25;
    --panel-2: #171a21;
    --border: #2a2f3a;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --accent: #6f9bff;
    --accent-soft: #1d2740;
    --ok: #57cc8a;
    --ok-soft: #16301f;
    --fail: #ff8080;
    --fail-soft: #331a1a;
    --warn: #e8b464;
    --warn-soft: #33270f;
    --run: #6f9bff;
    --run-soft: #1d2740;
    --idle: #9aa1ad;
    --idle-soft: #22262f;
    --bar-fill: #3987e5;
    --bar-track: #24324a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.loading { padding: 3rem; color: var(--muted); }

/* ------------------------------------------------------------- Grundgerüst */

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1.1rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 650; letter-spacing: -0.01em; }
.brand .mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent);
  color: #fff; display: grid; place-items: center; font-size: 15px; font-weight: 700;
}
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); letter-spacing: 0; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  padding: 0.45rem 0.6rem; border-radius: 7px; color: var(--text);
  font-size: 14px; display: flex; justify-content: space-between; align-items: center;
}
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 550; }
.nav .count { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0 0.6rem; margin-bottom: 4px; }

.sidebar .spacer { flex: 1; }
.whoami { font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 0.8rem; }
.whoami strong { color: var(--text); display: block; font-size: 13px; }

.main { padding: 1.6rem 2rem 4rem; max-width: 1180px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.3rem; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 0.2rem; font-size: 21px; letter-spacing: -0.02em; }
.page-head p { margin: 0; color: var(--muted); font-size: 13.5px; max-width: 64ch; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* -------------------------------------------------------------- Bausteine */

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.panel + .panel { margin-top: 1.1rem; }
.panel h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.panel-head { padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.panel-body { padding: 1rem; }
.panel-body.tight { padding: 0; }

button, .btn {
  font: inherit; font-size: 13.5px; padding: 0.4rem 0.8rem; border-radius: 7px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  cursor: pointer; display: inline-flex; align-items: center; gap: 0.4rem;
}
button:hover, .btn:hover { background: var(--panel-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--fail); border-color: var(--fail); background: transparent; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.small { padding: 0.22rem 0.5rem; font-size: 12.5px; }

input, select, textarea {
  font: inherit; font-size: 14px; padding: 0.42rem 0.6rem; border-radius: 7px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 0.25rem; }
.field { margin-bottom: 0.8rem; }
.row { display: flex; gap: 0.8rem; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 180px; }

.badge {
  display: inline-flex; align-items: center; gap: 0.3rem; font-size: 11.5px; font-weight: 600;
  padding: 0.12rem 0.45rem; border-radius: 5px; letter-spacing: 0.01em; white-space: nowrap;
}
.badge.success { background: var(--ok-soft); color: var(--ok); }
.badge.failed { background: var(--fail-soft); color: var(--fail); }
.badge.running { background: var(--run-soft); color: var(--run); }
.badge.queued { background: var(--idle-soft); color: var(--idle); }
.badge.cancelled, .badge.skipped { background: var(--warn-soft); color: var(--warn); }
.badge.never { background: var(--idle-soft); color: var(--idle); }
.badge.library { background: var(--idle-soft); color: var(--idle); }
.badge.app { background: var(--accent-soft); color: var(--accent); }

.badge.running::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------------ Jobs */

.job-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); gap: 0.8rem; }
.job-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.85rem 0.95rem; display: flex; flex-direction: column; gap: 0.55rem;
}
.job-card.is-running { border-color: var(--run); }
.job-card.is-failed { border-color: var(--fail); }
.job-card .title { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.job-card .title a { font-weight: 600; color: var(--text); font-size: 15px; }
.job-card .meta { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0.35rem 0.7rem; }
.job-card .foot { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-top: auto; }
.job-card .affects { font-size: 12px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; padding: 0.55rem 1rem; border-bottom: 1px solid var(--border); }
td { padding: 0.5rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
td.num { font-variant-numeric: tabular-nums; color: var(--muted); }

.empty { padding: 1.6rem 1rem; text-align: center; color: var(--muted); font-size: 13.5px; }

/* ------------------------------------------------------------------ Build */

.steps { display: flex; flex-direction: column; }
.step { display: flex; align-items: center; gap: 0.6rem; padding: 0.42rem 1rem; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.step:last-child { border-bottom: none; }
.step .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--idle); }
.step.success .dot { background: var(--ok); }
.step.failed .dot { background: var(--fail); }
.step.running .dot { background: var(--run); animation: pulse 1.1s ease-in-out infinite; }
.step.cancelled .dot { background: var(--warn); }
.step .msg { color: var(--fail); font-size: 12.5px; }

.log {
  background: #0d1017; color: #d6dae2; font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  padding: 0.9rem 1rem; border-radius: var(--radius); max-height: 62vh; overflow: auto;
  white-space: pre-wrap; word-break: break-word; border: 1px solid var(--border);
}
.log .meta { color: #6f9bff; }
.log .err { color: #ff9f9f; }

.log-bar { display: flex; justify-content: space-between; align-items: center; margin: 0 0 0.5rem; gap: 1rem; }

/* ------------------------------------------------------------------ Graph */

.graph-row { display: grid; grid-template-columns: 220px 1fr; gap: 1rem; padding: 0.7rem 1rem; border-bottom: 1px solid var(--border); align-items: start; }
.graph-row:last-child { border-bottom: none; }
.chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chip { font-size: 12px; padding: 0.1rem 0.45rem; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.chip.strong { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* ------------------------------------------------------------------ Login */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 1.6rem; }
.login-card h1 { margin: 0 0 0.3rem; font-size: 19px; }
.login-card p.lead { margin: 0 0 1.2rem; color: var(--muted); font-size: 13.5px; }

.notice { padding: 0.55rem 0.75rem; border-radius: 7px; font-size: 13px; margin-bottom: 0.9rem; }
.notice.error { background: var(--fail-soft); color: var(--fail); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.info { background: var(--accent-soft); color: var(--accent); }

.toast-host { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 50; }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; padding: 0.6rem 0.85rem; font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); max-width: 340px; }
.toast.error { border-left-color: var(--fail); }
.toast.ok { border-left-color: var(--ok); }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 0.8rem; }
  .sidebar .spacer { display: none; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-group { display: none; }
  .whoami { border-top: none; padding-top: 0; }
  .main { padding: 1.1rem 1rem 3rem; }
}

/* Laufende Zeiten zählen jede Sekunde hoch - Ziffernbreite fixieren, damit
   die Spalte dabei nicht zappelt. */
.live {
  font-variant-numeric: tabular-nums;
  color: var(--run);
  font-weight: 550;
}

/* --------------------------------------------------- Laufzeit-Balken */

.dur { display: flex; flex-direction: column; gap: 3px; min-width: 5.5rem; }
.dur-value { font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }

/* Spur und Füllung, kein Rahmen: getrennt wird über die Farbstufe, nicht über
   eine gezeichnete Kante. */
.dur-track {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: var(--bar-track);
}
.dur-fill {
  display: block;
  height: 100%;
  background: var(--bar-fill);
  /* Rundes Datenende, eckig an der Grundlinie - der Balken wächst von links. */
  border-radius: 0 4px 4px 0;
  transition: width 0.4s ease-out;
}

/* Kleiner Hinweis auf Builds, die eine Bibliothek unter sich ausgelöst hat. */
.dep {
  color: var(--muted);
  margin-right: 3px;
  font-size: 13px;
  cursor: help;
}

/* Hauptprojekte heben sich in der Buildliste von den Bibliotheken ab. */
a.is-app { font-weight: 650; }

/* ------------------------------------ Hauptprojekte über die volle Breite */

.job-rows { display: flex; flex-direction: column; gap: 0.6rem; }

.job-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 1.2rem;
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.95rem;
}
.job-row.is-running { border-color: var(--run); }
.job-row.is-failed { border-color: var(--fail); }
.job-row .title { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.job-row .title a { font-size: 15.5px; color: var(--text); }
.job-row .meta {
  display: flex; flex-wrap: wrap; gap: 0.25rem 0.9rem;
  font-size: 12.5px; color: var(--muted); margin-top: 0.3rem;
}
.job-row-actions { display: flex; gap: 0.4rem; }

/* ------------------------------------------------ Kleiner Säulenverlauf */

/* Eine Serie, eine Farbe. Die Grundlinie ist eine zurückhaltende Haarlinie,
   kein Rahmen um die Säulen - getrennt wird über die 2px Fläche dazwischen. */
.spark {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 30px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
}
.spark-col {
  width: 9px;
  min-height: 3px;
  background: var(--bar-fill);
  /* Rundes Datenende oben, eckig an der Grundlinie. */
  border-radius: 4px 4px 0 0;
  cursor: help;
}

@media (max-width: 720px) {
  .job-row { grid-template-columns: 1fr; gap: 0.6rem; }
  .job-row-actions { justify-content: flex-start; }
}

/* --------------------------------------------------------------- Reiter */

/* BELBO und Hairlist laufen auf getrennten Servern. Sie in einer Ansicht zu
   mischen lädt zum Verwechseln ein - hier sieht man immer nur eine Linie. */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.1rem;
}
.tab {
  padding: 0.5rem 0.9rem;
  font-size: 14.5px;
  font-weight: 550;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count {
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 0.4rem;
  color: var(--muted);
}
.tab.active .count { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

.system-block > .panel:first-child { margin-top: 0; }

/* ------------------------------------------- Tabellen mit festen Spalten */

/* Die Release-Ansicht setzt je Projekt eine eigene Tabelle. Ohne feste Breiten
   richtet jede ihre Spalten nach dem eigenen Inhalt aus, und die Blöcke stehen
   versetzt untereinander. */
table.fixed { table-layout: fixed; }

/* Bei fester Breite kann Inhalt überstehen - lieber sauber abschneiden als die
   Spalte sprengen. Der vollständige Wert steht im Tooltip. */
table.fixed td.nowrap,
table.fixed td .dur-value {
  overflow: hidden;
  text-overflow: ellipsis;
}
table.fixed td { overflow-wrap: anywhere; }
