:root {
  color-scheme: light;
  --page: #dfe1e5;
  --panel: #f7f7f7;
  --chat: #ededed;
  --line: #d7d7d7;
  --text: #111111;
  --muted: #7b7b7b;
  --assistant-bubble: #ffffff;
  --user-bubble: #95ec69;
  --button: #07c160;
  --button-disabled: #9fd9b5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
}

button,
textarea {
  font: inherit;
}

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

.app {
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr) auto;
  width: min(860px, 100%);
  height: 100dvh;
  margin: 0 auto;
  background: var(--chat);
  border-inline: 1px solid #d4d4d4;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.mode-switch {
  position: absolute;
  left: 10px;
  display: flex;
  gap: 4px;
  border-radius: 999px;
  padding: 3px;
  background: #e9e9e9;
}

.mode-button {
  border: 0;
  border-radius: 999px;
  padding: 5px 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  cursor: pointer;
}

.mode-button.active {
  background: #ffffff;
  color: #222222;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.chat-title {
  display: grid;
  justify-items: center;
  gap: 2px;
  line-height: 1.1;
}

.title-name {
  font-size: 1rem;
  font-weight: 600;
}

.title-status {
  color: var(--muted);
  font-size: 0.72rem;
}

.text-button {
  position: absolute;
  right: 12px;
  border: 0;
  border-radius: 6px;
  padding: 7px 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.text-button:hover {
  color: var(--text);
  background: #eeeeee;
}

.chat {
  position: relative;
  min-height: 0;
}

.messages {
  height: 100%;
  overflow-y: auto;
  padding: 18px 14px 22px;
  scroll-behavior: auto;
  contain: content;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.empty-state[hidden] {
  display: none;
}

.empty-state p {
  margin: 6px 0 0;
  color: #333333;
  font-size: 0.95rem;
  font-weight: 600;
}

.empty-state span {
  max-width: 260px;
  font-size: 0.86rem;
  line-height: 1.5;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 16px;
}

.message.user {
  flex-direction: row-reverse;
}

.avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  color: #ffffff;
  font-weight: 700;
  user-select: none;
}

.avatar-assistant {
  background: #2d3540;
}

.avatar-user {
  background: #5777a8;
}

.bubble {
  position: relative;
  max-width: min(660px, calc(100% - 62px));
  border-radius: 6px;
  padding: 9px 11px;
  line-height: 1.62;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
}

.assistant .bubble {
  background: var(--assistant-bubble);
}

.user .bubble {
  background: var(--user-bubble);
}

.bubble::before {
  content: "";
  position: absolute;
  top: 12px;
  width: 0;
  height: 0;
  border-block: 6px solid transparent;
}

.assistant .bubble::before {
  left: -6px;
  border-right: 7px solid var(--assistant-bubble);
}

.user .bubble::before {
  right: -6px;
  border-left: 7px solid var(--user-bubble);
}

.message.pending .bubble {
  color: var(--muted);
}

.body p {
  margin: 0 0 0.65rem;
}

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

.body code {
  border-radius: 4px;
  padding: 0.08rem 0.28rem;
  background: rgba(0, 0, 0, 0.06);
}

.body pre {
  overflow: auto;
  border-radius: 6px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.06);
}

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

.composer textarea {
  display: block;
  width: 100%;
  min-height: 38px;
  max-height: 132px;
  resize: none;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--text);
  line-height: 1.45;
}

.composer textarea:focus {
  outline: none;
}

.composer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  display: none;
}

#send {
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  background: var(--button);
  color: #ffffff;
  font-weight: 600;
  cursor: pointer;
}

#send:disabled {
  cursor: not-allowed;
  background: var(--button-disabled);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

@media (max-width: 720px) {
  .app {
    grid-template-rows: 64px minmax(0, 1fr) auto;
    border-inline: 0;
  }

  .topbar {
    height: 64px;
    align-items: flex-start;
    padding-top: 7px;
  }

  .mode-switch {
    inset: auto auto 7px 50%;
    transform: translateX(-50%);
  }

  .messages {
    padding-inline: 10px;
  }

  .avatar {
    width: 36px;
    height: 36px;
  }

  .bubble {
    max-width: calc(100% - 56px);
  }
}
