.assistant-text,
.stream-message,
.user-message-rich {
  min-width: 0;
}

.user-message-rich {
  margin: 0;
  font-size: 14px;
  line-height: 1.72;
}

.inline-code {
  padding: .16em .42em;
  border: 1px solid rgba(65, 82, 112, .08);
  border-radius: 6px;
  color: #405571;
  background: rgba(230, 236, 246, .84);
  font: .9em/1.45 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
}

.message.user .inline-code {
  color: inherit;
  border-color: rgba(255, 255, 255, .18);
  background: rgba(255, 255, 255, .14);
}

.chat-code-block {
  width: min(100%, 680px);
  margin: 12px 0;
  overflow: hidden;
  border: 1px solid rgba(117, 139, 175, .2);
  border-radius: 15px;
  background: #111827;
  box-shadow: 0 10px 28px rgba(18, 28, 48, .13);
}

.chat-code-block header {
  min-height: 34px;
  padding: 0 8px 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  color: #9eacc1;
  background: rgba(255, 255, 255, .035);
  font: 700 8px/1 system-ui, sans-serif;
  letter-spacing: .08em;
}

.chat-code-block header button {
  min-width: 48px;
  min-height: 27px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  color: #cbd5e1;
  background: rgba(255, 255, 255, .08);
  font: 650 8px/1 system-ui, sans-serif;
  transition: color .18s ease, background .18s ease, transform .18s ease;
}

.chat-code-block header button:active {
  transform: scale(.95);
}

.chat-code-block header button.copied {
  color: #b7f7dc;
  background: rgba(52, 211, 153, .16);
}

.chat-code-block pre {
  max-width: 100%;
  margin: 0;
  padding: 14px;
  overflow: auto;
  overscroll-behavior-x: contain;
  color: #e5edf7;
  background: transparent;
  -webkit-overflow-scrolling: touch;
}

.chat-code-block pre code {
  display: block;
  width: max-content;
  min-width: 100%;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  font: 9px/1.7 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre;
  overflow-wrap: normal;
}

.math-render {
  display: inline-block;
  max-width: 100%;
  vertical-align: -.08em;
}

.math-render.display {
  display: block;
  margin: 12px 0;
  padding: 10px 4px;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: 12px;
  background: rgba(239, 244, 251, .62);
  text-align: center;
  -webkit-overflow-scrolling: touch;
}

.math-render.display .katex-display {
  width: max-content;
  min-width: 100%;
  margin: 0;
}

.math-fallback {
  color: #8b4260;
  background: rgba(244, 229, 237, .7);
}

.chat-table-scroll {
  width: 100%;
  max-width: 100%;
  margin: 12px 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border: 1px solid rgba(85, 107, 143, .14);
  border-radius: 14px;
  background: rgba(248, 250, 253, .72);
  box-shadow: 0 8px 24px rgba(29, 45, 73, .055);
  -webkit-overflow-scrolling: touch;
}

.chat-table-scroll:focus-visible {
  outline: 2px solid rgba(59, 112, 202, .55);
  outline-offset: 2px;
}

.chat-table {
  width: 100%;
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  color: inherit;
  font-size: 12px;
  line-height: 1.55;
}

.chat-table th,
.chat-table td {
  min-width: 92px;
  padding: 9px 11px;
  border-right: 1px solid rgba(85, 107, 143, .1);
  border-bottom: 1px solid rgba(85, 107, 143, .1);
  vertical-align: top;
  white-space: normal;
  overflow-wrap: anywhere;
}

.chat-table th {
  color: #475a75;
  background: rgba(226, 233, 244, .58);
  font-weight: 750;
  white-space: nowrap;
}

.chat-table tr > :last-child { border-right: 0; }
.chat-table tbody tr:last-child td { border-bottom: 0; }
.chat-table .align-center { text-align: center; }
.chat-table .align-right { text-align: right; }

:root[data-theme="dark"] .chat-table-scroll {
  border-color: rgba(137, 164, 202, .14);
  background: rgba(18, 30, 47, .74);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .14);
}

:root[data-theme="dark"] .chat-table th,
:root[data-theme="dark"] .chat-table td {
  border-color: rgba(137, 164, 202, .11);
}

:root[data-theme="dark"] .chat-table th {
  color: #c7d4e7;
  background: rgba(74, 101, 138, .18);
}

:root[data-theme="colorful"] .chat-table-scroll {
  border-color: rgba(255, 255, 255, .12);
  background: rgba(0, 0, 0, .12);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

:root[data-theme="colorful"] .chat-table th,
:root[data-theme="colorful"] .chat-table td {
  border-color: rgba(255, 255, 255, .09);
}

:root[data-theme="colorful"] .chat-table th {
  color: rgba(255, 255, 255, .9);
  background: rgba(255, 255, 255, .08);
}

:root[data-theme="dark"] .inline-code {
  color: #c9d6e9;
  border-color: rgba(255, 255, 255, .08);
  background: rgba(255, 255, 255, .08);
}

:root[data-theme="dark"] .math-render.display {
  background: rgba(255, 255, 255, .045);
}

:root[data-theme="colorful"] .math-render.display {
  color: inherit;
  border: 1px solid rgba(255, 255, 255, .1);
  background: rgba(0, 0, 0, .1);
  backdrop-filter: blur(8px);
}

@media (orientation: landscape) and (max-height: 560px) {
  .user-message-rich {
    font-size: 12px;
  }

  .chat-code-block {
    margin: 8px 0;
    border-radius: 12px;
  }

  .chat-code-block pre {
    padding: 10px 12px;
  }

  .chat-code-block pre code {
    font-size: 8px;
  }

  .math-render.display {
    margin: 8px 0;
    padding: 7px 3px;
  }

  .chat-table-scroll { margin: 8px 0; border-radius: 11px; }
  .chat-table { font-size: 11px; }
  .chat-table th,
  .chat-table td { min-width: 84px; padding: 7px 9px; }
}

@media (max-width: 360px) and (orientation: portrait) {
  .user-message-rich {
    font-size: 13.5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-code-block header button {
    transition: none;
  }
}
