:root {
  --font-sans: "PingFang SC", "Microsoft YaHei", "HarmonyOS Sans SC", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --brand: #4d6bfe;
  --user-bubble: #eff1f5;
  --user-text: #1f2329;
  --send-bg: var(--brand);
  --send-color: #fff;
  --text: #1f2329;
  --muted: #8a8f99;
  --line: rgba(15, 23, 42, 0.09);
  --hover: rgba(15, 23, 42, 0.05);
  --assistant-avatar-size: 30px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background: #fff;
  font-family: var(--font-sans);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button {
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
}

a { color: inherit; text-decoration: none; }

button:disabled, [aria-disabled="true"] { cursor: default; }

.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  height: 1em;
  flex: none;
}

.icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

[hidden], .is-hidden { display: none !important; }

.app {
  display: flex;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w, 260px);
  flex: 0 0 var(--sidebar-w, 260px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--sidebar-bg, #f7f8fa);
  border-right: 1px solid var(--sidebar-line, transparent);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 18px 16px 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.02em;
  min-width: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.brand-mark svg { width: 100%; height: 100%; display: block; }

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.hero-logo img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
}

.side-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: 9px;
  color: var(--sidebar-text, #3d4148);
  font-size: 14px;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.side-item:hover { background: var(--sidebar-hover, rgba(15, 23, 42, 0.05)); }

.side-item.active {
  background: var(--sidebar-active, rgba(77, 107, 254, 0.1));
  color: var(--sidebar-active-text, var(--brand));
  font-weight: 500;
}

.side-item .icon { font-size: 17px; opacity: 0.85; }

.side-item .side-extra {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.side-label {
  padding: 16px 20px 7px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.01em;
}

.history-block {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 10px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--sidebar-text, #3d4148);
  font-size: 13px;
  text-align: left;
}

.history-item:hover { background: var(--sidebar-hover, rgba(15, 23, 42, 0.05)); }

.history-item.active {
  background: var(--sidebar-active, rgba(77, 107, 254, 0.1));
  color: var(--sidebar-active-text, var(--brand));
}

.history-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex: 1;
}

.history-time {
  flex: none;
  color: var(--muted);
  font-size: 11px;
}

.history-empty {
  padding: 7px 10px;
  color: var(--muted);
  font-size: 13px;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--sidebar-line, rgba(15, 23, 42, 0.06));
}

.sidebar-footer .side-item {
  flex: 1;
  min-height: 32px;
  padding: 6px 8px;
  font-size: 13px;
}

.main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--main-bg, #fff);
  position: relative;
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 64px;
  padding: 0 var(--main-pad, 26px);
  color: var(--text);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-region {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.22) transparent;
}

.chat-scroll::-webkit-scrollbar { width: 8px; }
.chat-scroll::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, 0.22); border-radius: 999px; }

.messages {
  width: min(var(--chat-width, 820px), 100%);
  margin: 0 auto;
  padding: 22px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.messages:empty { display: none; }

.welcome {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
  text-align: center;
}

.welcome-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.welcome h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 32px);
  line-height: 1.3;
  letter-spacing: -0.03em;
  font-weight: 600;
}

.welcome p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.composer-hero-slot,
.composer-bottom-slot {
  width: 100%;
  display: flex;
  justify-content: center;
}

.composer-bottom-slot {
  flex: none;
  padding: 0 var(--main-pad, 26px) var(--composer-bottom-pad, 22px);
}

.composer-bottom-slot:empty { display: none; }

.composer {
  width: min(var(--composer-width, 820px), 100%);
  background: var(--composer-bg, #fff);
  border: 1px solid var(--composer-border, #e2e5ea);
  border-radius: var(--composer-radius, 18px);
  padding: var(--composer-pad, 14px 16px 10px);
  box-shadow: var(--composer-shadow, 0 8px 28px rgba(15, 23, 42, 0.05));
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.composer:focus-within {
  border-color: var(--brand);
  box-shadow: var(--composer-focus-shadow, 0 0 0 3px rgba(77, 107, 254, 0.09));
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 26px;
  max-height: 180px;
  padding: 0 2px;
  border: 0;
  outline: 0;
  background: transparent;
  resize: none;
  line-height: 1.65;
  font-size: 15px;
  color: var(--text);
}

.composer textarea::placeholder { color: var(--placeholder, #9aa0aa); }

.composer-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
}

.composer-tools-left, .composer-tools-right {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.composer-tools-left { overflow-x: auto; scrollbar-width: none; }
.composer-tools-left::-webkit-scrollbar { display: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  color: var(--icon-color, #5b616b);
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover { background: var(--hover); }

.icon-btn .icon { font-size: 18px; }

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 7px;
  border-radius: 8px;
  color: var(--tool-color, #5b616b);
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.tool-chip:hover { background: var(--hover); color: var(--text); }

.tool-chip .icon { font-size: 16px; }
.tool-chip .chip-sub { color: var(--brand); font-size: 10px; font-weight: 600; }

.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--send-bg);
  color: var(--send-color);
  flex: none;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

.send-btn .icon { font-size: 18px; }
.send-btn:hover:not(:disabled) { transform: translateY(-1px); }
.send-btn:disabled { opacity: 0.34; cursor: default; transform: none; }

.stop-btn {
  background: var(--stop-bg, #1f2329);
  color: #fff;
}

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

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

.message.user .bubble {
  max-width: min(76%, 640px);
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  background: var(--user-bubble);
  color: var(--user-text);
  line-height: 1.65;
  font-size: 14.5px;
  word-break: break-word;
  white-space: pre-wrap;
}

.bubble-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  max-width: 80%;
}

.message.assistant {
  align-items: flex-start;
}

.assistant-avatar {
  flex: none;
  width: var(--assistant-avatar-size);
  height: var(--assistant-avatar-size);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--avatar-bg, #f1f3f6);
  color: var(--brand);
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
}

.assistant-avatar svg { width: 68%; height: 68%; display: block; }

.assistant-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: inherit;
}

.assistant-main {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  padding-top: 1px;
}

.assistant-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.model-chip {
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--model-chip-bg, #f1f3f6);
  color: var(--model-chip-text, #7d838d);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.assistant-content {
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.76;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.assistant-content.is-streaming {
  white-space: pre-wrap;
}

.assistant-actions, .user-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.message:hover .assistant-actions,
.message:focus-within .assistant-actions,
.message:hover .user-actions,
.message:focus-within .user-actions { opacity: 1; }

.assistant-actions button, .user-actions button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
}

.assistant-actions button:hover, .user-actions button:hover {
  background: var(--hover);
  color: var(--text);
}

.assistant-actions .icon, .user-actions .icon { font-size: 13px; }

.message.assistant.is-streaming .assistant-actions { display: none; }

.message-error {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff1f1;
  color: #c0392b;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
}

.typing-indicator i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brand);
  opacity: 0.45;
  animation: cloneTyping 1.1s infinite ease-in-out;
}

.typing-indicator i:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator i:nth-child(3) { animation-delay: 0.3s; }

@keyframes cloneTyping {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-3px); opacity: 0.9; }
}

.assistant-content > :first-child { margin-top: 0; }
.assistant-content > :last-child { margin-bottom: 0; }
.assistant-content p { margin: 0 0 10px; }
.assistant-content h1,
.assistant-content h2,
.assistant-content h3,
.assistant-content h4 { margin: 18px 0 8px; line-height: 1.4; font-weight: 600; }
.assistant-content h1 { font-size: 1.35em; }
.assistant-content h2 { font-size: 1.22em; }
.assistant-content h3 { font-size: 1.1em; }
.assistant-content ul,
.assistant-content ol { margin: 8px 0 12px; padding-left: 1.5em; }
.assistant-content li { margin: 3px 0; }
.assistant-content blockquote {
  margin: 10px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--brand);
  background: rgba(100, 116, 139, 0.06);
  color: var(--muted);
}
.assistant-content a { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; }
.assistant-content code { font-family: var(--font-mono); font-size: 0.9em; }
.assistant-content :not(pre) > code {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(100, 116, 139, 0.1);
}
.assistant-content pre {
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: #111827;
  color: #e5e7eb;
  overflow-x: auto;
  line-height: 1.55;
}
.assistant-content pre code { color: inherit; font-size: 12.5px; }
.assistant-content table {
  border-collapse: collapse;
  max-width: 100%;
  margin: 10px 0;
  display: block;
  overflow-x: auto;
  font-size: 13px;
}
.assistant-content th,
.assistant-content td {
  border: 1px solid var(--line);
  padding: 6px 9px;
  text-align: left;
  vertical-align: top;
}
.assistant-content th { background: rgba(100, 116, 139, 0.07); font-weight: 600; }
.assistant-content hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.assistant-content img { max-width: 100%; border-radius: 8px; }

.clone-toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translate(-50%, 12px);
  z-index: 90;
  max-width: min(88vw, 420px);
  padding: 9px 14px;
  border-radius: 10px;
  background: rgba(31, 35, 41, 0.9);
  color: #fff;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  backdrop-filter: blur(8px);
}

.clone-toast.show { opacity: 1; transform: translate(-50%, 0); }

.top-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  border-radius: 7px;
  color: var(--top-link, #5b616b);
  font-size: 13px;
  white-space: nowrap;
}

.top-link:hover { background: var(--hover); color: var(--text); }

.hrx-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 9px;
  border-radius: 7px;
  color: var(--hrx-link, var(--brand));
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.hrx-link:hover { background: var(--hrx-hover, rgba(77, 107, 254, 0.08)); }

.hrx-link::after { content: "↗"; font-size: 12px; opacity: 0.7; }

.mobile-only { display: none !important; }

@media (max-width: 860px) {
  :root { --sidebar-w: 248px; }
  .sidebar {
    position: fixed;
    z-index: 40;
    inset: 0 auto 0 0;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: 18px 0 45px rgba(15, 23, 42, 0.13);
  }
  .sidebar-collapsed .sidebar { transform: translateX(0); }
  .sidebar-collapsed::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(15, 23, 42, 0.28);
  }
  .mobile-only { display: inline-flex !important; }
  .messages { padding: 16px 16px 22px; }
  .composer-bottom-slot { padding: 0 14px 14px; }
  .composer { --composer-radius: 16px; }
  .welcome { padding: 18px 16px; }
  .topbar { padding: 0 14px; min-height: 56px; }
  .top-link, .hrx-link { font-size: 12px; }
}

@media (hover: none) {
  .assistant-actions, .user-actions { opacity: 1; }
}
