/* ============================================================
   基础重置
   ============================================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  width: 100%;
  -webkit-text-size-adjust: 100%;
}

html.chat-document {
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: #ededed;
  color: #111111;
  font-size: 16px;
  overscroll-behavior: none;
}

/* ⭐ 只有聊天页锁死页面 */
body.chat-page {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ============================================================
   容器（聊天页专用）
   ⭐ 高度以 JS 行内样式为主，CSS 只兜底
   ============================================================ */
body.chat-page .container {
  width: var(--app-width, 100%);
  max-width: 900px;
  height: 100vh;
  height: var(--app-height, 100dvh);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  overflow: hidden;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  box-sizing: border-box;
}

@media (min-width: 768px) {
  body.chat-page .container {
    height: 90vh; /* PC 端固定 90vh，JS 不会覆盖 */
    border-radius: 16px;
    border: 1px solid #e5e5e5;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  }
}

/* ============================================================
   顶部
   ============================================================ */
header {
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #ffffff;
  flex-shrink: 0;
}
header.hidden {
  display: none;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.header-left h1 {
  font-size: 16px;
  font-weight: 600;
  color: #111111;
}

.header-left .sub-title {
  font-size: 12px;
  color: #888888;
}

.header-btn {
  background: none;
  border: none;
  color: #666666;
  font-size: 18px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background 0.15s;
  flex-shrink: 0;
}

.header-btn:hover {
  background: #f5f5f5;
}

.avatar {
  font-size: 24px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ============================================================
   消息区
   ============================================================ */
.chat-area {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ============================================================
   欢迎页
   ============================================================ */
.welcome-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px 20px;
  text-align: center;
}

.welcome-page.hidden {
  display: none;
}

.welcome-logo {
  font-size: 72px;
  margin-bottom: 20px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

.welcome-title {
  font-size: 36px;
  font-weight: 500;
  color: #111111;
  margin-bottom: 40px;
  letter-spacing: -0.5px;
}

.welcome-input-box {
  width: 100%;
  max-width: 560px;
  background: #f5f5f5;
  border-radius: 28px;
  padding: 8px 8px 8px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  transition:
    border-color 0.15s,
    background 0.15s;
  margin-bottom: 32px;
}

.welcome-input-box:focus-within {
  border-color: #e0e0e0;
  background: #fafafa;
}

.welcome-input-box input {
  flex: 1;
  padding: 12px 0;
  border: none;
  background: transparent;
  color: #111111;
  font-size: 16px;
  outline: none;
  min-width: 0;
}

.welcome-input-box input::placeholder {
  color: #999999;
}
.welcome-send-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #1a1a1a;
  color: #ffffff;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s,
    transform 0.1s;
}

.welcome-send-btn:hover {
  background: #333333;
}

.welcome-send-btn:active {
  transform: scale(0.92);
}

.welcome-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 560px;
}

.action-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px;
  background: #ffffff;
  border: 1px solid #e5e5e5;
  border-radius: 28px;
  font-size: 15px;
  color: #111111;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.action-card:hover {
  background: #fafafa;
  border-color: #d0d0d0;
}

.action-card:active {
  background: #f5f5f5;
  transform: scale(0.99);
}

.action-icon {
  font-size: 18px;
}

.action-text {
  font-weight: 500;
}

/* ============================================================
   消息列表
   ============================================================ */
.messages-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 16px;
}

/* ============================================================
   消息气泡
   ============================================================ */
.message {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  animation: fadeIn 0.2s ease;
  max-width: 100%;
  -webkit-touch-callout: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.user {
  flex-direction: row-reverse;
}

.message .avatar {
  font-size: 20px;
  flex-shrink: 0;
  align-self: flex-start;
  width: 32px;
  text-align: center;
}

.message .bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  line-height: 1.6;
  font-size: 15px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  box-sizing: border-box;
}

.message.user .bubble {
  background: #1a1a1a;
  color: #ffffff;
  border-bottom-right-radius: 6px;
}

.message.assistant .bubble {
  background: #f5f5f5;
  color: #111111;
  border-bottom-left-radius: 6px;
}

.message .bubble .image-container {
  margin-top: 8px;
  width: 100%;
}

.message .bubble .image-container img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  display: block;
}

.message .bubble:has(.image-container) {
  padding: 8px 10px;
}

.message-menu {
  position: fixed;
  z-index: 10003;
  padding: 4px;
  background: #ffffff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
}

.message-menu button {
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #111111;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}

.message-menu button:active {
  background: #f5f5f5;
}

.download-btn {
  display: inline-block;
  padding: 6px 12px;
  background: #07c160;
  color: #ffffff;
  text-decoration: none;
  font-size: 13px;
  border-radius: 6px;
  text-align: center;
  transition: background 0.2s;
  align-self: flex-start;
}

.download-btn:hover,
.download-btn:active {
  background: #06ad56;
}

/* ============================================================
   底部输入区
   ============================================================ */
.input-area-wrapper {
  border-top: 1px solid #f0f0f0;
  background: #ffffff;
  flex-shrink: 0;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  position: relative;
}

.input-area-wrapper.hidden {
  display: none;
}

.input-area {
  display: flex;
  gap: 8px;
  align-items: center;
  background: #f5f5f5;
  border-radius: 24px;
  padding: 6px 6px 6px 16px;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}

.input-area:focus-within {
  border-color: #e0e0e0;
}

.input-area input {
  flex: 1;
  padding: 10px 0;
  border: none;
  background: transparent;
  color: #111111;
  font-size: 16px;
  outline: none;
  min-width: 0;
}

.input-area input::placeholder {
  color: #999999;
}

.input-area input:disabled {
  opacity: 0.5;
}

.input-area button {
  height: 40px;
  /* width: 58px; */
  border: none;
  border-radius: 30px;
  background: #1a1a1a;
  color: #ffffff;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  /* justify-content: center; */
}
#sendBtn{
  padding: 0 20px;
}
.input-area button:active:not(:disabled) {
  background: #333333;
}

.input-area button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#plusBtn {
  width: 40px;
  height: 40px;
  padding: 0;
  box-sizing: border-box;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #666666;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s,
    transform 0.2s;
}

#plusBtn:hover {
  background: #ebebeb;
}

#plusBtn:active {
  transform: scale(0.92);
}

#plusBtn.open {
  transform: rotate(45deg);
}

/* ============================================================
   + 号菜单
   ============================================================ */
.plus-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 60px;
  background: #ffffff;
  border: 1px solid #e5e5e5;
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  z-index: 100;
  min-width: 150px;
}

.plus-menu.hidden {
  display: none;
}

.plus-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: none;
  background: none;
  color: #111111;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
  text-align: left;
  white-space: nowrap;
  transition: background 0.15s;
}

.plus-menu-item:active {
  background: #f5f5f5;
}

.plus-menu-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  color: #666666;
}

/* ============================================================
   引用 / 上传预览条
   ============================================================ */
.quote-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #f5f5f5;
  border-radius: 8px;
  margin-bottom: 8px;
  gap: 8px;
}

.quote-bar.hidden {
  display: none;
}

.quote-content {
  flex: 1;
  min-width: 0;
  border-left: 3px solid #1a1a1a;
  padding-left: 8px;
}

.quote-label {
  font-size: 11px;
  color: #1a1a1a;
  display: block;
}

.quote-text {
  font-size: 12px;
  color: #888888;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quote-cancel {
  background: none;
  border: none;
  color: #888888;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
}

.upload-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #f5f5f5;
  border-radius: 8px;
  margin-bottom: 8px;
}

.upload-preview.hidden {
  display: none;
}

.upload-preview-img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.upload-preview-info {
  flex: 1;
  min-width: 0;
}

.upload-preview-name {
  font-size: 12px;
  color: #888888;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-preview-cancel {
  background: none;
  border: none;
  color: #888888;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
}

/* ============================================================
   会话 / 素材库 / 用户面板
   ============================================================ */
.session-panel,
.draft-panel,
.user-panel {
  position: fixed;
  top: var(--app-offset-top, 0px);
  height: 100vh;
  height: var(--app-height, 100dvh);
  background: #ffffff;
  display: flex;
  flex-direction: column;
  z-index: 9999;
  transition: transform 0.3s;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.06);
}

.session-panel {
  left: 0;
  width: 280px;
  max-width: 70vw;
  padding-left: env(safe-area-inset-left);
  border-right: 1px solid #e5e5e5;
}

.draft-panel {
  right: 0;
  width: 380px;
  max-width: 90vw;
  padding-right: env(safe-area-inset-right);
  border-left: 1px solid #e5e5e5;
}

.user-panel {
  right: 0;
  width: 320px;
  max-width: 85vw;
  padding-right: env(safe-area-inset-right);
  border-left: 1px solid #e5e5e5;
}

.session-panel.hidden {
  transform: translateX(-100%);
}

.draft-panel.hidden,
.user-panel.hidden {
  transform: translateX(100%);
}

.session-header,
.draft-header,
.user-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px 16px;
  border-bottom: 1px solid #f0f0f0;
  font-weight: 600;
  color: #111111;
}

.session-header button,
.draft-header button {
  background: none;
  border: none;
  color: #666666;
  font-size: 18px;
  cursor: pointer;
}

.new-session-btn {
  margin: 12px;
  padding: 10px;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  background: #ffffff;
  color: #111111;
  font-size: 14px;
  cursor: pointer;
}

.new-session-btn:hover {
  background: #f5f5f5;
}

.session-list,
.draft-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px calc(12px + env(safe-area-inset-right))
    calc(16px + env(safe-area-inset-bottom))
    calc(12px + env(safe-area-inset-left));
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  grid-auto-rows: max-content;
  align-content: start;
  gap: 12px;
}

.draft-item {
  display: flex;
  flex-direction: column;
  min-width: 0;
  align-self: start;
  overflow: hidden;
  border: 1px solid #e8e8e8;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.draft-thumb {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  background: transparent;
}

.draft-item .meta {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  color: #666666;
  font-size: 12px;
}

.draft-item .meta strong {
  overflow: hidden;
  color: #222222;
  font-size: 14px;
  line-height: 1.5;
  display: -webkit-box;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
}

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

.draft-actions a {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 6px 9px;
  border: 1px solid #e5e5e5;
  border-radius: 7px;
  background: #ffffff;
  color: #333333;
  font-size: 12px;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

.draft-actions a:active {
  background: #f3f3f3;
}

.draft-actions .delete-btn {
  border-color: #f2dada;
  color: #c43c3c;
}

.session-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: #111111;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  transition: background 0.15s;
}

.session-item:hover {
  background: #f5f5f5;
}

.session-item.active {
  background: #e8e8e8;
  font-weight: 500;
}

.session-item .delete-session {
  color: #fa5151;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition:
    opacity 0.15s,
    background 0.15s;
  pointer-events: none;
}

.session-item.active .delete-session {
  opacity: 0.8;
  pointer-events: auto;
}

.session-item.active .delete-session:hover,
.session-item.active .delete-session:active {
  opacity: 1;
  background: #ffeaea;
}

@media (min-width: 768px) {
  .session-item:hover .delete-session {
    opacity: 0.8;
    pointer-events: auto;
  }
  .session-item:hover .delete-session:hover {
    opacity: 1;
    background: #ffeaea;
  }
}

.session-group-title {
  font-size: 12px;
  color: #999999;
  padding: 12px 12px 6px;
  font-weight: 500;
  user-select: none;
}

.session-group-title:first-child {
  padding-top: 8px;
}

/* ============================================================
   Markdown
   ============================================================ */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-size: 15px;
  font-weight: 600;
  margin: 10px 0 6px;
  color: #111111;
}

.markdown-body p {
  margin: 6px 0;
  line-height: 1.7;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 22px;
  margin: 6px 0;
}

.markdown-body li {
  margin: 4px 0;
}

.markdown-body code {
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

/* ============================================================
   用户菜单按钮
   ============================================================ */
.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid #e5e5e5;
  border-radius: 20px;
  background: #ffffff;
  color: #111111;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  flex-shrink: 0;
}

.user-menu-btn:hover {
  background: #f5f5f5;
  border-color: #d0d0d0;
}

.user-menu-btn .user-avatar {
  font-size: 14px;
}

.user-menu-btn .user-name {
  font-weight: 500;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   用户面板
   ============================================================ */
.user-panel-title {
  font-size: 15px;
}

.user-panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-panel-profile {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: #f9f9f9;
  border-radius: 12px;
  margin-bottom: 8px;
}

.user-panel-avatar {
  font-size: 36px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid #e5e5e5;
}

.user-panel-info {
  flex: 1;
  min-width: 0;
}

.user-panel-name {
  font-size: 16px;
  font-weight: 600;
  color: #111111;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-panel-role {
  font-size: 12px;
  color: #888888;
}

.user-panel-divider {
  height: 1px;
  background: #f0f0f0;
  margin: 8px 0;
}

.user-panel-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #111111;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
  font-family: inherit;
  width: 100%;
}

.user-panel-item.hidden {
  display: none;
}

.user-panel-item:hover {
  background: #f5f5f5;
}

.user-panel-item:active {
  background: #ebebeb;
}

.user-panel-item-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.user-panel-footer {
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: #ffffff;
  flex-shrink: 0;
}

.user-panel-logout {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  background: #fff1f1;
  color: #fa5151;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s;
  font-family: inherit;
  min-height: 44px;
}

.user-panel-logout:hover {
  background: #ffe1e1;
}

.user-panel-logout:active {
  background: #ffd4d4;
  transform: scale(0.99);
}

/* ============================================================
   账号管理
   ============================================================ */
.admin-panel {
  position: fixed;
  top: var(--app-offset-top, 0px);
  right: 0;
  bottom: auto;
  left: 0;
  height: 100vh;
  height: var(--app-height, 100dvh);
  padding-right: env(safe-area-inset-right);
  padding-left: env(safe-area-inset-left);
  background: #ffffff;
  display: flex;
  flex-direction: column;
  z-index: 10000;
  transition: transform 0.3s;
}

.admin-panel.hidden {
  display: none;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid #f0f0f0;
  background: #ffffff;
}

.admin-title {
  font-size: 16px;
  font-weight: 600;
  color: #111111;
}

.admin-tabs {
  display: flex;
  padding: 0 16px;
  border-bottom: 1px solid #f0f0f0;
  background: #ffffff;
  gap: 4px;
}

.admin-tab {
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: #888888;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 4px;
}

.admin-tab:hover {
  color: #111111;
}

.admin-tab.active {
  color: #111111;
  border-bottom-color: #1a1a1a;
}

.admin-tab-count {
  font-size: 12px;
  color: #999999;
  background: #f5f5f5;
  padding: 1px 6px;
  border-radius: 8px;
}

.admin-tab.active .admin-tab-count {
  background: #ebebeb;
  color: #111111;
}

.admin-user-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-user-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid #f0f0f0;
  border-radius: 12px;
  background: #ffffff;
  transition: all 0.15s;
}

.admin-user-card:hover {
  border-color: #e0e0e0;
}

.admin-user-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-user-avatar {
  font-size: 24px;
}

.admin-user-info {
  flex: 1;
  min-width: 0;
}

.admin-user-name {
  font-size: 15px;
  font-weight: 600;
  color: #111111;
  margin-bottom: 2px;
}

.admin-user-meta {
  font-size: 12px;
  color: #888888;
}

.admin-user-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.admin-action-btn {
  padding: 6px 12px;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  background: #ffffff;
  color: #111111;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.admin-action-btn:hover {
  background: #f5f5f5;
  border-color: #d0d0d0;
}

.admin-action-btn.danger {
  color: #fa5151;
  border-color: #f5c6c6;
}

.admin-action-btn.danger:hover {
  background: #fff1f1;
}

.admin-empty {
  text-align: center;
  color: #999999;
  font-size: 14px;
  padding: 40px 20px;
}

.admin-footer {
  border-top: 1px solid #f0f0f0;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: #ffffff;
  flex-shrink: 0;
}

.admin-footer.hidden {
  display: none;
}

.admin-add-btn {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  background: #1a1a1a;
  color: #ffffff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
  min-height: 44px;
}

.admin-add-btn:hover {
  background: #333333;
}

/* ============================================================
   弹窗
   ============================================================ */
.admin-dialog,
.name-dialog {
  position: fixed;
  top: var(--app-offset-top, 0px);
  right: 0;
  bottom: auto;
  left: 0;
  height: 100vh;
  height: var(--app-height, 100dvh);
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  padding: 20px;
}

.admin-dialog.hidden,
.name-dialog.hidden {
  display: none;
}

.admin-dialog-content,
.name-dialog-content {
  background: #ffffff;
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
  max-height: calc(100vh - 40px);
  max-height: calc(var(--app-height, 100dvh) - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.name-dialog-content h3,
.admin-dialog-content h3 {
  font-size: 16px;
  font-weight: 600;
  color: #111111;
  margin-bottom: 4px;
}

.admin-dialog-subtitle {
  font-size: 13px;
  color: #888888;
  margin-bottom: 4px;
}

.admin-dialog-content input,
.name-dialog-content input {
  padding: 12px 14px;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  background: #ffffff;
  color: #111111;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.admin-dialog-content input:focus,
.name-dialog-content input:focus {
  border-color: #1a1a1a;
}

.admin-dialog-error,
.name-error {
  color: #fa5151;
  font-size: 13px;
  min-height: 18px;
  margin: 0;
}

.admin-dialog-btns,
.name-dialog-btns {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.admin-dialog-btns button,
.name-dialog-btns button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

#adminAddCancel,
#adminResetCancel,
#nameCancel {
  background: #f5f5f5;
  color: #111111;
}

#adminAddCancel:hover,
#adminResetCancel:hover,
#nameCancel:hover {
  background: #ebebeb;
}

#adminAddConfirm,
#adminResetConfirm,
#nameSubmit {
  background: #1a1a1a;
  color: #ffffff;
}

#adminAddConfirm:hover,
#adminResetConfirm:hover,
#nameSubmit:hover {
  background: #333333;
}

/* ============================================================
   素材预览弹窗
   ============================================================ */
.preview-dialog {
  position: fixed;
  top: var(--app-offset-top, 0px);
  right: 0;
  bottom: auto;
  left: 0;
  height: 100vh;
  height: var(--app-height, 100dvh);
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10002;
  padding: 20px;
}

.preview-content {
  background: #ffffff;
  border-radius: 12px;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #e5e5e5;
  font-weight: 600;
  color: #111111;
  background: #f7f7f7;
}

.preview-header button {
  background: none;
  border: none;
  color: #111111;
  font-size: 18px;
  cursor: pointer;
}

.preview-image {
  max-width: 80vw;
  max-height: 60vh;
  object-fit: contain;
  background: #f7f7f7;
  display: block;
}

.preview-meta {
  padding: 12px 16px;
  color: #888888;
  font-size: 13px;
  line-height: 1.6;
  border-top: 1px solid #e5e5e5;
}

.preview-actions {
  padding: 12px 16px;
  border-top: 1px solid #e5e5e5;
  display: flex;
  justify-content: flex-end;
}

/* ============================================================
   移动端
   ============================================================ */
@media (max-width: 767px),
  (max-height: 500px) {
  header {
    padding: 10px 12px;
  }

  .header-left h1 {
    font-size: 15px;
  }

  .header-left .sub-title {
    font-size: 11px;
  }

  .avatar {
    font-size: 22px;
  }

  .welcome-logo {
    font-size: 56px;
  }

  .welcome-title {
    font-size: 28px;
    margin-bottom: 32px;
  }

  .welcome-input-box {
    padding: 6px 6px 6px 16px;
  }

  .action-card {
    padding: 12px 16px;
    font-size: 14px;
  }

  .messages-list {
    padding: 16px 12px;
  }

  .message .bubble {
    font-size: 14px;
    max-width: 85%;
  }

  .input-area-wrapper {
    padding: 10px 12px;
    padding-bottom: 10px;
  }

  .session-panel {
    width: 75vw;
  }

  .draft-panel {
    width: 100vw;
    max-width: 100vw;
  }

  .user-panel {
    width: 75vw;
  }

  .user-menu-btn {
    padding: 3px 8px;
    font-size: 12px;
  }

  .user-menu-btn .user-name {
    max-width: 50px;
  }

  .chat-page input,
  .admin-dialog-content input,
  .name-dialog-content input {
    font-size: 16px;
  }

  .name-dialog-content {
    width: calc(100vw - 40px);
    max-width: 340px;
  }

  .preview-dialog {
    padding: 0;
    align-items: stretch;
  }

  .preview-content {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: var(--app-height, 100dvh);
    max-height: 100vh;
    max-height: var(--app-height, 100dvh);
    padding-right: env(safe-area-inset-right);
    padding-left: env(safe-area-inset-left);
    border-radius: 0;
  }

  .preview-image {
    max-width: 100vw;
    max-height: 60vh;
    max-height: 60dvh;
    flex: 1;
  }

  .preview-actions {
    padding-right: calc(16px + env(safe-area-inset-right));
    padding-left: calc(16px + env(safe-area-inset-left));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .preview-actions .download-btn {
    flex: 1;
    text-align: center;
    padding: 12px;
    font-size: 15px;
  }
}

@media (max-width: 767px) and (max-height: 500px),
  (max-height: 500px) {
  body.chat-page .container {
    width: 100%;
    max-width: none;
    height: 100vh;
    height: var(--app-height, 100dvh);
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .welcome-page {
    justify-content: flex-start;
    padding: 12px 16px;
  }

  .welcome-logo {
    font-size: 40px;
    margin-bottom: 8px;
  }

  .welcome-title {
    font-size: 22px;
    margin-bottom: 12px;
  }

  .welcome-input-box {
    margin-bottom: 12px;
  }

  .welcome-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .action-card {
    flex-direction: column;
    gap: 4px;
    padding: 8px 4px;
    font-size: 12px;
  }
}

/* ============================================================
   阻止移动端滚动穿透
   ============================================================ */
body.drawer-open {
  overflow: hidden;
}