:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2128;
  --muted: #646d78;
  --accent: #2f6fdb;
  --accent-text: #ffffff;
  --danger: #c93a3a;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --info: #2f6fdb;
  --neutral: #6b7280;
  --code-bg: #0f1419;
  --code-text: #d6dde6;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fresh: #57bb8a;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2c333d;
    --text: #e3e7ec;
    --muted: #8e97a3;
    --accent: #5b8ff0;
    --accent-text: #0b1220;
    --danger: #ef6b6b;
    --ok: #4cc382;
    --warn: #e0a84a;
    --info: #5b8ff0;
    --neutral: #9aa3ae;
    --code-bg: #0b0e12;
    --fresh: #2e8b57;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--mono); font-size: 12.5px; }

/* --- layout --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; font-size: 15px; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text); }
.health { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.health.failing { color: var(--danger); font-weight: 600; margin-right: 12px; }
.health.failing:hover { text-decoration: none; filter: brightness(0.9); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--danger); }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.page-header h1 { font-size: 20px; margin: 0; font-weight: 650; }
.page-header .spacer { flex: 1; }
.updated { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.subtle { color: var(--muted); }
.crumb { color: var(--muted); font-size: 13px; margin-bottom: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-body { padding: 16px; }
.card h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }

/* --- tables --- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td .secondary { color: var(--muted); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.truncate { max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* --- controls --- */

button, .button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: 0.55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover:not(:disabled) { filter: brightness(1.07); background: var(--accent); }
button.danger { color: var(--danger); }
button.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
button.small { padding: 3px 8px; font-size: 12.5px; }
select.small { padding: 3px 6px; font-size: 12.5px; }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }

input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="date"], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 9px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 0;
  border-color: var(--accent);
}
textarea { width: 100%; resize: vertical; }
textarea.code { font-family: var(--mono); font-size: 12.5px; }
input.invalid, select.invalid, textarea.invalid, .chips.invalid { border-color: var(--danger); }

.switch { position: relative; display: inline-block; width: 32px; height: 18px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 9px; background: var(--border); cursor: pointer; transition: background 0.15s;
}
.switch span::before {
  content: ""; position: absolute; width: 14px; height: 14px; left: 2px; top: 2px; border-radius: 50%;
  background: #fff; transition: transform 0.15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(14px); }
.switch input:disabled + span { opacity: 0.5; cursor: default; }

/* --- forms --- */

.form-grid { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 14px 20px; align-items: start; }
.form-grid > label, .form-grid > .label { padding-top: 6px; font-weight: 500; }
.form-grid .hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.form-grid > label .hint { font-weight: normal; overflow-wrap: anywhere; }
.form-grid .error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }
.form-grid input[type="text"], .form-grid input[type="number"], .form-grid select { width: 100%; max-width: 420px; }
.form-actions { display: flex; gap: 8px; align-items: center; padding: 16px; border-top: 1px solid var(--border); }
.form-actions .spacer { flex: 1; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; padding-top: 5px; }
.checks label { display: inline-flex; align-items: center; gap: 6px; font-weight: normal; }
.inline { display: inline-flex; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 8px; }

.chips {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  max-width: 620px; min-height: 34px; padding: 4px 6px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.chips:focus-within { border-color: var(--accent); }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; font-size: 13px;
}
.chip button { border: none; background: none; padding: 0 4px; color: var(--muted); font-size: 14px; line-height: 1; }
.chips input { border: none; outline: none; background: transparent; flex: 1; min-width: 120px; padding: 3px 2px; }
.chips input:focus { outline: none; }

.notice {
  padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 13px;
}
.notice.error { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.notice.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); background: color-mix(in srgb, var(--warn) 10%, var(--surface)); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }

/* --- login --- */

.login { max-width: 340px; margin: 12vh auto 0; padding: 0 16px; }
.login .brand { display: block; text-align: center; margin-bottom: 16px; font-size: 18px; }
.login label { display: block; font-weight: 500; margin-bottom: 12px; }
.login input { display: block; width: 100%; margin-top: 4px; }
.login .notice { margin-bottom: 12px; }
.login button { width: 100%; margin-top: 4px; }

.section-title {
  grid-column: 1 / -1; margin: 10px 0 0; padding-top: 14px; border-top: 1px solid var(--border);
  font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em;
}
.section-title:first-child { border-top: none; padding-top: 0; margin-top: 0; }

/* --- badges --- */

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600;
  background: color-mix(in srgb, var(--neutral) 15%, transparent); color: var(--neutral); white-space: nowrap;
}
.badge.queued { color: var(--neutral); }
.badge.running { color: var(--info); background: color-mix(in srgb, var(--info) 15%, transparent); }
.badge.succeeded { color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.badge.partial { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); }
.badge.failed { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.badge.source { color: var(--text); background: var(--surface-2); border: 1px solid var(--border); font-weight: 500; }
.badge.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); }

.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button.active { background: var(--surface-2); border-color: var(--muted); }
.count { color: var(--muted); font-weight: normal; margin-left: 2px; }

/* --- runs --- */

.meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px 24px; }
.meta div > span:first-child { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.log {
  margin: 0; padding: 12px 14px; height: 480px; overflow: auto;
  background: var(--code-bg); color: var(--code-text);
  border-radius: 0 0 var(--radius) var(--radius); white-space: pre-wrap; word-break: break-word;
}
.log-header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.log-header h2 { margin: 0; }
.snapshot-shot { display: block; max-height: 520px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
.snapshot-shot img { display: block; width: 100%; }

/* --- dialog & toasts --- */

dialog {
  border: 1px solid var(--border); border-radius: 8px; padding: 0; width: 460px; max-width: calc(100vw - 32px);
  background: var(--surface); color: var(--text); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(10, 14, 20, 0.45); }
dialog h2 { margin: 0; padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 15px; }
dialog .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
dialog .dialog-body label.field { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
dialog .form-actions { justify-content: flex-end; }

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  min-width: 260px; max-width: 420px; padding: 10px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--ok);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--info); }

/* --- jobs & searches --- */

tr.muted-row td { opacity: 0.6; }
a.button { text-decoration: none; color: var(--text); }
a.button.primary { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
a.button.small, label.button.small { padding: 3px 8px; font-size: 12.5px; }
a.badge.source:hover { text-decoration: none; border-color: var(--muted); }

.description { line-height: 1.6; max-width: 820px; overflow-wrap: anywhere; }
.description.plain { white-space: pre-wrap; }
.description h4 { margin: 1em 0 0.4em; font-size: 14px; }
.description p { margin: 0 0 0.8em; }
.description ul, .description ol { padding-left: 22px; margin: 0 0 0.8em; }
pre.raw {
  margin: 12px 0 0; padding: 12px; max-height: 420px; overflow: auto; border-radius: var(--radius);
  background: var(--code-bg); color: var(--code-text); white-space: pre-wrap; word-break: break-word;
}

.group { border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius); background: var(--surface); }
.group.any { border-left-color: var(--warn); }
.group .group { margin-top: 8px; }
.group-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.group-body { padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.cond { padding: 2px 0; }
.cond-row { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.cond-row > select { max-width: 240px; }
.cond.has-error .cond-row { padding: 4px; margin: -4px; border-radius: var(--radius); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.group .error, .cond .error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }
.form-grid .group select, .form-grid .group input[type="text"] { width: auto; max-width: 240px; }
.form-grid .group .group-head select { min-width: 150px; }
.form-grid .stack select { width: auto; }

/* --- applications --- */

th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
.pre-wrap { white-space: pre-wrap; }
a.badge.succeeded:hover { text-decoration: none; filter: brightness(0.95); }

/* --- application charts --- */

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stats-grid .card + .card { margin-top: 0; }
.viz-card { padding: 14px 16px; }
.viz-card h2 { margin: 0; }
.viz-card table { margin-top: 8px; }
.viz-sub { font-size: 12.5px; margin: 2px 0 12px; }
.viz-foot { font-size: 12.5px; margin-top: 10px; }
.viz-legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.viz-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.viz-key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.viz-key.line { width: 12px; height: 2px; border-radius: 1px; }

.hbars { display: flex; flex-direction: column; }
.hbar-row { display: grid; grid-template-columns: 130px minmax(0, 1fr); align-items: center; gap: 10px; padding: 3px 0; border-radius: 4px; outline: none; }
.hbar-row:hover, .hbar-row:focus-visible { background: var(--surface-2); }
.hbar-label { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { display: flex; align-items: center; gap: 6px; min-width: 0; }
.hbar { flex: none; height: 14px; background: var(--series-1); border-radius: 0 4px 4px 0; }
.hbar-value { font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.cols { --plot-h: 150px; padding-left: 26px; }
.cols-plot { position: relative; height: var(--plot-h); margin-top: 18px; }
.cols-grid { position: absolute; left: 0; right: 0; border-top: 1px solid var(--border); }
.cols-grid span { position: absolute; right: calc(100% + 6px); top: -8px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cols-row { position: absolute; inset: 0; display: flex; }
.col-slot { flex: 1; display: flex; align-items: flex-end; justify-content: center; outline: none; border-radius: 4px 4px 0 0; }
.col-slot:hover, .col-slot:focus-visible { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.col-stack { position: relative; width: min(20px, 70%); display: flex; flex-direction: column-reverse; gap: 2px; }
.col-seg { display: block; min-height: 1px; }
.col-seg.top { border-radius: 4px 4px 0 0; }
.col-total { position: absolute; bottom: calc(100% + 3px); left: 50%; transform: translateX(-50%); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.cols-axis { display: flex; margin-top: 6px; }
.cols-axis span { flex: 1; text-align: center; font-size: 11px; color: var(--muted); white-space: nowrap; }

.viz-tip {
  position: fixed; z-index: 40; pointer-events: none; padding: 8px 10px; min-width: 120px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15); font-size: 12.5px;
}
.viz-tip-title { color: var(--muted); margin-bottom: 4px; }
.viz-tip-row { display: flex; align-items: center; gap: 6px; }
.viz-tip-row span:last-child { color: var(--muted); }

.stats-grid .viz-card.wide { grid-column: 1 / -1; }
.sankey { width: 100%; }
.sankey svg { display: block; overflow: visible; }
.sankey-link { fill-opacity: 0.35; outline: none; transition: fill-opacity 0.1s; }
.sankey-link:hover, .sankey-link:focus-visible { fill-opacity: 0.65; }
.sankey g { outline: none; }
.sankey-label {
  font-size: 12.5px; fill: var(--text);
  paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round;
}
.sankey-value { fill: var(--muted); font-variant-numeric: tabular-nums; }

.viz-rows { margin-bottom: 16px; display: flex; flex-direction: column; gap: 16px; }
.viz-rows .stats-grid { margin-bottom: 0; position: relative; }
.viz-row-min { position: absolute; top: 10px; right: 10px; z-index: 1; color: var(--muted); }
.viz-row-bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px 8px 16px; }
.viz-row-bar .subtle { flex: 1; font-size: 13px; }

/* --- jobs per day --- */

.jobs-per-day { margin-bottom: 16px; }
.viz-head { display: flex; align-items: center; gap: 8px; }
.viz-head .spacer { flex: 1; }
.cols-line { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.cols-line polyline { fill: none; stroke: var(--text); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
