/* Traces page styles -- builds on styles.css */

/* Override .app to be a flex column so filter-bar + shell stack cleanly */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.app .topbar { flex-shrink: 0; }
.app .filter-bar { flex-shrink: 0; }
.app .traces-shell { flex: 1; min-height: 0; }

/* ---- filter bar ---- */
.filter-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-wrap: wrap;
}
.filter-bar .search-input {
  position: relative; min-width: 280px; flex: 1 1 280px; max-width: 460px;
}
.filter-bar .search-input input {
  width: 100%; height: 30px;
  background: white; border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 0 8px 0 30px; font-size: 12.5px; outline: none;
}
.filter-bar .search-input input:focus { border-color: #0d0d0d; }
.filter-bar .search-input .ic {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); pointer-events: none;
}
.filter-bar .filter-chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 30px; padding: 0 10px;
  background: white; border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: 12px; cursor: pointer;
  color: var(--text);
}
.filter-bar .filter-chip .k { color: var(--text-muted); }
.filter-bar .filter-chip .v { font-weight: 500; }
.filter-bar .filter-chip:hover { background: var(--row-hover); }
.filter-bar .filter-chip.set { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.filter-bar .filter-chip.set .k { color: var(--accent); opacity: 0.7; }
.filter-bar .filter-chip .x { color: inherit; opacity: 0.6; }
.filter-bar .filter-chip .x:hover { opacity: 1; }
.filter-bar .live-tail {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: white;
  font-size: 12px; cursor: pointer;
}
.filter-bar .live-tail.on { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.filter-bar .live-tail.on .dot { background: var(--accent); animation: pulse 1.4s infinite; }
.filter-bar .live-tail .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); }

/* ---- main split ---- */
.traces-shell {
  display: grid;
  grid-template-columns: 520px 1fr;
  min-height: 0;
  height: 100%;
}
.trace-list-col {
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0; background: var(--bg);
}
.trace-detail-col {
  display: flex; flex-direction: column;
  min-height: 0; background: var(--bg-subtle);
}

/* ---- summary strip ---- */
.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}
.summary-strip .cell {
  background: white;
  padding: 9px 12px;
}
.summary-strip .lbl {
  font-size: 10px; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.06em; font-weight: 600;
}
.summary-strip .val {
  font-size: 14px; font-weight: 600; margin-top: 2px;
  font-family: var(--font-mono);
  display: flex; align-items: baseline; gap: 4px;
}
.summary-strip .val .unit { font-size: 10.5px; color: var(--text-muted); font-weight: 500; }
.summary-strip .val .delta { font-size: 10px; font-weight: 600; }
.summary-strip .val .delta.up { color: #b91c1c; }
.summary-strip .val .delta.down { color: var(--accent); }

/* ---- trace list table ---- */
.trace-table-head {
  display: grid;
  grid-template-columns: 16px 1fr 56px 70px;
  gap: 8px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: 10.5px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
}
.trace-list {
  flex: 1; overflow-y: auto;
  min-height: 0;
}
.trace-row {
  display: grid;
  grid-template-columns: 16px 1fr 56px 70px;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  align-items: center;
  position: relative;
}
.trace-row:hover { background: var(--row-hover); }
.trace-row.active { background: white; box-shadow: inset 3px 0 0 #0d0d0d; }

.trace-row .status-col { display: grid; place-items: center; }
.trace-row .status-col .dot {
  width: 8px; height: 8px; border-radius: 50%;
}
.trace-row .status-col .dot.ok { background: var(--accent); }
.trace-row .status-col .dot.err { background: #ef4444; }
.trace-row .status-col .dot.warn { background: var(--orange); }
.trace-row .status-col .dot.running { background: var(--blue); animation: pulse 1.2s infinite; }

.trace-row .main { min-width: 0; }
.trace-row .head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 2px;
}
.trace-row .head .agent-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 500;
  flex-shrink: 0;
}
.trace-row .head .agent-chip .av {
  width: 16px; height: 16px; border-radius: 4px;
  display: grid; place-items: center;
  font-size: 9px; font-weight: 700; color: white;
}
.trace-row .head .when {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint);
  margin-left: auto; flex-shrink: 0;
}
.trace-row .input-preview {
  font-size: 12.5px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: 3px;
}
.trace-row .meta-row {
  display: flex; gap: 10px; align-items: center;
  font-size: 10.5px; color: var(--text-muted);
  font-family: var(--font-mono);
  overflow: hidden;
}
.trace-row .meta-row .m {
  display: inline-flex; align-items: center; gap: 3px;
  white-space: nowrap;
}
.trace-row .meta-row .m svg { opacity: 0.55; }
.trace-row .meta-row .id-pill {
  background: var(--bg-subtle); padding: 1px 5px; border-radius: 3px;
  color: var(--text-muted); border: 1px solid var(--border);
}
.trace-row .dur-col {
  font-family: var(--font-mono); font-size: 12px; color: var(--text);
  text-align: right;
}
.trace-row .dur-col .bar {
  display: block; height: 3px; border-radius: 2px;
  background: var(--bg-sunken); margin-top: 4px;
  overflow: hidden; position: relative;
}
.trace-row .dur-col .bar .fill { display: block; height: 100%; background: var(--text-muted); border-radius: 2px; }
.trace-row.active .dur-col .bar .fill { background: #0d0d0d; }
.trace-row .cost-col {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted);
  text-align: right;
}

/* ---- trace detail ---- */
.detail-tabs {
  display: flex; gap: 2px;
  padding: 8px 16px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.detail-tabs button {
  background: transparent; border: 0;
  padding: 8px 12px; border-radius: 0;
  color: var(--text-muted); font-size: 12.5px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 6px;
}
.detail-tabs button:hover { color: var(--text); }
.detail-tabs button.active {
  color: var(--text); font-weight: 600;
  border-bottom-color: #0d0d0d;
}
.detail-tabs button .count {
  font-family: var(--font-mono); font-size: 10.5px;
  background: var(--bg-subtle); padding: 1px 5px; border-radius: 3px;
}

.detail-header {
  padding: 14px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: white;
}
.detail-header .top {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 6px;
}
.detail-header .av {
  width: 26px; height: 26px; border-radius: 6px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: white;
}
.detail-header .title { font-size: 14px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-header .actions { display: flex; gap: 6px; }
.detail-header .ids {
  display: flex; gap: 14px;
  font-family: var(--font-mono); font-size: 11px; color: var(--text-muted);
  flex-wrap: wrap;
}
.detail-header .ids span { white-space: nowrap; }
.detail-header .ids .k { color: var(--text-faint); }
.detail-header .ids .copyable { cursor: pointer; }
.detail-header .ids .copyable:hover { color: var(--text); }
.detail-header .badges {
  display: flex; gap: 6px; margin-top: 8px; align-items: center;
  flex-wrap: wrap;
}
.badge-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px;
  padding: 2px 7px; border-radius: 999px;
  background: var(--bg-subtle); color: var(--text);
  border: 1px solid var(--border);
}
.badge-pill.ok    { background: var(--accent-bg); color: var(--accent); border-color: transparent; }
.badge-pill.err   { background: #fee2e2; color: #b91c1c; border-color: transparent; }
.badge-pill.warn  { background: #fef3c7; color: var(--warn); border-color: transparent; }
.badge-pill.mono  { font-family: var(--font-mono); font-size: 10.5px; }

.detail-body-split {
  display: grid;
  grid-template-columns: 1fr 380px;
  flex: 1; min-height: 0; overflow: hidden;
}
.waterfall-pane {
  background: var(--bg);
  overflow: auto;
  border-right: 1px solid var(--border);
}
.inspector-pane {
  background: var(--bg);
  overflow-y: auto;
  border-left: 1px solid var(--border);
}

/* ---- run execution (mirrors Playground Observability > Runs) ---- */
.trace-execution-pane {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  background: var(--bg-subtle);
}
.trace-execution-card {
  margin: 0;
  max-width: 980px;
}
.trace-execution-card .turn-usage {
  white-space: normal;
}
.trace-execution-loading {
  padding: 18px 12px;
  color: var(--text-muted);
  font-size: 12px;
}
.trace-timeline-item.error .gut.tool .node { background: #ef4444; }
.trace-timeline-item.error .label .kind.tool { background: #fee2e2; color: #b91c1c; }
.trace-final-output {
  border-top: 1px solid var(--border);
  padding: 0 12px 12px;
}
.trace-final-output > button {
  width: 100%;
  min-height: 34px;
  padding: 8px 0 5px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-align: left;
  text-transform: uppercase;
}
.trace-final-output > button:hover { color: var(--text); }
.trace-final-output pre {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-subtle);
  color: var(--text);
  padding: 10px 12px;
  white-space: pre-wrap;
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 1.55;
}

/* ---- waterfall ---- */
.wf-container { padding: 14px 16px 24px; }
.wf-summary {
  display: flex; align-items: center; gap: 14px;
  font-size: 11px; color: var(--text-muted);
  margin-bottom: 10px; font-family: var(--font-mono);
}
.wf-summary .legend {
  display: inline-flex; align-items: center; gap: 4px;
}
.wf-summary .legend .sw {
  width: 8px; height: 8px; border-radius: 2px;
}

.wf-table {
  display: grid;
  grid-template-columns: 240px 1fr 64px;
  gap: 0;
  font-size: 12px;
}
.wf-header-row {
  display: contents;
  font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
}
.wf-header-row > div {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 2;
}
.wf-axis {
  position: relative; height: 26px;
}
.wf-axis .tick {
  position: absolute; top: 0; bottom: 0;
  border-left: 1px dashed var(--border);
  font-family: var(--font-mono); font-size: 10px; color: var(--text-faint);
  padding-left: 4px;
}
.wf-axis .tick::before {
  content: ""; position: absolute; bottom: 0; left: -1px; height: 4px;
  border-left: 1px solid var(--border-strong);
}

.wf-row {
  display: contents;
  cursor: pointer;
}
.wf-row > .lbl,
.wf-row > .bar-wrap,
.wf-row > .dur {
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  background: white;
  transition: background 80ms ease;
}
.wf-row:hover > .lbl,
.wf-row:hover > .bar-wrap,
.wf-row:hover > .dur { background: var(--row-hover); }
.wf-row.active > .lbl,
.wf-row.active > .bar-wrap,
.wf-row.active > .dur { background: #fdf6e3; }
.wf-row.active > .lbl { box-shadow: inset 3px 0 0 #d97706; }

.wf-row .lbl {
  display: flex; align-items: center; gap: 6px;
  min-width: 0;
}
.wf-row .lbl .indent { display: inline-block; flex-shrink: 0; }
.wf-row .lbl .kind {
  font-family: var(--font-mono); font-size: 9.5px;
  padding: 1px 5px; border-radius: 3px;
  text-transform: uppercase; font-weight: 600;
  flex-shrink: 0;
}
.wf-row .lbl .kind.llm   { background: #fbe7fd; color: var(--pink); }
.wf-row .lbl .kind.tool  { background: #eaf1ff; color: var(--blue); }
.wf-row .lbl .kind.mcp   { background: #f3e7fd; color: var(--pink); }
.wf-row .lbl .kind.err   { background: #fee2e2; color: #b91c1c; }
.wf-row .lbl .kind.run   { background: #e6f4ee; color: var(--accent); }
.wf-row .lbl .nm {
  font-size: 12.5px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 500;
}
.wf-row .lbl .icn { color: var(--text-muted); display: grid; place-items: center; flex-shrink: 0; }

.wf-row .bar-wrap {
  position: relative;
  height: 28px;
  display: flex; align-items: center;
}
.wf-row .bar-wrap .bar {
  position: absolute;
  height: 14px; border-radius: 3px;
  background: var(--text-muted);
  display: flex; align-items: center;
  min-width: 2px;
}
.wf-row .bar-wrap .bar.llm   { background: linear-gradient(90deg, #f0abfc, #c026d3); }
.wf-row .bar-wrap .bar.tool  { background: linear-gradient(90deg, #93c5fd, #2563eb); }
.wf-row .bar-wrap .bar.mcp   { background: linear-gradient(90deg, #d8b4fe, #7c3aed); }
.wf-row .bar-wrap .bar.err   { background: linear-gradient(90deg, #fca5a5, #ef4444); }
.wf-row .bar-wrap .bar.run   { background: linear-gradient(90deg, #6ee7b7, #10a37f); }
.wf-row .bar-wrap .grid-line {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: var(--border); opacity: 0.5;
}
.wf-row .dur {
  font-family: var(--font-mono); font-size: 11px; color: var(--text);
  text-align: right;
}

/* ---- step inspector ---- */
.inspect {
  padding: 14px 16px 24px;
}
.inspect-header {
  margin-bottom: 12px;
}
.inspect-header .top {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
}
.inspect-header .kind {
  font-family: var(--font-mono); font-size: 10px;
  padding: 1px 6px; border-radius: 3px;
  text-transform: uppercase; font-weight: 600;
}
.inspect-header .kind.llm   { background: #fbe7fd; color: var(--pink); }
.inspect-header .kind.tool  { background: #eaf1ff; color: var(--blue); }
.inspect-header .kind.mcp   { background: #f3e7fd; color: var(--pink); }
.inspect-header .kind.err   { background: #fee2e2; color: #b91c1c; }
.inspect-header .kind.run   { background: #e6f4ee; color: var(--accent); }
.inspect-header h3 {
  margin: 0; font-size: 14px; font-weight: 600;
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.inspect-header .dur {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-muted);
}

.inspect-section {
  margin-bottom: 14px;
}
.inspect-section .sec-head {
  font-size: 10.5px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
  margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}
.inspect-section .sec-head .copy {
  margin-left: auto; cursor: pointer; font-size: 10.5px;
  padding: 1px 6px; border-radius: 3px; color: var(--text-muted);
}
.inspect-section .sec-head .copy:hover { background: var(--row-hover); color: var(--text); }
.inspect-section pre {
  margin: 0;
  background: #0d0d0d; color: #e5e5e5;
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-family: var(--font-mono); font-size: 11px;
  line-height: 1.55;
  overflow: auto; max-height: 240px;
}
.inspect-section pre.text {
  background: white; color: var(--text);
  border: 1px solid var(--border);
  font-family: var(--font-sans); font-size: 12.5px; line-height: 1.55;
  white-space: pre-wrap;
}
.inspect-section .kv {
  background: white; border: 1px solid var(--border); border-radius: var(--r-sm);
  font-family: var(--font-mono); font-size: 11.5px;
  padding: 8px 10px;
}
.inspect-section .kv .row { display: flex; gap: 8px; padding: 2px 0; }
.inspect-section .kv .k { color: var(--text-muted); min-width: 80px; }
.inspect-section .kv .v { color: var(--text); }
.model-io-items {
  display: grid;
  gap: 8px;
}
.model-io-item {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  position: relative;
}
.model-io-item summary {
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 64px 6px 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  list-style-position: inside;
}
.model-io-item summary .mono {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 11px;
}
.model-io-copy {
  position: absolute;
  top: 6px;
  right: 10px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text-muted);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 10.5px;
  cursor: pointer;
}
.model-io-copy:hover {
  color: var(--text);
  background: var(--row-hover);
}
.model-io-item pre {
  border-radius: 0;
  border-top: 1px solid var(--border);
  max-height: 320px;
}
.model-io-item pre.text {
  margin: 0;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
}

/* ---- dashboard ---- */
.dash {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 12px;
  padding: 16px;
}
.dash .panel {
  background: white; border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  display: flex; flex-direction: column;
  min-height: 0;
}
.dash .panel .head {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 10px;
}
.dash .panel .head h4 { margin: 0; font-size: 12px; font-weight: 600; color: var(--text); }
.dash .panel .head .sub { font-size: 11px; color: var(--text-muted); }
.dash .span-3  { grid-column: span 3; }
.dash .span-4  { grid-column: span 4; }
.dash .span-6  { grid-column: span 6; }
.dash .span-8  { grid-column: span 8; }
.dash .span-12 { grid-column: span 12; }

.kpi-num {
  font-size: 26px; font-weight: 600; font-family: var(--font-mono);
  letter-spacing: -0.02em;
}
.kpi-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; font-family: var(--font-mono); }
.kpi-sub .up { color: #b91c1c; }
.kpi-sub .down { color: var(--accent); }

.tool-bar-row {
  display: grid; grid-template-columns: 110px 1fr 50px;
  gap: 8px; align-items: center;
  font-size: 12px; padding: 3px 0;
}
.tool-bar-row .nm { font-family: var(--font-mono); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-bar-row .bar {
  background: var(--bg-sunken); height: 8px; border-radius: 4px; overflow: hidden;
}
.tool-bar-row .bar .fill { display: block; height: 100%; border-radius: 4px; }
.tool-bar-row .num { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); text-align: right; }

/* ---- sparkline ---- */
.spark {
  width: 100%;
  height: 50px;
}
.spark path { fill: none; stroke: #0d0d0d; stroke-width: 1.5; }
.spark .area { fill: rgba(13,13,13,0.05); stroke: none; }
.spark .err-area { fill: rgba(239,68,68,0.08); stroke: none; }
.spark .err-line { stroke: #ef4444; }
.spark .axis { stroke: var(--border); stroke-width: 1; }
.spark .gridline { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2,2; opacity: 0.5; }
.spark .label { font-family: var(--font-mono); font-size: 9px; fill: var(--text-muted); }
