/* Execution Trace Viewer — standalone page styles */

:root {
  --tv-bg: #0f1419;
  --tv-bg-elev: #1a2332;
  --tv-bg-panel: #151c27;
  --tv-border: #2a3544;
  --tv-text: #e7ecf3;
  --tv-muted: #8b9bb0;
  --tv-accent: #3b82f6;
  --tv-accent-soft: rgba(59, 130, 246, 0.15);
  --tv-success: #22c55e;
  --tv-error: #ef4444;
  --tv-warn: #f59e0b;
  --tv-radius: 10px;
  --tv-font: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --tv-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --tv-type-tool_call: #38bdf8;
  --tv-type-llm_call: #a78bfa;
  --tv-type-agent: #34d399;
  --tv-type-chain: #fbbf24;
  --tv-type-event: #94a3b8;
  --tv-type-span: #fb7185;
  --tv-type-workflow_step: #f97316;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--tv-bg);
  color: var(--tv-text);
  font-family: var(--tv-font);
  font-size: 14px;
  line-height: 1.45;
}

.hidden { display: none !important; }

.tv-app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-width: 100%;
}

.tv-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 12px 24px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--tv-border);
  background: var(--tv-bg-elev);
}

.tv-header-brand {
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.tv-header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.tv-back {
  color: var(--tv-muted);
  text-decoration: none;
  font-size: 0.85rem;
}
.tv-back:hover { color: var(--tv-accent); }

.tv-privacy {
  margin: 0;
  margin-left: auto;
  color: var(--tv-muted);
  font-size: 0.8rem;
}

.tv-identity {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 0.85rem;
  color: var(--tv-muted);
}
.tv-identity strong { color: var(--tv-text); font-weight: 500; }
.tv-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.tv-badge-status-completed,
.tv-badge-status-success { background: rgba(34, 197, 94, 0.2); color: var(--tv-success); }
.tv-badge-status-error,
.tv-badge-status-failed { background: rgba(239, 68, 68, 0.2); color: var(--tv-error); }
.tv-badge-status-running { background: rgba(245, 158, 11, 0.2); color: var(--tv-warn); }
.tv-badge-grade {
  background: var(--tv-accent-soft);
  color: #93c5fd;
  font-size: 0.9rem;
  padding: 4px 10px;
}

/* Drop zone */
.tv-dropzone {
  margin: 40px auto;
  max-width: 640px;
  width: calc(100% - 40px);
  border: 2px dashed var(--tv-border);
  border-radius: 16px;
  background: var(--tv-bg-panel);
  transition: border-color 0.15s, background 0.15s;
  outline: none;
}
.tv-dropzone.dragover {
  border-color: var(--tv-accent);
  background: var(--tv-accent-soft);
}
.tv-dropzone-inner {
  padding: 48px 28px;
  text-align: center;
}
.tv-dropzone-title {
  margin: 0 0 8px;
  font-size: 1.2rem;
  font-weight: 600;
}
.tv-dropzone-sub {
  margin: 0 0 24px;
  color: var(--tv-muted);
}
.tv-dropzone-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.tv-load-status {
  margin: 16px 0 0;
  color: var(--tv-muted);
  min-height: 1.2em;
}
.tv-load-status.error { color: var(--tv-error); }

.tv-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--tv-border);
  background: var(--tv-bg-elev);
  color: var(--tv-text);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}
.tv-btn:hover { border-color: var(--tv-accent); }
.tv-btn-primary {
  background: var(--tv-accent);
  border-color: var(--tv-accent);
  color: #fff;
  font-weight: 600;
}
.tv-btn-primary:hover { filter: brightness(1.08); }
.tv-btn-icon {
  background: transparent;
  border: none;
  color: var(--tv-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
}
.tv-btn-icon:hover { color: var(--tv-text); }

code {
  font-family: var(--tv-mono);
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Tabs */
.tv-tabs {
  display: flex;
  gap: 2px;
  padding: 0 12px;
  border-bottom: 1px solid var(--tv-border);
  background: var(--tv-bg-elev);
  overflow-x: auto;
}
.tv-tabs button {
  appearance: none;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--tv-muted);
  padding: 10px 14px;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
}
.tv-tabs button:hover { color: var(--tv-text); }
.tv-tabs button[aria-selected="true"] {
  color: var(--tv-text);
  border-bottom-color: var(--tv-accent);
}
.tv-tab-reset {
  margin-left: auto !important;
  color: var(--tv-muted) !important;
}

.tv-view {
  flex: 1;
  padding: 16px 20px 32px;
  min-height: 0;
  overflow: auto;
}

/* Cards / grids */
.tv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.tv-card {
  background: var(--tv-bg-panel);
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius);
  padding: 14px 16px;
}
.tv-card-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tv-muted);
  margin-bottom: 4px;
}
.tv-card-value {
  font-size: 1.25rem;
  font-weight: 600;
}
.tv-card-sub {
  font-size: 0.8rem;
  color: var(--tv-muted);
  margin-top: 2px;
}

.tv-section {
  margin-bottom: 24px;
}
.tv-section h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 600;
}

.tv-table-wrap {
  overflow: auto;
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius);
}
table.tv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.tv-table th,
.tv-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--tv-border);
  vertical-align: top;
}
.tv-table th {
  background: var(--tv-bg-elev);
  color: var(--tv-muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.tv-table tr:hover td { background: rgba(255, 255, 255, 0.03); }
.tv-table tr.error-row td { background: rgba(239, 68, 68, 0.08); }
.tv-table .mono { font-family: var(--tv-mono); font-size: 0.8rem; }
.tv-expand {
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--tv-mono);
  font-size: 0.75rem;
  background: var(--tv-bg);
  padding: 8px;
  border-radius: 6px;
  margin-top: 6px;
}

.tv-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.tv-toolbar input[type="search"],
.tv-toolbar input[type="text"],
.tv-toolbar select {
  background: var(--tv-bg);
  border: 1px solid var(--tv-border);
  border-radius: 6px;
  color: var(--tv-text);
  padding: 6px 10px;
  font: inherit;
}
.tv-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--tv-muted);
  font-size: 0.85rem;
}

.tv-status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.tv-status-dot.success { background: var(--tv-success); }
.tv-status-dot.error,
.tv-status-dot.failed { background: var(--tv-error); }

.tv-type-chip {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.tv-type-tool_call { background: rgba(56, 189, 248, 0.2); color: var(--tv-type-tool_call); }
.tv-type-llm_call { background: rgba(167, 139, 250, 0.2); color: var(--tv-type-llm_call); }
.tv-type-agent { background: rgba(52, 211, 153, 0.2); color: var(--tv-type-agent); }
.tv-type-chain { background: rgba(251, 191, 36, 0.2); color: var(--tv-type-chain); }
.tv-type-event { background: rgba(148, 163, 184, 0.2); color: var(--tv-type-event); }
.tv-type-span { background: rgba(251, 113, 133, 0.2); color: var(--tv-type-span); }
.tv-type-workflow_step { background: rgba(249, 115, 22, 0.2); color: var(--tv-type-workflow_step); }

/* Timeline / DAG chart hosts */
.tv-chart {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius);
  background: var(--tv-bg-panel);
}
.tv-chart svg { display: block; }
.tv-chart-hint {
  color: var(--tv-muted);
  font-size: 0.8rem;
  margin: 8px 0 0;
}

/* DAG call tree (HTML) */
.tv-dag-tree {
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius);
  background: var(--tv-bg-panel);
  max-height: calc(100vh - 220px);
  min-height: 360px;
  overflow: auto;
  font-size: 0.82rem;
}
.tv-dag-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 8px;
  border-bottom: 1px solid rgba(42, 53, 68, 0.55);
  min-height: 30px;
}
.tv-dag-row:hover { background: rgba(255, 255, 255, 0.04); }
.tv-dag-row.is-error { background: rgba(239, 68, 68, 0.08); }
.tv-dag-toggle {
  flex: 0 0 18px;
  width: 18px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--tv-muted);
  cursor: pointer;
  font-size: 0.75rem;
  line-height: 22px;
  text-align: center;
}
.tv-dag-toggle:hover { color: var(--tv-text); }
.tv-dag-toggle-spacer {
  flex: 0 0 18px;
  width: 18px;
  display: inline-block;
}
.tv-dag-label {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--tv-text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  padding: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
}
.tv-dag-label:hover { color: #93c5fd; text-decoration: underline; }
.tv-dag-time {
  flex: 0 0 110px;
  color: var(--tv-muted);
  font-family: var(--tv-mono);
  font-size: 0.72rem;
}
.tv-dag-lat {
  flex: 0 0 72px;
  color: var(--tv-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.tv-dag-kids {
  flex: 0 0 28px;
  text-align: right;
  color: var(--tv-muted);
  font-size: 0.75rem;
}

/* Judge */
.tv-dim-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
  margin: 6px 0;
}
.tv-dim-bar > span {
  display: block;
  height: 100%;
  background: var(--tv-accent);
  border-radius: 4px;
}
.tv-dim-card {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius);
  background: var(--tv-bg-panel);
}
.tv-dim-card h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
}
.tv-dim-meta {
  color: var(--tv-muted);
  font-size: 0.8rem;
}
.tv-prose {
  max-width: 900px;
  line-height: 1.55;
}
.tv-prose h1, .tv-prose h2, .tv-prose h3 { margin-top: 1.2em; }
.tv-prose p { margin: 0.6em 0; }
.tv-prose ul { padding-left: 1.3em; }
.tv-list-plain {
  margin: 0;
  padding-left: 1.2em;
}
.tv-list-plain li { margin-bottom: 6px; }

/* Events virtual list */
.tv-event-list {
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius);
  height: calc(100vh - 220px);
  min-height: 320px;
  overflow: auto;
  background: var(--tv-bg-panel);
  position: relative;
}
.tv-event-spacer { position: absolute; left: 0; top: 0; width: 1px; pointer-events: none; }
.tv-event-window { position: absolute; left: 0; right: 0; }
.tv-event-row {
  display: grid;
  grid-template-columns: 160px 180px 1fr;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--tv-border);
  font-size: 0.8rem;
  cursor: pointer;
}
.tv-event-row:hover { background: rgba(255, 255, 255, 0.04); }
.tv-event-row .time { color: var(--tv-muted); font-family: var(--tv-mono); font-size: 0.75rem; }
.tv-event-row .etype { font-weight: 600; }
.tv-event-detail {
  grid-column: 1 / -1;
  margin-top: 4px;
}

/* Drawer */
.tv-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(480px, 100vw);
  height: 100%;
  background: var(--tv-bg-elev);
  border-left: 1px solid var(--tv-border);
  z-index: 40;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.35);
}
.tv-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--tv-border);
}
.tv-drawer-header h2 {
  margin: 0;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tv-drawer-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
}
.tv-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 30;
}

.tv-cdn-error {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--tv-error);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  z-index: 100;
  font-weight: 500;
}

.tv-empty {
  color: var(--tv-muted);
  padding: 24px;
  text-align: center;
}

.mono { font-family: var(--tv-mono); font-size: 0.8rem; }

/* Marks payloads recovered from metadata or the event stream. */
.tv-payload-source {
  color: var(--tv-muted);
  font-family: var(--tv-mono);
  font-size: 0.72rem;
  font-weight: 400;
}
.tv-error-text { color: var(--tv-error); }
.tv-drawer-body .tv-empty,
.detail-row .tv-empty {
  padding: 6px 0;
  text-align: left;
  font-size: 0.85rem;
}

/* —— Behavior tab: LLM saw vs tools —— */
.tv-behavior { display: flex; flex-direction: column; gap: 14px; }

.tv-behavior-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tv-stat {
  background: var(--tv-bg-elev);
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius);
  padding: 10px 14px;
  min-width: 88px;
}
.tv-stat-n { display: block; font-size: 1.25rem; font-weight: 600; }
.tv-stat-l { color: var(--tv-muted); font-size: 0.75rem; }
.tv-stat-good .tv-stat-n { color: var(--tv-success); }
.tv-stat-bad .tv-stat-n { color: var(--tv-error); }
.tv-stat-warn .tv-stat-n { color: var(--tv-warn); }

.tv-behavior-stages { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tv-stage-chip {
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--tv-border);
  background: var(--tv-bg-panel);
}
.tv-stage-PASS { border-color: rgba(34, 197, 94, 0.45); color: var(--tv-success); }
.tv-stage-DEGRADED { border-color: rgba(245, 158, 11, 0.45); color: var(--tv-warn); }
.tv-stage-FAIL { border-color: rgba(239, 68, 68, 0.45); color: var(--tv-error); }

.tv-behavior-avoid {
  background: var(--tv-bg-panel);
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius);
  padding: 10px 14px;
}
.tv-behavior-avoid ul { margin: 6px 0 0; padding-left: 18px; }
.tv-muted { color: var(--tv-muted); }

.tv-behavior-grid {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 12px;
  min-height: calc(100vh - 280px);
  align-items: stretch;
}

.tv-behavior-nav,
.tv-behavior-saw,
.tv-behavior-tools-pane {
  background: var(--tv-bg-panel);
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius);
  padding: 12px;
  overflow: auto;
  max-height: calc(100vh - 260px);
}

.tv-behavior-nav h3,
.tv-pane-head h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.tv-step-list { list-style: none; margin: 0; padding: 0; }
.tv-step-list li {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.tv-step-list li:hover { background: var(--tv-accent-soft); }
.tv-step-list li.selected {
  border-color: var(--tv-accent);
  background: var(--tv-accent-soft);
}
.tv-step-list li.pressure .tv-step-meta { color: var(--tv-warn); }
.tv-step-idx {
  font-family: var(--tv-mono);
  color: var(--tv-muted);
  font-size: 0.75rem;
  min-width: 28px;
}
.tv-step-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tv-step-model { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-step-meta { color: var(--tv-muted); font-size: 0.75rem; }

.tv-ctx-bars { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 12px; }
.tv-ctx-row { display: grid; grid-template-columns: 120px 1fr 64px; gap: 8px; align-items: center; }
.tv-ctx-label { font-size: 0.75rem; color: var(--tv-muted); overflow: hidden; text-overflow: ellipsis; }
.tv-ctx-track {
  height: 8px;
  background: var(--tv-bg);
  border-radius: 999px;
  overflow: hidden;
}
.tv-ctx-fill { display: block; height: 100%; background: var(--tv-accent); }
.tv-ctx-n { text-align: right; color: var(--tv-muted); }

/* Full prompt/task text in Behavior — pane scrolls; do not clip content. */
.tv-behavior-saw .tv-expand,
.tv-behavior-saw .tv-saw-system,
.tv-behavior-saw .tv-saw-user {
  max-height: none;
}
.tv-behavior-saw h4,
.tv-behavior-tools-pane h4 {
  margin: 12px 0 6px;
  font-size: 0.8rem;
  color: var(--tv-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tv-tool-class {
  display: inline-block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--tv-border);
  margin-right: 4px;
}
.tv-tool-class-useful { color: var(--tv-success); border-color: rgba(34, 197, 94, 0.4); }
.tv-tool-class-failed { color: var(--tv-error); border-color: rgba(239, 68, 68, 0.4); }
.tv-tool-class-wasted { color: var(--tv-warn); border-color: rgba(245, 158, 11, 0.4); }

.tv-btn-tiny { padding: 2px 8px; font-size: 0.75rem; }
.tv-req-tools { margin: 0; padding-left: 18px; }
.tv-tool-snips pre {
  margin: 4px 0 8px;
  max-height: 120px;
  overflow: auto;
  font-size: 0.75rem;
  background: var(--tv-bg);
  padding: 6px 8px;
  border-radius: 6px;
}

@media (max-width: 1100px) {
  .tv-behavior-grid {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  .tv-behavior-nav,
  .tv-behavior-saw,
  .tv-behavior-tools-pane {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .tv-privacy { display: none; }
  .tv-event-row { grid-template-columns: 1fr; }
}
