/* ==========================================================================
   DeepSeek Chat — 样式表
   兼容目标：iPadOS 13.2 的 Safari 13（不能用的东西见文末注释）
   ========================================================================== */

:root {
  --bg: #ffffff;
  --bg-sidebar: #f7f7f8;
  --bg-elevated: #ffffff;
  --bg-hover: #ededf0;
  --bg-active: #e6e8f5;
  --bubble: #f0f1f4;
  --text: #1f2023;
  --text-soft: #54575e;
  --text-dim: #8b8f97;
  --border: #e6e6ea;
  --accent: #4d6bfe;
  --accent-press: #3a55e0;
  --accent-soft: rgba(77, 107, 254, 0.1);
  --danger: #d24545;
  --code-bg: #f7f8fa;
  --code-head: #eef0f3;
  --code-text: #24292f;
  --shadow: 0 12px 40px rgba(15, 20, 40, 0.16);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --app-h: 100%;
}

[data-theme="dark"] {
  --bg: #16171a;
  --bg-sidebar: #101113;
  --bg-elevated: #1f2125;
  --bg-hover: #26282d;
  --bg-active: #2b3040;
  --bubble: #24262b;
  --text: #eceef2;
  --text-soft: #b3b7c0;
  --text-dim: #82868f;
  --border: #2a2c32;
  --accent: #7d94ff;
  --accent-press: #93a6ff;
  --accent-soft: rgba(125, 148, 255, 0.16);
  --danger: #ff6b6b;
  --code-bg: #14161a;
  --code-head: #1b1e23;
  --code-text: #dfe3ea;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

button:focus {
  outline: none;
}

input,
textarea,
select {
  font-family: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

/* ---------------------------------------------------------------- 布局 */

.app {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  height: 100%;
  height: var(--app-h);
  overflow: hidden;
}

.main {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-width: 0;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
}

/* ---------------------------------------------------------------- 侧栏 */

.sidebar {
  width: 272px;
  -webkit-flex: 0 0 272px;
  flex: 0 0 272px;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  z-index: 20;
}

.sidebar-head {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  padding: 14px 14px 10px 16px;
}

.brand {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  font-weight: 600;
  font-size: 15.5px;
  letter-spacing: 0.01em;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  color: #fff;
  background-image: -webkit-linear-gradient(315deg, #4d6bfe 0%, #7b5cff 100%);
  background-image: linear-gradient(135deg, #4d6bfe 0%, #7b5cff 100%);
  margin-right: 9px;
  -webkit-flex: 0 0 28px;
  flex: 0 0 28px;
}

.new-chat {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  margin: 4px 12px 10px;
  height: 42px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14.5px;
  font-weight: 500;
  -webkit-transition: background 0.15s ease;
  transition: background 0.15s ease;
}

.new-chat svg {
  margin-right: 6px;
}

.new-chat:active {
  background: var(--bg-hover);
}

.search-wrap {
  position: relative;
  margin: 0 12px 6px;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  margin-top: -8px;
  color: var(--text-dim);
  pointer-events: none;
}

.search {
  width: 100%;
  height: 36px;
  padding: 0 10px 0 33px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: var(--bg-hover);
  font-size: 16px; /* iOS 上小于 16px 会自动放大页面 */
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}

.search::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search:focus {
  border-color: var(--accent);
  background: var(--bg-elevated);
}

.chat-list {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 8px 8px;
}

.group-label {
  font-size: 11.5px;
  color: var(--text-dim);
  padding: 12px 8px 5px;
  font-weight: 500;
}

.chat-item {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  width: 100%;
  padding: 9px 8px 9px 10px;
  border-radius: 9px;
  color: var(--text-soft);
  font-size: 14.5px;
  text-align: left;
  margin-bottom: 1px;
  -webkit-transition: background 0.12s ease;
  transition: background 0.12s ease;
}

.chat-item:active {
  background: var(--bg-hover);
}

.chat-item.active {
  background: var(--bg-active);
  color: var(--text);
}

.chat-item .title {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-del {
  -webkit-flex: 0 0 26px;
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  color: var(--text-dim);
  opacity: 0.55;
  margin-left: 4px;
}

.chat-del:active,
.chat-del:hover {
  color: var(--danger);
  opacity: 1;
  background: rgba(210, 69, 69, 0.1);
}

.empty-list {
  padding: 24px 12px;
  font-size: 13.5px;
  color: var(--text-dim);
  text-align: center;
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 8px;
  display: -webkit-flex;
  display: flex;
}

.foot-btn {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  height: 38px;
  border-radius: 9px;
  color: var(--text-soft);
  font-size: 13.5px;
}

.foot-btn svg {
  margin-right: 5px;
}

.foot-btn:active {
  background: var(--bg-hover);
}

/* ---------------------------------------------------------------- 顶栏 */

.topbar {
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  height: 56px;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  padding: 0 12px 0 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  z-index: 10;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  color: var(--text-soft);
}

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

.text-btn {
  width: auto;
  padding: 0 10px;
  font-size: 13.5px;
  color: var(--text-dim);
  white-space: nowrap;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
}

.topbar-title {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-width: 0;
  margin: 0 8px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
}

.select-wrap {
  position: relative;
  margin-right: 2px;
}

.model-select {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: 9px;
  height: 32px;
  padding: 0 24px 0 10px;
  font-size: 13.5px;
  color: var(--text-soft);
  max-width: 172px;
  outline: none;
}

.select-caret {
  position: absolute;
  right: 8px;
  top: 50%;
  margin-top: -7px;
  color: var(--text-dim);
  pointer-events: none;
}

/* ---------------------------------------------------------------- 消息区 */

.messages {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 0 18px;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

/* 空对话时把欢迎页垂直居中 */
.messages.is-empty {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
}

.msg {
  max-width: 860px;
  margin: 0 auto;
  padding: 11px 24px;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: start;
  -webkit-align-items: flex-start;
  align-items: flex-start;
}

.msg-avatar {
  width: 30px;
  height: 30px;
  -webkit-flex: 0 0 30px;
  flex: 0 0 30px;
  border-radius: 50%;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  margin-right: 13px;
  font-size: 11.5px;
  font-weight: 600;
  color: #fff;
  background-image: -webkit-linear-gradient(315deg, #4d6bfe 0%, #7b5cff 100%);
  background-image: linear-gradient(135deg, #4d6bfe 0%, #7b5cff 100%);
  -webkit-user-select: none;
  user-select: none;
}

.msg-user .msg-avatar {
  background: #9aa0aa;
  background-image: none;
  margin-right: 0;
  margin-left: 13px;
}

.msg-body {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-width: 0;
  padding-top: 2px;
}

.msg-user {
  -webkit-box-orient: horizontal;
  -webkit-box-direction: reverse;
  -webkit-flex-direction: row-reverse;
  flex-direction: row-reverse;
}

.msg-user .msg-body {
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: end;
  -webkit-justify-content: flex-end;
  justify-content: flex-end;
}

.bubble {
  display: inline-block;
  max-width: 100%;
  background: var(--bubble);
  border-radius: 18px;
  padding: 9px 15px;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.msg-actions {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  margin-top: 7px;
  min-height: 24px;
}

.act-btn {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  height: 26px;
  padding: 0 9px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-right: 2px;
  white-space: nowrap;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
}

.act-btn svg {
  margin-right: 4px;
}

.act-btn:active {
  background: var(--bg-hover);
  color: var(--text-soft);
}

.msg-meta {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-left: 8px;
  white-space: nowrap;
}

/* 思考过程 */

.think {
  margin: 2px 0 8px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--code-bg);
  overflow: hidden;
}

.think > summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-soft);
  list-style: none;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  outline: none;
}

.think > summary::-webkit-details-marker {
  display: none;
}

/* 折叠指示箭头：默认朝右，展开后朝下 */
.think > summary::after {
  content: "";
  display: block;
  width: 6px;
  height: 6px;
  margin-left: 8px;
  border-right: 1.5px solid var(--text-dim);
  border-bottom: 1.5px solid var(--text-dim);
  -webkit-transform: rotate(-45deg);
  transform: rotate(-45deg);
  -webkit-transition: -webkit-transform 0.15s ease;
  transition: transform 0.15s ease;
}

.think[open] > summary::after {
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
}

.think-body {
  padding: 0 12px 10px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-soft);
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 190px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.spinner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  margin-right: 7px;
  -webkit-animation: spin 0.8s linear infinite;
  animation: spin 0.8s linear infinite;
}

@-webkit-keyframes spin {
  to {
    -webkit-transform: rotate(360deg);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 错误卡片 */

.err-card {
  border: 1px solid rgba(210, 69, 69, 0.35);
  background: rgba(210, 69, 69, 0.07);
  border-radius: 12px;
  padding: 10px 13px;
  font-size: 14px;
  color: var(--text);
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: start;
  -webkit-align-items: flex-start;
  align-items: flex-start;
}

.err-card .err-icon {
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  margin-right: 8px;
  color: var(--danger);
  margin-top: 2px;
}

.err-body {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-width: 0;
}

.err-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.err-msg {
  color: var(--text-soft);
  font-size: 13.5px;
  word-wrap: break-word;
}

.err-actions {
  margin-top: 8px;
}

.stopped-tag {
  display: inline-block;
  font-size: 11.5px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1px 9px;
  margin-top: 6px;
}

/* 空状态 */

.welcome {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 26px;
  text-align: center;
}

.welcome-mark {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  margin: 0 auto 16px;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  color: #fff;
  background-image: -webkit-linear-gradient(315deg, #4d6bfe 0%, #7b5cff 100%);
  background-image: linear-gradient(135deg, #4d6bfe 0%, #7b5cff 100%);
  -webkit-box-shadow: 0 10px 26px rgba(77, 107, 254, 0.3);
  box-shadow: 0 10px 26px rgba(77, 107, 254, 0.3);
}

.welcome-title {
  font-size: 25px;
  line-height: 1.3;
  margin: 0 0 8px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.welcome-sub {
  color: var(--text-dim);
  font-size: 14px;
  margin: 0 0 22px;
}

.chips {
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  margin: 0 -4px;
}

.chip {
  margin: 5px 4px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--text-soft);
  font-size: 13.5px;
  -webkit-transition: border-color 0.15s ease, background 0.15s ease;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.chip:active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ---------------------------------------------------------------- Markdown */

.md {
  font-size: 16px;
  line-height: 1.72;
  word-wrap: break-word;
  overflow-wrap: break-word;
  color: var(--text);
}

.md > *:first-child {
  margin-top: 0;
}

.md > *:last-child {
  margin-bottom: 0;
}

.md p {
  margin: 0 0 10px;
}

.md h1,
.md h2,
.md h3,
.md h4,
.md h5,
.md h6 {
  line-height: 1.35;
  margin: 18px 0 8px;
  font-weight: 600;
  letter-spacing: -0.005em;
}

.md h1 {
  font-size: 22px;
}

.md h2 {
  font-size: 19.5px;
}

.md h3 {
  font-size: 17.5px;
}

.md h4,
.md h5,
.md h6 {
  font-size: 16px;
}

.md ul,
.md ol {
  margin: 0 0 10px;
  padding-left: 24px;
}

.md li {
  margin: 3px 0;
}

.md li > p {
  margin: 0 0 4px;
}

.md li > ul,
.md li > ol {
  margin: 3px 0;
}

.md blockquote {
  margin: 10px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 9px 9px 0;
  color: var(--text-soft);
}

.md blockquote > p:last-child {
  margin-bottom: 0;
}

.md hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

.md a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(77, 107, 254, 0.35);
  word-break: break-all;
}

.md code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--code-text);
}

.md strong {
  font-weight: 600;
}

.md .task-box {
  margin-right: 2px;
  color: var(--text-dim);
}

.md .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 12px 0;
}

.md table {
  border-collapse: collapse;
  font-size: 14.5px;
  min-width: 60%;
}

.md th,
.md td {
  border: 1px solid var(--border);
  padding: 7px 11px;
  text-align: left;
  vertical-align: top;
}

.md th {
  background: var(--bg-hover);
  font-weight: 600;
}

/* 代码块 */

.codeblock {
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--code-bg);
  overflow: hidden;
}

.codeblock-head {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  padding: 5px 8px 5px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--code-head);
}

.codeblock-lang {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-dim);
}

.codeblock-copy {
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 9px;
  border-radius: 6px;
}

.codeblock-copy:active {
  background: rgba(127, 127, 127, 0.16);
  color: var(--text);
}

.codeblock pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.codeblock pre code {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.62;
  white-space: pre;
  background: none;
  border: 0;
  padding: 0;
  color: var(--code-text);
}

/* 流式输出时的光标：只挂在段落、标题、列表项末尾，
   代码块 / 表格后面不加，否则光标会单独掉到下一行左边。 */
.is-streaming .md > p:last-child::after,
.is-streaming .md > h1:last-child::after,
.is-streaming .md > h2:last-child::after,
.is-streaming .md > h3:last-child::after,
.is-streaming .md > h4:last-child::after,
.is-streaming .md > ul:last-child > li:last-child::after,
.is-streaming .md > ol:last-child > li:last-child::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 3px;
  vertical-align: -2px;
  background: var(--accent);
  -webkit-animation: blink 1.05s steps(1) infinite;
  animation: blink 1.05s steps(1) infinite;
}

@-webkit-keyframes blink {
  50% {
    opacity: 0;
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ---------------------------------------------------------------- 输入区 */

.composer {
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  padding: 6px 16px 10px;
  background: var(--bg);
}

/* 待发送的图片 */
.attach-preview {
  max-width: 820px;
  margin: 0 auto 6px;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
}

/* 待发送的文档 */
.doc-chip {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  height: 40px;
  padding: 0 8px 0 11px;
  margin-left: 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-soft);
  font-size: 13px;
  max-width: 320px;
}

.doc-chip svg {
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  margin-right: 7px;
  color: var(--accent);
}

.doc-chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.attach-remove-inline {
  position: static;
  width: 22px;
  height: 22px;
  margin-left: 6px;
  background: transparent;
  color: var(--text-dim);
}

.attach-remove-inline:active {
  background: var(--bg-hover);
  color: var(--danger);
}

.attach-chip {
  position: relative;
  width: 66px;
  height: 66px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--code-bg);
}

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

.attach-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(20, 22, 28, 0.72);
  color: #fff;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
}

.attach-btn {
  -webkit-flex: 0 0 34px;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  margin: 2px 8px 2px 0;
  border-radius: 50%;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  color: var(--text-dim);
}

.attach-btn:active {
  background: var(--bg-hover);
  color: var(--accent);
}

/* 气泡里的图片 */
.bubble-img {
  display: block;
  max-width: 220px;
  max-height: 220px;
  width: auto;
  height: auto;
  border-radius: 12px;
  margin-bottom: 6px;
  cursor: pointer;
}

/* 点开看大图 */
.lightbox {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 220;
  background: rgba(8, 9, 12, 0.92);
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-animation: fade 0.16s ease;
  animation: fade 0.16s ease;
}

.lightbox img {
  max-width: 94%;
  max-height: 88%;
  border-radius: 6px;
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
}

.bubble-img + .bubble-text {
  display: block;
}

.img-dropped {
  display: inline-block;
  font-size: 11.5px;
  color: var(--text-dim);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 2px 8px;
  margin-bottom: 6px;
}

/* 气泡里的文件标签 */
.bubble-file {
  display: -webkit-inline-flex;
  display: inline-flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  height: 24px;
  padding: 0 9px;
  margin-bottom: 6px;
  border-radius: 7px;
  background: rgba(127, 127, 127, 0.14);
  font-size: 12px;
  color: var(--text-soft);
  max-width: 100%;
  overflow: hidden;
}

.bubble-file svg {
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  margin-right: 5px;
}

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

.composer-inner {
  max-width: 820px;
  margin: 0 auto;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: end;
  -webkit-align-items: flex-end;
  align-items: flex-end;
  padding: 5px 5px 5px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--bg-elevated);
  -webkit-box-shadow: 0 2px 10px rgba(20, 25, 50, 0.04);
  box-shadow: 0 2px 10px rgba(20, 25, 50, 0.04);
}

.composer-inner:focus-within {
  border-color: var(--accent);
}

.input {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: none;
  background: none;
  resize: none;
  font-size: 16px;
  line-height: 1.55;
  padding: 8px 6px 8px 0;
  max-height: 168px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  color: var(--text);
  display: block;
}

.input::-webkit-input-placeholder {
  color: var(--text-dim);
}

.send {
  -webkit-flex: 0 0 38px;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-transition: background 0.15s ease, opacity 0.15s ease;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.send:active {
  background: var(--accent-press);
}

.send[disabled] {
  opacity: 0.3;
}

.send .stop-icon {
  display: none;
}

.composer.is-busy .send {
  background: var(--text);
  opacity: 1;
}

.composer.is-busy .send .send-icon {
  display: none;
}

.composer.is-busy .send .stop-icon {
  display: block;
}

.composer-foot {
  max-width: 820px;
  margin: 0 auto;
  padding: 5px 8px 0;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-dim);
}

/* ---------------------------------------------------------------- 弹窗 */

.modal {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding: 16px;
}

.modal-mask {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(10, 12, 20, 0.42);
  -webkit-animation: fade 0.16s ease;
  animation: fade 0.16s ease;
}

@-webkit-keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 86%;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
  background: var(--bg-elevated);
  border-radius: 18px;
  -webkit-box-shadow: var(--shadow);
  box-shadow: var(--shadow);
  overflow: hidden;
  -webkit-animation: pop 0.18s ease;
  animation: pop 0.18s ease;
}

@-webkit-keyframes pop {
  from {
    opacity: 0;
    -webkit-transform: scale(0.97);
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
}

.modal-small {
  max-width: 400px;
}

.modal-head {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  padding: 14px 12px 10px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  font-size: 16.5px;
  margin: 0;
  font-weight: 600;
}

.modal-body {
  padding: 14px 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-foot {
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: end;
  -webkit-justify-content: flex-end;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.field {
  display: block;
  margin-bottom: 15px;
}

.field-label {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text);
}

.field-help {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 6px;
}

.field-input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 16px;
  line-height: 1.5;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

select.field-input {
  height: 38px;
  padding: 0 10px;
}

textarea.field-input {
  resize: vertical;
}

.field-input:focus {
  border-color: var(--accent);
}

.field-row {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
}

.field-half {
  -webkit-flex: 1 1 0;
  flex: 1 1 0;
  min-width: 0;
}

.field-half:first-child {
  margin-right: 10px;
}

.btn-row {
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
}

.btn {
  height: 36px;
  padding: 0 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
  display: -webkit-inline-flex;
  display: inline-flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  margin: 0 8px 6px 0;
}

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

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:active {
  background: var(--accent-press);
}

.btn-danger {
  color: var(--danger);
  border-color: rgba(210, 69, 69, 0.4);
}

.btn-danger:active {
  background: rgba(210, 69, 69, 0.1);
}

.storage-note,
.version-note {
  font-size: 11.5px;
  color: var(--text-dim);
  margin: 4px 0;
  line-height: 1.5;
}

/* 导出格式按钮 */
.export-actions {
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  margin-top: 4px;
}

.export-actions .btn {
  margin: 0 8px 8px 0;
  height: 42px;
  padding: 0 16px;
  font-size: 14.5px;
}

.btn-export svg {
  margin-right: 7px;
  color: var(--accent);
}

/* 悬浮菜单（导出格式、顶栏更多） */
.popmenu {
  position: fixed;
  z-index: 150;
  min-width: 176px;
  padding: 6px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  -webkit-box-shadow: var(--shadow);
  box-shadow: var(--shadow);
  -webkit-animation: pop 0.14s ease;
  animation: pop 0.14s ease;
}

.popmenu-item {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 15px;
  color: var(--text);
  text-align: left;
}

.popmenu-item svg {
  margin-right: 9px;
  color: var(--text-dim);
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
}

.popmenu-item:active {
  background: var(--bg-hover);
}

.popmenu-item.is-danger {
  color: var(--danger);
}

.popmenu-item.is-danger svg {
  color: var(--danger);
}

.confirm-text {
  font-size: 14.5px;
  color: var(--text-soft);
  margin: 0;
  line-height: 1.6;
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  margin: 8px 0 0;
}

/* ---------------------------------------------------------------- 其它 */

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  -webkit-transform: translateX(-50%) translateY(8px);
  transform: translateX(-50%) translateY(8px);
  background: rgba(28, 30, 36, 0.94);
  color: #fff;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: 22px;
  z-index: 200;
  max-width: 78%;
  text-align: center;
  opacity: 0;
  -webkit-transition: opacity 0.18s ease, -webkit-transform 0.18s ease;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  -webkit-transform: translateX(-50%) translateY(0);
  transform: translateX(-50%) translateY(0);
}

.scrim {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(10, 12, 20, 0.4);
  z-index: 15;
  -webkit-animation: fade 0.18s ease;
  animation: fade 0.18s ease;
}

.noscript {
  padding: 40px 20px;
  text-align: center;
  font-size: 15px;
}

/* 滚动条（桌面浏览器更好看，iPad 上不可见） */
.chat-list::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.codeblock pre::-webkit-scrollbar,
.think-body::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.chat-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
.codeblock pre::-webkit-scrollbar-thumb,
.think-body::-webkit-scrollbar-thumb {
  background: rgba(140, 145, 155, 0.35);
  border-radius: 4px;
}

.chat-list::-webkit-scrollbar-track,
.messages::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track,
.codeblock pre::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------------------------------------------------------------- 响应式 */

.only-narrow {
  display: none;
}

@media (max-width: 800px) {
  .only-narrow {
    display: -webkit-flex;
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    -webkit-transform: translateX(-100%);
    transform: translateX(-100%);
    -webkit-transition: -webkit-transform 0.22s ease;
    transition: transform 0.22s ease;
    -webkit-box-shadow: 12px 0 40px rgba(0, 0, 0, 0.18);
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.18);
  }

  .app.nav-open .sidebar {
    -webkit-transform: translateX(0);
    transform: translateX(0);
  }

  .msg {
    padding: 10px 16px;
  }

  .composer {
    padding: 6px 10px 8px;
  }
}

@media (max-width: 520px) {
  .hide-narrow {
    display: none !important;
  }

  .welcome {
    padding: 0 18px;
  }

  .welcome-title {
    font-size: 21px;
  }

  .chip {
    font-size: 13px;
    padding: 8px 12px;
  }

  .msg {
    padding: 9px 12px;
  }

  .msg-avatar {
    width: 26px;
    height: 26px;
    -webkit-flex-basis: 26px;
    flex-basis: 26px;
    margin-right: 9px;
  }

  .msg-user .msg-avatar {
    margin-left: 9px;
  }

  .md {
    font-size: 15.5px;
  }

  .model-select {
    max-width: 116px;
  }

  .hint {
    display: none;
  }

  .composer-foot {
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
  }
}

/* 横屏 iPad：稍微收窄行宽，读起来更舒服 */
@media (min-width: 1000px) and (min-height: 700px) {
  .msg {
    padding-left: 32px;
    padding-right: 32px;
  }
}
