// 品牌色
$brand-color: #0055AA;
$brand-color-light: #EBF5FF;
$brand-color-hover: #004488;

.chat-room-container {
    display: flex;
    height: 100%;
    background: #f8fafc;
    position: relative;
    overflow: hidden;
    font-family: 'Inter', 'Noto Sans SC', sans-serif;
}

// ==================== 折叠状态的侧边栏 ====================
.sidebar-collapsed {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 48px;
    background: #fff;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    z-index: 10;

    .sidebar-toggle-btn {
        padding: 8px;
        color: #64748b;
        background: transparent;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s;
        margin-bottom: 8px;

        &:hover {
            color: $brand-color;
            background: $brand-color-light;
        }
    }

    .sidebar-icons {
        flex: 1;
        overflow-y: auto;
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        padding: 8px 0;
    }

    .sidebar-icon-btn {
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        background: linear-gradient(135deg, $brand-color 0%, $brand-color-hover 100%);
        border: none;
        border-radius: 50%;
        cursor: pointer;
        transition: all 0.2s;
        font-size: 12px;
        font-weight: 600;

        &:hover {
            transform: scale(1.1);
        }

        &.active {
            box-shadow: 0 0 0 2px $brand-color-light;
        }
    }

    .expand-btn {
        padding: 8px;
        color: #94a3b8;
        background: transparent;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s;

        &:hover {
            color: #64748b;
            background: #f1f5f9;
        }
    }
}

// ==================== 展开时的关闭按钮 ====================
.sidebar-close-btn {
    position: absolute;
    left: 256px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-left: none;
    border-radius: 0 8px 8px 0;
    padding: 8px;
    cursor: pointer;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
    transition: all 0.2s;
    color: #64748b;

    &:hover {
        background: #f8fafc;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.1);
    }
}

// ==================== 聊天室列表侧边栏 ====================
.room-list-sidebar {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 0;
    background: #fff;
    border-right: 1px solid #e2e8f0;
    z-index: 10;
    transition: all 0.3s ease;
    overflow: hidden;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.08);

    &.open {
        width: 256px;
    }

    .sidebar-inner {
        width: 256px;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .sidebar-header {
        height: 56px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px;
        border-bottom: 1px solid #f1f5f9;

        .title {
            font-weight: 600;
            font-size: 16px;
            color: #1e293b;
        }
    }

    .search-box {
        padding: 12px 16px;
        border-bottom: 1px solid #f1f5f9;

        .el-input {
            --el-input-border-radius: 8px;
        }
    }

    .room-list-container {
        flex: 1;
        overflow-y: auto;
        padding: 8px;
    }

    .room-item {
        display: flex;
        align-items: flex-start;
        gap: 12px;
        padding: 12px;
        margin-bottom: 4px;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s;
        position: relative;

        &:hover {
            background: #f8fafc;
        }

        &.active {
            background: $brand-color-light;
        }

        .room-avatar {
            width: 48px;
            height: 48px;
            border-radius: 50%;
            background: linear-gradient(135deg, $brand-color 0%, $brand-color-hover 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-weight: 600;
            font-size: 16px;
            flex-shrink: 0;
        }

        .room-info {
            flex: 1;
            min-width: 0;
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        .room-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
        }

        .room-name {
            font-size: 14px;
            font-weight: 500;
            color: #374151;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .room-time {
            font-size: 12px;
            color: #94a3b8;
            flex-shrink: 0;
        }

        .last-message-row {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .last-message {
            flex: 1;
            font-size: 13px;
            color: #64748b;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .unread-badge {
            flex-shrink: 0;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            min-width: 18px;
            height: 18px;
            padding: 0 6px;
            background: #ef4444;
            color: white;
            border-radius: 9px;
            font-size: 11px;
            font-weight: 600;
        }
    }

    .empty-tip {
        padding: 32px 16px;
        text-align: center;
        color: #94a3b8;
        font-size: 14px;
    }
}

// ==================== 主聊天区域 ====================
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #fff;
    margin-left: 48px;
    transition: margin-left 0.3s ease;

    &.sidebar-open {
        margin-left: 256px;
    }
}

// ==================== 聊天室头部 ====================
.chat-header {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid #e2e8f0;
    background: #fff;

    .header-left {
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .room-avatar-small {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: linear-gradient(135deg, $brand-color 0%, $brand-color-hover 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-weight: 600;
        font-size: 14px;
    }

    .room-title-group {
        .room-name-text {
            font-size: 16px;
            font-weight: 600;
            color: #1e293b;
        }

        .room-subtitle {
            font-size: 12px;
            color: #94a3b8;
            margin-top: 2px;
        }
    }

    .header-actions {
        display: flex;
        align-items: center;
        gap: 8px;
    }
}

// ==================== 消息容器 ====================
.messages-container {
    flex: 1;
    overflow-y: auto;
    background: #f8fafc;
}

// ==================== 空状态 ====================
.empty-state {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;

    .empty-content {
        text-align: center;
        max-width: 400px;

        .empty-icon {
            width: 80px;
            height: 80px;
            background: $brand-color-light;
            border-radius: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 16px;
            color: $brand-color;
        }

        .empty-title {
            font-size: 18px;
            font-weight: 600;
            color: #1e293b;
            margin: 0 0 8px;
        }

        .empty-desc {
            font-size: 14px;
            color: #64748b;
            margin: 0;
        }
    }
}

// ==================== 消息列表 ====================
.messages-list {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 16px;

    .message-row {
        display: flex;
        gap: 12px;
        margin-bottom: 24px;

        &.is-me {
            flex-direction: row-reverse;

            .message-bubble {
                background: $brand-color;
                color: #fff;
                border-radius: 16px 16px 4px 16px;

                .message-time {
                    text-align: right;
                    color: rgba(255, 255, 255, 0.7);
                }
            }
        }

        &.other {
            .message-bubble {
                background: #fff;
                border: 1px solid #f1f5f9;
                border-radius: 16px 16px 16px 4px;
                box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
            }
        }
    }

    .message-avatar {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        flex-shrink: 0;
        overflow: hidden;

        img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
    }

    .message-content-wrapper {
        max-width: 70%;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .message-bubble {
        padding: 12px 16px;

        .message-text {
            font-size: 14px;
            line-height: 1.6;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
    }

    .message-files {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-top: 8px;
    }

    .file-item {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s;
        border: 1px solid rgba(255, 255, 255, 0.2);

        &:hover {
            background: rgba(255, 255, 255, 0.2);
        }

        .file-icon {
            width: 32px;
            height: 32px;
            border-radius: 6px;
            background: rgba(255, 255, 255, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .file-info {
            .file-name {
                font-size: 13px;
                font-weight: 500;
            }

            .file-size {
                font-size: 11px;
                opacity: 0.8;
                margin-top: 2px;
            }
        }
    }

    .other .file-item {
        background: #f8fafc;
        border-color: #e2e8f0;

        &:hover {
            background: #f1f5f9;
        }

        .file-icon {
            background: $brand-color-light;
            color: $brand-color;
        }

        .file-info {
            color: #374151;
        }
    }

    .message-time {
        font-size: 12px;
        color: #94a3b8;
        padding: 0 4px;
    }
}

// ==================== 输入区域 ====================
.input-area {
    padding: 16px 24px 24px;
    background: #fff;
    border-top: 1px solid #e2e8f0;

    .action-buttons {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-bottom: 12px;
    }

    .input-wrapper {
        max-width: 900px;
        margin: 0 auto;
    }

    .input-card {
        background: #f8fafc;
        border-radius: 12px;
        border: 1px solid #e2e8f0;
        overflow: hidden;
        transition: all 0.2s;

        &:focus-within {
            border-color: $brand-color;
            background: #fff;
        }
    }

    .input-row {
        padding: 12px 16px;
    }

    .chat-textarea {
        width: 100%;
        border: none;
        outline: none;
        resize: none;
        font-size: 14px;
        color: #374151;
        background: transparent;
        line-height: 1.5;
        min-height: 60px;
        max-height: 150px;

        &::placeholder {
            color: #94a3b8;
        }
    }

    .toolbar-row {
        padding: 8px 16px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-top: 1px solid #e2e8f0;
        background: #fff;
    }

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

    .tool-btn {
        padding: 8px;
        color: #94a3b8;
        background: transparent;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s;

        &:hover {
            color: $brand-color;
            background: $brand-color-light;
        }
    }

    .send-btn {
        padding: 8px 16px;
        background: #e2e8f0;
        color: #94a3b8;
        border: none;
        border-radius: 8px;
        cursor: not-allowed;
        transition: all 0.2s;
        font-size: 14px;
        font-weight: 500;
        display: flex;
        align-items: center;
        gap: 6px;

        &.active {
            background: $brand-color;
            color: #fff;
            cursor: pointer;
            box-shadow: 0 2px 8px rgba($brand-color, 0.3);

            &:hover {
                background: $brand-color-hover;
            }
        }
    }
}

// ==================== 工单详情对话框 ====================
.workcase-dialog {
    .el-dialog__header {
        padding: 20px 24px;
        border-bottom: 1px solid #e2e8f0;
    }

    .el-dialog__body {
        padding: 24px;
    }
}

// ==================== 聊天室包装容器 ====================
.chat-room-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
}

// ==================== 自动填充加载遮罩 ====================
.auto-fill-mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    gap: 16px;

    .loading-spinner {
        width: 40px;
        height: 40px;
        border: 3px solid #e2e8f0;
        border-top-color: $brand-color;
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }

    .loading-text {
        font-size: 14px;
        color: #64748b;
        font-weight: 500;
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
