:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: #1f252b;
  background: #eef1f3;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  color: #dfe5e9;
  background: #20262c;
  border-right: 1px solid #14191d;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 54px;
  padding: 0 9px 18px;
  border-bottom: 1px solid #363e45;
}

.brand-mark,
.message-avatar {
  width: 32px;
  height: 32px;
  display: grid;
  flex: 0 0 32px;
  place-items: center;
  color: #ffffff;
  font-weight: 750;
  background: #168b68;
  border-radius: 6px;
}

.brand strong,
.brand span {
  display: block;
  letter-spacing: 0;
}

.brand strong {
  font-size: 14px;
}

.brand div > span {
  margin-top: 3px;
  color: #929da6;
  font-size: 11px;
}

.view-nav {
  display: grid;
  gap: 3px;
  margin-top: 16px;
}

.nav-button {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 12px;
  color: #aeb8c0;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 5px;
}

.nav-button span {
  width: 20px;
  color: #7f8b94;
  font-family: "Cascadia Code", Consolas, monospace;
  font-weight: 700;
  text-align: center;
}

.nav-button:hover,
.nav-button.active {
  color: #ffffff;
  background: #343c43;
}

.nav-button.active span {
  color: #5fd0a7;
}

.connection-panel {
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding: 15px 10px 4px;
  color: #aeb8c0;
  font-size: 12px;
  border-top: 1px solid #363e45;
}

.connection-panel > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  background: #77828b;
  border-radius: 50%;
}

.status-dot.online {
  background: #42c793;
}

.status-dot.offline {
  background: #e66a67;
}

.text-button {
  padding: 5px 0;
  color: #8edbbf;
  text-align: left;
  background: transparent;
  border: 0;
}

.main-area {
  min-width: 0;
}

.app-view {
  display: none;
  min-height: 100vh;
}

.app-view.active {
  display: block;
}

.chat-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
}

.conversation {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #ffffff;
}

.view-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 17px 24px;
  border-bottom: 1px solid #dfe4e8;
}

.view-header.compact {
  min-height: 82px;
  background: #ffffff;
}

h1,
h2,
p {
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 14px;
}

.view-header p {
  margin: 5px 0 0;
  color: #74808a;
  font-size: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.run-state {
  padding: 5px 9px;
  color: #5e6972;
  font-size: 12px;
  background: #edf0f2;
  border-radius: 4px;
}

.run-state.running {
  color: #09684c;
  background: #def4eb;
}

.run-state.failed {
  color: #9a3532;
  background: #fbe5e4;
}

.message-list {
  min-height: 0;
  padding: 26px clamp(22px, 6vw, 84px) 36px;
  overflow-y: auto;
}

.connection-settings {
  padding: 14px clamp(18px, 5vw, 70px);
  background: #f6f8f9;
  border-bottom: 1px solid #dfe4e8;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.settings-grid .wide,
.context-grid .wide {
  grid-column: 1 / -1;
}

.connection-settings textarea,
.tool-form textarea {
  width: 100%;
  margin-top: 5px;
  padding: 9px 10px;
  color: #252b30;
  background: #ffffff;
  border: 1px solid #c7cfd5;
  border-radius: 4px;
  outline: none;
  resize: vertical;
}

.settings-note {
  margin: 8px 0 0;
  color: #76828b;
  font-size: 11px;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  max-width: 900px;
  margin: 0 auto 26px;
}

.user-message {
  justify-content: flex-end;
}

.user-message .message-content {
  max-width: 75%;
  padding: 12px 14px;
  background: #edf1f3;
  border-radius: 6px;
}

.message-content {
  min-width: 0;
  color: #242a30;
  font-size: 14px;
  line-height: 1.65;
}

.message-content strong {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
}

.message-content p,
.answer-text {
  margin: 0;
  white-space: pre-wrap;
}

.markdown-body {
  white-space: normal;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 20px 0 9px;
  color: #20262b;
  line-height: 1.35;
}

.markdown-body h1 {
  font-size: 20px;
}

.markdown-body h2 {
  font-size: 17px;
}

.markdown-body h3 {
  font-size: 15px;
}

.markdown-body p {
  margin: 0 0 13px;
}

.markdown-body ul,
.markdown-body ol {
  margin: 8px 0 15px;
  padding-left: 24px;
}

.markdown-body li {
  margin: 4px 0;
}

.markdown-body code {
  padding: 2px 5px;
  color: #7c2f4d;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.9em;
  background: #f0f2f4;
  border: 1px solid #e1e5e8;
  border-radius: 3px;
}

.markdown-body pre {
  margin: 12px 0 16px;
  padding: 14px;
  overflow: auto;
  color: #dce5eb;
  background: #252c32;
  border: 1px solid #171c20;
  border-radius: 5px;
}

.markdown-body pre code {
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
}

.markdown-body blockquote {
  margin: 12px 0;
  padding: 8px 13px;
  color: #5c6871;
  background: #f5f7f8;
  border-left: 3px solid #63ad92;
}

.markdown-body a {
  color: #08745a;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.markdown-body hr {
  margin: 20px 0;
  border: 0;
  border-top: 1px solid #dfe4e8;
}

.markdown-table-wrap {
  max-width: 100%;
  margin: 12px 0 17px;
  overflow-x: auto;
  border: 1px solid #d7dde1;
  border-radius: 5px;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.markdown-body th,
.markdown-body td {
  padding: 9px 11px;
  text-align: left;
  vertical-align: top;
  border-right: 1px solid #e1e5e8;
  border-bottom: 1px solid #e1e5e8;
}

.markdown-body th:last-child,
.markdown-body td:last-child {
  border-right: 0;
}

.markdown-body tbody tr:last-child td {
  border-bottom: 0;
}

.markdown-body th {
  color: #39444c;
  font-weight: 700;
  background: #f0f3f5;
}

.markdown-body tbody tr:nth-child(even) {
  background: #fafbfb;
}

.answer-text.streaming::after {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 3px;
  content: "";
  vertical-align: -2px;
  background: #168b68;
  animation: blink 900ms infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.composer {
  margin: 0 clamp(18px, 5vw, 70px) 22px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid #bfc8cf;
  border-radius: 7px;
  box-shadow: 0 7px 28px rgb(36 46 54 / 9%);
}

.composer > textarea {
  width: 100%;
  min-height: 66px;
  max-height: 180px;
  padding: 3px 4px;
  color: #20262b;
  line-height: 1.5;
  resize: vertical;
  background: transparent;
  border: 0;
  outline: 0;
}

.context-settings {
  margin-top: 7px;
  padding-top: 9px;
  border-top: 1px solid #e3e7ea;
}

.context-settings summary {
  color: #69757e;
  font-size: 12px;
  cursor: pointer;
}

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

label {
  color: #647079;
  font-size: 11px;
  font-weight: 650;
}

input,
.tool-form textarea {
  width: 100%;
  margin-top: 5px;
  padding: 9px 10px;
  color: #252b30;
  background: #ffffff;
  border: 1px solid #c7cfd5;
  border-radius: 4px;
  outline: none;
}

input:focus,
.tool-form textarea:focus {
  border-color: #168b68;
  box-shadow: 0 0 0 3px rgb(22 139 104 / 12%);
}

.code-input,
pre {
  font-family: "Cascadia Code", Consolas, monospace;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 9px;
}

#composer-hint {
  color: #89939b;
  font-size: 11px;
}

.send-button {
  min-width: 82px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #ffffff;
  font-weight: 650;
  background: #168b68;
  border: 1px solid #168b68;
  border-radius: 5px;
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.primary-button,
.secondary-button {
  min-height: 34px;
  padding: 0 12px;
  font-weight: 650;
  border-radius: 5px;
}

.primary-button {
  color: #ffffff;
  background: #168b68;
  border: 1px solid #168b68;
}

.secondary-button {
  color: #126c53;
  background: #ffffff;
  border: 1px solid #aebdb5;
}

.activity-panel {
  min-width: 0;
  background: #f4f6f7;
  border-left: 1px solid #d9dfe3;
}

.activity-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 18px;
  background: #f9fafb;
  border-bottom: 1px solid #d9dfe3;
}

.activity-header h2 {
  font-size: 14px;
}

.activity-header span {
  display: block;
  margin-top: 4px;
  color: #7b8790;
  font-size: 11px;
  overflow-wrap: anywhere;
}

#activity-count {
  margin: 0;
  white-space: nowrap;
}

.run-summary {
  padding: 14px 16px 16px;
  background: #eef2f4;
  border-bottom: 1px solid #d9dfe3;
}

.summary-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: #4d5b64;
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.summary-refresh {
  padding: 0;
  color: #168b68;
  font-size: 11px;
  font-weight: 650;
  background: transparent;
  border: 0;
}

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

.summary-card,
.trace-summary-card {
  min-width: 0;
  padding: 10px 11px;
  background: #ffffff;
  border: 1px solid #dce2e6;
  border-radius: 6px;
}

.summary-card span,
.trace-summary-card span {
  display: block;
  margin-bottom: 5px;
  color: #7b8790;
  font-size: 10px;
  font-weight: 650;
}

.summary-card strong,
.trace-summary-card strong {
  display: block;
  min-width: 0;
  color: #252d33;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.summary-card strong[data-status="completed"] {
  color: #08745a;
}

.summary-card strong[data-status="failed"],
.summary-card strong[data-status="summary_error"] {
  color: #a63e3b;
}

.summary-card strong[data-status="running"],
.summary-card strong[data-status="created"],
.summary-card strong[data-status="loading"] {
  color: #746018;
}

.summary-message {
  margin: 10px 0 0;
  color: #6d7982;
  font-size: 11px;
  line-height: 1.5;
}

.activity-list {
  margin: 0;
  padding: 18px;
  list-style: none;
}

.activity-empty {
  padding: 28px 12px;
  color: #87929a;
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}

.activity-item {
  position: relative;
  min-height: 54px;
  padding: 0 0 17px 27px;
  border-left: 1px solid #cbd3d8;
}

.activity-item:last-child {
  border-left-color: transparent;
}

.activity-item::before {
  position: absolute;
  top: 2px;
  left: -6px;
  width: 11px;
  height: 11px;
  content: "";
  background: #ffffff;
  border: 2px solid #8d9aa3;
  border-radius: 50%;
}

.activity-item.active::before {
  background: #168b68;
  border-color: #168b68;
  box-shadow: 0 0 0 4px rgb(22 139 104 / 14%);
}

.activity-item.done::before {
  background: #45b78e;
  border-color: #45b78e;
}

.activity-item.failed::before {
  background: #d85c58;
  border-color: #d85c58;
}

.activity-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.activity-title strong {
  font-size: 12px;
}

.activity-title time {
  color: #929ca4;
  font-size: 10px;
}

.activity-detail {
  margin: 5px 0 0;
  color: #6c7881;
  font-size: 11px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.tool-layout {
  min-height: calc(100vh - 82px);
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
}

.tool-form,
.tool-output {
  padding: 24px;
}

.tool-form {
  background: #ffffff;
  border-right: 1px solid #d9dfe3;
}

.tool-form label {
  display: block;
  margin-bottom: 18px;
}

.tool-form textarea {
  resize: vertical;
}

.primary-button,
.secondary-button {
  min-height: 36px;
  padding: 7px 14px;
  font-weight: 650;
  border-radius: 4px;
}

.primary-button {
  color: #ffffff;
  background: #168b68;
  border: 1px solid #168b68;
}

.tool-form .primary-button {
  width: 100%;
}

.secondary-button {
  color: #245f4d;
  background: #ffffff;
  border: 1px solid #9fb5ad;
}

.tool-output {
  min-width: 0;
}

.output-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
  color: #68747d;
  font-size: 12px;
}

.tool-output pre {
  min-height: 580px;
  max-height: calc(100vh - 145px);
  margin: 0;
  padding: 18px;
  overflow: auto;
  color: #d9e2e8;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  background: #252c32;
  border: 1px solid #171c20;
  border-radius: 5px;
}

.trace-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 110px;
  gap: 10px;
  padding: 18px 24px;
  background: #ffffff;
  border-bottom: 1px solid #d9dfe3;
}

.trace-toolbar input {
  margin: 0;
}

.trace-meta {
  display: flex;
  gap: 28px;
  padding: 13px 24px;
  color: #6f7a83;
  font-size: 12px;
  background: #f8f9fa;
  border-bottom: 1px solid #d9dfe3;
}

.trace-meta strong {
  margin-left: 5px;
  color: #2a3035;
}

.trace-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 16px 24px;
  background: #eef2f4;
  border-bottom: 1px solid #d9dfe3;
}

.trace-summary-card.wide {
  grid-column: 1 / -1;
}

.trace-timeline {
  margin: 0;
  padding: 24px 32px 30px 58px;
  list-style: none;
}

.trace-item {
  position: relative;
  padding: 0 0 24px 22px;
  border-left: 2px solid #ccd4d9;
}

.trace-item:last-child {
  border-left-color: transparent;
}

.trace-item::before {
  position: absolute;
  top: 2px;
  left: -7px;
  width: 12px;
  height: 12px;
  content: "";
  background: #168b68;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #168b68;
}

.trace-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.trace-title strong {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12px;
}

.trace-title time {
  color: #87929a;
  font-size: 11px;
}

.trace-item pre {
  margin: 0;
  padding: 12px;
  overflow: auto;
  font-size: 11px;
  line-height: 1.5;
  background: #ffffff;
  border: 1px solid #dce2e6;
  border-radius: 4px;
}

.trace-empty {
  padding: 60px 0;
  color: #87929a;
  text-align: center;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 44px));
  padding: 11px 14px;
  color: #ffffff;
  background: #293139;
  border-radius: 4px;
  box-shadow: 0 8px 28px rgb(0 0 0 / 20%);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: #a63e3b;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .brand div,
  .nav-button:not(.active) {
    font-size: 0;
  }

  .nav-button {
    justify-content: center;
    padding: 0;
    font-size: 0;
  }

  .nav-button span {
    font-size: 17px;
  }

  .connection-panel span:not(.status-dot),
  .connection-panel .text-button {
    display: none;
  }

  .connection-panel > div {
    justify-content: center;
  }

  .chat-layout {
    grid-template-columns: minmax(0, 1fr) 300px;
  }

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

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    display: grid;
    grid-template-columns: auto 1fr;
    padding: 8px 12px;
  }

  .brand {
    min-height: 44px;
    padding: 0 12px 0 0;
    border: 0;
  }

  .brand div {
    display: none;
  }

  .view-nav {
    display: flex;
    justify-content: flex-end;
    margin: 0;
  }

  .nav-button,
  .nav-button:not(.active) {
    width: 44px;
    font-size: 0;
  }

  .connection-panel {
    display: none;
  }

  .chat-layout {
    display: block;
  }

  .conversation {
    min-height: calc(100vh - 60px);
  }

  .activity-panel {
    border-top: 1px solid #d9dfe3;
    border-left: 0;
  }

  .trace-summary {
    grid-template-columns: 1fr;
  }

  .trace-summary-card.wide {
    grid-column: auto;
  }

  .context-grid,
  .tool-layout {
    grid-template-columns: 1fr;
  }

  .tool-form {
    border-right: 0;
    border-bottom: 1px solid #d9dfe3;
  }

  .message-list {
    padding: 20px 16px 28px;
  }

  .composer {
    margin: 0 12px 14px;
  }
}
