:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e2e7ef;
  --text: #182230;
  --muted: #64748b;
  --side: #0f172a;
  --side-2: #1e293b;
  --side-text: #cbd5e1;
  --accent: #2563eb;
  --ok: #16a34a;
  --fail: #dc2626;
  --warn: #d97706;
  --term: #0b1220;
  --term-text: #d6e2f5;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: grid;
  grid-template-columns: 248px 1fr;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--side);
  color: var(--side-text);
  padding: 18px 12px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #22d3ee);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .15);
}
.brand-name { color: #fff; font-weight: 650; font-size: 15px; }
.brand-sub { font-size: 12px; color: #94a3b8; }
#nav { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  margin: 14px 10px 6px; font-size: 11px; letter-spacing: .08em;
  text-transform: uppercase; color: #64748b;
}
.tab {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--side-text); text-decoration: none;
}
.tab:hover { background: var(--side-2); color: #fff; }
.tab.active { background: #1d4ed8; color: #fff; }
.tab-name { flex: 1; font-weight: 520; }
.tab-meta, .tab-count { font-size: 12px; color: #94a3b8; }
.tab.active .tab-meta, .tab.active .tab-count { color: #dbeafe; }
.tab-icon.grid {
  width: 10px; height: 10px; border-radius: 2px;
  background:
    linear-gradient(currentColor 0 0) 0 0 / 4px 4px no-repeat,
    linear-gradient(currentColor 0 0) 6px 0 / 4px 4px no-repeat,
    linear-gradient(currentColor 0 0) 0 6px / 4px 4px no-repeat,
    linear-gradient(currentColor 0 0) 6px 6px / 4px 4px no-repeat;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: #475569; flex: none; }
.dot.ok { background: var(--ok); }
.dot.failed { background: var(--fail); }
.dot.running { background: var(--warn); animation: pulse 1s infinite; }
.sidebar-foot { font-size: 12px; color: #64748b; padding: 10px 10px 0; border-top: 1px solid var(--side-2); }

/* Main */
main { min-width: 0; height: 100vh; overflow-y: auto; padding: 28px 32px 48px; outline: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.page-head h1 { display: flex; align-items: center; gap: 12px; margin: 0; font-size: 24px; }
.lede { margin: 6px 0 0; color: var(--muted); max-width: 70ch; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
h2:first-child { margin-top: 0; }

/* All flows grid: every card the same size */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  grid-auto-rows: 300px;
  gap: 16px;
}
.card {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
  border-top: 3px solid #cbd5e1;
}
.card.ok { border-top-color: var(--ok); }
.card.failed { border-top-color: var(--fail); }
.card.running { border-top-color: var(--warn); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-title { font-weight: 650; font-size: 16px; color: var(--text); text-decoration: none; }
.card-title:hover { color: var(--accent); }

.output {
  flex: 1; min-height: 0; margin: 0; overflow: auto;
  background: var(--term); color: var(--term-text);
  border-radius: 8px; padding: 10px 12px;
  font: 12px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}
.output.tall { height: 220px; flex: none; }

/* Buttons */
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions.big { margin-top: 2px; }
.btn {
  flex: 1; padding: 7px 12px; border-radius: 7px; cursor: pointer;
  font: inherit; font-weight: 560;
  border: 1px solid var(--line); background: #fff; color: var(--text);
}
.actions.big .btn { flex: none; padding: 8px 16px; }
.btn:hover:not(:disabled) { border-color: #94a3b8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #1d4ed8; }
.btn.danger { color: var(--fail); border-color: #fecaca; }
.btn.danger:hover:not(:disabled) { background: #fef2f2; border-color: var(--fail); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.busy { opacity: 1; animation: pulse 1s infinite; }

/* Pills and badges */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 560; white-space: nowrap;
  background: #eef2f7; color: var(--muted);
}
.pill.ok { background: #dcfce7; color: #166534; }
.pill.failed { background: #fee2e2; color: #991b1b; }
.pill.running { background: #fef3c7; color: #92400e; }
.variant { font: 600 11px var(--mono); text-transform: uppercase; padding: 2px 7px; border-radius: 5px; background: #e0e7ff; color: #3730a3; }
.variant.slow { background: #fef3c7; color: #92400e; }
.variant.error { background: #fee2e2; color: #991b1b; }
.proto { font: 600 11px var(--mono); padding: 1px 6px; border-radius: 4px; background: #eef2f7; }

/* Flow page */
.hops { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; list-style: none; padding: 0; margin: 0 0 22px; }
.hops li.hop {
  font: 12.5px var(--mono); background: #fff; border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 10px;
}
.hops li.arrow { color: var(--muted); }
.split { display: grid; grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr); gap: 18px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }

.run { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; border-left: 3px solid var(--ok); }
.run.failed { border-left-color: var(--fail); }
.run summary { display: flex; align-items: center; gap: 10px; padding: 8px 10px; cursor: pointer; list-style: none; }
.run summary::-webkit-details-marker { display: none; }
.run summary::before { content: "\25B8"; color: var(--muted); }
.run[open] summary::before { content: "\25BE"; }
.run-when { font-weight: 560; }
.run-dur { margin-left: auto; font: 12px var(--mono); color: var(--muted); }
.run-error { margin: 0; padding: 8px 12px; color: #991b1b; background: #fef2f2; }
.steps { width: 100%; border-collapse: collapse; font-size: 13px; }
.steps th { text-align: left; font-weight: 560; color: var(--muted); font-size: 12px; padding: 6px 10px; border-top: 1px solid var(--line); }
.steps td { padding: 6px 10px; border-top: 1px solid var(--line); vertical-align: top; }
.steps td.num { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.steps td.detail { word-break: break-word; color: #334155; }
.steps tr.failed td { background: #fef2f2; }

.kind-group + .kind-group { margin-top: 16px; }
.kind-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.kind { font-weight: 650; font-size: 12px; padding: 2px 8px; border-radius: 5px; }
.kind.keep { background: #dcfce7; color: #166534; }
.kind.redact { background: #fee2e2; color: #991b1b; }
.kind.masked { background: #fef3c7; color: #92400e; }
.declared { margin: 0; padding-left: 18px; color: #334155; }
.declared li { margin: 3px 0; }
.wire { margin-left: 6px; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }

.filters { margin-bottom: 18px; }
.filters-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.filters-head h2 { margin: 0; }
.filters > p { margin: 6px 0 12px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button {
  font: inherit; font-size: 13px; padding: 5px 12px; border: 0; background: #fff;
  color: var(--muted); cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.on { background: var(--side); color: #fff; }
.kfl-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.kfl-title { display: flex; align-items: center; gap: 8px; font-weight: 560; margin-bottom: 4px; }
.kfl-row { display: flex; gap: 8px; align-items: stretch; }
.kfl {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 7px;
  background: var(--term); color: var(--term-text);
  font: 12.5px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}
.btn.copy { flex: none; padding: 0 14px; }
.offscreen { position: fixed; left: -9999px; top: 0; }

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

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 1; padding: 10px; }
  .brand { padding-bottom: 8px; }
  #nav { flex-direction: row; overflow-x: auto; }
  .nav-label, .sidebar-foot, .tab-meta { display: none; }
  main { height: auto; padding: 20px 16px; }
  .split { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
}
