:root {
  --bg: #f5f6f8;
  --sidebar: #f0f2f5;
  --panel: #ffffff;
  --ink: #1f2329;
  --muted: #8a919f;
  --line: #e6e8ec;
  --accent: #3370ff;
  --accent-soft: #edf2ff;
  --user-bubble: #3370ff;
  --bot-bubble: #ffffff;
  --radius: 16px;
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}
body {
  color: var(--ink);
  background: var(--bg);
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  min-height: 0;
}

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

.sidebar-top {
  flex-shrink: 0;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.sidebar-brand {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: transparent;
  border-radius: 12px;
  padding: 6px 4px 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2px;
}
.sidebar-logo {
  display: block;
  width: 80%;
  max-width: 176px;
  height: auto;
  object-fit: contain;
  margin: 0 auto;
}
.new-chat {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, border-color .15s;
}
.new-chat:hover { background: var(--accent-soft); border-color: #c9d7ff; color: var(--accent); }

.conv-list {
  flex: 1;
  overflow: auto;
  padding: 8px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conv-item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  color: var(--ink);
  border: 0;
  background: transparent;
  text-align: left;
  width: 100%;
}
.conv-item:hover { background: rgba(255,255,255,.7); }
.conv-item.active { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.conv-item .title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 14px;
  min-width: 0;
}
.conv-item .more-btn {
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 8px;
  letter-spacing: 1px;
}
.conv-item:hover .more-btn,
.conv-item.menu-open .more-btn,
.conv-item.active .more-btn { opacity: 1; }
.conv-item .more-btn:hover { background: rgba(0,0,0,.06); color: var(--ink); }

.conv-menu {
  position: absolute;
  top: calc(100% - 4px);
  right: 8px;
  z-index: 30;
  min-width: 120px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(31, 35, 41, 0.12);
  padding: 4px;
  display: none;
}
.conv-menu.open { display: block; }
.conv-menu button {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
}
.conv-menu button:hover { background: #f3f5f8; }
.conv-menu button.danger { color: #d14343; }
.conv-menu button.danger:hover { background: #fff1f1; }

.sidebar-bottom {
  border-top: 1px solid var(--line);
  padding: 12px 14px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #3370ff, #10b981);
  color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
}
.user-name { font-size: 14px; font-weight: 600; }
.linkish {
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer; padding: 0; font-size: 12px;
}
.linkish:hover { color: var(--accent); }

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(800px 300px at 50% -10%, rgba(51,112,255,.08), transparent 60%),
    var(--bg);
}

.topbar {
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid transparent;
}
.chat-title {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.ghost-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  height: 32px;
  padding: 0 12px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}
.ghost-btn:hover { color: var(--ink); border-color: #cfd4dc; }
.icon-btn {
  border: 0; background: transparent; font-size: 18px; cursor: pointer;
}
.mobile-only { display: none; }

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px 0 24px;
  -webkit-overflow-scrolling: touch;
}

.welcome {
  width: 100%;
  max-width: none;
  margin: 12vh auto 0;
  text-align: center;
  padding: 0 10%;
  box-sizing: border-box;
}
.welcome-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;
  border-radius: 18px;
  background: transparent;
  box-shadow: none;
  display: grid;
  place-items: center;
  overflow: visible;
  padding: 0;
}
.welcome-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.welcome h2 { margin: 0 0 8px; font-size: 28px; font-weight: 700; letter-spacing: .01em; }
.welcome p { margin: 0; color: var(--muted); font-size: 14px; }

.msg-row {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding: 14px 10%;
  box-sizing: border-box;
}
.msg-row.user { flex-direction: row-reverse; }
.msg-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  max-width: calc(100% - 44px);
  min-width: 0;
}
.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  flex: none; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff;
}
.msg-row.assistant .msg-avatar { background: linear-gradient(135deg, #3370ff, #10b981); }
.msg-row.user .msg-avatar { background: #5b6575; }

.stream-status {
  font-size: 12px;
  color: var(--accent);
  padding: 4px 2px;
}

.meta-panel {
  border: 1px solid var(--line);
  background: #f8f9fb;
  border-radius: 12px;
  overflow: hidden;
}
.meta-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 0;
  background: transparent;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.meta-toggle:hover { color: var(--ink); }
.meta-arrow {
  transition: transform .15s ease;
  color: #a0a7b4;
}
.meta-panel.open .meta-arrow { transform: rotate(90deg); }
.meta-body {
  display: none;
  padding: 0 12px 10px;
  font-size: 12px;
  line-height: 1.65;
  color: #5c6573;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow: auto;
}
.meta-panel.open .meta-body { display: block; }
.meta-panel.thinking .meta-label { color: #6b7280; }
.quotes-body { display: none; padding: 0 10px 10px; }
.meta-panel.open .quotes-body { display: grid; gap: 8px; }
.quote-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
.quote-source {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}
.quote-text {
  font-size: 12px;
  color: #5c6573;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.bubble {
  max-width: 100%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-row.user .bubble {
  max-width: min(72%, calc(100% - 44px));
}
.msg-row.assistant .bubble {
  background: var(--bot-bubble);
  border: 1px solid var(--line);
  border-top-left-radius: 6px;
}
.msg-row.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-top-right-radius: 6px;
}

.bubble.streaming::after {
  content: "";
  display: inline-block;
  width: 6px; height: 14px;
  margin-left: 2px;
  background: var(--accent);
  vertical-align: -2px;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.error-tip {
  width: 100%;
  max-width: none;
  margin: 8px auto;
  padding: 10px 10%;
  box-sizing: border-box;
  color: #d14343;
  font-size: 13px;
}

.composer-wrap {
  flex-shrink: 0;
  padding: 0 10% 18px;
  box-sizing: border-box;
  background: linear-gradient(180deg, transparent, var(--bg) 28%);
}
.composer {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(31,35,41,.06);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px 12px 12px 16px;
  align-items: end;
}
.composer textarea {
  resize: none;
  border: 0;
  outline: none;
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  max-height: 160px;
  min-height: 24px;
  padding: 6px 0;
  background: transparent;
  color: var(--ink);
}
.send-btn {
  width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: var(--accent); color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.send-btn:disabled { background: #c9d0dc; cursor: not-allowed; }
.hint {
  width: 100%;
  max-width: none;
  margin: 8px auto 0;
  text-align: center;
  font-size: 12px;
  line-height: 1.6;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
}
.hint-warn {
  color: #d14343;
  font-weight: 600;
}
.hint-sep {
  color: #8a919f;
}
.hint-copy {
  color: #1f2329;
}

@media (max-width: 1100px) {
  .msg-row,
  .composer-wrap,
  .welcome,
  .error-tip {
    padding-left: 6%;
    padding-right: 6%;
  }
  .composer-wrap { padding-left: 6%; padding-right: 6%; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 86vw);
    z-index: 20;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 8px 0 30px rgba(0,0,0,.08);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .msg-row,
  .composer-wrap,
  .welcome,
  .error-tip {
    padding-left: 4%;
    padding-right: 4%;
  }
  .composer-wrap { padding-left: 4%; padding-right: 4%; padding-bottom: 18px; }
  .conv-item .more-btn { opacity: 1; }
}
