* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: #EDEDED;
    color: #191919;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100vh;
    height: 100dvh;
}

.container {
    display: flex;
    height: 100%;
    max-width: 100%;
    background: #EDEDED;
    overflow: hidden;
}

/* 左侧会话列表侧边栏 */
.sidebar {
    width: 260px;
    background: #2B2B2B;
    color: #fff;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #3D3D3D;
    transition: transform 0.3s ease;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.sidebar.collapsed {
    transform: translateX(-100%);
}

.sidebar-header {
    padding: 12px;
    border-bottom: 1px solid #3D3D3D;
    display: flex;
    align-items: center;
    gap: 8px;
}

.new-chat-btn {
    flex: 1;
    padding: 10px 12px;
    background: #00A0E9;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.2s;
}

.new-chat-btn:active {
    background: #0088CC;
}

.new-chat-btn .icon {
    font-size: 18px;
    font-weight: bold;
}

.toggle-sidebar-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid #3D3D3D;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: background 0.2s;
}

.toggle-sidebar-btn:active {
    background: #3D3D3D;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.conversation-list {
    padding: 8px;
}

.conversation-item {
    padding: 12px;
    margin-bottom: 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.conversation-item:hover {
    background: #3D3D3D;
}

.conversation-item.active {
    background: #00A0E9;
}

.conversation-item .icon {
    font-size: 16px;
    flex-shrink: 0;
}

.conversation-item .content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.conversation-item .title {
    font-size: 14px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.conversation-item .time {
    font-size: 12px;
    color: #999;
}

/* 主内容区域 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

/* 头部 - 企业微信蓝色风格 */
.header {
    background: #2B4B6B;  /* 企业微信深蓝色 */
    color: #fff;
    padding: 12px 16px;
    text-align: center;
    position: relative;
    z-index: 100;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.show-sidebar-btn {
    position: absolute;
    left: 12px;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: none; /* 默认隐藏，侧边栏收起时显示 */
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.show-sidebar-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar.collapsed ~ .main-content .show-sidebar-btn {
    display: flex;
}

.header h1 {
    font-size: 17px;
    font-weight: 500;
    line-height: 1.4;
}

/* 消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-y: scroll; /* 强制滚动条，防止抖动 */
    padding: 12px 16px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain; /* 防止过度滚动影响父元素 */
}

/* 消息项 */
.message-item {
    margin-bottom: 12px;
    animation: fadeIn 0.2s ease-in;
}

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

/* 用户消息（右对齐） */
.message-user {
    display: flex;
    justify-content: flex-end;
}

.message-user .message-bubble {
    background: #00A0E9;  /* 企业微信蓝色 */
    color: #fff;
    border-radius: 6px;
    border-top-right-radius: 2px;
    max-width: 75%;
    padding: 10px 12px;
    word-wrap: break-word;
    word-break: break-word;
    font-size: 16px;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 160, 233, 0.2);
}

/* AI 消息（左对齐） */
.message-assistant {
    display: flex;
    justify-content: flex-start;
}

.message-assistant .message-bubble {
    background: #F4F5F7;
    color: #191919;
    border-radius: 6px;
    border-top-left-radius: 2px;
    max-width: 75%;
    padding: 10px 12px;
    word-wrap: break-word;
    word-break: break-word;
    font-size: 16px;
    line-height: 1.5;
    position: relative;
}

/* 消息时间 */
.message-time {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
    padding: 0 4px;
}

.message-user .message-time {
    text-align: right;
}

.message-assistant .message-time {
    text-align: left;
}

/* 思考中气泡 */
.message-thinking {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 12px;
}

.message-thinking .message-bubble {
    background: #F4F5F7;
    color: #999;
    border-radius: 6px;
    border-top-left-radius: 2px;
    padding: 10px 12px;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.thinking-dots {
    display: inline-flex;
    gap: 4px;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: thinking 1.4s infinite;
}

.thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes thinking {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    30% {
        opacity: 1;
        transform: scale(1);
    }
}

/* 输入区域（固定在底部） */
.input-area {
    background: #F7F7F7;
    border-top: 1px solid #E5E5E5;
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #fff;
    border-radius: 6px;
    padding: 8px;
    border: 1px solid #E5E5E5;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    position: relative;
}

/* 输入模式切换按钮（左侧 - 企业微信风格） */
.input-mode-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.2s;
}

.input-mode-btn:active {
    transform: scale(0.9);
}

.mode-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    line-height: 1;
}

.mode-icon svg {
    width: 100%;
    height: 100%;
    color: inherit;
}

/* 语音输入按钮（按住说话 - 企业微信风格） */
.voice-btn {
    flex: 1;
    height: 36px;
    background: #fff;
    border: 1px solid #D9D9D9;
    border-radius: 4px;
    color: #191919;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    transition: all 0.2s;
}

.voice-btn:active {
    background: #F7F7F7;
}

.voice-btn.recording {
    background: #ECECEC;
    color: #FF3B30;
}

.voice-btn.canceling {
    background: #FFE5E5;
    color: #FF3B30;
}

.voice-text {
    pointer-events: none;
}

.text-input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    resize: none;
    font-size: 16px;
    line-height: 1.5;
    padding: 6px 8px;
    max-height: 100px; /* 约4行的高度 */
    overflow-y: auto;
    font-family: inherit;
    background: transparent;
    color: #191919;
}

.text-input::placeholder {
    color: #999;
}

.send-btn {
    padding: 8px 16px;
    background: #00A0E9;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    min-width: 60px;
    height: 36px;
    transition: background 0.2s;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0, 160, 233, 0.2);
}

.send-btn:not(:disabled):active {
    background: #0088CC;  /* 按下时的深蓝色 */
}

.send-btn:not(:disabled):hover {
    background: #0099DD;  /* 悬停时的蓝色 */
}

.send-btn:disabled {
    background: #D9D9D9;
    color: #999;
    cursor: not-allowed;
}

.send-btn.sending {
    background: #D9D9D9;
    color: #999;
    cursor: not-allowed;
}


/* Toast 提示 */
.toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 16px 30px;
    border-radius: 8px;
    font-size: 16px;
    z-index: 99999 !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s, visibility 0.3s;
    max-width: 80%;
    word-wrap: break-word;
    white-space: pre-wrap;
    text-align: center;
    min-width: 100px;
}

.toast.show {
    opacity: 1 !important;
    visibility: visible !important;
}

/* 滚动条样式 */
.chat-messages::-webkit-scrollbar,
.sidebar-content::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track,
.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 移动端适配 */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        height: 100dvh; /* 使用动态视口高度，不受软键盘影响 */
        z-index: 1000;
        width: 280px;
        overflow-y: auto;
    }
    
    .sidebar.collapsed {
        transform: translateX(-100%);
    }
    
    /* 确保侧边栏在打开时覆盖其他内容 */
    .sidebar:not(.collapsed) {
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    }
    
    /* 防止软键盘弹出时影响布局 */
    .container {
        height: 100vh;
        height: 100dvh;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    .main-content {
        width: 100%;
    }
    
    .message-bubble {
        max-width: 80% !important;
    }
}

@media (max-width: 480px) {
    .message-bubble {
        max-width: 80% !important;
    }
}

/* 安全区域适配（iPhone X 等） */
@supports (padding: max(0px)) {
    .input-area {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}

/* 修复移动端软键盘问题 */
html {
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}

/* 阻止输入框获得焦点时的默认滚动行为 */
.text-input:focus,
.voice-btn:active {
    scroll-margin-bottom: 0;
}

/* 确保输入区域固定在底部，不受软键盘影响 */
@media (max-width: 768px) {
    .input-area {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
    }
    
    /* 给消息区域底部留出输入框的空间 */
    .chat-messages {
        padding-bottom: 80px;
    }
}

