/* Chat 现代美化版 */
:root {
  --primary: var(--accent-500);
  --bg-main: var(--surface-0);
  --bubble-user: var(--accent-500);
  --bubble-agent: var(--surface-1);
  --text-main: var(--text-primary);
  --chat-shell: linear-gradient(180deg, color-mix(in srgb, var(--surface-1) 88%, transparent), color-mix(in srgb, var(--surface-2) 96%, transparent));
}

body {
  font-family: 'Noto Sans SC', 'Manrope', sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
}

.icon-svg {
  width: 1.15rem;
  height: 1.15rem;
}

.toolbar-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.5rem;
  padding: 0.55rem 0.9rem;
  border-radius: 9999px;
  font-weight: 700;
  font-size: 0.6875rem;
  line-height: 1;
  transition: all 0.2s ease;
}

.toolbar-pill-danger {
  background: #ffe4e6;
  color: #e11d48;
}

.toolbar-pill-danger:hover {
  background: #fecdd3;
}

.toolbar-pill-neutral {
  background: #f1f5f9;
  color: #475569;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.toolbar-pill-neutral:hover {
  background: #2563eb;
  color: #fff;
}

.toolbar-icon {
  width: 0.95rem;
  height: 0.95rem;
  flex-shrink: 0;
}

.toolbar-label {
  white-space: nowrap;
}

.floating-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.8rem;
  height: 2.8rem;
}

.floating-icon-svg {
  width: 1.1rem;
  height: 1.1rem;
}

.status-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  flex-shrink: 0;
}

.send-icon {
  width: 1.1rem;
  height: 1.1rem;
}

.modal-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
}

.modal-icon {
  width: 1.2rem;
  height: 1.2rem;
}

#input {
  transition: height 0.12s ease-out, background-color 0.2s ease, box-shadow 0.2s ease;
  overflow-y: hidden;
}

#input:focus {
  overflow-y: auto;
}

/* 滚动条美化 */
.scroll-thin::-webkit-scrollbar { width: 5px; height: 5px; }
.scroll-thin::-webkit-scrollbar-track { background: transparent; }
.scroll-thin::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 10px; }

/* 聊天气泡核心样式 */
.chat-bubble {
  position: relative;
  margin-bottom: 1.25rem;
  padding: 1rem 1.25rem;
  border-radius: 1.25rem;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
  overflow-x: auto; /* 防止内部宽元素撑破气泡 */
  backdrop-filter: blur(12px);
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-bubble[data-role="user"] {
  background-color: var(--bubble-user);
  color: white;
  border-bottom-right-radius: 0.25rem;
  box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
}

.chat-bubble[data-role="assistant"] {
  background-color: var(--bubble-agent);
  color: var(--text-main);
  border: 1px solid var(--border-soft);
  border-bottom-left-radius: 0.25rem;
}

.chat-bubble[data-role="tool"] {
  background-color: var(--surface-2);
  color: var(--text-secondary);
  border: 1px dashed var(--border-strong);
  font-size: 0.8rem;
  padding: 0.75rem 1rem;
}

/* 会话列表项美化 */
#sessionList > div {
  transition: all 0.2s;
  cursor: pointer;
  margin: 0.25rem 0.5rem;
  border-radius: 0.75rem;
  border: none;
}

#sessionSidebar,
#chatView > div > section {
  background: var(--chat-shell);
}

#sessionList > div.bg-blue-50\/70 {
  background-color: var(--accent-050) !important;
  box-shadow: inset 0 0 0 1px var(--accent-100);
}

/* 工具调用卡片 */
.tool-call-card {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 0.75rem;
  margin-top: 0.5rem;
  overflow: hidden;
}

.tool-call-head {
  background: var(--surface-3);
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: monospace;
  font-weight: bold;
}

.tool-arg-row {
  display: flex;
  padding: 0.25rem 0.75rem;
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.75rem;
}

.tool-arg-key {
  color: var(--text-muted);
  width: 80px;
  flex-shrink: 0;
}

.tool-arg-val {
  word-break: break-word;
  color: var(--text-primary);
}

/* 移动端特殊适配 */
@media (max-width: 640px) {
  .mobile-bubble-max { max-width: 92% !important; }
  #sessionSidebar {
    width: min(88vw, 320px);
  }
  .icon-button {
    width: 2.75rem;
    height: 2.75rem;
  }
  .icon-svg {
    width: 1.25rem;
    height: 1.25rem;
  }
  .toolbar-pill {
    min-width: 2.75rem;
    padding: 0.65rem 0.8rem;
  }
  .toolbar-label {
    display: none;
  }
  .toolbar-icon {
    width: 1.05rem;
    height: 1.05rem;
  }
  .floating-icon-button {
    width: 3rem;
    height: 3rem;
  }
  .floating-icon-svg {
    width: 1.2rem;
    height: 1.2rem;
  }
  .status-icon {
    width: 1.05rem;
    height: 1.05rem;
  }
  .send-button {
    width: 2.9rem;
    height: 2.9rem;
  }
  .send-icon {
    width: 1.2rem;
    height: 1.2rem;
  }
  .modal-icon-wrap {
    width: 2.75rem;
    height: 2.75rem;
  }
  .modal-icon {
    width: 1.25rem;
    height: 1.25rem;
  }
  .chat-bubble {
    padding: 0.9rem 1rem;
    border-radius: 1.1rem;
  }
  #messages {
    padding: 0.9rem 0.8rem 1rem;
  }
  #composerBar {
    padding: 0.8rem;
  }
  #composerBar button,
  #approvalBar button,
  header button,
  aside button,
  aside a {
    min-height: 44px;
  }
  header {
    align-items: flex-start;
  }
}

/* Typing 动画 */
.typing-dot {
  width: 4px;
  height: 4px;
  background: currentColor;
  border-radius: 50%;
  animation: typing 1.4s infinite both;
  display: inline-block;
  margin-right: 2px;
  opacity: 0.4;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.2); opacity: 1; }
}

/* Markdown 渲染样式 */
.md-content {
  font-size: 0.875rem; /* text-sm */
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  transition: opacity 0.14s ease;
  animation: stream-fade 0.18s ease;
}
.md-content p { margin-bottom: 0.75rem; }
.md-content p:last-child { margin-bottom: 0; }
.md-content pre {
  background-color: var(--code-bg);
  padding: 0.75rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 0.5rem 0 0.75rem 0;
  font-size: 0.8125rem;
  border: 1px solid var(--border-soft);
}
.md-content code {
  background-color: var(--code-inline-bg);
  padding: 0.15rem 0.3rem;
  border-radius: 0.25rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85em;
}
.md-content pre code {
  background-color: transparent;
  padding: 0;
  font-size: 1em;
}
.md-content ul, .md-content ol {
  margin-bottom: 0.75rem;
  padding-left: 1.5rem;
}
.md-content ul { list-style-type: disc; }
.md-content ol { list-style-type: decimal; }

@keyframes stream-fade {
  from { opacity: 0.78; }
  to { opacity: 1; }
}
.md-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.75rem;
  display: block;
  overflow-x: auto;
}
.md-content th, .md-content td {
  border: 1px solid var(--border-soft);
  padding: 0.5rem;
}
.md-content th { background-color: var(--surface-2); font-weight: 600; }
.md-content a { color: var(--accent-500); text-decoration: underline; }
.md-content blockquote {
  border-left: 4px solid var(--border-strong);
  padding-left: 1rem;
  color: var(--text-muted);
  margin-left: 0;
  margin-right: 0;
  font-style: italic;
}

@media (max-width: 1024px) {
  #chatView {
    padding: 0;
  }
  #chatView > .relative {
    gap: 0;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  #sessionSidebar {
    width: min(72vw, 320px);
  }
  #composerBar {
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
  }
}

:root[data-theme='dark'] #chatView,
:root[data-theme='dark'] #composerBar,
:root[data-theme='dark'] #messages,
:root[data-theme='dark'] #approvalBar,
:root[data-theme='dark'] #sessionSidebar,
:root[data-theme='dark'] #chatView section,
:root[data-theme='dark'] #authView > div,
:root[data-theme='dark'] #newSessionModal > div {
  color: var(--text-primary);
}

:root[data-theme='dark'] #chatView section,
:root[data-theme='dark'] #sessionSidebar,
:root[data-theme='dark'] #authView > div,
:root[data-theme='dark'] #newSessionModal > div,
:root[data-theme='dark'] #composerBar,
:root[data-theme='dark'] #approvalBar {
  background: color-mix(in srgb, var(--surface-1) 92%, transparent) !important;
  border-color: var(--border-soft) !important;
}

:root[data-theme='dark'] #authView input,
:root[data-theme='dark'] #newSessionModal input,
:root[data-theme='dark'] #newSessionModal select {
  background: color-mix(in srgb, var(--surface-2) 92%, transparent) !important;
  border-color: var(--border-soft) !important;
  color: var(--text-primary) !important;
}

:root[data-theme='dark'] #authView input::placeholder,
:root[data-theme='dark'] #newSessionModal input::placeholder {
  color: var(--text-muted) !important;
}

:root[data-theme='dark'] #messages {
  background: color-mix(in srgb, var(--surface-0) 65%, transparent) !important;
}

:root[data-theme='dark'] .toolbar-pill-neutral {
  background: var(--surface-3);
  color: var(--text-secondary);
}

:root[data-theme='dark'] .toolbar-pill-danger {
  background: color-mix(in srgb, var(--danger-500) 25%, transparent);
  color: #fecdd3;
}

:root[data-theme='dark'] #chatView header [data-theme-toggle],
:root[data-theme='dark'] #chatView header [data-theme-mode-select] {
  background: color-mix(in srgb, var(--surface-2) 92%, transparent) !important;
  border-color: var(--border-soft) !important;
  color: var(--text-secondary) !important;
}

:root[data-theme='dark'] #chatView header [data-theme-toggle]:hover,
:root[data-theme='dark'] #chatView header [data-theme-mode-select]:hover {
  color: var(--text-primary) !important;
}

:root[data-theme='dark'] .chat-bubble[data-role='assistant'] {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

