:root {
  color-scheme: light;
  --blue: #3168f6;
  --blue-strong: #2457dc;
  --blue-soft: #eaf0ff;
  --green: #20b27a;
  --ink: #20283a;
  --muted: #77839a;
  --line: #e4e9f2;
  --surface: #ffffff;
  --page: #f5f7fb;
  --danger: #d94444;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--page);
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 424px minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  min-height: 620px;
  overflow: hidden;
  background: var(--surface);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: #fbfcff;
  padding: 28px 18px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 24px;
  color: inherit;
  text-decoration: none;
}

.brand-name {
  font-size: 17px;
  line-height: 1;
  font-weight: 800;
  color: #17345f;
}

.brand-logo {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  object-fit: cover;
  box-shadow: 0 8px 20px rgba(28, 85, 190, 0.14);
}

.empty-logo {
  display: block;
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;
  border-radius: 18px;
  object-fit: cover;
  box-shadow: 0 12px 28px rgba(28, 85, 190, 0.16);
}

.assistant-avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-top: 4px;
  border-radius: 16px;
  background: #eef4ff;
  box-shadow: 0 8px 18px rgba(28, 85, 190, 0.1);
}

.assistant-avatar img {
  width: 50px;
  height: 50px;
  border-radius: 14px;
  object-fit: cover;
}

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  min-height: 62px;
  border-radius: 8px;
  color: #fff;
  background: var(--blue);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.new-chat:hover {
  background: var(--blue-strong);
}

.new-chat span {
  font-size: 22px;
  font-weight: 300;
  line-height: 1;
}

.skill-upload-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.skill-upload-panel[hidden] {
  display: none;
}

.skill-upload-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.skill-upload-head span {
  min-width: 0;
  overflow: hidden;
  color: #2a3550;
  font-size: 10px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.skill-upload-button {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 7px;
  color: #fff;
  background: #20b27a;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}

.skill-upload-button:hover {
  background: #168e62;
}

.skill-upload-button:disabled {
  background: #c2c8d4;
  cursor: not-allowed;
}

.skill-upload-meta {
  min-height: 16px;
  margin-top: 8px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.debug-toggle-panel {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.debug-toggle-panel[hidden] {
  display: none;
}

.debug-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #2a3550;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}

.debug-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.debug-switch {
  position: relative;
  flex: 0 0 auto;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #c7d0df;
  transition: background 0.16s ease;
}

.debug-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(38, 55, 88, 0.22);
  transition: transform 0.16s ease;
}

.debug-toggle input:checked + .debug-switch {
  background: var(--blue);
}

.debug-toggle input:checked + .debug-switch::after {
  transform: translateX(16px);
}

.debug-toggle input:focus-visible + .debug-switch {
  outline: 2px solid rgba(49, 104, 246, 0.35);
  outline-offset: 2px;
}

.debug-toggle-meta {
  min-height: 16px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.conversation-list {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  margin-top: 14px;
  overflow-y: auto;
  padding: 0 8px 76px 0;
  scrollbar-gutter: stable;
}

.conversation-list::-webkit-scrollbar {
  width: 8px;
}

.conversation-list::-webkit-scrollbar-track {
  background: transparent;
}

.conversation-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #c7d0df;
}

.conversation-list::-webkit-scrollbar-thumb:hover {
  background: #9eabc1;
}

.conversation-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: center;
  min-height: 82px;
  width: 100%;
  border-radius: 8px;
  color: #6f7b92;
  background: transparent;
}

.conversation-item:hover,
.conversation-item.active {
  color: var(--blue);
  background: var(--blue-soft);
}

.conversation-select {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 82px;
  width: 100%;
  padding: 12px 0 12px 18px;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.conversation-icon {
  width: 17px;
  height: 17px;
  border: 2px solid currentColor;
  border-radius: 4px;
  border-top-left-radius: 2px;
}

.conversation-copy {
  min-width: 0;
}

.conversation-copy strong,
.conversation-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-copy strong {
  font-size: 12px;
  line-height: 1.3;
  color: currentColor;
}

.conversation-copy small {
  margin-top: 4px;
  font-size: 10px;
  color: #8b96ac;
}

.conversation-menu-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 38px;
  margin-right: 6px;
  border-radius: 7px;
  background: transparent;
  color: currentColor;
  font-weight: 800;
  cursor: pointer;
}

.conversation-menu-button:hover,
.conversation-menu-button[aria-expanded="true"] {
  background: rgba(49, 104, 246, 0.12);
}

.conversation-popover {
  position: absolute;
  top: 56px;
  right: 10px;
  z-index: 20;
  min-width: 118px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(38, 55, 88, 0.16);
}

.conversation-delete {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--danger);
  background: transparent;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.conversation-delete:hover {
  background: #fff0f0;
}

.conversation-delete:disabled {
  color: #c2c8d4;
  cursor: not-allowed;
}

.chat-pane {
  display: grid;
  grid-template-rows: 82px minmax(0, 1fr) auto;
  min-width: 0;
  height: 100vh;
  background: var(--surface);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  padding: 0 32px;
}

.chat-header h1 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 800;
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 22px;
  min-width: 0;
}

.assistant-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--green);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.assistant-state span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
}

.assistant-state.loading {
  color: #e09a28;
}

.assistant-state.offline {
  color: var(--muted);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: #2a3550;
  font-size: 10px;
  font-weight: 800;
}

.user-profile[hidden] {
  display: none;
}

.user-profile img {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border: 1px solid #d8deea;
  border-radius: 50%;
  object-fit: cover;
  background: #eef2fb;
}

.user-profile span {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-scroll {
  min-height: 0;
  overflow-y: auto;
  padding: 34px 46px 36px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 28px;
  max-width: 1460px;
  margin: 0 auto;
}

.empty-chat {
  max-width: 560px;
  margin: 20vh auto 0;
  text-align: center;
  color: var(--muted);
}

.empty-chat.hidden {
  display: none;
}

.empty-chat h2 {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 18px;
}

.empty-chat p {
  margin: 0;
  font-size: 11px;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  width: 100%;
}

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

.message-row.from-assistant {
  justify-content: flex-start;
}

.avatar {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #eef2fb;
  color: #30405f;
  font-weight: 800;
}

.user-avatar {
  border: 1px solid #d8deea;
  background: linear-gradient(#f7f9fd, #eef3fa);
  overflow: hidden;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bubble-wrap {
  max-width: min(980px, 76%);
}

.from-assistant .bubble-wrap {
  max-width: min(1320px, 86%);
}

.bubble {
  min-height: 48px;
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  font-size: 14px;
  line-height: 1.55;
}

.from-user .bubble {
  padding: 16px 22px;
  color: #fff;
  background: var(--blue);
}

.from-assistant .bubble {
  padding: 0;
}

.guarded-reveal {
  margin-top: 8px;
}

.guarded-reveal-link {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  padding: 0;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.4;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.guarded-reveal-link:hover {
  color: var(--blue-strong);
}

.guarded-original {
  margin-top: 10px;
  border: 1px solid #dbe5f5;
  border-radius: 8px;
  background: #fbfdff;
  padding: 14px 16px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
}

.bubble.failed {
  padding: 14px 18px;
  color: var(--danger);
  border: 1px solid #f3c7c7;
  background: #fff7f7;
}

.bubble p {
  margin: 0 0 16px;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble strong {
  font-weight: 800;
  color: #1f2a44;
}

.bubble code {
  padding: 2px 6px;
  border-radius: 5px;
  color: #174287;
  background: #eef4ff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.88em;
}

.message-heading,
.message-section-title {
  margin: 22px 0 10px;
  color: #1e2a42;
  line-height: 1.35;
  font-weight: 850;
}

.message-heading:first-child,
.message-section-title:first-child {
  margin-top: 0;
}

.message-heading {
  font-size: 1.08em;
}

.message-section-title {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 3px 10px;
  border-radius: 7px;
  color: #174287;
  background: #eef4ff;
  font-size: 0.94em;
}

.message-list {
  margin: 0 0 18px;
  padding-left: 1.4em;
}

.message-list li {
  margin: 6px 0;
  padding-left: 2px;
}

.bubble blockquote {
  margin: 0 0 18px;
  padding: 10px 14px;
  border-left: 4px solid #9db8f6;
  border-radius: 0 7px 7px 0;
  color: #4f5d78;
  background: #f5f8ff;
}

.message-meta {
  margin-top: 7px;
  color: #8791a6;
  font-size: 10px;
  text-align: right;
}

.from-assistant .message-meta {
  text-align: left;
}

.tool-traces {
  margin-top: 14px;
  border: 1px solid #dbe4f3;
  border-radius: 8px;
  background: #f8fbff;
  color: #2a3550;
  font-size: 10px;
}

.tool-traces summary {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  color: #24507f;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
}

.tool-trace-list {
  display: grid;
  gap: 10px;
  padding: 0 12px 12px;
}

.tool-trace-item {
  border: 1px solid #e1e8f4;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.tool-trace-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border-bottom: 1px solid #edf1f8;
  color: #24304a;
}

.tool-trace-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
}

.tool-trace-index,
.tool-trace-type,
.tool-trace-status {
  flex: 0 0 auto;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
}

.tool-trace-index {
  color: #4e5c78;
  background: #eef2f8;
}

.tool-trace-type {
  color: #2457dc;
  background: #edf3ff;
}

.tool-trace-status.complete {
  color: #127a56;
  background: #e9f8f2;
}

.tool-trace-status.running {
  color: #9a640c;
  background: #fff4dc;
}

.tool-trace-status.failed {
  color: var(--danger);
  background: #fff0f0;
}

.tool-trace-meta {
  padding: 7px 10px 0;
  color: #8a95aa;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 10px;
}

.tool-trace-payload {
  padding: 8px 10px 10px;
}

.tool-trace-payload span {
  display: block;
  margin-bottom: 5px;
  color: #56637c;
  font-size: 10px;
  font-weight: 800;
}

.tool-trace-payload pre {
  max-height: 360px;
  margin: 0;
  overflow: auto;
  border-radius: 7px;
  background: #111827;
  color: #dbeafe;
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 10px;
  line-height: 1.45;
}

.table-wrap {
  max-width: 100%;
  margin: 12px 0 22px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.45;
}

th,
td {
  padding: 13px 16px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

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

tr:last-child td {
  border-bottom: 0;
}

th {
  color: #2d3851;
  background: #f6f8fd;
  font-weight: 800;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 60px;
  align-items: end;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding: 18px 42px 24px;
  background: rgba(255, 255, 255, 0.96);
}

.composer textarea {
  width: 100%;
  min-height: 58px;
  max-height: 180px;
  resize: none;
  border: 0;
  border-radius: 8px;
  outline: none;
  background: #f0f4fb;
  padding: 17px 22px;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.35;
}

.composer textarea:disabled {
  color: #8b96aa;
}

.send-button {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #a9c1ff;
  color: #fff;
  cursor: pointer;
}

.send-button:not(:disabled) {
  background: var(--blue);
}

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

.send-button span {
  font-size: 17px;
  line-height: 1;
}

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

  .sidebar {
    max-height: 240px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 16px;
  }

  .brand {
    padding-bottom: 12px;
  }

  .new-chat {
    min-height: 50px;
  }

  .conversation-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
  }

  .conversation-item {
    flex: 0 0 250px;
  }

  .chat-pane {
    height: calc(100vh - 240px);
    grid-template-rows: 64px minmax(0, 1fr) auto;
  }

  .chat-header {
    padding: 0 18px;
  }

  .chat-header h1 {
    font-size: 13px;
  }

  .header-right {
    gap: 12px;
  }

  .user-profile span {
    display: none;
  }

  .message-scroll {
    padding: 22px 18px;
  }

  .bubble-wrap,
  .from-assistant .bubble-wrap {
    max-width: calc(100% - 62px);
  }

  .bubble {
    font-size: 11px;
  }

  table {
    font-size: 10px;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 52px;
    padding: 12px 14px 16px;
  }

  .send-button {
    width: 52px;
    height: 52px;
  }
}
