:root {
  --brand: #615ced;
  --brand-2: #3d6bff;
  --brand-soft: rgba(97, 92, 237, 0.12);
  --bg: #f4f4f6;
  --sidebar: #fafafa;
  --surface: #ffffff;
  --text: #1c1c1f;
  --muted: #8a8a93;
  --line: #ebebef;
  --user: #ecebff;
  --shadow: 0 10px 40px rgba(28, 28, 31, 0.08);
  --sidebar-w: 280px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --brand: #8b7cff;
  --brand-2: #6b8cff;
  --brand-soft: rgba(139, 124, 255, 0.16);
  --bg: #121214;
  --sidebar: #18181b;
  --surface: #1e1e22;
  --text: #ececef;
  --muted: #9a9aa3;
  --line: #2c2c32;
  --user: #2a2750;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, textarea, input { font-family: inherit; }
button { cursor: pointer; }
a { color: var(--brand); text-decoration: none; }

.app {
  display: flex;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 14px 12px 12px;
  gap: 8px;
  transition: width 0.2s ease, transform 0.2s ease;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
}
.brand img { border-radius: 9px; display: block; }

.icon-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--brand-soft); color: var(--text); }

.btn-new, .btn-temp {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.92rem;
  text-align: left;
}
.btn-new {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  border: 0;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(97, 92, 237, 0.28);
}
.btn-new:hover { filter: brightness(1.05); }
.btn-temp[aria-pressed="true"] {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
}

.sidebar-search input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.86rem;
  outline: none;
}
.sidebar-search input:focus { border-color: var(--brand); }

.conv-list {
  flex: 1;
  overflow: auto;
  padding: 6px 0 12px;
}
.conv-group {
  font-size: 0.72rem;
  color: var(--muted);
  padding: 10px 8px 4px;
  letter-spacing: 0.04em;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 8px;
  text-align: left;
  font-size: 0.88rem;
}
.conv-item:hover, .conv-item.active { background: var(--brand-soft); }
.conv-item .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-item .more {
  opacity: 0;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}
.conv-item:hover .more, .conv-item.active .more { opacity: 1; }

.app.sidebar-collapsed .sidebar {
  width: 72px;
}
.app.sidebar-collapsed .brand-text,
.app.sidebar-collapsed .btn-new span,
.app.sidebar-collapsed .btn-temp span,
.app.sidebar-collapsed .sidebar-search,
.app.sidebar-collapsed .conv-list {
  display: none;
}
.app.sidebar-collapsed .btn-new,
.app.sidebar-collapsed .btn-temp {
  justify-content: center;
  padding: 10px;
}

.sidebar-mask {
  display: none;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 0;
  min-height: 52px;
}
.menu-btn { display: none; }
.topbar-spacer { flex: 1; }
.auth-btn {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
}
.auth-btn:hover { border-color: var(--brand); color: var(--brand); }
.auth-btn.primary {
  height: 42px;
  padding: 0 22px;
  background: var(--brand);
  color: #fff;
  border-color: transparent;
  font-size: 0.95rem;
}
.auth-btn.primary:hover { color: #fff; filter: brightness(1.06); }
.user-menu { position: relative; }
.user-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 220px;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 4px 6px 4px 4px;
  border-radius: 999px;
}
.user-btn:hover { background: var(--bg); }
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--brand-soft);
  flex-shrink: 0;
}
.user-avatar.lg { width: 44px; height: 44px; }
.user-avatar.fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 700;
}
.user-avatar.lg.fallback { font-size: 1.05rem; }
.user-name {
  font-size: 0.84rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}
.user-drop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 14px 10px;
  z-index: 40;
}
.user-drop-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.user-drop-id {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.user-drop-id strong {
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-drop-id span {
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-drop-dl {
  margin: 10px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.user-drop-dl > div {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 8px;
  align-items: baseline;
}
.user-drop-dl dt {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}
.user-drop-dl dd {
  margin: 0;
  font-size: 0.84rem;
  word-break: break-all;
}
.user-drop-logout {
  display: block;
  text-align: center;
  padding: 8px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
}
.user-drop-logout:hover {
  background: var(--bg);
  color: var(--text);
}

.model-wrap { position: relative; }
.model-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 10px;
}
.model-btn:hover { background: var(--bg); }
.model-btn.is-static {
  cursor: default;
  padding-left: 10px;
}
.model-btn.is-static:hover { background: transparent; }
.model-btn.is-static svg { display: none; }
.model-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 20;
}
.model-option {
  display: flex;
  flex-direction: column;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text);
}
.model-option:hover, .model-option.active { background: var(--brand-soft); }
.model-option small { color: var(--muted); font-size: 0.75rem; }

.banner {
  margin: 8px 18px 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: #fff4e5;
  color: #8a5a00;
  font-size: 0.88rem;
}
html[data-theme="dark"] .banner {
  background: #3a2a12;
  color: #f0c48a;
}

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 20px 8px;
  text-align: center;
}
.welcome-logo {
  border-radius: 16px;
  box-shadow: 0 10px 24px rgba(97, 92, 237, 0.28);
  margin-bottom: 16px;
}
.welcome h1 {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 4vw, 2.1rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.welcome-sub {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 0.95rem;
}
.suggest-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 240px));
  gap: 10px;
  width: min(520px, 100%);
}
.suggest-card {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--text);
}
.suggest-card:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}
.suggest-card strong { display: block; font-size: 0.9rem; margin-bottom: 4px; }
.suggest-card span { color: var(--muted); font-size: 0.78rem; }

.login-gate { margin-bottom: 8px; }

.app.need-login .btn-new,
.app.need-login .btn-temp,
.app.need-login .sidebar-search,
.app.need-login .conv-list,
.app.need-login .model-wrap,
.app.need-login .composer-dock {
  display: none;
}

.thread {
  flex: 1;
  overflow: auto;
  padding: 8px 0 12px;
}
.messages {
  width: min(820px, calc(100% - 32px));
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 12px 0 28px;
}

.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg.user { flex-direction: row-reverse; }
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  flex-shrink: 0;
  overflow: hidden;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}
.avatar img { width: 100%; height: 100%; display: block; }
.msg.user .avatar { display: none; }

.bubble { min-width: 0; max-width: 100%; }
.msg.user .bubble {
  background: var(--user);
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  white-space: pre-wrap;
  line-height: 1.65;
  max-width: min(640px, 85%);
}
.msg.assistant .content {
  line-height: 1.75;
  font-size: 0.97rem;
}
.msg.assistant .content > *:first-child { margin-top: 0; }
.msg.assistant .content > *:last-child { margin-bottom: 0; }
.msg.assistant .content p { margin: 0.55em 0; }
.msg.assistant .content h1,
.msg.assistant .content h2,
.msg.assistant .content h3 { margin: 1em 0 0.4em; line-height: 1.3; }
.msg.assistant .content ul, .msg.assistant .content ol { padding-left: 1.3em; }
.msg.assistant .content blockquote {
  margin: 0.8em 0;
  padding: 0.2em 0 0.2em 12px;
  border-left: 3px solid var(--brand);
  color: var(--muted);
}
.msg.assistant .content code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--bg);
  padding: 0.1em 0.35em;
  border-radius: 6px;
}
.md-code {
  margin: 0.8em 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #0f1117;
  color: #e8e8ee;
}
.md-code-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  font-size: 0.75rem;
  color: #b8b8c4;
  background: #171922;
}
.md-copy {
  border: 0;
  background: transparent;
  color: #c8c8d4;
  font-size: 0.75rem;
}
.md-code pre {
  margin: 0;
  padding: 12px 14px 14px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.84rem;
  line-height: 1.55;
}
.md-code code { background: none; padding: 0; color: inherit; }
.md-table { overflow: auto; margin: 0.8em 0; }
.md-table table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.md-table th, .md-table td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
}

.think-box {
  margin: 0 0 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  overflow: hidden;
}
.think-toggle {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 0.82rem;
}
.think-body {
  padding: 0 12px 10px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.65;
  white-space: pre-wrap;
}
.think-box.collapsed .think-body { display: none; }

.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
.msg-actions button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.78rem;
}
.msg-actions button:hover { background: var(--bg); color: var(--text); }

.cursor {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  background: var(--brand);
  border-radius: 1px;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.9s step-end infinite;
}
.dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 8px 3px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s infinite;
}
.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 50% { opacity: 0; } }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.composer-dock {
  padding: 0 16px calc(12px + env(safe-area-inset-bottom, 0px));
}
.composer {
  width: min(820px, 100%);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 10px 12px 8px;
}
.composer textarea {
  width: 100%;
  border: 0;
  resize: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.55;
  max-height: 180px;
  padding: 4px 4px 6px;
}
.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.composer-tools { display: flex; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.78rem;
}
.chip[aria-pressed="true"] {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}
.send-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.send-btn:disabled { opacity: 0.35; cursor: default; }
.send-btn.stop { background: var(--text); }
.composer-foot {
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
  margin: 8px 0 0;
}

.app.temp-on .composer { outline: 1px dashed var(--brand); }

@media (max-width: 860px) {
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed;
    z-index: 30;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-105%);
    box-shadow: var(--shadow);
  }
  .app.sidebar-open .sidebar { transform: none; }
  .sidebar-mask {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 25;
  }
  .sidebar-mask[hidden] { display: none; }
  .app.sidebar-collapsed .sidebar { width: var(--sidebar-w); }
  .app.sidebar-collapsed .brand-text,
  .app.sidebar-collapsed .btn-new span,
  .app.sidebar-collapsed .btn-temp span,
  .app.sidebar-collapsed .sidebar-search,
  .app.sidebar-collapsed .conv-list { display: unset; }
  .suggest-grid { grid-template-columns: 1fr; }
}
