/* 布局样式 */

/* 主布局 */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

/* 左侧边栏 */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s ease;
    position: relative;
}

/* 侧边栏收起状态 - 完全隐藏 */
.sidebar.collapsed {
    width: 0;
    overflow: hidden;
    border-right: none;
}

/* 侧边栏收起时隐藏内容 */
.sidebar.collapsed .sidebar-header,
.sidebar.collapsed .session-list,
.sidebar.collapsed .sidebar-footer {
    opacity: 0;
    pointer-events: none;
}

.sidebar-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    transition: opacity 0.2s ease;
}

/* 侧边栏收起/展开按钮（固定在侧边栏右侧边缘中央） */
.sidebar-toggle-btn {
    position: absolute;
    right: -15px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
}

.sidebar-toggle-btn:hover {
    background: var(--bg-primary);
    color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-50%) scale(1.1);
}

.sidebar-toggle-btn:active {
    transform: translateY(-50%) scale(0.95);
}

/* 侧边栏收起时，按钮移到屏幕左侧 */
.sidebar.collapsed .sidebar-toggle-btn {
    position: fixed;
    left: 0;
    right: auto;
    border-radius: 0 50% 50% 0;
    border-left: none;
}

/* 收起状态：显示展开图标 */
.sidebar.collapsed .sidebar-toggle-btn .icon-collapse {
    display: none;
}

.sidebar.collapsed .sidebar-toggle-btn .icon-expand {
    display: block !important;
}

/* 展开状态：显示收起图标 */
.sidebar:not(.collapsed) .sidebar-toggle-btn .icon-collapse {
    display: block;
}

.sidebar:not(.collapsed) .sidebar-toggle-btn .icon-expand {
    display: none;
}

.sidebar-footer {
    padding: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    transition: opacity 0.2s ease;
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-sm);
}

/* 主聊天区域 */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
    align-items: center; /* 居中对齐 */
}

.chat-header {
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: var(--spacing-lg) var(--spacing-xl);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: var(--content-max-width); /* 使用变量 */
    gap: var(--spacing-md);
}

/* 汉堡菜单按钮 - 默认隐藏 */
.menu-toggle-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.menu-toggle-btn:hover {
    background: var(--bg-secondary);
}

.menu-toggle-btn:active {
    transform: scale(0.95);
}

.chat-header h1 {
    font-size: 1.125rem;
    font-weight: 600;
    flex: 1;
}

/* 统一的角色选择器（Web端和移动端） */
.role-selector-unified {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.role-select {
    padding: 8px 32px 8px 12px;
    border: 2px solid #d1d5db;
    border-radius: 10px;
    background: white;
    color: #1f2937;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    min-width: 140px;
    height: 42px; /* 统一高度 */
    display: flex;
    align-items: center;
}

.role-select:hover {
    border-color: #9ca3af;
}

.role-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(51, 112, 255, 0.1);
}

.clear-history-btn {
    background: white;
    border: 2px solid #e5e7eb;
    color: #6b7280;
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 500;
    height: 42px; /* 统一高度 */
}

.clear-history-btn:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
}

.clear-history-btn:active {
    transform: scale(0.95);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    width: 100%;
    max-width: var(--content-max-width); /* 使用变量 */
    position: relative;
}

/* 渐进式朦胧遮罩 - 当内容接近输入框时 */
.chat-messages::after {
    content: '';
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(to top, var(--bg-primary) 0%, transparent 100%);
    pointer-events: none;
    z-index: 1;
}

.input-container {
    padding: 16px var(--spacing-xl);
    border-top: none;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    background: var(--bg-primary);
    position: relative;
    width: 100%;
    max-width: var(--content-max-width);
    z-index: 2;
}

/* 移动端紧凑布局 */
@media (max-width: 768px) {
    .input-container {
        padding: 8px var(--spacing-lg);
        gap: 4px;
    }
    
    /* 文件预览容器紧凑间距 */
    .file-preview-container {
        margin-bottom: 4px;
    }
}

/* 豆包风格 - 外层容器 */
.input-outer-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: #f7f8fa; /* 浅灰色背景 */
    border: 1px solid #e5e7eb; /* 灰色边框 */
    border-radius: 16px; /* 圆角 */
    transition: all 0.2s ease;
    width: 100%;
}

/* 移动端输入容器紧凑间距 */
@media (max-width: 768px) {
    .input-outer-container {
        gap: 8px;
        padding: 10px;
    }
}

/* 聚焦时边框变蓝 */
.input-outer-container:focus-within {
    border-color: var(--primary-color);
    background: #ffffff; /* 聚焦时背景变白 */
}

/* 输入框容器 - 增加高度 */
.input-textarea-box {
    width: 100%;
    min-height: 40px; /* 缩短一半 */
    max-height: 300px;
    overflow-y: auto;
    border-radius: 0;
}

/* 自定义滚动条 */
.input-textarea-box::-webkit-scrollbar {
    width: 6px;
}

.input-textarea-box::-webkit-scrollbar-track {
    background: transparent;
}

.input-textarea-box::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.input-textarea-box::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* 输入框样式 */
.input-textarea-box .text-input {
    width: 100%;
    min-height: 40px; /* 缩短一半 */
    max-height: 300px;
    padding: 0;
    border: none;
    background: transparent;
    resize: none;
    font-size: 15px;
    line-height: 24px;
    color: var(--text-primary);
    outline: none;
    overflow-y: auto;
}

.input-textarea-box .text-input::placeholder {
    color: var(--text-tertiary);
}

/* 底部工具栏 */
.input-bottom-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 4px;
    flex-wrap: nowrap;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.toolbar-left {
    flex: 1;
    min-width: 0;
    overflow: visible;
}

/* 工具栏按钮 */
.toolbar-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    padding: 0;
}

.toolbar-btn:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.toolbar-btn:active {
    transform: scale(0.95);
}

.toolbar-btn .icon {
    width: 20px;
    height: 20px;
}

/* 深度思考按钮 - 使用 !important 确保样式优先级 */
.deep-thinking-btn {
    background: #f0f7ff !important;
    color: #3b82f6 !important;
    border: 1px solid #bfdbfe !important;
    padding: 0 14px !important;
    gap: 6px !important;
    width: auto !important;
    min-width: auto !important;
    height: 36px !important;
    border-radius: 18px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
}

.deep-thinking-btn:hover {
    background: #dbeafe !important;
    border-color: #93c5fd !important;
}

.deep-thinking-btn.active {
    background: #3b82f6 !important;
    color: white !important;
    border-color: #3b82f6 !important;
}

.deep-thinking-btn .icon {
    width: 18px !important;
    height: 18px !important;
    flex-shrink: 0 !important;
}

.deep-thinking-btn span {
    font-size: 14px !important;
    font-weight: 500 !important;
    white-space: nowrap !important;
}

/* 移动端优化：深度思考按钮保持完整显示 */
@media (max-width: 768px) {
    .toolbar-btn {
        width: 32px;
        height: 32px;
    }
    
    .toolbar-btn .icon {
        width: 18px;
        height: 18px;
    }
}

/* 小屏幕优化 */
@media (max-width: 375px) {
    .toolbar-btn {
        width: 30px;
        height: 30px;
    }
    
    .toolbar-btn .icon {
        width: 16px;
        height: 16px;
    }
    
    .deep-thinking-btn {
        padding: 0 10px !important;
        height: 30px !important;
        gap: 4px !important;
        border-radius: 15px !important;
        width: auto !important;
        min-width: 90px !important;
    }
    
    .deep-thinking-btn .icon {
        width: 14px !important;
        height: 14px !important;
    }
    
    .deep-thinking-btn span {
        font-size: 12px !important;
    }
}

/* 发送按钮特殊样式 */
.send-btn-toolbar {
    background: var(--primary-color) !important;
    color: white !important;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    transition: all 0.2s;
}

.send-btn-toolbar:hover {
    background: #2563eb !important;
    transform: scale(1.05);
}

.send-btn-toolbar:active {
    transform: scale(0.95);
}

.send-btn-toolbar:disabled {
    background: var(--bg-secondary) !important;
    color: var(--text-tertiary) !important;
    cursor: not-allowed;
}

/* 停止模式样式 */
.send-btn-toolbar.stop-mode {
    background: #ef4444 !important;
}

.send-btn-toolbar.stop-mode:hover {
    background: #dc2626 !important;
    transform: scale(1.05);
}

.send-btn-toolbar.stop-mode:active {
    transform: scale(0.95);
}

/* 隐藏旧的样式 */
.input-area-wrapper,
.input-action-btn,
.send-btn-new {
    display: none !important;
}

.status-indicator {
    padding: 10px var(--spacing-xl);
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-tertiary);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    width: 100%;
    max-width: var(--content-max-width); /* 使用变量 */
}

/* 响应式布局 */
@media (max-width: 768px) {
    /* 隐藏PC端侧边栏伸缩按钮 */
    .sidebar-toggle-btn {
        display: none !important;
    }
    
    /* 显示汉堡菜单按钮 */
    .menu-toggle-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        height: 100vh;
        width: 260px !important; /* 强制设置宽度，覆盖collapsed类的width: 0 */
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
        overflow: visible !important; /* 覆盖collapsed类的overflow: hidden */
    }
    
    /* 移动端侧边栏内容始终可见 */
    .sidebar .sidebar-header,
    .sidebar .session-list,
    .sidebar .sidebar-footer {
        opacity: 1 !important;
        pointer-events: auto !important;
    }
    
    .sidebar.show {
        left: 0;
    }
    
    /* 遮罩层 */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .sidebar-overlay.show {
        display: block;
        opacity: 1;
    }
    
    .chat-container {
        width: 100%;
    }
    
    .chat-header {
        padding: 12px 16px;
        gap: 10px;
    }
    
    .chat-header h1 {
        font-size: 1rem;
        flex: 1;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* 移动端角色选择器调整 */
    .role-selector-unified {
        flex: 1;
        max-width: 220px;
    }
    
    .role-select {
        font-size: 13px;
        padding: 7px 28px 7px 10px;
        min-width: 120px;
    }
    
    .clear-history-btn .btn-text {
        display: none; /* 移动端隐藏文字，只显示图标 */
    }
    
    .clear-history-btn {
        padding: 7px;
    }
    
    /* 历史徽章在移动端缩小 */
    .header-badge {
        font-size: 0.7rem;
        padding: 2px 6px;
    }
    
    .chat-messages {
        padding: var(--spacing-md);
    }
    
    .input-container {
        padding: 12px var(--spacing-lg);
        gap: 8px;
    }
    
    .status-indicator {
        padding: var(--spacing-sm) var(--spacing-lg);
        font-size: 0.75rem;
    }
}

@media (max-width: 480px) {
    .chat-header {
        padding: 10px 12px;
    }
    
    .chat-header h1 {
        font-size: 0.9rem;
    }
    
    /* 小屏幕上进一步调整 */
    .role-selector-unified {
        max-width: 180px;
    }
    
    .role-select {
        font-size: 12px;
        padding: 6px 26px 6px 8px;
        min-width: 100px;
    }
    
    .clear-history-btn {
        padding: 6px;
    }
    
    .clear-history-btn svg {
        width: 16px;
        height: 16px;
    }
    
    /* 历史徽章在小屏幕上隐藏 */
    .header-badge {
        display: none;
    }
    
    .input-container {
        flex-wrap: wrap;
    }
    
    .message {
        max-width: 95%;
    }
    
    .text-input {
        min-height: 44px;
    }
    
    .rec-card {
        font-size: 0.8rem;
        padding: 10px;
    }
}


/* 隐藏旧的按钮样式 */
.voice-btn,
.add-btn:not(.toolbar-btn),
.send-btn:not(.send-btn-toolbar) {
    display: none !important;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .input-outer-container {
        padding: 12px;
        border-radius: 14px; /* 移动端圆角稍小 */
    }
    
    .input-textarea-box {
        min-height: 40px; /* 缩短一半 */
        max-height: 200px;
    }
    
    .input-textarea-box .text-input {
        min-height: 40px; /* 缩短一半 */
        font-size: 14px;
        line-height: 22px;
    }
    
    .toolbar-btn {
        width: 32px;
        height: 32px;
    }
    
    .toolbar-btn .icon {
        width: 18px;
        height: 18px;
    }
    
    .send-btn-toolbar {
        width: 36px;
        height: 36px;
    }
}

/* 小屏幕优化 */
@media (max-width: 375px) {
    .input-outer-container {
        padding: 10px;
        gap: 8px;
        border-radius: 12px;
    }
    
    .input-textarea-box {
        min-height: 35px; /* 小屏幕稍微小一点 */
    }
    
    .toolbar-btn {
        width: 30px;
        height: 30px;
    }
    
    .send-btn-toolbar {
        width: 34px;
        height: 34px;
    }
    
    .toolbar-left,
    .toolbar-right {
        gap: 2px;
    }
}
