:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e6e8ef;
  --accent: #4f46e5;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --blue: #2563eb;
  --green: #059669;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  min-height: 100%;
}

body::before {
  content: "";
  display: block;
  height: 3px;
  background: var(--accent);
}

h1, h2, h3, p { margin: 0; }

button { font: inherit; color: inherit; }

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 20px 28px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.brand { display: flex; gap: 12px; align-items: flex-start; min-width: 0; }

.mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  letter-spacing: -0.04em;
  flex: none;
}

h1 { font-size: 22px; letter-spacing: -0.03em; line-height: 1.15; }

.tagline { margin-top: 3px; color: var(--muted); font-size: 14px; }

.header-side { text-align: right; flex: none; }

.portfolio {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  font-size: 14px;
}

.portfolio:hover { text-decoration: underline; }

.source-note { margin-top: 3px; color: #94a3b8; font-size: 12px; }

.banner {
  margin-top: 12px;
  background: #eef2ff;
  border: 1px solid #e0e7ff;
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 8px 12px;
  color: #312e81;
  font-size: 13.5px;
}

.dora {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stat, .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.stat { padding: 10px 12px; min-width: 0; }

.stat-label, .hint, .stage-label, .k {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stat-value {
  display: block;
  margin-top: 2px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-sub, .hint, .meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.chart-card, .pipeline-card, .env-card, #history { margin-top: 12px; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px 0;
}

.card-head h2 { font-size: 15px; letter-spacing: -0.02em; }

.chart { display: block; width: 100%; height: auto; }

.chart-card { padding-bottom: 8px; }

.bar { fill: var(--accent); }

.bar-count, .bar-label {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  fill: var(--muted);
}

.bar-count { font-size: 11px; font-weight: 700; }

.bar-label { font-size: 11px; }

.layout {
  margin-top: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 12px;
  align-items: start;
}

.layout .pipeline-card,
.layout .env-card { margin-top: 0; }

.head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tabs { display: flex; gap: 4px; }

.tab, .chip-btn, .primary {
  border-radius: 999px;
  cursor: pointer;
}

.tab, .chip-btn {
  border: 1px solid transparent;
  background: transparent;
  padding: 5px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.tab.active, .chip-btn.active {
  background: #eef2ff;
  color: var(--accent);
  border-color: #e0e7ff;
}

.primary {
  border: 0;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  font-weight: 650;
  border-radius: 10px;
}

.primary:disabled { opacity: 0.55; cursor: not-allowed; }

.primary:not(:disabled):hover { background: #4338ca; }

.flash {
  margin: 8px 14px 0;
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
}

.graph {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  padding: 12px 14px 0;
  align-items: stretch;
}

.stage { min-width: 0; display: flex; flex-direction: column; gap: 6px; position: relative; }

.stage:not(:last-child)::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 46%;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid #cbd5e1;
}

.nodes { display: flex; flex-direction: column; gap: 6px; justify-content: center; flex: 1; }

.node {
  display: flex;
  gap: 6px;
  align-items: center;
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 10px;
  padding: 6px 6px;
  cursor: pointer;
  min-width: 0;
}

.node.selected { box-shadow: 0 0 0 2px var(--accent); }

.node-ico { width: 1em; flex: none; font-size: 13px; text-align: center; }

.node-text { min-width: 0; display: flex; flex-direction: column; }

.node-name {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-time {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
}

.st-success { border-left-color: var(--ok); }
.st-failure { border-left-color: var(--bad); }
.st-in_progress { border-left-color: var(--accent); }
.st-queued { border-left-color: #94a3b8; }
.st-skipped { border-left-color: #cbd5e1; color: #64748b; }
.st-rolled_back { border-left-color: var(--warn); }

.st-in_progress .node-ico { color: var(--accent); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.st-in_progress .node-ico { animation: pulse 1.2s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  .st-in_progress .node-ico { animation: none; }
}

.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin: 8px 14px 0;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
}

.legend li { display: flex; align-items: center; gap: 4px; }

.log-card { margin: 10px 14px 14px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }

.log-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  background: #0f172a;
  color: #e2e8f0;
  padding: 8px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.log {
  margin: 0;
  height: 220px;
  overflow: auto;
  background: #f8fafc;
  color: #0f172a;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.env-card { padding-bottom: 12px; }

.env { padding: 10px 14px 4px; }

.env + .env { border-top: 1px solid var(--line); margin-top: 4px; }

.env h3 { font-size: 14px; }

.env-top, .colors, .colors div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.colors { flex-direction: column; align-items: stretch; margin-top: 8px; gap: 4px; }

.colors div { justify-content: flex-start; }

.ver { font-size: 12px; color: var(--ink); }

.swatch {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  text-transform: lowercase;
}

.swatch.blue { background: var(--blue); }
.swatch.green { background: var(--green); }

.pct {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 700;
}

.traffic {
  display: flex;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #eef2f7;
  margin: 8px 0;
}

.seg.blue { background: var(--blue); }
.seg.green { background: var(--green); }

.pending { margin-top: 4px; font-size: 12px; color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 500; }

.env-card .hint { padding: 4px 14px 0; }

.table-wrap { overflow-x: auto; padding: 8px 6px 12px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tbody tr { cursor: pointer; }

tbody tr:hover { background: #f8fafc; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  background: #f1f5f9;
  color: #334155;
  white-space: nowrap;
}

.pill.st-success { background: #dcfce7; color: #166534; }
.pill.st-failure { background: #fee2e2; color: #991b1b; }
.pill.st-rolled_back { background: #ffedd5; color: #9a3412; }
.pill.st-in_progress { background: #eef2ff; color: #3730a3; }
.pill.st-queued, .pill.st-skipped { background: #f1f5f9; color: #475569; }

#panel-yaml { padding: 8px 14px 14px; }

.wf-switch { display: flex; gap: 6px; margin: 8px 0; }

.yaml {
  margin: 0;
  max-height: 420px;
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 12px;
  padding: 12px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  counter-reset: yaml;
}

.yaml-line { padding: 0 12px 0 0; white-space: pre-wrap; word-break: break-word; }

.yaml-line::before {
  counter-increment: yaml;
  content: counter(yaml);
  display: inline-block;
  width: 2.6em;
  margin-right: 0.8em;
  text-align: right;
  color: #64748b;
}

.tok-k { color: #a5b4fc; }
.tok-s { color: #86efac; }
.tok-c { color: #94a3b8; }

footer {
  margin-top: 18px;
  color: var(--muted);
  font-size: 12px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 980px) {
  .dora { grid-template-columns: 1fr 1fr; }
  .layout { grid-template-columns: 1fr; }
  .graph {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .stage { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 8px; align-items: center; }
  .stage:not(:last-child)::after { display: none; }
  .nodes { flex-direction: row; flex-wrap: wrap; }
  .node { width: auto; min-width: 108px; }
  .head-actions, .card-head { align-items: flex-start; }
}

@media (max-width: 640px) {
  .wrap { padding: 12px 12px 24px; }
  .top { flex-direction: column; }
  .header-side { text-align: left; }
  .stat-label { font-size: 10px; letter-spacing: 0.03em; }
  .stat-value { font-size: 18px; }
  .bar-label { font-size: 9px; letter-spacing: 0; }
  .bar-count { font-size: 10px; }
  .card-head, .head-actions { flex-direction: column; }
  .log { height: 200px; }
  .nodes { flex-direction: column; }
  .node { width: 100%; }
  h1 { font-size: 20px; }
}
