:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e6;
  --text: #1c2128;
  --muted: #677180;
  --accent: #2f6fdb;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --ok-bg: #e3f4ea;
  --warn: #9a6200;
  --warn-bg: #fdf1dc;
  --err: #c0362c;
  --err-bg: #fbe7e5;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #232830;
    --border: #2f3640;
    --text: #e6e9ee;
    --muted: #8d97a5;
    --accent: #5b93f0;
    --accent-text: #0d1117;
    --ok: #5cc98a;
    --ok-bg: #173323;
    --warn: #e8b25a;
    --warn-bg: #3a2c12;
    --err: #f07a70;
    --err-bg: #3d1c1a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

h2 { font-size: 1rem; margin: 0; }

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

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 1.1rem; }

.nav { display: flex; gap: 4px; margin-right: auto; margin-left: 24px; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 7px;
  font-size: .9rem;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 600; }

a { color: var(--accent); }
.brand svg { width: 24px; height: 24px; fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; }

.mode {
  font-size: .8rem;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50vw;
}
.mode-mock { background: var(--warn-bg); color: var(--warn); }
.mode-live { background: var(--ok-bg); color: var(--ok); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 480px) minmax(0, 1fr);
  gap: 20px;
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 24px;
  align-items: start;
}
.side { display: grid; gap: 20px; min-width: 0; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 0 16px; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .nav { order: 3; width: 100%; margin: 0; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 0;
}
.card > h2 { margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }

form { display: grid; gap: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1 1 160px; }

.field { display: grid; gap: 5px; min-width: 0; border: 0; padding: 0; margin: 0; }
.field > span, .field > legend { font-size: .82rem; color: var(--muted); font-weight: 550; padding: 0; }

input:not([type=radio]):not([type=range]), select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=range] { width: 100%; accent-color: var(--accent); }

.ticket {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  transition: border-color .15s;
}
.ticket:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.ticket svg {
  width: 18px;
  height: 18px;
  margin-left: 10px;
  flex: none;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.7;
  stroke-linejoin: round;
}
.ticket input:not([type=radio]):not([type=range]) {
  border: 0;
  outline: none;
  background: transparent;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  letter-spacing: .03em;
}
.ticket.is-valid { border-color: var(--ok); }
.ticket.is-valid svg { stroke: var(--ok); }
.ticket.is-invalid { border-color: var(--err); }
.ticket-open {
  padding: 0 10px;
  text-decoration: none;
  font-weight: 600;
}
.ticket-hint { color: var(--muted); font-size: .75rem; }
.ticket-hint.is-error { color: var(--err); }

.chip-ticket {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-weight: 500;
  margin-left: 6px;
  vertical-align: 1px;
  text-decoration: none;
  color: var(--accent);
}
a.chip-ticket:hover { border-color: var(--accent); }


.user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
}
.user-badge svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.activity-wrap { overflow-x: auto; }
.activity { width: 100%; border-collapse: collapse; font-size: .87rem; }
.activity td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}
.activity td:first-child { padding-left: 0; }
.activity td:last-child { padding-right: 0; text-align: right; }
.activity tr:last-child td { border-bottom: 0; }
.activity .empty { color: var(--muted); }
.act-name { font-weight: 600; width: 100%; }
.act-user { color: var(--muted); font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .8rem; }
.act-time { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.act-day { font-style: italic; }
.activity .chip-ticket { margin-left: 0; }

.type-tag {
  display: inline-block;
  min-width: 44px;
  text-align: center;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--muted);
  border: 1px solid var(--border);
}

.pill-info { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.pill-muted { background: var(--surface-2); color: var(--muted); }

.netbox {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 12px 14px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  min-width: 0;
}
/* float holt die Legende aus der Rahmenlinie in den Kasten; im Grid wird sie zur ersten Zeile */
.netbox > .netbox-head {
  float: left;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0 8px;
  margin: 0;
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
  font-weight: 600;
}
.source-badge {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  padding: 1px 7px;
  border-radius: 4px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--surface);
}
.netbox:disabled { opacity: .6; }
.netbox select { background: var(--surface); }

select { max-width: 100%; min-width: 0; text-overflow: ellipsis; }

.net-info {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 3px 14px;
  margin: 0;
  font-size: .82rem;
}
.net-info dt { color: var(--muted); }
.net-info dd { margin: 0; font-family: ui-monospace, "SF Mono", Consolas, monospace; overflow-wrap: anywhere; }
.net-info dd small { font-family: system-ui, sans-serif; margin-left: 6px; }

.usage-bar {
  display: inline-block;
  width: 80px;
  height: 6px;
  margin-right: 8px;
  border-radius: 3px;
  background: var(--border);
  vertical-align: middle;
  overflow: hidden;
}
.usage-bar > span { display: block; height: 100%; background: var(--ok); }
.usage-high > span { background: var(--warn); }
.usage-full > span { background: var(--err); }

.net-problems {
  margin: 0;
  padding: 8px 12px 8px 28px;
  border-radius: 7px;
  background: var(--err-bg);
  color: var(--err);
  font-size: .82rem;
}

.tpl-info { color: var(--muted); font-size: .8rem; min-height: 1.2em; }
.tpl-missing { color: var(--err); }
.tpl-specs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.chip {
  font-size: .75rem;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

button {
  font: inherit;
  border-radius: 7px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 6px 12px;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  padding: 10px;
}
button:disabled { opacity: .6; cursor: progress; }
button.danger:hover { color: var(--err); border-color: var(--err); }

.banner { padding: 10px 12px; border-radius: 7px; font-size: .9rem; }
.banner ul { margin: 6px 0 0; padding-left: 18px; }
.banner-error { background: var(--err-bg); color: var(--err); }
.banner-ok { background: var(--ok-bg); color: var(--ok); }

.muted { color: var(--muted); font-size: .85rem; }

.vm-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.vm-list .empty { color: var(--muted); padding: 8px 0; }
.vm {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}
.vm-name { font-weight: 600; overflow-wrap: anywhere; }
.vm-meta { color: var(--muted); font-size: .8rem; grid-column: 1; }
.vm-actions { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 8px; align-items: center; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-building { background: var(--warn-bg); color: var(--warn); }
.pill-building::before { animation: pulse 1.2s ease-in-out infinite; }
.pill-ready { background: var(--ok-bg); color: var(--ok); }
.pill-failed, .pill-unknown { background: var(--err-bg); color: var(--err); }

@keyframes pulse { 50% { opacity: .25; } }

details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: 12px; }

.preview {
  margin: 0;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 7px;
  font: 12.5px/1.5 ui-monospace, "SF Mono", Consolas, monospace;
  overflow: auto;
  max-height: 480px;
  white-space: pre;
}
.preview.invalid { color: var(--muted); white-space: pre-wrap; }

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

.layout-single { grid-template-columns: minmax(0, 1fr); }
.card-intro { margin: 0 0 14px; }
.filter { max-width: 280px; }

.builds-table, .diff-table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.builds-table th, .diff-table th {
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.builds-table td, .diff-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}
.builds-table tbody tr { cursor: pointer; }
.builds-table tbody tr:hover { background: var(--surface-2); }
.builds-table tr.is-selected { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.builds-table .act-name { width: auto; }
.builds-table .empty { color: var(--muted); cursor: default; }

.hash { font-size: .75rem; color: var(--muted); }
.config-link { font-size: .75rem; font-weight: 500; margin-left: 6px; text-decoration: none; }
.config-link:hover { text-decoration: underline; }
.act-name a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--muted); }
.act-name a:hover { color: var(--accent); border-color: var(--accent); }
code { font-family: ui-monospace, "SF Mono", Consolas, monospace; }

.detail-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.detail-head h2 { font-size: 1.1rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.detail-head p { margin: 6px 0 0; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.versions { margin: 14px 0 0; font-size: .85rem; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.versions a.type-tag { text-decoration: none; }
.versions a.type-tag:hover { border-color: var(--accent); color: var(--accent); }
.type-tag.is-current { border-color: var(--accent); color: var(--accent); }

.detail-info { margin: 16px 0; font-size: .87rem; }
.detail-info dd { font-family: system-ui, sans-serif; }

#build-detail h3 { font-size: .95rem; margin: 20px 0 8px; }
.diff-table td { white-space: normal; overflow-wrap: anywhere; }
.diff-table td:first-child { white-space: nowrap; }
.diff-changed td:nth-child(2) code { color: var(--err); }
.diff-changed td:nth-child(3) code { color: var(--ok); }
.diff-added td:nth-child(3) code { color: var(--ok); }
.diff-removed td:nth-child(2) code { color: var(--err); text-decoration: line-through; }

.json-block { margin-top: 12px; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.json-block > summary { font-weight: 600; font-size: .9rem; justify-content: flex-start; }
.json-block[open] > summary { margin-bottom: 10px; }
.json-block .preview { max-height: 420px; }

/* --- Build-Task: Schritte mit Status ------------------------------------- */

.task {
  margin-top: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.task-done { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.task-failed { border-color: color-mix(in srgb, var(--err) 45%, var(--border)); }
.task h3 { font-size: .95rem; margin: 0; overflow-wrap: anywhere; }
.task-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.task > h3 { margin-bottom: 10px; }
.task .banner { margin-top: 12px; }
.task-note { margin: 6px 0 0; }
.task-links { margin: 8px 0 0; font-size: .87rem; }

.task-steps { list-style: none; margin: 0; padding: 0; }
.step { position: relative; display: flex; gap: 10px; padding-bottom: 12px; }
.step:last-child { padding-bottom: 0; }
/* Verbindungslinie zwischen den Symbolen */
.step:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 9px;
  top: 22px;
  bottom: 2px;
  width: 2px;
  background: var(--border);
}
.step-done:not(:last-child)::after { background: var(--ok); }

.step-icon {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.step-running .step-icon {
  border-color: var(--warn-bg);
  border-top-color: var(--warn);
  animation: spin .8s linear infinite;
}
.step-done .step-icon { border-color: var(--ok); background: var(--ok); color: var(--surface); }
.step-done .step-icon::before { content: "✓"; }
.step-failed .step-icon { border-color: var(--err); background: var(--err); color: var(--surface); }
.step-failed .step-icon::before { content: "✕"; }
.step-skipped .step-icon { border-style: dashed; }

.step-body { display: flex; flex-direction: column; min-width: 0; padding-top: 1px; }
.step-label { font-size: .9rem; }
.step-pending .step-label, .step-skipped .step-label { color: var(--muted); }
.step-skipped .step-label { text-decoration: line-through; }
.step-detail { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.step-failed .step-detail { color: var(--err); }

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .step-running .step-icon { animation: none; border-color: var(--warn); }
}
