/* ==========================================
   全局重置与基础样式
   ========================================== */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; background: #1e1e20; color: #ececf1; overflow: hidden; }

/* 滚动条美化 (暗色) */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #666; }

/* ==========================================
   登录页样式
   ========================================== */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; background: #171717; }
.login-card { background: #1e1e20; padding: 40px; border-radius: 12px; width: 320px; box-shadow: 0 4px 24px rgba(0,0,0,.5); border: 1px solid #333; }
.login-card h1 { font-size: 22px; margin-bottom: 8px; color: #fff; }
.muted { color: #8e8ea0; font-size: 13px; margin-bottom: 20px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid #444; border-radius: 8px; margin-bottom: 12px; background: #2a2a2d; color: #fff; outline: none; }
.login-card input:focus { border-color: #10a37f; }
.login-card button { width: 100%; padding: 10px; border: none; border-radius: 8px; background: #10a37f; color: #fff; cursor: pointer; font-weight: bold; }
.login-card button:hover { background: #1a7f64; }
.error { color: #ef4444; font-size: 13px; margin-top: 8px; }

/* ==========================================
   主界面布局 (侧边栏)
   ========================================== */
.app { display: flex; height: 100vh; background: #1e1e20; }
.sidebar { width: 260px; background: #171717; color: #ececf1; display: flex; flex-direction: column; padding: 12px; gap: 8px; border-right: 1px solid #2a2a2d; }
.sidebar button { padding: 10px; border: 1px solid #333; border-radius: 6px; cursor: pointer; background: transparent; color: #fff; display: flex; align-items: center; justify-content: center; gap: 8px; transition: background 0.2s; }
#newChatBtn { background: #10a37f; border: none; font-weight: bold; }
#newChatBtn:hover { background: #1a7f64; }

.session-list { flex: 1; overflow-y: auto; margin-top: 10px; }
.session-item { padding: 10px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; color: #ececf1; display: flex; justify-content: space-between; align-items: center; transition: background 0.2s; }
.session-item:hover, .session-item.active { background: #2a2a2d; }
.session-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.action-btns { display: none; gap: 4px; align-items: center; }
.session-item:hover .action-btns { display: flex; }
.action-icon { font-size: 14px; color: #8e8ea0; padding: 4px; border-radius: 4px; transition: all 0.2s; }
.action-icon:hover { background: #444; color: #fff; }
.delete-icon:hover { color: #ef4444; }
.logout { background: transparent; color: #8e8ea0; font-size: 13px; border: none; cursor: pointer; margin-top: auto; padding: 10px; text-align: left; }
.logout:hover { color: #fff; }

/* ==========================================
   聊天区
   ========================================== */
.chat-main { position: relative; flex: 1; display: flex; flex-direction: column; width: calc(100% - 260px); }
.messages { flex: 1; overflow-y: auto; padding: 20px 0; display: flex; flex-direction: column; align-items: center; }
.msg { width: 100%; max-width: 800px; margin-bottom: 24px; padding: 0 20px; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }

/* 用户气泡 */
.msg.user .msg-text {
    background: #2f2f2f;
    padding: 12px 20px;
    border-radius: 12px;
    border-bottom-right-radius: 4px;
    max-width: 85%;
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-wrap;
}

/* AI 消息 */
.msg.assistant .msg-text {
    width: 100%;
    line-height: 1.7;
    word-break: break-word;
}

/* Markdown 渲染样式 */
.msg.assistant p { margin-bottom: 12px; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 10px 0 10px 20px; }
.msg.assistant table { border-collapse: collapse; margin: 10px 0; width: 100%; }
.msg.assistant th, .msg.assistant td { border: 1px solid #444; padding: 8px 12px; }
.msg.assistant :not(pre) > code {
    background: #2f2f2f;
    color: #fca5a5;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: Consolas, monospace;
}

/* ==========================================
   代码块样式
   ========================================== */
.msg.assistant pre {
    background: #131314;
    border: 1px solid #333;
    border-radius: 8px;
    margin: 16px 0;
    position: relative;
    overflow: hidden;
}
.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1e1e20;
    padding: 8px 16px;
    border-bottom: 1px solid #333;
}
.code-lang {
    color: #8e8ea0;
    font-size: 12px;
    font-family: Consolas, monospace;
    text-transform: uppercase;
}
.msg.assistant pre code {
    display: block;
    padding: 16px;
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13.5px;
    line-height: 1.5;
    color: #e5e5e5;
}
.copy-btn {
    background: transparent;
    color: #8e8ea0;
    border: none;
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}
.copy-btn:hover { background: #333; color: #fff; }

/* ==========================================
   思考过程框 (适配暗色)
   ========================================== */
.think-box {
    background: #2a2a2d;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 14px;
    color: #a3a3a3;
    width: 100%;
    border-left: 4px solid #10a37f;
}
.think-box summary {
    cursor: pointer;
    font-weight: bold;
    color: #10a37f;
    user-select: none;
    outline: none;
}
.think-box .think-content {
    margin-top: 10px;
    white-space: pre-wrap;
    line-height: 1.6;
    border-top: 1px solid #444;
    padding-top: 10px;
}

/* ==========================================
   输入区 (彻底适配暗色主题)
   ========================================== */
.input-container {
    padding: 10px 20px 24px;
    background: #1e1e20;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 统一的外框 */
.input-box-wrapper {
    width: 100%;
    max-width: 800px; /* 与聊天区同宽 */
    border: 1px solid #444;
    border-radius: 12px;
    background: #2a2a2d;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 聚焦时的外框发光效果 */
.input-box-wrapper:focus-within {
    border-color: #10a37f;
    box-shadow: 0 0 0 1px #10a37f;
}

/* 上排：输入框 */
textarea#input {
    width: 100%;
    min-height: 48px;
    max-height: 200px;
    padding: 16px 16px 8px 16px;
    border: none;
    background: transparent;
    color: #ececf1;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    overflow-y: auto;
}
textarea#input::placeholder { color: #6b7280; }

/* 下排：控制栏 */
.input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px 12px 12px;
}

/* 左侧复选框组 */
.toggle-options {
    display: flex;
    gap: 15px;
}
.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #8e8ea0;
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}
.toggle-label input[type="checkbox"] {
    cursor: pointer;
    accent-color: #10a37f;
    width: 14px;
    height: 14px;
}
.toggle-label:hover { color: #ececf1; }
.toggle-label:has(input:checked) { color: #10a37f; }

/* 右侧按钮组 */
.action-buttons {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 纯净版上传按钮 (SVG 图标，暗色适配) */
.icon-btn {
    background: transparent;
    border: none;
    color: #8e8ea0;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.icon-btn:hover {
    background: #444;
    color: #fff;
}

/* 发送按钮 */
.send-btn {
    background: #10a37f;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}
.send-btn:hover { background: #1a7f64; }

/* 停止按钮 */
.stop-btn {
    background: transparent;
    color: #ef4444;
    border: 1px solid #ef4444;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}
.stop-btn:hover { background: #ef4444; color: #fff; }

/* 附件预览区 (暗色适配) */
.attachment-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    max-width: 800px;
    width: 100%;
    margin-bottom: 12px;
}
.attachment-chip {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #2a2a2d;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 13px;
    color: #ececf1;
    max-width: 220px;
}
.attachment-chip .file-icon { font-size: 16px; }
.attachment-chip .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip .remove-file {
    cursor: pointer;
    color: #8e8ea0;
    font-size: 14px;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 4px;
}
.attachment-chip .remove-file:hover { background: #444; color: #ef4444; }

/* 用户消息中回显附件 */
.msg-attachments {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.msg-attachment-item {
    background: #2a2a2d;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    color: #8e8ea0;
}

/* ==========================================
   悬浮回到底部按钮
   ========================================== */
.scroll-down-btn {
    position: absolute;
    bottom: 120px;
    right: 30px;
    background: #10a37f;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: bold;
    z-index: 100;
    transition: all 0.3s ease;
    opacity: 0.9;
}
.scroll-down-btn:hover {
    opacity: 1;
    background: #1a7f64;
    transform: translateY(-2px);
}
.scroll-down-btn.generating .arrow { animation: bounce 1s infinite; }
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(4px); }
}

/* ==========================================
   拖拽遮罩层
   ========================================== */
#dropOverlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(23, 23, 23, 0.8);
    border: 3px dashed #10a37f;
    z-index: 9999; display: none; justify-content: center; align-items: center;
    backdrop-filter: blur(4px); pointer-events: none;
}
#dropOverlay.active { display: flex; }
.drop-text {
    background: #2a2a2d;
    padding: 20px 40px;
    border-radius: 12px;
    font-size: 20px;
    color: #10a37f;
    font-weight: bold;
    border: 1px solid #444;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
/* 确保表单占满宽度且垂直排列 */
.chat-form {
    width: 100%;
    display: flex;
    flex-direction: column;
}
/* ==========================================
   图片附件缩略图专用样式
   ========================================== */
.img-preview-wrapper {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #444;
    background: #131314;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.img-thumbnail {
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.2s;
}

/* 悬浮时图片稍微放大 */
.img-preview-wrapper:hover .img-thumbnail {
    transform: scale(1.05);
}

/* 图片上的删除按钮悬浮在右上角 */
.img-preview-wrapper .remove-file {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s;
    backdrop-filter: blur(2px);
}

.img-preview-wrapper:hover .remove-file {
    opacity: 1;
}

.img-preview-wrapper .remove-file:hover {
    background: #ef4444;
    transform: scale(1.1);
}

/* ==========================================
   右侧文本预览抽屉
   ========================================== */
.preview-drawer {
    position: fixed; /* 固定在屏幕右侧 */
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px; /* 抽屉宽度 */
    max-width: 85vw;
    background: #1e1e20;
    border-left: 1px solid #333;
    box-shadow: -4px 0 20px rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    flex-direction: column;

    /* 默认隐藏在右侧屏幕外 */
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    visibility: hidden;
}

/* 展开时的状态 */
.preview-drawer.open {
    transform: translateX(0);
    visibility: visible;
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid #333;
    background: #2a2a2d;
}

.drawer-header span {
    color: #ececf1;
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80%;
}

.drawer-body {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.drawer-body pre {
    margin: 0;
    color: #e5e5e5;
    font-family: Consolas, Monaco, monospace;
    font-size: 13.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}
/* ==========================================
   底部 AI 免责声明
   ========================================== */
.ai-disclaimer {
    text-align: center;
    color: #6b7280;
    font-size: 12px;
    padding: 10px 0;
    font-style: italic;
}

/* ==========================================
   AI 消息底部操作栏 (复制 / 重新生成)
   ========================================== */
.msg-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px dashed #333;
    width: 100%;
}

.action-btn {
    background: transparent;
    border: 1px solid transparent;
    color: #8e8ea0;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 12px;
    gap: 4px;
}

.action-btn:hover {
    background: #2a2a2d;
    color: #ececf1;
    border-color: #444;
}

.action-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}