:root {
  --paper: #f6f8f5;
  --surface: #ffffff;
  --ink: #161a18;
  --muted: #68716c;
  --line: #d9dfda;
  --line-strong: #b8c2bc;
  --teal: #147b82;
  --teal-soft: #d9eff0;
  --green: #326b4d;
  --green-soft: #dcece3;
  --amber: #a86418;
  --amber-soft: #f4e7d2;
  --red: #aa3d4a;
  --red-soft: #f4dde0;
  --blue: #315e8b;
  --shadow: 0 1px 2px rgb(16 24 20 / 7%), 0 8px 24px rgb(16 24 20 / 5%);
  font-family: "Aptos", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  min-height: 40px;
  cursor: pointer;
}

button:active,
.packet-actions a:active {
  transform: scale(0.96);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgb(20 123 130 / 25%);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 20px;
  background: rgb(255 255 255 / 94%);
  box-shadow: 0 1px 0 var(--line);
  backdrop-filter: blur(12px);
}

.brand,
.run-meta,
.pane-heading,
.inspection-header,
.packet-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  font-weight: 760;
}

.brand-mark {
  display: block;
  width: 21px;
  height: 14px;
  background:
    linear-gradient(
      90deg,
      transparent 0 8%,
      var(--teal) 8% 19%,
      transparent 19% 34%,
      var(--red) 34% 45%,
      transparent 45% 60%,
      var(--amber) 60% 71%,
      transparent 71% 86%,
      var(--green) 86% 100%
    );
}

.run-meta {
  gap: 10px;
  min-width: 0;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

#run-id {
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state-chip {
  padding: 4px 7px;
  border-radius: 4px;
  background: #e9ecea;
  color: #4e5652;
  font-family: "Aptos", "Segoe UI", sans-serif;
  font-weight: 700;
}

.state-chip[data-state="finalized"],
.state-chip[data-state="exact"] {
  background: var(--green-soft);
  color: var(--green);
}

.state-chip[data-state="initialized"],
.state-chip[data-state="discovered"] {
  background: var(--teal-soft);
  color: var(--teal);
}

.state-chip[data-state="identity_ambiguous"] {
  background: var(--amber-soft);
  color: var(--amber);
}

.state-chip[data-state="failed"] {
  background: var(--red-soft);
  color: var(--red);
}

.workspace {
  display: grid;
  min-height: calc(100vh - 58px);
  grid-template-columns: minmax(190px, 0.7fr) minmax(390px, 1.45fr) minmax(320px, 1.15fr);
}

.trace-pane,
.conversation-pane,
.inspection-pane {
  min-width: 0;
}

.trace-pane {
  padding: 20px 16px;
  border-right: 1px solid var(--line);
  background: #eef2ef;
}

.conversation-pane {
  display: flex;
  min-height: calc(100vh - 58px);
  flex-direction: column;
  background: var(--surface);
}

.inspection-pane {
  padding: 20px;
  border-left: 1px solid var(--line);
}

.pane-heading {
  justify-content: space-between;
  gap: 12px;
}

.pane-heading h2,
.inspection-header h1 {
  margin: 0;
  font-size: 15px;
  line-height: 1.25;
  text-wrap: balance;
}

.count,
.tab-button span {
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.count {
  color: var(--muted);
  font-size: 12px;
}

.adapter-trace {
  display: grid;
  gap: 0;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.adapter-row {
  position: relative;
  display: grid;
  min-height: 54px;
  grid-template-columns: 13px 1fr;
  gap: 11px;
  align-items: start;
}

.adapter-row::before {
  position: absolute;
  top: 13px;
  bottom: -7px;
  left: 5px;
  width: 2px;
  content: "";
  background: var(--line-strong);
}

.adapter-row:last-child::before {
  display: none;
}

.trace-dot {
  position: relative;
  z-index: 1;
  width: 12px;
  height: 12px;
  margin-top: 2px;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  background: var(--paper);
}

.adapter-row[data-status="success"] .trace-dot {
  border-color: var(--green);
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.adapter-row[data-status="http_error"] .trace-dot,
.adapter-row[data-status="parse_error"] .trace-dot {
  border-color: var(--red);
  background: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}

.adapter-row[data-status="no_results"] .trace-dot {
  border-color: var(--amber);
  background: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
}

.adapter-name {
  display: block;
  font-size: 13px;
  font-weight: 700;
  text-transform: capitalize;
}

.adapter-detail {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 14px;
  padding: 28px 24px;
  overflow: auto;
}

.message {
  max-width: 86%;
  padding: 13px 15px;
  border-radius: 6px;
  box-shadow: var(--shadow);
  line-height: 1.45;
  text-wrap: pretty;
}

.message p {
  margin: 4px 0 0;
}

.assistant-message {
  align-self: flex-start;
  background: #edf5f3;
  box-shadow: inset 3px 0 0 var(--teal), var(--shadow);
}

.user-message {
  align-self: flex-end;
  background: #f2f0e9;
  box-shadow: inset -3px 0 0 var(--amber), var(--shadow);
}

.error-message {
  background: var(--red-soft);
  box-shadow: inset 3px 0 0 var(--red);
}

.welcome-hints {
  margin: 10px 0 0;
  padding-left: 18px;
  display: grid;
  gap: 7px;
}

.welcome-hints code {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.85em;
  word-break: break-all;
}

.welcome-try {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.example-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.example-chip {
  min-height: 34px;
  padding: 5px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--teal);
  font-size: 13px;
  font-weight: 600;
}

.example-chip:hover {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.message-label,
.eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.candidate-section {
  max-height: 44vh;
  padding: 18px 24px;
  overflow: auto;
  border-top: 1px solid var(--line);
  background: #fafbf9;
}

.search-field {
  display: block;
  margin: 12px 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.search-field input {
  width: 100%;
  min-height: 40px;
  margin-top: 5px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
}

.candidate-list {
  display: grid;
}

.candidate-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.candidate-row button,
.secondary-button {
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  transition-property: transform, background-color, border-color;
  transition-duration: 120ms;
}

.candidate-title {
  display: block;
  font-size: 13px;
  font-weight: 720;
}

.candidate-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 10px;
  overflow-wrap: anywhere;
}

.composer {
  position: sticky;
  bottom: 0;
  padding: 14px 20px 16px;
  border-top: 1px solid var(--line);
  background: rgb(255 255 255 / 96%);
}

.composer > label:first-child {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.composer textarea {
  width: 100%;
  min-height: 58px;
  max-height: 140px;
  resize: vertical;
  padding: 10px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
}

.composer-row button {
  min-width: 108px;
  padding: 0 16px;
  border: 0;
  border-radius: 5px;
  background: var(--teal);
  color: white;
  font-weight: 760;
  transition-property: transform, background-color;
  transition-duration: 120ms;
}

.composer-row button:hover {
  background: #0e686e;
}

.composer-row button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.llm-toggle {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
}

.inspection-header {
  min-height: 44px;
  justify-content: space-between;
  gap: 12px;
}

.inspection-header h1 {
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.tab-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 18px;
  border-bottom: 1px solid var(--line-strong);
}

.tab-button {
  padding: 8px 4px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  transition-property: color, border-color, transform;
  transition-duration: 120ms;
}

.tab-button.active {
  border-color: var(--teal);
  color: var(--ink);
}

.inspection-panel {
  max-height: calc(100vh - 235px);
  padding: 8px 0 20px;
  overflow: auto;
}

.evidence-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.evidence-field {
  display: block;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 10px;
  overflow-wrap: anywhere;
}

.evidence-value {
  display: block;
  margin-top: 5px;
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.evidence-state {
  display: inline-block;
  margin-top: 7px;
  padding: 3px 5px;
  border-radius: 3px;
  background: #e8ece9;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
}

.evidence-state[data-state="reported_unverified"] {
  background: var(--teal-soft);
  color: var(--teal);
}

.evidence-state[data-state="conflicting"] {
  background: var(--red-soft);
  color: var(--red);
}

.empty-state {
  padding: 24px 0;
  color: var(--muted);
  font-size: 13px;
}

.packet-actions {
  position: sticky;
  bottom: 0;
  gap: 8px;
  padding: 12px 0 0;
  background: var(--paper);
}

.packet-actions a {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 8px 11px;
  border-radius: 4px;
  background: var(--ink);
  color: white;
  font-size: 12px;
  font-weight: 720;
  text-decoration: none;
  transition-property: transform, background-color;
  transition-duration: 120ms;
}

.packet-actions a:first-child {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

@media (max-width: 1050px) {
  .workspace {
    grid-template-columns: 170px minmax(370px, 1.3fr) minmax(290px, 1fr);
  }
}

@media (max-width: 820px) {
  .workspace {
    display: block;
  }

  .trace-pane {
    padding: 13px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .adapter-trace {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 10px;
  }

  .adapter-row {
    min-height: 38px;
    grid-template-columns: 10px minmax(0, 1fr);
    gap: 7px;
  }

  .adapter-row::before {
    display: none;
  }

  .trace-dot {
    width: 9px;
    height: 9px;
  }

  .adapter-detail {
    display: none;
  }

  .conversation-pane {
    min-height: 58vh;
  }

  .inspection-pane {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .inspection-panel {
    max-height: none;
  }
}

@media (max-width: 520px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
    padding: 10px 14px;
  }

  #run-id {
    max-width: 70vw;
  }

  .workspace {
    min-height: calc(100vh - 78px);
  }

  .adapter-trace {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .conversation {
    padding: 20px 14px;
  }

  .message {
    max-width: 94%;
  }

  .composer {
    padding: 12px 14px;
  }

  .composer-row {
    grid-template-columns: 1fr;
  }

  .composer-row button {
    min-height: 44px;
  }

  .candidate-section,
  .inspection-pane {
    padding-right: 14px;
    padding-left: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
