* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", sans-serif;
  background: #212121;
  color: #ececec;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
.app { display: flex; height: 100vh; }

/* Sidebar */
.sidebar {
  width: 260px;
  background: #171717;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #2a2a2a;
  flex-shrink: 0;
}
.new-chat {
  margin: 12px;
  padding: 10px 14px;
  background: transparent;
  color: #ececec;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  font-family: inherit;
}
.new-chat:hover { background: #2a2a2a; }
.convs {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}
.conv-item {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  color: #cdcdcd;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}
.conv-item:hover { background: #2a2a2a; }
.conv-item.active { background: #2f2f2f; color: #fff; }
.conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-del {
  display: none;
  background: transparent;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}
.conv-item:hover .conv-del { display: inline-block; }
.conv-del:hover { color: #f55; }
.footer {
  padding: 10px 14px;
  font-size: 12px;
  color: #888;
  border-top: 1px solid #2a2a2a;
}

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  padding: 14px 20px;
  border-bottom: 1px solid #2a2a2a;
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}
.topbar #title {
  color: #b0b0b0;
  font-weight: 400;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* 模型选择按钮 */
.model-picker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  color: #ececec;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  max-width: 220px;
}
.model-picker:hover { background: #333; border-color: #4a4a4a; }
.model-picker .caret { color: #888; font-size: 11px; }
.model-picker #modelName {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 模型下拉浮层 */
.model-menu {
  position: absolute;
  top: 52px;
  left: 56px;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  padding: 6px;
  min-width: 220px;
  max-height: 360px;
  overflow-y: auto;
  z-index: 200;
}
.model-menu[hidden] { display: none; }
.model-menu .model-item {
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  color: #cdcdcd;
  display: flex;
  align-items: center;
  gap: 8px;
}
.model-menu .model-item:hover { background: #333; color: #fff; }
.model-menu .model-item.active { background: #2f2f2f; color: #19c37d; }
.model-menu .model-item .check {
  margin-left: auto;
  color: #19c37d;
  visibility: hidden;
}
.model-menu .model-item.active .check { visibility: visible; }
.model-menu .model-empty {
  padding: 12px;
  color: #888;
  font-size: 13px;
  text-align: center;
}

@media (max-width: 768px) {
  .model-picker { font-size: 13px; padding: 5px 8px; max-width: 140px; }
  .model-menu { left: 14px; right: 14px; min-width: 0; }
  .topbar #title { display: none; }
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
}
.empty {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  font-size: 22px;
}
.msg-row {
  max-width: 760px;
  margin: 0 auto 24px;
  padding: 0 20px;
  display: flex;
  gap: 16px;
}
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}
.user .avatar { background: #5436da; }
.assistant .avatar { background: #19c37d; }
.bubble {
  flex: 1;
  min-width: 0;
  line-height: 1.7;
  word-wrap: break-word;
  padding-top: 4px;
}
.user .bubble { white-space: pre-wrap; }
.bubble pre {
  position: relative;
  background: #0d1117;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  padding: 12px;
  padding-right: 56px;
  overflow-x: auto;
  margin: 12px 0;
  font-size: 13px;
}
.bubble pre code { background: transparent; padding: 0; }
.bubble code {
  background: #2f2f2f;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
.bubble p { margin: 8px 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { padding-left: 24px; margin: 8px 0; }
.bubble li { margin: 4px 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  margin: 16px 0 8px;
  line-height: 1.3;
}
.bubble h1 { font-size: 22px; }
.bubble h2 { font-size: 19px; }
.bubble h3 { font-size: 17px; }
.bubble blockquote {
  border-left: 3px solid #3a3a3a;
  padding-left: 12px;
  margin: 8px 0;
  color: #b0b0b0;
}
.bubble table {
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
}
.bubble th, .bubble td {
  border: 1px solid #3a3a3a;
  padding: 6px 12px;
  text-align: left;
}
.bubble th { background: #2a2a2a; }
.bubble a { color: #7eb6ff; text-decoration: none; }
.bubble a:hover { text-decoration: underline; }

/* 代码块右上角的「下载 / 复制」按钮组 */
.pre-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.bubble pre:hover .pre-actions { opacity: 0.85; }
.bubble pre .pre-actions:hover { opacity: 1; }
.pre-btn {
  background: #1e252f;
  color: #b0b0b0;
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.pre-btn:hover { background: #2a2f38; color: #ececec; }
.pre-btn.copied { color: #19c37d; border-color: #19c37d; }

/* Composer */
.composer {
  padding: 12px 20px 18px;
  border-top: 1px solid #2a2a2a;
}

/* 全屏拖拽上传遮罩 */
.dropzone-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none; /* 不挡 document 的 drop 事件 */
  animation: dropzone-fade-in 0.12s ease-out;
}
.dropzone-overlay[hidden] { display: none; }
.dropzone-inner {
  border: 3px dashed #19c37d;
  border-radius: 16px;
  padding: 48px 64px;
  background: rgba(25, 195, 125, 0.08);
  text-align: center;
  max-width: 90%;
}
.dropzone-icon { font-size: 56px; line-height: 1; }
.dropzone-text {
  font-size: 22px;
  font-weight: 500;
  color: #19c37d;
  margin-top: 16px;
}
.dropzone-hint {
  font-size: 13px;
  color: #b0b0b0;
  margin-top: 10px;
}
@keyframes dropzone-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (max-width: 768px) {
  .dropzone-inner { padding: 32px 28px; }
  .dropzone-icon { font-size: 44px; }
  .dropzone-text { font-size: 18px; }
}
.input-wrap {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #2f2f2f;
  border: 1px solid #3a3a3a;
  border-radius: 24px;
  padding: 6px 6px 6px 16px;
}
.input-wrap:focus-within { border-color: #4a4a4a; }
#input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #ececec;
  font-family: inherit;
  font-size: 15px;
  resize: none;
  max-height: 200px;
  padding: 8px 0;
  line-height: 1.5;
}
.send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #ececec;
  color: #171717;
  border: none;
  cursor: pointer;
  font-weight: bold;
  font-size: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.send-btn:hover { background: #fff; }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.hint {
  text-align: center;
  font-size: 12px;
  color: #666;
  margin-top: 8px;
}

/* Streaming cursor */
.cursor::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  color: #19c37d;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink {
  to { visibility: hidden; }
}

/* Hamburger menu (mobile only) */
.menu-btn {
  display: none;
  background: transparent;
  color: #ececec;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 0 6px 0 0;
  margin-right: 4px;
  line-height: 1;
  font-family: inherit;
}

/* Mobile sidebar backdrop */
.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

/* Mobile responsive — sidebar slides in as a drawer */
@media (max-width: 768px) {
  .menu-btn { display: inline-block; }

  .topbar {
    display: flex;
    align-items: center;
    padding: 10px 14px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.5);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .backdrop { display: block; }

  .msg-row {
    padding: 0 12px;
    gap: 10px;
    margin-bottom: 16px;
  }
  .avatar {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }
  .composer { padding: 8px 10px 14px; }
  .input-wrap { padding: 4px 4px 4px 12px; }
  #input {
    font-size: 16px;  /* iOS Safari focus 时不自动放大页面 */
    max-height: 120px;
  }
  .bubble pre {
    font-size: 12px;
    padding: 10px;
    padding-right: 48px;
  }
  .empty { font-size: 18px; }

  /* 手机无 hover,代码块按钮常驻显示 */
  .pre-actions { opacity: 0.85; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #4a4a4a; }

/* 图片生成按钮 */
.image-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  color: #b0b0b0;
  border: 1px solid #3a3a3a;
  cursor: pointer;
  font-size: 13px;
  flex-shrink: 0;
  font-family: inherit;
}
.image-btn:hover { background: #2a2a2a; color: #ececec; }
.image-btn.active {
  background: #19c37d;
  color: #171717;
  border-color: #19c37d;
}

/* 文件上传按钮(📎)*/
.file-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  color: #b0b0b0;
  border: 1px solid #3a3a3a;
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
  font-family: inherit;
  line-height: 1;
}
.file-btn:hover { background: #2a2a2a; color: #ececec; }

/* 输入框上方的附件预览栏 */
.attachments {
  max-width: 760px;
  margin: 0 auto 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.attachments:empty { display: none; }
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 10px;
  background: #2f2f2f;
  border: 1px solid #3a3a3a;
  border-radius: 14px;
  font-size: 12px;
  color: #cdcdcd;
  max-width: 280px;
}
.attachment-chip .chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-chip .chip-size {
  color: #888;
  flex-shrink: 0;
}
.attachment-chip .chip-x {
  background: transparent;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  font-family: inherit;
}
.attachment-chip .chip-x:hover { color: #f55; }
.attachment-chip.readonly { background: #262626; }

/* 图片附件 chip:左侧带缩略图 */
.attachment-chip.image { padding-left: 4px; }
.attachment-chip .chip-thumb {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
  flex-shrink: 0;
}

/* 用户消息气泡里的附件列表 */
.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  align-items: flex-start;
}

/* 用户消息里粘贴/上传的图片 */
.msg-attachments .msg-image {
  max-width: 320px;
  max-height: 320px;
  border-radius: 8px;
  border: 1px solid #3a3a3a;
  display: block;
  cursor: zoom-in;
}

/* 聊天里的图片渲染 */
.bubble img {
  max-width: 100%;
  max-height: 512px;
  border-radius: 8px;
  display: block;
}

/* 图片容器 + 下载按钮 */
.img-wrap {
  position: relative;
  display: inline-block;
  margin: 8px 0;
  max-width: 100%;
}
.img-wrap img { margin: 0; }
.img-dl-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #ececec;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}
.img-wrap:hover .img-dl-btn { opacity: 1; }
.img-dl-btn:hover { background: rgba(0, 0, 0, 0.85); }
@media (max-width: 768px) {
  /* 手机上常驻显示(无 hover) */
  .img-dl-btn { opacity: 0.85; }
}

/* ─── 文件下载卡片(AI 生成的 PDF / Word / PPT)──────── */
.file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0;
  padding: 12px 14px;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 10px;
  max-width: 420px;
  transition: background 0.15s, border-color 0.15s;
}
.file-card:hover {
  background: #303030;
  border-color: #4a4a4a;
}
.file-icon {
  font-size: 30px;
  line-height: 1;
  flex-shrink: 0;
  width: 40px;
  text-align: center;
}
.file-info {
  flex: 1;
  min-width: 0;
}
.file-name {
  color: #ececec;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-meta {
  color: #888;
  font-size: 12px;
  margin-top: 2px;
}
.file-dl-btn {
  flex-shrink: 0;
  padding: 7px 14px;
  background: #10a37f;
  color: #fff !important;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background 0.15s;
}
.file-dl-btn:hover:not(:disabled) { background: #0d8c6c; }
.file-dl-btn:disabled {
  background: #555;
  cursor: not-allowed;
}
.file-card.error {
  background: #3a2a2a;
  border-color: #5a3030;
}
.file-card.error .file-name { color: #f87171; }
.bubble-files {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
