:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --border: #d8dee8;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --code-bg: #f3f4f6;
  --warning: #9a6700;
}

body.dark {
  --bg: #0f172a;
  --panel: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #374151;
  --accent: #60a5fa;
  --accent-soft: #172554;
  --code-bg: #020617;
  --warning: #fbbf24;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 10px;
}

input,
button {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 9px 12px;
}

input[type="search"] {
  width: min(360px, 36vw);
}

button {
  cursor: pointer;
}

.wide-button {
  margin-top: 14px;
  width: 100%;
}

.layout {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

.summary-row {
  display: grid;
  align-items: start;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.summary-row > .card {
  min-width: 0;
}

.diagram-card {
  align-self: start;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.card h2 {
  margin-top: 0;
}

.summary-grid {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px 12px;
}

.summary-grid.wide {
  grid-template-columns: 140px minmax(0, 1fr);
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.trial-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin: 12px 0 6px;
  text-transform: uppercase;
}

.round-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.round-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  text-align: left;
  width: 100%;
}

.round-item.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.round-name {
  font-weight: 700;
}

.behavior {
  color: var(--muted);
  font-size: 12px;
  grid-column: 1 / -1;
}

.status,
.badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  padding: 2px 8px;
}

.status.completed {
  color: #027a48;
}

.status.error {
  color: #b42318;
}

.status.user_instruction_only {
  color: var(--warning);
}

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

.detail-header h2 {
  margin-bottom: 4px;
}

.detail-header p {
  color: var(--muted);
  margin-top: 0;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin: 12px -16px 16px;
  padding: 0 16px 12px;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.overview-section {
  margin-top: 18px;
}

.overview-section h3 {
  margin-bottom: 8px;
}

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

.evidence-pill {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.evidence-pill.ok {
  background: #ecfdf3;
  border-color: #abefc6;
}

.evidence-pill.warn {
  background: #fffaeb;
  border-color: #fedf89;
}

body.dark .evidence-pill.ok {
  background: #052e1a;
  border-color: #167a42;
}

body.dark .evidence-pill.warn {
  background: #3b2f05;
  border-color: #b08900;
}

.evidence-pill strong,
.evidence-pill span {
  display: block;
}

.evidence-pill span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.actor-flow {
  align-items: stretch;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 110px 1fr 110px 1fr 80px 1fr;
  margin: 18px 0;
}

.actor-box {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 14px;
}

.actor-box strong,
.actor-box span {
  display: block;
}

.actor-box span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.flow-arrow {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  justify-content: center;
  text-align: center;
}

.flow-arrow::before,
.flow-arrow::after {
  background: var(--border);
  content: "";
  flex: 1;
  height: 1px;
}

.flow-arrow span {
  padding: 0 6px;
}

.round-flow {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.interaction-round {
  border-radius: 14px;
  display: block;
  padding: 14px;
  text-align: left;
  width: 100%;
}

.interaction-round:hover {
  border-color: var(--accent);
}

.interaction-round-header {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.interaction-round h3 {
  margin: 10px 0 6px;
}

.interaction-round p {
  color: var(--muted);
  margin: 0 0 12px;
}

.round-pill {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
}

.round-evidence {
  display: grid;
  gap: 6px 10px;
  grid-template-columns: 110px minmax(0, 1fr);
  margin: 0;
}

.review-step {
  border-left: 3px solid var(--accent);
  color: var(--muted);
  margin: 2px 0 2px 18px;
  padding: 8px 12px;
}

.timeline-section {
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.10), transparent 30%),
    linear-gradient(180deg, rgba(37, 99, 235, 0.04), transparent 48%);
  border: 1px solid var(--border);
  border-radius: 18px;
  margin: 18px 0;
  overflow-x: auto;
  padding: 18px;
}

.timeline-header {
  align-items: flex-start;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  min-width: 980px;
}

.timeline-header h3 {
  margin: 0 0 4px;
}

.timeline-header p {
  margin: 0;
}

.timeline-hint {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  margin-top: 8px !important;
}

.timeline-range {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-weight: 700;
  padding: 5px 10px;
  white-space: nowrap;
}

.timeline-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  min-width: 980px;
}

.timeline-summary span {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  padding: 5px 9px;
}

.timeline-summary strong {
  color: var(--text);
}

.timeline-scale,
.timeline-lane {
  display: grid;
  gap: 12px;
  grid-template-columns: 150px minmax(820px, 1fr);
  min-width: 980px;
}

.timeline-scale {
  margin-top: 16px;
}

.timeline-track {
  background:
    linear-gradient(to right, var(--border) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.10));
  background-size: 25% 100%, 100% 100%;
  border-left: 1px solid var(--border);
  border-radius: 10px;
  min-height: 38px;
  position: relative;
}

body.dark .timeline-track {
  background:
    linear-gradient(to right, var(--border) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.015));
  background-size: 25% 100%, 100% 100%;
}

.timeline-scale .timeline-track {
  min-height: 28px;
}

.timeline-tick {
  color: var(--muted);
  font-size: 11px;
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}

.timeline-tick i {
  background: var(--border);
  display: block;
  height: 10px;
  margin: 0 auto 4px;
  width: 1px;
}

.timeline-lanes {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.timeline-lane {
  border-radius: 12px;
  padding: 3px 0;
}

.timeline-lane:hover .timeline-track {
  outline: 1px solid var(--accent);
}

.lane-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding-top: 8px;
  text-align: right;
}

.timeline-span {
  border: 0;
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.18);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 1px;
  height: 32px;
  justify-content: center;
  overflow: hidden;
  padding: 4px 10px;
  position: absolute;
  text-align: left;
  top: 3px;
  transition: filter 120ms ease, transform 120ms ease;
  white-space: nowrap;
}

.timeline-span:hover {
  filter: brightness(1.08);
  overflow: visible;
  transform: translateY(-1px);
  z-index: 10;
}

.timeline-span:focus-visible {
  overflow: visible;
  z-index: 10;
}

.timeline-span.selectable {
  cursor: pointer;
}

.timeline-span.selectable::after {
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: inherit;
  content: "";
  inset: 3px;
  pointer-events: none;
  position: absolute;
}

.timeline-span.selectable:hover {
  box-shadow: 0 10px 26px rgba(220, 104, 3, 0.32);
}

.timeline-span.selected {
  outline: 3px solid var(--text);
  outline-offset: 2px;
  z-index: 4;
}

body.dark .timeline-span.selected {
  outline-color: #ffffff;
}

.timeline-span span,
.timeline-span small {
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-floating-tooltip {
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  max-width: min(360px, 60vw);
  min-width: 240px;
  opacity: 0;
  overflow: visible;
  padding: 9px 11px;
  pointer-events: none;
  position: fixed;
  text-overflow: clip;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
  white-space: pre-line;
  z-index: 1000;
}

.timeline-floating-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.timeline-span small {
  font-size: 10px;
  opacity: 0.85;
}

.timeline-span.inferred {
  border: 2px dashed rgba(255, 255, 255, 0.86);
}

.timeline-span.logical {
  background-image:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.20) 0 7px, transparent 7px 14px);
  border: 1px solid rgba(255, 255, 255, 0.74);
}

.timeline-span.user,
.legend-dot.user {
  background-color: #7c3aed;
}

.timeline-span.harbor,
.legend-dot.harbor {
  background-color: #2563eb;
}

.timeline-span.agent,
.legend-dot.agent {
  background-color: #dc6803;
}

.timeline-span.session,
.legend-dot.session {
  background-color: #039855;
}

.timeline-span.sandbox,
.legend-dot.sandbox {
  background-color: #0e7490;
}

.timeline-span.verify,
.legend-dot.verify {
  background-color: #c11574;
}

.timeline-legend {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
  min-width: 980px;
}

.timeline-legend span {
  align-items: center;
  display: inline-flex;
  font-size: 12px;
  gap: 6px;
}

.legend-dot {
  border-radius: 999px;
  display: inline-block;
  height: 10px;
  width: 10px;
}

.timeline-source-legend {
  border-top: 1px solid var(--border);
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
  min-width: 980px;
  padding-top: 12px;
}

.timeline-source-legend span {
  align-items: center;
  display: inline-flex;
  font-size: 12px;
  gap: 7px;
}

.source-sample {
  background: var(--accent);
  border-radius: 999px;
  display: inline-block;
  height: 12px;
  width: 28px;
}

.source-sample.inferred {
  border: 2px dashed var(--accent);
  background: transparent;
}

.source-sample.logical {
  background:
    repeating-linear-gradient(135deg, var(--accent) 0 5px, transparent 5px 10px),
    var(--accent-soft);
  border: 1px solid var(--accent);
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  line-height: 1.45;
  max-height: 70vh;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.event {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 10px 0;
  padding: 10px;
}

.event summary {
  cursor: pointer;
  font-weight: 700;
}

.nested-events {
  margin: 8px 0 16px;
}

.nested-event {
  background: rgba(37, 99, 235, 0.04);
  margin-left: 12px;
}

.sequence-svg-wrap {
  background: #f8fbff;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 16px 0;
  overflow: auto;
  padding: 12px;
}

.sequence-svg {
  display: block;
  min-width: 1300px;
}

.participant-box {
  fill: var(--panel);
  stroke: var(--accent);
  stroke-width: 1.4;
}

.participant-text {
  fill: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.lifeline {
  stroke: #b8c7d9;
  stroke-dasharray: 6 6;
  stroke-width: 1.2;
}

.message-line {
  stroke: var(--accent);
  stroke-width: 1.8;
}

.message-line.ok {
  stroke: #168a52;
}

.message-line.missing {
  stroke: var(--warning);
  stroke-dasharray: 5 4;
}

.arrow-head {
  fill: var(--accent);
}

.message-label {
  fill: var(--text);
  font-size: 11px;
}

.fragment-box {
  fill: rgba(42, 127, 255, 0.06);
  stroke: var(--border);
  stroke-dasharray: 5 4;
}

.fragment-label {
  fill: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.mermaid-source {
  margin-top: 14px;
}

.mermaid-source summary {
  cursor: pointer;
  font-weight: 700;
}

.muted {
  color: var(--muted);
}

.warning {
  color: var(--warning);
  font-weight: 700;
}

.hidden {
  display: none;
}

@media (max-width: 900px) {
  .topbar {
    display: block;
  }

  .top-actions {
    margin-top: 12px;
  }

  input[type="search"] {
    width: 100%;
  }

  .content {
    display: flex;
  }

  .evidence-grid,
  .actor-flow {
    grid-template-columns: 1fr;
  }

  .flow-arrow::before,
  .flow-arrow::after {
    display: none;
  }

  .sequence-svg {
    min-width: 1100px;
  }
}
