/* ============================================================================
   DHFlow run viewer
   Direction: a precise operational instrument. Monospace carries the data
   (run ids, timings, step names, payloads) because this is a debugging tool and
   the type treatment itself should read as "readout". Hairline structure, calm
   surface. The one bold element is the signal-trace timeline: each step is a
   node on a wire, and the wire segment into a node is colored by its status -
   data visibly hopping through the flow.
   ============================================================================ */

:root {
  --canvas:   #E9EDF1;
  --surface:  #FFFFFF;
  --surface-2:#F4F6F9;
  --ink:      #15202C;
  --muted:    #61728A;
  --faint:    #93A1B5;
  --hairline: #DAE0E8;
  --hairline-strong: #C6CFDA;

  /* brand: a deep "relay" teal, kept for structure not decoration */
  --relay:    #0E7C86;
  --relay-bright: #14B8C4;

  /* functional status colors */
  --ok:       #15803D;
  --ok-bg:    #E7F4EC;
  --fail:     #D6453D;
  --fail-bg:  #FBEAE9;
  --run:      #B45309;
  --run-bg:   #FAF0DF;
  --idle:     #94A3B8;

  --sans: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --r: 9px;
  --shadow: 0 1px 2px rgba(21,32,44,.04), 0 6px 20px rgba(21,32,44,.05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* beat class-level display rules */

html, body {
  margin: 0;
  height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ---- top bar ------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 16px; height: 16px; border-radius: 4px;
  background: var(--relay);
  position: relative;
  box-shadow: 0 0 0 3px rgba(14,124,134,.14);
}
.brand-mark::after {
  content: ""; position: absolute; inset: 0; border-radius: 4px;
  background: var(--relay-bright); transform: scale(.45);
}
.brand-name { font-weight: 600; letter-spacing: -.01em; font-size: 15px; }
.brand-env {
  font-family: var(--mono); font-size: 11px; font-weight: 500;
  color: var(--relay); background: rgba(14,124,134,.10);
  padding: 2px 8px; border-radius: 999px; text-transform: lowercase;
}

/* ---- layout -------------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: 232px minmax(280px, 360px) 1fr;
  height: calc(100% - 56px);
  min-height: 0;
}
.rail, .runs, .detail { min-height: 0; overflow: auto; }
.rail   { background: var(--surface-2); border-right: 1px solid var(--hairline); }
.runs   { background: var(--canvas); border-right: 1px solid var(--hairline); }
.detail { background: var(--surface); }

/* ---- rail (flows) -------------------------------------------------------- */
.rail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px;
  position: sticky; top: 0; background: var(--surface-2);
}
.icon-btn {
  border: 1px solid var(--hairline); background: var(--surface);
  color: var(--muted); width: 26px; height: 26px; border-radius: 7px;
  cursor: pointer; font-size: 14px; line-height: 1;
}
.icon-btn:hover { color: var(--ink); border-color: var(--hairline-strong); }
.icon-btn.spin { animation: spin .6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

.flow-list { padding: 4px 8px 16px; }
.flow-item {
  display: block; width: 100%; text-align: left; cursor: pointer;
  border: 1px solid transparent; background: none;
  padding: 9px 10px; border-radius: 8px; margin-bottom: 2px;
  font-family: inherit; color: var(--ink);
}
.flow-item:hover { background: rgba(21,32,44,.04); }
.flow-item.active { background: var(--surface); border-color: var(--hairline); box-shadow: var(--shadow); }
.flow-item .fi-title { font-weight: 500; font-size: 13.5px; }
.flow-item .fi-meta {
  display: flex; align-items: center; gap: 6px; margin-top: 3px;
  font-family: var(--mono); font-size: 10.5px; color: var(--faint);
}

/* ---- runs list ----------------------------------------------------------- */
.runs-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 16px 18px 12px; position: sticky; top: 0;
  background: var(--canvas); z-index: 1;
}
.runs-title { margin: 2px 0 0; font-size: 18px; font-weight: 600; letter-spacing: -.015em; }
.run-now {
  font-family: var(--mono); font-size: 12px; font-weight: 500;
  color: #fff; background: var(--relay); border: none;
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  box-shadow: var(--shadow);
}
.run-now:hover { background: #0c6a73; }
.run-now:disabled { opacity: .55; cursor: default; }

.run-list { padding: 0 12px 24px; }
.run-card {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: 12px; width: 100%; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r); padding: 12px 14px; margin: 6px 0;
  font-family: inherit; color: var(--ink); box-shadow: var(--shadow);
}
.run-card:hover { border-color: var(--hairline-strong); }
.run-card.active { border-color: var(--relay); box-shadow: 0 0 0 1px var(--relay), var(--shadow); }
.run-id { display: block; font-family: var(--mono); font-size: 12px; font-weight: 500; }
.run-sub { display: block; font-family: var(--mono); font-size: 10.5px; color: var(--faint); margin-top: 2px; }
.run-dur { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* status pill + dot ------------------------------------------------------- */
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.success { background: var(--ok); }
.dot.failed  { background: var(--fail); }
.dot.running { background: var(--run); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.pill {
  font-family: var(--mono); font-size: 10px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px;
}
.pill.success { color: var(--ok); background: var(--ok-bg); }
.pill.failed  { color: var(--fail); background: var(--fail-bg); }
.pill.running { color: var(--run); background: var(--run-bg); }

/* ---- detail / signal trace ---------------------------------------------- */
.detail-empty {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; color: var(--faint);
}
.trace-glyph {
  width: 3px; height: 76px; border-radius: 3px;
  background: linear-gradient(var(--hairline-strong), var(--relay-bright), var(--hairline-strong));
  position: relative;
}
.trace-glyph::before, .trace-glyph::after {
  content: ""; position: absolute; left: 50%; transform: translateX(-50%);
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--hairline-strong);
}
.trace-glyph::before { top: -6px; }
.trace-glyph::after  { bottom: -6px; border-color: var(--relay-bright); }

.detail-body { padding: 20px 26px 40px; max-width: 760px; }

.run-summary {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding-bottom: 16px; border-bottom: 1px solid var(--hairline); margin-bottom: 20px;
}
.run-summary h2 { margin: 0; font-family: var(--mono); font-size: 15px; font-weight: 500; }
.run-summary .meta {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  display: flex; gap: 14px; flex-wrap: wrap; margin-left: auto;
}

/* the trace: a wire down the left, nodes per step */
.trace { position: relative; padding-left: 30px; }
.trace::before {
  content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px;
  width: 2px; background: var(--hairline-strong); border-radius: 2px;
}

.node { position: relative; margin-bottom: 4px; }
/* colored wire segment into this node, by status */
.node::before {
  content: ""; position: absolute; left: -24px; top: -2px; width: 2px; height: 28px;
}
.node:first-child::before { height: 0; }
.node.success::before { background: var(--ok); }
.node.failed::before  { background: var(--fail); }
.node.running::before { background: var(--run); }

.node-bullet {
  position: absolute; left: -29px; top: 14px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--idle); z-index: 1;
}
.node.success .node-bullet { border-color: var(--ok); }
.node.failed  .node-bullet { border-color: var(--fail); }
.node.running .node-bullet { border-color: var(--run); animation: pulse 1.1s infinite; }

.step {
  width: 100%; text-align: left; cursor: pointer; font-family: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.step:hover { border-color: var(--hairline-strong); }
.step-head { display: flex; align-items: center; gap: 10px; }
.step-name { font-family: var(--mono); font-weight: 500; font-size: 13px; }
.step-action {
  font-family: var(--mono); font-size: 10.5px; color: var(--faint);
  background: var(--surface-2); padding: 2px 7px; border-radius: 6px;
}
.step-dur { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-left: auto; }
.chev { color: var(--faint); transition: transform .15s ease; }
.step[aria-expanded="true"] .chev { transform: rotate(90deg); }

.step-body { display: none; margin-top: 12px; }
.step[aria-expanded="true"] .step-body { display: block; }
.io-label {
  font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--faint); margin: 12px 0 6px;
}
.io-label:first-child { margin-top: 0; }
pre.json {
  margin: 0; background: var(--surface-2); border: 1px solid var(--hairline);
  border-radius: 7px; padding: 11px 13px; overflow: auto;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.55; color: #233044;
}
pre.json.error { background: var(--fail-bg); border-color: #f0cfcd; color: #8e2a25; }

.empty { color: var(--faint); font-size: 13px; padding: 18px 14px; }

/* ---- responsive ---------------------------------------------------------- */
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; grid-auto-rows: min-content; height: auto; }
  .rail, .runs { border-right: none; border-bottom: 1px solid var(--hairline); }
  .rail { display: none; }            /* keep mobile focused on runs + detail */
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}

:focus-visible { outline: 2px solid var(--relay); outline-offset: 2px; border-radius: 4px; }
