:root {
  color-scheme: light;
  --bg: #F7F7F8;
  --panel: #FFFFFF;
  --surface-2: #EFEFF2;
  --text: #171717;
  --muted: #6B7280;
  --border: rgba(23, 23, 23, 0.1);
  --brand: #4B3FE3;
  --brand-soft: #EFEDFF;
  --brand-on: #FFFFFF;
  --danger: #E8463A;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0E0E10;
    --panel: #161618;
    --surface-2: #26262A;
    --text: #EDEDED;
    --muted: #A1A1AA;
    --border: rgba(255, 255, 255, 0.1);
    --brand: #6054F1;
    --brand-soft: #201C4A;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, "PingFang SC", system-ui, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.spacer { flex: 1; }

.shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- 侧栏 ---------- */
.sidebar {
  flex: none;
  width: 264px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 12px;
  border-right: 1px solid var(--border);
  background: var(--panel);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 6px 6px;
  font-size: 14px;
  font-weight: 600;
}

.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brand);
}

.new-chat {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}

.new-chat:hover { background: var(--surface-2); }

.convos {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0;
}

.convo {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.convo:hover { background: var(--surface-2); }
.convo.active { background: var(--surface-2); }

.convo-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13.5px;
}

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

.convo-del {
  flex: none;
  display: none;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}

.convo:hover .convo-del { display: grid; }
.convo.active .convo-del { display: grid; }
.convo-del:hover { background: var(--border); color: var(--text); }

.side-foot {
  padding: 4px 6px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
}

/* ---------- 主区 ---------- */
.main {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}

.conv-title {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.model-badge {
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
}

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

.only-mobile { display: none; }

.thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px 0 8px;
  -webkit-overflow-scrolling: touch;
}

.thread-inner {
  flex: 1;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.welcome {
  margin: auto;
  padding: 32px 12px;
  max-width: 520px;
  text-align: center;
  color: var(--muted);
}

.welcome h1 { margin: 0 0 8px; font-size: 22px; color: var(--text); }
.welcome p { margin: 0 0 18px; font-size: 14px; }

.welcome-tips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
}

.welcome-tips span {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
}

/* ---------- 消息 ---------- */
.row { display: flex; gap: 10px; }
.row.user { justify-content: flex-end; }

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-top: 2px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 10px;
  font-weight: 600;
}

.content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row.user .content {
  flex: none;
  max-width: 82%;
  align-items: flex-end;
}

.bubble {
  font-size: 15px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.row.assistant .bubble { padding: 0; }
.row.user .bubble {
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
}

.bubble pre {
  margin: 8px 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.55;
}

.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.bubble :not(pre) > code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-2);
}

.row.user .bubble :not(pre) > code { background: rgba(255, 255, 255, 0.16); }

.think {
  padding: 2px 0 2px 12px;
  border-left: 2px solid var(--border);
}

.think summary {
  list-style: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 12.5px;
  user-select: none;
}

.think summary::-webkit-details-marker { display: none; }
.think summary::before { content: "▸ "; }
.think[open] summary::before { content: "▾ "; }

.think-body {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.files { display: flex; flex-wrap: wrap; gap: 6px; }

.msg-img {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
}

.file-chip span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.dots { display: inline-flex; gap: 4px; padding: 6px 0; }

.dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite;
}

.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

/* ---------- 输入区 ---------- */
.composer {
  flex: none;
  width: calc(100% - 32px);
  max-width: 820px;
  margin: 0 auto calc(env(safe-area-inset-bottom) + 14px);
  padding: 10px 12px 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.05);
}

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

.composer textarea::placeholder { color: var(--muted); }

.bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.tool {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}

.tool:hover { background: var(--surface-2); }

.tool-chip {
  height: 30px;
  max-width: 40vw;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-chip:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.tool-chip:disabled { opacity: 0.55; cursor: not-allowed; }

.primary {
  height: 34px;
  padding: 0 16px;
  border: 0;
  border-radius: 9px;
  background: var(--brand);
  color: var(--brand-on);
  font-size: 13.5px;
  font-weight: 500;
}

.primary.ghost {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.menu-wrap { position: relative; }

.menu {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  z-index: 30;
  width: 290px;
  max-width: calc(100vw - 40px);
  max-height: 60vh;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.menu-effort { width: 180px; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.menu-item:hover { background: var(--surface-2); }
.menu-item.active { background: var(--brand-soft); }

.mi-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.mi-label { font-size: 13.5px; }
.mi-sub { font-size: 11.5px; color: var(--muted); }
.mi-check { color: var(--brand); font-size: 13px; opacity: 0; }
.menu-item.active .mi-check { opacity: 1; }

/* ---------- 附件 ---------- */
.attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 2px 8px;
}

.att {
  position: relative;
  width: 54px;
  height: 54px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.att img { display: block; width: 100%; height: 100%; object-fit: cover; }

.att.file {
  width: auto;
  max-width: 220px;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px 0 9px;
  border-radius: 8px;
}

.att-name {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.att-x {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11px;
  line-height: 1;
}

.att:not(.file) .att-x { position: absolute; top: 3px; right: 3px; }
.att.file .att-x { background: transparent; color: var(--muted); }

/* ---------- 拖拽层 / 提示 ---------- */
.drop {
  position: absolute;
  inset: 10px;
  z-index: 15;
  display: grid;
  place-items: center;
  border: 2px dashed var(--brand);
  border-radius: 16px;
  background: color-mix(in srgb, var(--brand-soft) 88%, transparent);
  pointer-events: none;
}

.drop-inner { color: var(--brand); font-size: 14px; font-weight: 500; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 100px);
  z-index: 50;
  max-width: 88vw;
  padding: 9px 14px;
  border-radius: 10px;
  background: #222226;
  color: #fff;
  font-size: 13px;
  text-align: center;
  transform: translateX(-50%);
}

/* ---------- 口令 ---------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.gate-card {
  width: 100%;
  max-width: 340px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel);
}

.gate-card h2 { margin: 0 0 8px; font-size: 18px; }
.gate-card p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }

.gate-card input {
  width: 100%;
  margin-bottom: 12px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.gate-card button {
  width: 100%;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: var(--brand-on);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
}

.gate-card .err {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 13px;
}

/* ---------- 移动端 ---------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 18;
  display: none;
  background: rgba(0, 0, 0, 0.42);
}

@media (max-width: 860px) {
  .only-mobile { display: grid; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: 280px;
    padding-top: calc(env(safe-area-inset-top) + 14px);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open .scrim { display: block; }

  .topbar { padding-top: env(safe-area-inset-top); }

  .thread-inner { padding: 0 14px; }

  .row.user .content { max-width: 88%; }

  .composer {
    width: calc(100% - 20px);
    margin-bottom: calc(env(safe-area-inset-bottom) + 8px);
  }

  .composer textarea { font-size: 16px; }

  .model-badge { display: none; }

  .menu { width: 260px; }
}
