:root {
  color-scheme: light;
  --bg: #f7f9fc;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #dbe3ef;
  --soft: #f3f7ff;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --warn: #b45309;
  --shadow: 0 14px 34px rgba(37, 99, 235, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

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

button,
textarea,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  min-height: 38px;
  padding: 0 14px;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

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

.history-sidebar {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: #f3f7ff;
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 18px 16px;
  background: #ffffff;
}

.sidebar-header h2,
.chat-header h2,
.agent-config h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
}

.sidebar-header p,
.chat-header p,
.agent-config p,
.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.history-list {
  display: grid;
  grid-auto-rows: max-content;
  align-content: start;
  gap: 8px;
  height: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px 10px;
  overscroll-behavior: contain;
}

.history-item {
  display: grid;
  gap: 5px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.04);
  padding: 11px;
  text-align: left;
  white-space: normal;
}

.history-item:hover {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.history-row-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.history-question {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  font-size: 14px;
  font-weight: 750;
}

.history-delete {
  border-radius: 999px;
  background: #fee2e2;
  color: var(--danger);
  font-size: 12px;
  line-height: 1;
  padding: 5px 7px;
}

.history-preview {
  display: -webkit-box;
  overflow: hidden;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 450;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.history-time {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.chat-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  padding: 18px 20px;
  gap: 12px;
  background: #ffffff;
}

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

.topbar h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: 0;
}

.status-stack {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.model-switch,
.model-fixed {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  padding: 4px 6px 4px 12px;
}

.model-fixed strong {
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 13px;
  padding: 5px 9px;
}

.model-switch select {
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 750;
  padding: 0 8px;
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  font-size: 13px;
  padding: 8px 12px;
  white-space: nowrap;
}

.status-pill.offline {
  color: var(--warn);
}

.agent-bar {
  display: grid;
  grid-template-columns: minmax(340px, 0.9fr) minmax(0, 1.1fr);
  gap: 12px;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.agent-config {
  display: grid;
  gap: 10px;
}

.config-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, 0.8fr) auto;
  gap: 10px;
}

.config-grid input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fbff;
  padding: 8px 10px;
}

.readonly-config {
  grid-template-columns: minmax(0, 0.6fr) minmax(0, 1.4fr);
}

.config-note {
  min-height: 38px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fbff;
  color: var(--muted);
  font-size: 13px;
  padding: 8px 10px;
}

.tool-list {
  display: grid;
  align-content: start;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  max-height: 120px;
  overflow-y: auto;
}

.tool-item {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fbff;
  padding: 9px;
}

.tool-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.tool-item span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.ghost-btn {
  min-height: 30px;
  border: 1px solid var(--line);
  background: #fff;
  color: #334155;
  padding: 0 10px;
  font-size: 13px;
}

.ghost-btn:hover {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: var(--accent-dark);
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.chat-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.chat-log {
  min-height: 0;
  overflow-y: auto;
  padding: 22px max(22px, 6vw);
  background: #ffffff;
}

.empty-state,
.mini-empty {
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
}

.empty-state {
  min-height: 260px;
}

.mini-empty {
  min-height: 72px;
  padding: 12px;
  font-size: 13px;
}

.chat-message {
  display: grid;
  gap: 6px;
  margin: 0 0 14px;
}

.chat-message.user {
  justify-items: end;
}

.chat-message.assistant,
.chat-message.process {
  justify-items: start;
}

.message-meta {
  display: flex;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  padding: 0 4px;
}

.message-bubble {
  position: relative;
  width: fit-content;
  max-width: min(860px, 88%);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
  padding: 14px 16px;
}

.chat-message.user .message-bubble {
  border-color: #2563eb;
  background: #2563eb;
  color: #ffffff;
}

.chat-message.process .message-bubble {
  border-color: #bfdbfe;
  background: #f8fbff;
  max-width: min(780px, 84%);
}

.message-badge {
  width: fit-content;
  margin-bottom: 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 750;
  padding: 3px 8px;
}

.chat-message.user .message-badge {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.workflow-message {
  justify-items: start;
}

.workflow-details {
  width: min(860px, 88%);
  border: 1px solid #bfdbfe;
  border-radius: 16px;
  background: #f8fbff;
  overflow: hidden;
}

.workflow-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  padding: 12px 14px;
  font-weight: 750;
}

.workflow-details summary::-webkit-details-marker {
  display: none;
}

.workflow-details summary::before {
  content: "▸";
  color: var(--accent);
  margin-right: 2px;
}

.workflow-details[open] summary::before {
  content: "▾";
}

.workflow-summary-status {
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 750;
  padding: 4px 8px;
  white-space: nowrap;
}

.workflow-steps {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 12px;
}

.workflow-step {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 12px;
}

.workflow-step-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: #344054;
  font-size: 13px;
  font-weight: 750;
}

.workflow-step-title span:last-child {
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

.workflow-pre {
  overflow-x: auto;
  white-space: pre-wrap;
  border: 0;
  border-radius: 10px;
  background: #f8fafc;
  color: #1f2937;
  margin: 0;
  padding: 10px;
  font-size: 12.5px;
  line-height: 1.6;
}

.workflow-pre p {
  margin: 0 0 8px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  border-top: 1px solid var(--line);
  background: #fff;
  padding: 14px max(14px, 5vw);
}

textarea {
  width: 100%;
  min-height: 64px;
  max-height: 160px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.08);
  color: var(--ink);
  line-height: 1.55;
  padding: 11px 12px;
}

#run-btn {
  min-width: 86px;
  min-height: 44px;
  border-radius: 18px;
}

.markdown-body {
  overflow-wrap: anywhere;
  line-height: 1.58;
  font-size: 14px;
}

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

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

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.workflow-pre h1,
.workflow-pre h2,
.workflow-pre h3,
.workflow-pre h4 {
  margin: 14px 0 8px;
  line-height: 1.3;
}

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

.markdown-body h2,
.workflow-pre h2 {
  font-size: 18px;
}

.markdown-body h3,
.workflow-pre h3 {
  font-size: 16px;
}

.markdown-body h4,
.workflow-pre h4 {
  font-size: 15px;
}

.markdown-body ul,
.markdown-body ol,
.workflow-pre ul,
.workflow-pre ol {
  margin: 8px 0 8px 20px;
  padding: 0;
}

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

.markdown-body blockquote,
.workflow-pre blockquote {
  margin: 10px 0;
  border-left: 3px solid var(--accent);
  background: #eff6ff;
  color: #334155;
  padding: 8px 12px;
}

.markdown-body pre,
.workflow-pre pre {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202124;
  color: #f8fafc;
  padding: 12px;
}

.markdown-body code,
.workflow-pre code {
  border-radius: 6px;
  background: #eff6ff;
  color: #1e3a8a;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92em;
}

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

.markdown-body .table-wrap,
.workflow-pre .table-wrap {
  overflow-x: auto;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.markdown-body table,
.workflow-pre table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  background: #fff;
}

.markdown-body th,
.markdown-body td,
.workflow-pre th,
.workflow-pre td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

.markdown-body th,
.workflow-pre th {
  background: #eff6ff;
  color: #1e3a8a;
  font-weight: 750;
}

.markdown-body tr:last-child td,
.workflow-pre tr:last-child td {
  border-bottom: 0;
}

.markdown-body a,
.workflow-pre a {
  color: var(--accent-dark);
}

.artifact-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding-top: 10px;
}

.artifact-links a {
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 750;
  padding: 6px 10px;
  text-decoration: none;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-layout {
    display: block;
    height: auto;
  }

  .history-sidebar {
    display: none;
  }

  .chat-shell {
    height: 100vh;
    padding: 14px;
  }

  .agent-bar {
    grid-template-columns: 1fr;
  }

  .config-grid,
  .tool-list {
    grid-template-columns: 1fr;
  }
}
