/* 全局重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: system-ui, -apple-system, sans-serif;
}
body {
    display: flex;
    height: 100vh;
    overflow: hidden;
    transition: background 0.3s, color 0.3s;
}
/* Logo 样式 */
.logo-img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
}
/* ========== 亮色主题 ========== */
body.light {
    background: #fff;
    color: #222;
}
body.light .sidebar {
    background: #f7f8fa;
    border-right: 1px solid #e5e7eb;
}
body.light .chat-wrap {
    background: #ffffff;
}
body.light .msg-user {
    background: #1677ff;
    color: white;
}
body.light .msg-ai {
    background: #f0f2f5;
    color: #222;
}
body.light .modal-box {
    background: #fff;
}
body.light pre code {
    background: #f2f3f5;
}
body.light .code-copy-btn {
    background: #e4e6eb;
    color: #333;
}

/* ========== 深色主题 ========== */
body.dark {
    background: #17171a;
    color: #e5e7eb;
}
body.dark .sidebar {
    background: #1e1e24;
    border-right: 1px solid #2d2d34;
}
body.dark .chat-wrap {
    background: #17171a;
}
body.dark .msg-user {
    background: #2563eb;
    color: #fff;
}
body.dark .msg-ai {
    background: #27272f;
    color: #e5e7eb;
}
body.dark .modal-box {
    background: #1e1e24;
}
body.dark pre code {
    background: #111;
}
body.dark .code-copy-btn {
    background: #3a3a48;
    color: #eee;
}

/* ========== 侧边栏 ========== */
.sidebar {
    width: 400px;
    display: flex;
    flex-direction: column;
    padding: 12px;
}
.sidebar-top {
    flex: 1;
    overflow-y: auto;
}
.sidebar-bottom {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid #eee;
    display: flex;
    flex-direction: column;
    gap:6px;
}
.sidebar-title {
    font-size: 12px;
    color: #888;
    margin: 12px 0 6px;
    padding-left: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.new-chat-btn {
    font-size:12px;
    padding:2px 6px;
    cursor:pointer;
    background:#1677ff22;
    color:#1677ff;
    border-radius:4px;
}
.sidebar-item {
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    margin: 4px 0;
    font-size: 14px;
    display:flex;
    justify-content: space-between;
    align-items: center;
}
.sidebar-item:hover {
    background: rgba(130,130,130,0.12);
}
.sidebar-item.active {
    background: #1677ff22;
    color: #1677ff;
}
.chat-op-btn-group {
    display:none;
    gap:4px;
}
.sidebar-item:hover .chat-op-btn-group {
    display:flex;
}
.chat-rename,.chat-del {
    font-size:12px;
    padding:1px 4px;
    border-radius:3px;
    border:none;
    cursor:pointer;
}
.chat-rename {
    background:#52c41a22;
    color:#389e0d;
}
.chat-del {
    background:#ff4d4f22;
    color:#ff4d4f;
}
/* 侧边底部图标工具栏 */
.sidebar-bottom {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid rgba(120,120,120,0.12);
}
.sidebar-tool-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap:4px;
    padding: 10px 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}
body.light .tool-btn:hover {
    background: rgba(0,0,0,0.06);
}
body.dark .tool-btn:hover {
    background: rgba(255,255,255,0.08);
}
.tool-icon {
    font-size: 20px;
}
.tool-label {
    display: none !important;
}
.sidebar-tool-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr); /* 5个按钮均分 */
    gap: 8px;
}
.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 12px 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}
/* 会话操作小按钮缩小 */
.chat-op-btn-group button {
    width: 22px;
    height: 22;
    font-size: 13px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
/* 危险按钮区分颜色 */
#clear-current-session .tool-icon {
    color: #ff4d4f;
}
#export-json .tool-icon {
    color: #1677ff;
}
#export-txt .tool-icon {
    color: #52c41a;
}
#open-setting .tool-icon {
    color: #722ed1;
}
#export-lora .tool-icon {
    color: #722ed1;
}

/* ========== 聊天主区域 ========== */


.msg-box {
    margin-bottom: 16px;
    max-width: 75%;
    position:relative;
}
.msg-user {
    margin-left: auto;
    padding: 10px 14px;
    border-radius: 12px 2px 12px 12px;
}
.msg-ai {
    margin-right: auto;
    padding: 10px 14px;
    border-radius: 2px 12px 12px 12px;
}
/* AI消息复制按钮 */
.ai-copy-all {
    position:absolute;
    top:4px;
    right:4px;
    font-size:12px;
    padding:2px 6px;
    border:none;
    border-radius:4px;
    cursor:pointer;
    opacity:0;
}
.msg-ai:hover .ai-copy-all {
    opacity:1;
}
/* Markdown 基础样式 */
.msg-ai h1,.msg-ai h2,.msg-ai h3 {
    margin:8px 0;
}
.msg-ai p {
    margin:6px 0;
    line-height:1.6;
}
.msg-ai pre {
    border-radius:6px;
    padding:10px;
    overflow-x:auto;
    margin:8px 0;
    position:relative;
}
.msg-ai code {
    padding:2px 6px;
    border-radius:4px;
}
.code-copy-btn {
    position:absolute;
    top:6px;
    right:6px;
    font-size:12px;
    padding:2px 6px;
    border:none;
    border-radius:4px;
    cursor:pointer;
}
/* 上传图片预览 */
.upload-img-preview {
    max-width:240px;
    border-radius:6px;
    margin:6px 0;
}
/* 底部输入栏 */

.input-left-tool {
    display:flex;
    flex-direction:column;
    gap:6px;
}
.upload-file-btn {
    width:36px;
    height:36px;
    border-radius:6px;
    border:1px solid #ccc;
    display:flex;
    align-items:center;
    justify-content:center;
    cursor:pointer;
}
#chat-input {
    flex: 1;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid #ddd;
    resize: none;
    height: 60px;
}
.send-btn-group {
    display:flex;
    flex-direction:column;
    gap:6px;
}
#send-btn {
    padding: 0 20px;
    background: #1677ff;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    height:36px;
}
#stop-stream-btn {
    padding: 0 20px;
    background: #ff4d4f;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    height:36px;
    display:none;
}
/* 弹窗通用 */
.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
}
.modal-box {
    width: 600px;
    max-height:85vh;
    overflow-y:auto;
    padding: 24px;
    border-radius: 10px;
}
.modal-sm {
    width:360px;
}
.modal-title {
    font-size: 18px;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
}
.close-modal {
    cursor: pointer;
    font-size: 22px;
}
.form-item {
    margin-bottom: 14px;
}
.form-item label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
}
.form-item input,
.form-item select,
.form-item textarea {
    width: 100%;
    padding: 9px 12px;
    border-radius: 6px;
    border: 1px solid #ccc;
}
.form-item textarea {
    min-height:80px;
    resize:vertical;
}
.row-two {
    display:flex;
    gap:10px;
}
.row-two .form-item {
    flex:1;
}
.save-config {
    margin-top: 10px;
    width: 100%;
    padding: 10px;
    background: #1677ff;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}
.loading-text {
    opacity:0.6;
}
/* 隐藏原生文件input */
#file-input {
    display:none;
}

/* 侧边栏顶部Logo MantisAI */
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 10px 16px;
    border-bottom: 1px solid rgba(120,120,0.12);
    margin-bottom: 10px;
    /* 取消两端对齐，改为左靠，登录区自动挤到右侧 */
    justify-content: flex-start;
}
.login-area {
    margin-left: auto; /* 登录区域自动推到最右边 */
    display: flex;
    align-items: center;
    gap: 10px;
}
.login-btn {
    padding: 4px 10px;
    border-radius: 6px;
    border: none;
    background: #1677ff;
    color: #fff;
    cursor: pointer;
}
.logout-btn {
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid #ff4d4f;
    color: #ff4d4f;
    background: transparent;
    cursor: pointer;
}
body.dark .logout-btn {
    border-color: #ff7875;
    color: #ff7875;
}
.logo-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #1677ff;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}
.logo-text {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.5px;
}
/* 深色主题logo适配 */
body.dark .logo-icon {
    background: #2563eb;
}

/* 设置弹窗标签页 */
.setting-tabs {
    display: flex;
    border-bottom: 1px solid #ccc;
    margin-bottom: 16px;
}
.tab-item {
    padding: 8px 16px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 2px solid transparent;
}
.tab-item.active {
    border-bottom-color: #1677ff;
    color: #1677ff;
}
body.dark .setting-tabs {
    border-bottom-color: #333;
}
body.dark .tab-item.active {
    color: #69b1ff;
    border-bottom-color: #69b1ff;
}
.tab-panel {
    padding: 4px 0;
}

/* 侧边栏列表前置图标 */
.sidebar-item {
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    margin: 4px 0;
    font-size: 14px;
    display: flex;
    align-items: center;
    /* 左右两端对齐：图标文字靠左，操作按钮靠右 */
    justify-content: space-between;
    gap: 8px;
}
/* 左侧图标+文字容器，强制靠左不撑开 */
.item-left-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 1;
}
.item-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}
/* 文字自动靠左，剩余空间留给右侧按钮 */
.chat-name, .sidebar-item > span:nth-child(2) {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* 亮色主题图标微调 */
body.light .item-icon {
    opacity: 0.8;
}
/* 深色主题图标提亮 */
body.dark .item-icon {
    opacity: 0.9;
}
.sidebar-item:hover .item-icon {
    opacity: 1;
}
.sidebar-item.active .item-icon {
    color: #1677ff;
}
body.dark .sidebar-item.active .item-icon {
    color: #69b1ff;
}

/* 页面横向布局支持拉伸 */
body {
    display: flex;
    height: 100vh;
    overflow: hidden;
    transition: background 0.3s, color 0.3s;
}

/* 侧边栏宽度变量，默认280，限制最小/最大宽度 */
.sidebar {
    width: 280px;
    min-width: 220px;
    max-width: 850px;
    display: flex;
    flex-direction: column;
    padding: 12px;
}

/* 拖拽分割条样式 */
.resize-handle {
    width: 4px;
    background: transparent;
    cursor: col-resize;
    transition: background 0.15s;
}
.resize-handle:hover,
.resize-handle.active {
    background: #1677ff;
}
body.dark .resize-handle:hover,
body.dark .resize-handle.active {
    background: #69b1ff;
}

/* 右侧聊天自动占满剩余宽度 */


#chat-input {
    flex: 1;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid #ddd;
    resize: vertical; /* 只允许上下拖拽 */
    min-height: 60px;
    max-height: 220px;
    height: 60px;
    overflow-y: auto;
}
body.dark #chat-input {
    background: #27272f;
    color: #e5e7eb;
    border-color: #3a3a48;
}

.send-btn-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
#send-btn {
    width: 40px;
    height: 40px;
    background: #1677ff;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
#stop-stream-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    background: #ff4d4f;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    display: none;
    align-items: center;
    justify-content: center;
}

body.dark .chat-input-area {
    border-color: #2d2d34;
}

/* 输入框外层容器 */
.textarea-wrap {
    position: relative;
    width: 100%;
}

#chat-input {
    width: 100%;
    padding: 12px 14px 44px 14px;
    border-radius: 8px;
    border: 1px solid #ddd;
    resize: none;
    min-height: 60px;
    max-height: 220px;
    height: 80px;
    overflow-y: auto;
    box-sizing: border-box;
}
body.dark #chat-input {
    background: #27272f;
    color: #e5e7eb;
    border-color: #3a3a48;
}

/* 右上角拖拽手柄 */
.resize-handle-input {
    position: absolute;
    right: 6px;
    top: 6px;
    width: 18px;
    height: 18px;
    cursor: ns-resize !important;
    opacity: 0.6;
    border-top: 2px solid #999;
    border-right: 2px solid #999;
    z-index: 999 !important; /* 层级最高，不会被遮挡 */
    pointer-events: auto !important; /* 允许接收鼠标点击 */
}
.resize-handle-input:hover {
    opacity: 1;
}
body.dark .resize-handle-input {
    border-color: #ccc;
}

/* 输入框内部底部工具栏 */
.input-inner-toolbar {
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 2;
}

/* 上传附件按钮 */
.upload-file-btn {
    font-size: 14px;
    cursor: pointer;
    opacity: 0.8;
}
.upload-file-btn:hover {
    opacity: 1;
}
#file-input {
    display: none;
}

/* 发送停止按钮组横向排列 */
.send-btn-group {
    display: flex;
    gap: 6px;
}
#send-btn {
    width: 32px;
    height: 32px;
    background: #1677ff;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
#stop-stream-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    background: #ff4d4f;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    display: none;
    align-items: center;
    justify-content: center;
}

/* 只读昵称输入框置灰 */
#login-nick {
    background: #f5f5f5 !important;
    color: #666 !important;
    cursor: default;
}
body.dark #login-nick {
    background: #333 !important;
    color: #aaa !important;
}

body.dark #login-nick[readonly] {
    background: #333 !important;
    color: #aaa !important;
}
body.dark #login-nick:not([readonly]) {
    background: #27272f !important;
    color: #eee !important;
}

/* 单条消息容器 */
/* 消息外层容器，控制左右对齐 */
.msg-wrap {
    width: 100%;
    padding: 10px 14px;
    box-sizing: border-box;
}
.msg-user-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}
.msg-ai-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

/* 头部小字：作者+时间 */
.msg-header {
    font-size: 11px;
    opacity: 0.75;
    margin-bottom: 5px;
    display: flex;
    gap: 10px;
}
.user-header {
    flex-direction: row-reverse; /* 用户信息靠右 */
}
.ai-header {
    flex-direction: row; /* AI模型信息靠左 */
}
.msg-author {
    font-weight: 500;
}
.msg-time {}

/* 原有气泡样式不变，这里只补充间距 */
.msg-box {
    max-width: 72%;
}

/* AI等待加载三点动画 */
.loading-dot {
    display: flex;
    gap: 4px;
    font-size: 22px;
    line-height: 1.6;
    padding: 6px 0;
}
.loading-dot span {
    animation: dotAnim 1.4s infinite ease-in-out;
}
.loading-dot span:nth-child(1) { animation-delay: 0s; }
.loading-dot span:nth-child(2) { animation-delay: 0.2s; }
.loading-dot span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotAnim {
    0%, 100% { opacity: 0.2; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-4px); }
}

/* 深色主题适配 */
body.dark .loading-dot span {
    color: #ccc;
}
body.light .loading-dot span {
    color: #555;
}

/* 文件预览容器 */
.file-preview-container {
  display: flex;
  gap: 8px;
  padding: 4px;
  flex-wrap: wrap;
  align-items: center;
}

/* 单个文件预览项 */
.file-preview-item {
  position: relative;
  width: 60px;
  height: 60px;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  background: #f9fafb;
}

/* 图片缩略图 */
.file-preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 非图片文件图标容器 */
.file-icon-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  font-size: 12px;
  color: #6b7280;
}

.file-icon {
  font-size: 24px;
  margin-bottom: 4px;
}

/* 预览项删除按钮 */
.file-preview-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ef4444;
  color: white;
  border: none;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* 聊天消息中的附件样式 */
.chat-attach-file {
  display: inline-block;
  margin-top: 8px;
  margin-left: 8px;
}

.chat-attach-file .file-preview-item {
  width: 40px;
  height: 40px;
}

 /* 上传文件预览样式 */
.upload-preview-container {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 4px;
    flex-wrap: wrap;
    max-width: 300px;
    margin-left: 4px;
	width:300px;
}
.upload-preview-item {
    position: relative;
	
	display: inline-block;
    width: 40px;
    height: 40px;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
}
.upload-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.upload-preview-file-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9fafb;
    font-size: 18px;
}
.upload-preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ff4d4f;
    color: white;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 1px solid white;
}
/* 聊天消息附件样式 */
.chat-attachments {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.chat-attachment-item {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
}
.chat-attachment-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.chat-attachment-file-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9fafb;
    font-size: 24px;
}

/* 顶部标题栏 */
.chat-header {
    height: 30px;
    min-height: 30px;
    max-height: 70%;
    padding: 0 14px;
    display: flex;
    align-items: top;
    background: #f3f3f3;
    /* 必须加relative，拖拽条才能以它为基准 */
    position: relative;
    box-sizing: border-box;
    /* 底部留8px空间给拖拽条，不被chat-wrap盖住 */
    padding-bottom:8px;
	padding-top:8px;
}
.dark .chat-header{
    background:#242424;
}
.chat-header-title{
    font-size:14px;
    z-index:2;
    position:top;
	width:100%;
	Vertical-align: top;
}
/* 加粗拖拽分割线，一眼可见 */
/* 拖拽分割线 提升层级，不会被遮挡 */
.chat-header-resize-handle {
    position:absolute;
    left:0;
    bottom:0;
    width:100%;
    height:8px;
    background:transparent;
    cursor:ns-resize;
    transition: background 0.15s;
    z-index:99; /* 层级最高，不会被聊天内容盖住 */
}
.chat-header-resize-handle:hover{
    background:#4096ff !important;
}
.chat-header-resize-handle:active{
    background:#1677ff !important;
}


/* 聊天外层容器必须占满高度 */
.chat-main {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* 聊天内容自动占剩余空间 */
/* 聊天内容区域 不能贴紧顶部，避开拖拽条 */
.chat-wrap {
    flex:1;
    overflow-y:auto;
    padding:24px;
	width:95%;
}

.chat-input-area{
    flex-shrink:0;
	width:98%;
}

/* 弹窗基础拖拽样式 */
.modal-box {
    position: relative;
}
/* 弹窗标题栏 拖拽抓手 */
.modal-title {
    cursor: move;
    user-select: none;
}
/* 拖拽时禁止页面文字选中 */
body.drag-modal {
    user-select: none;
}

.modal-mask .modal-box {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}