:root {
  --bg: #f6f5f1; --panel: #ffffff; --panel-2: #f1efe9; --border: #e3e0d7; --border-strong: #d2cec2;
  --text: #1f1e1b; --muted: #6b675e; --faint: #9a958a;
  --accent: #c8623f; --accent-soft: #f7e3da; --accent-text: #9c4527;
  --ok: #2f7d4f; --ok-soft: #dcf0e2; --warn: #9a6a00; --warn-soft: #f8ecc9;
  --bad: #b3372e; --bad-soft: #f8dcd8; --info: #2f5f9e; --info-soft: #dce7f6;
  --add: #e3f4e6; --add-text: #1e6b39; --del: #fbe4e1; --del-text: #9b2c22;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  --radius: 10px; --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513; --panel: #1e1d1a; --panel-2: #262420; --border: #2f2d28; --border-strong: #3d3a33;
    --text: #ecebe6; --muted: #a29d91; --faint: #716c62;
    --accent: #e0805e; --accent-soft: #3a261d; --accent-text: #f0a487;
    --ok: #5cc184; --ok-soft: #1b3325; --warn: #e2b54a; --warn-soft: #382d12;
    --bad: #ec7468; --bad-soft: #3d1d1a; --info: #7ea9e6; --info-soft: #1b2738;
    --add: #15291c; --add-text: #7fd39b; --del: #331816; --del-text: #f19a90;
    --shadow: 0 1px 2px rgb(0 0 0 / .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161513; --panel: #1e1d1a; --panel-2: #262420; --border: #2f2d28; --border-strong: #3d3a33;
  --text: #ecebe6; --muted: #a29d91; --faint: #716c62;
  --accent: #e0805e; --accent-soft: #3a261d; --accent-text: #f0a487;
  --ok: #5cc184; --ok-soft: #1b3325; --warn: #e2b54a; --warn-soft: #382d12;
  --bad: #ec7468; --bad-soft: #3d1d1a; --info: #7ea9e6; --info-soft: #1b2738;
  --add: #15291c; --add-text: #7fd39b; --del: #331816; --del-text: #f19a90;
  --shadow: 0 1px 2px rgb(0 0 0 / .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1320px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; letter-spacing: -.01em; }
.brand img { width: 26px; height: 26px; }
.repo-chip { font-family: var(--mono); font-size: 12px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--border); padding: 3px 8px; border-radius: 999px; }
.spacer { flex: 1; }
.worker { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.pulse.on { background: var(--accent); box-shadow: 0 0 0 0 var(--accent); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); } 100% { box-shadow: 0 0 0 8px transparent; } }

/* ---------- layout ---------- */
main { max-width: 1320px; margin: 0 auto; padding: 20px; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { background: none; border: 0; padding: 9px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 560; }
.tab .count { font-size: 11px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; margin-left: 4px; }
.split { display: grid; grid-template-columns: minmax(340px, 440px) 1fr; gap: 16px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.panel-head h2, .panel-head h3 { margin: 0; font-size: 14px; font-weight: 620; }
.panel-body { padding: 16px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--panel); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 520; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.input { border: 1px solid var(--border-strong); background: var(--panel); border-radius: 8px; padding: 6px 10px; min-width: 0; }
.input:focus, .btn:focus-visible, .tab:focus-visible, .job:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.trigger-form { display: flex; gap: 8px; }
.trigger-form .input { width: 110px; }

/* ---------- status pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 560; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-queued { background: var(--panel-2); color: var(--muted); }
.s-running { background: var(--accent-soft); color: var(--accent-text); }
.s-running::before { animation: blink 1s infinite alternate; }
@keyframes blink { to { opacity: .25; } }
.s-pr_opened { background: var(--ok-soft); color: var(--ok); }
.s-skipped, .s-no_changes { background: var(--warn-soft); color: var(--warn); }
.s-failed { background: var(--bad-soft); color: var(--bad); }
.s-cancelled { background: var(--panel-2); color: var(--faint); }
.chip { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 0 6px; }

/* ---------- job list ---------- */
.joblist { max-height: calc(100vh - 290px); overflow-y: auto; }
.job { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: none; padding: 12px 16px; cursor: pointer; }
.job:last-child { border-bottom: 0; }
.job:hover { background: var(--panel-2); }
.job.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.job-top { display: flex; align-items: center; gap: 8px; }
.job-num { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.job-title { font-weight: 560; margin: 3px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.job-meta .stage { color: var(--accent-text); }

/* ---------- detail ---------- */
.detail-head { padding: 16px; border-bottom: 1px solid var(--border); }
.detail-head h2 { margin: 6px 0 8px; font-size: 18px; font-weight: 640; letter-spacing: -.01em; }
.detail-links { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); align-items: center; }
.detail-actions { display: flex; gap: 8px; margin-left: auto; }
.summary { margin: 12px 0 0; padding: 10px 12px; background: var(--panel-2); border-radius: 8px; font-size: 13px; }
.summary.err { background: var(--bad-soft); color: var(--bad); font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; }
.pr-banner { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: var(--ok-soft); color: var(--ok); font-weight: 560; }
.pr-banner a { color: inherit; text-decoration: underline; }
.subtabs { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--border); }

/* ---------- log timeline ---------- */
.log { padding: 8px 0; max-height: calc(100vh - 380px); min-height: 300px; overflow-y: auto; }
.ev { display: grid; grid-template-columns: 62px 22px 1fr; gap: 6px; padding: 4px 16px; align-items: start; }
.ev .time { font-family: var(--mono); font-size: 11px; color: var(--faint); padding-top: 2px; }
.ev .icon { width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center; font-size: 10px; font-weight: 700; margin-top: 1px; background: var(--panel-2); color: var(--muted); }
.ev .body { min-width: 0; }
.ev-assistant .body { white-space: pre-wrap; word-break: break-word; }
.ev-assistant .icon { background: var(--accent); color: #fff; }
.ev-tool .icon { background: var(--info-soft); color: var(--info); }
.ev-tool .name { font-weight: 600; font-size: 12px; color: var(--info); margin-right: 6px; }
.ev-tool .arg { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-all; color: var(--text); }
.ev-tool_result, .ev-tool_error { padding-top: 0; }
.ev-tool_result .icon, .ev-tool_error .icon { visibility: hidden; }
.ev details summary { cursor: pointer; color: var(--faint); font-size: 12px; list-style: none; }
.ev details summary::before { content: "▸ "; }
.ev details[open] summary::before { content: "▾ "; }
.ev details pre { margin: 4px 0 2px; padding: 8px 10px; background: var(--panel-2); border-radius: 6px; max-height: 320px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.ev-tool_error summary { color: var(--bad); }
.ev-stage { padding-top: 10px; }
.ev-stage .body { font-weight: 620; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.ev-stage .icon { background: none; }
.ev-stage .icon::after { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--muted); }
.ev-info .body, .ev-raw .body { color: var(--muted); }
.ev-error .icon { background: var(--bad-soft); color: var(--bad); }
.ev-error .body { color: var(--bad); white-space: pre-wrap; word-break: break-word; }
.ev-done .icon { background: var(--ok-soft); color: var(--ok); }
.ev-done .body { font-weight: 600; }
.edit-diff { margin-top: 4px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.edit-diff pre { margin: 0; padding: 6px 10px; white-space: pre-wrap; word-break: break-word; max-height: 240px; overflow: auto; }
.edit-diff .old { background: var(--del); color: var(--del-text); }
.edit-diff .new { background: var(--add); color: var(--add-text); }
.follow { position: sticky; bottom: 8px; display: flex; justify-content: center; pointer-events: none; }
.follow .btn { pointer-events: auto; box-shadow: var(--shadow); }

/* ---------- diff ---------- */
.diff { max-height: calc(100vh - 380px); overflow: auto; font-family: var(--mono); font-size: 12px; }
.diff .file { position: sticky; top: 0; background: var(--panel-2); border-bottom: 1px solid var(--border); padding: 6px 12px; font-weight: 600; }
.diff .ln { padding: 0 12px; white-space: pre; min-width: max-content; }
.diff .ln.a { background: var(--add); color: var(--add-text); }
.diff .ln.d { background: var(--del); color: var(--del-text); }
.diff .ln.h { color: var(--info); background: var(--info-soft); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 560; font-size: 12px; color: var(--muted); padding: 9px 14px; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.issue-title { font-weight: 560; color: var(--text); }
.labels { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.label { font-size: 11px; padding: 0 7px; border-radius: 999px; border: 1px solid; }
.author { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.author img { width: 18px; height: 18px; border-radius: 50%; }
.blocker { font-size: 11.5px; color: var(--faint); }

/* ---------- setup ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.check { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.check:last-child { border-bottom: 0; }
.check .mark { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.check .mark.ok { background: var(--ok-soft); color: var(--ok); }
.check .mark.no { background: var(--bad-soft); color: var(--bad); }
.check .t { font-weight: 560; }
.check .d { font-size: 12.5px; color: var(--muted); word-break: break-word; }
.field { display: grid; grid-template-columns: 1fr 200px; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.field:last-of-type { border-bottom: 0; }
.field .t { font-weight: 560; }
.field .d { font-size: 12px; color: var(--muted); }
.field .input, .field select { width: 100%; }
.switch { position: relative; width: 38px; height: 22px; justify-self: end; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; cursor: pointer; transition: .15s; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.copy-row { display: flex; gap: 8px; margin: 6px 0 12px; }
.copy-row code { flex: 1; padding: 6px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; overflow-x: auto; white-space: nowrap; }
ol.steps { margin: 0; padding-left: 20px; color: var(--muted); }
ol.steps li { margin: 4px 0; }
ol.steps b { color: var(--text); font-weight: 560; }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 13px; margin-bottom: 14px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 6px; }
.login-card p { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.login-card .input { width: 100%; padding: 9px 12px; margin-bottom: 10px; }
.login-card .btn { width: 100%; justify-content: center; padding: 9px; }
.login-card .err { color: var(--bad); font-size: 13px; min-height: 20px; margin-top: 8px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-size: 13px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 1000px) {
  .split, .grid2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .joblist, .log, .diff { max-height: none; }
  .split.has-detail .list-pane { display: none; }
}
@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar-inner { padding: 10px 16px; flex-wrap: wrap; }
  .repo-chip { display: none; }
  .field { grid-template-columns: 1fr; }
  .switch { justify-self: start; }
  .table .hide-sm { display: none; }
  .ev { grid-template-columns: 22px 1fr; padding: 4px 12px; }
  .ev .time { display: none; }
}

/* ---------- manual run dialog ---------- */
.run-dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgb(0 0 0 / .25); }
.run-dialog::backdrop { background: rgb(0 0 0 / .45); }
.run-form { padding: 20px; display: grid; gap: 10px; }
.run-form h3 { margin: 0; font-size: 16px; }
.run-sub { color: var(--muted); font-size: 13px; margin-top: -6px; }
.run-label { font-weight: 560; font-size: 13px; margin-top: 4px; }
.run-label span { color: var(--faint); font-weight: 400; }
.run-form textarea { width: 100%; resize: vertical; font: 13px/1.45 var(--sans); }
.run-check { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--muted); cursor: pointer; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.run-check b { color: var(--text); font-weight: 600; }
.run-check input { margin-top: 3px; accent-color: var(--accent); }
.run-warn { padding: 8px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 12.5px; }
.run-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.run-err { color: var(--bad); font-size: 13px; min-height: 0; }
.run-err:empty { display: none; }
.chip-override { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.summary.maint { background: var(--warn-soft); color: var(--text); }
.summary.maint b { color: var(--warn); display: block; margin-bottom: 2px; }
.summary.maint div { white-space: pre-wrap; }
