:root {
  --bg: #0b1120;
  --bg-2: #0f172a;
  --panel: #131c31;
  --panel-2: #1b2740;
  --border: #24304d;
  --border-soft: #1c2740;
  --text: #e6edf7;
  --muted: #8ea3c2;
  --faint: #63748f;
  --accent: #4f8cff;
  --accent-2: #38bdf8;
  --ok: #22c55e;
  --ok-dim: rgba(34, 197, 94, 0.15);
  --bad: #f43f5e;
  --bad-dim: rgba(244, 63, 94, 0.15);
  --warn: #f59e0b;
  --warn-dim: rgba(245, 158, 11, 0.15);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #16233f 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s;
  display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(180deg, #5b93ff, #3b7bff); border-color: #3b7bff; color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: transparent; border-color: #5a2733; color: #fda4b0; }
.btn-danger:hover { border-color: var(--bad); background: var(--bad-dim); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn-sm { padding: 0.32rem 0.6rem; font-size: 0.82rem; border-radius: 8px; }

input, select {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.85rem 1.5rem;
  background: rgba(11, 17, 32, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 1.1rem; font-weight: 800; letter-spacing: 0.2px; display: flex; align-items: center; gap: 0.5rem; }
.brand-mark { color: var(--accent-2); font-size: 1.3rem; }
.topbar-right { display: flex; align-items: center; gap: 0.6rem; }
.app-picker { display: flex; align-items: center; gap: 0.45rem; font-size: 0.85rem; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

/* ---------- summary cards ---------- */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.9rem; margin-bottom: 1.2rem; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.9rem 1.1rem; display: flex; flex-direction: column; gap: 0.25rem;
}
.stat .stat-label { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }
.stat .stat-value { font-size: 1.5rem; font-weight: 800; }
.stat .stat-sub { color: var(--faint); font-size: 0.78rem; }
.stat.good .stat-value { color: var(--ok); }
.stat.bad .stat-value { color: var(--bad); }

/* ---------- panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1.2rem; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1rem; }
.panel-head h2 { margin: 0; font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

/* ---------- pipeline ---------- */
.pipeline { display: flex; align-items: stretch; gap: 0; overflow-x: auto; padding-bottom: 0.4rem; }
.stage-wrap { display: flex; align-items: center; }
.connector { width: 34px; min-width: 22px; height: 2px; background: linear-gradient(90deg, var(--border), var(--accent)); position: relative; flex: 0 0 auto; margin: 0 2px; align-self: center; }
.connector::after { content: "›"; position: absolute; right: -4px; top: -12px; color: var(--accent); font-size: 1.1rem; }

.stage {
  flex: 1 1 0; min-width: 190px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 0.9rem; display: flex; flex-direction: column; gap: 0.6rem;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.stage.healthy { border-color: rgba(34, 197, 94, 0.35); }
.stage.unhealthy { border-color: rgba(244, 63, 94, 0.4); }
.stage.empty { opacity: 0.75; }
.stage.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.35); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 2px rgba(79,140,255,0.30); } 50% { box-shadow: 0 0 0 5px rgba(79,140,255,0.10); } }

.stage-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.stage-title { font-weight: 700; font-size: 0.98rem; }
.stage-ring { color: var(--faint); font-size: 0.72rem; font-family: ui-monospace, Menlo, monospace; }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.bad { background: var(--bad); box-shadow: 0 0 8px var(--bad); }
.dot.na { background: var(--faint); }

.stage-version { display: flex; flex-direction: column; gap: 0.15rem; }
.stage-version .v-cur { font-family: ui-monospace, Menlo, monospace; font-size: 1.05rem; font-weight: 700; }
.stage-version .v-meta { color: var(--faint); font-size: 0.72rem; }

.pill { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.12rem 0.5rem; border-radius: 999px; font-size: 0.72rem; font-weight: 600; }
.pill.ok { background: var(--ok-dim); color: var(--ok); }
.pill.bad { background: var(--bad-dim); color: var(--bad); }
.pill.na { background: rgba(99,116,143,0.15); color: var(--muted); }

.stage-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: auto; }
.seed-row { display: flex; gap: 0.35rem; width: 100%; }
.seed-row input { flex: 1; min-width: 0; }

.stage-running { display: flex; align-items: center; gap: 0.5rem; color: var(--accent-2); font-size: 0.82rem; font-weight: 600; margin-top: auto; }

/* ---------- progress panel ---------- */
.run { background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1.2rem; box-shadow: var(--shadow); animation: slidein 0.25s ease; }
@keyframes slidein { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.run-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-bottom: 0.8rem; }
.run-title { font-weight: 800; font-size: 1.02rem; display: flex; align-items: center; gap: 0.5rem; }
.run-bar { height: 6px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin-bottom: 0.9rem; }
.run-bar > span { display: block; height: 100%; }
.run-bar.running > span { width: 40%; background: linear-gradient(90deg, transparent, var(--accent), transparent); animation: indet 1.1s linear infinite; }
@keyframes indet { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
.run-bar.done-ok > span { width: 100%; background: var(--ok); }
.run-bar.done-bad > span { width: 100%; background: var(--bad); }

.steps { display: flex; flex-direction: column; gap: 0.15rem; }
.step { border-radius: 10px; padding: 0.5rem 0.6rem; }
.step:hover { background: var(--bg-2); }
.step-row { display: flex; align-items: center; gap: 0.6rem; cursor: pointer; }
.step-title { font-weight: 600; font-size: 0.9rem; flex: 1; }
.step-dur { color: var(--faint); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.step-logs { margin: 0.4rem 0 0.1rem 2.1rem; padding: 0.5rem 0.7rem; background: #0a0f1c; border: 1px solid var(--border-soft); border-radius: 8px; font-family: ui-monospace, Menlo, monospace; font-size: 0.78rem; color: #b9c6dd; white-space: pre-wrap; }

/* status icons */
.ic { width: 18px; height: 18px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; font-size: 12px; font-weight: 800; }
.ic.success { background: var(--ok-dim); color: var(--ok); }
.ic.failed { background: var(--bad-dim); color: var(--bad); }
.ic.skipped { background: rgba(99,116,143,0.15); color: var(--muted); }
.ic.running { background: transparent; }
.spinner { width: 15px; height: 15px; border: 2px solid rgba(79,140,255,0.25); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.badge.running { background: rgba(79,140,255,0.15); color: var(--accent); }
.badge.success { background: var(--ok-dim); color: var(--ok); }
.badge.failed { background: var(--bad-dim); color: var(--bad); }
.badge.pending { background: rgba(99,116,143,0.15); color: var(--muted); }

/* ---------- history ---------- */
.history { display: flex; flex-direction: column; gap: 0.4rem; }
.hrow { display: grid; grid-template-columns: 24px 90px 1fr auto; align-items: center; gap: 0.7rem; padding: 0.55rem 0.6rem; border-radius: 10px; border: 1px solid transparent; }
.hrow:hover { background: var(--bg-2); border-color: var(--border-soft); }
.hrow .h-action { font-weight: 700; text-transform: capitalize; }
.hrow .h-detail { color: var(--muted); font-size: 0.85rem; }
.hrow .h-detail .mono { font-family: ui-monospace, Menlo, monospace; color: var(--text); }
.hrow .h-time { color: var(--faint); font-size: 0.76rem; white-space: nowrap; }
.history-empty { color: var(--faint); padding: 0.6rem; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Menlo, monospace; }

/* ---------- toast ---------- */
.toast { position: fixed; right: 1.2rem; bottom: 1.2rem; z-index: 50; max-width: 420px; padding: 0.8rem 1rem; border-radius: 11px; box-shadow: var(--shadow); font-size: 0.9rem; animation: slidein 0.2s ease; }
.toast.ok { background: #10241a; border: 1px solid var(--ok); color: #b7f7cf; }
.toast.bad { background: #2a1219; border: 1px solid var(--bad); color: #ffc6cf; }

/* ---------- gate ---------- */
.gate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.gate-card { background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 2.2rem 2rem; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 0.8rem; text-align: center; box-shadow: var(--shadow); }
.gate-logo { font-size: 2.4rem; color: var(--accent-2); }
.gate-card h1 { margin: 0; font-size: 1.4rem; }
.gate-card p { margin: 0; }
.gate-error { color: var(--bad); font-size: 0.85rem; background: var(--bad-dim); padding: 0.5rem; border-radius: 8px; }
